Debian Codegraph @

js/src/jit-test/tests/wasm/ion-lazy-tables.js

raw
1 // |jit-test| skip-if: !getJitCompilerOptions()['baseline.enable']
2 // These tests need at least baseline to make sense.
3
4 const { assertStackTrace, startProfiling, endProfiling, assertEqPreciseStacks } = WasmHelpers;
5
6 const options = getJitCompilerOptions();
7 const TRIGGER = options['baseline.warmup.trigger'] + 10;
8 const ITER = 2 * TRIGGER;
9 const EXCEPTION_ITER = TRIGGER + 5;
10
11 const SLOW_ENTRY_STACK = ['', '!>', '0,!>', '!>', ''];
12 const FAST_ENTRY_STACK = ['', '>', '0,>', '>', ''];
13 const INLINED_CALL_STACK = ['', '0', ''];
14 const EXPECTED_STACKS = [SLOW_ENTRY_STACK, FAST_ENTRY_STACK, INLINED_CALL_STACK];
15
16 function main() {
17 var { table } = wasmEvalText(`(module
18 (func (param i32) (param i32) (result i32)
19 local.get 0
20 local.get 1
21 i32.add
22 )
23 (table (export "table") 10 funcref)
24 (elem (i32.const 0) 0)
25 )`).exports;
26
27 for (var i = 0; i < ITER; i++) {
28 startProfiling();
29 assertEq(table.get(0)(i, i+1), i*2+1);
30 assertEqPreciseStacks(endProfiling(), EXPECTED_STACKS);
31 }
32 }
33
34 function withTier2() {
35 setJitCompilerOption('wasm.delay-tier2', 1);
36
37 var module = new WebAssembly.Module(wasmTextToBinary(`(module
38 (func (param i32) (param i32) (result i32)
39 local.get 0
40 local.get 1
41 i32.add
42 )
43 (table (export "table") 10 funcref)
44 (elem (i32.const 0) 0)
45 )`));
46 var { table } = new WebAssembly.Instance(module).exports;
47
48 let i = 0;
49 do {
50 i++;
51 startProfiling();
52 assertEq(table.get(0)(i, i+1), i*2+1);
53 assertEqPreciseStacks(endProfiling(), EXPECTED_STACKS);
54 } while (!wasmHasTier2CompilationCompleted(module));
55
56 for (i = 0; i < ITER; i++) {
57 startProfiling();
58 assertEq(table.get(0)(i, i+1), i*2+1);
59 assertEqPreciseStacks(endProfiling(), EXPECTED_STACKS);
60 }
61
62 setJitCompilerOption('wasm.delay-tier2', 0);
63 }
64
65 enableGeckoProfiling();
66 main();
67 withTier2();
68 disableGeckoProfiling();