summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/tail-calls/return-call-profiling.js
blob: 2946a16d715ee18028bfb1fc493f8b7de2e12040 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Tests if the profiler (frame iterator) can unwind in the middle
// of collapse frame instructions.

enableGeckoProfiling();
try {
    enableSingleStepProfiling();
} catch (e) {
    // continue anyway if single step profiling is not supported
}

var ins = wasmEvalText(`
(module
    (func $f (param i64 i64 i64 i64 i64 i64 i64 i64 i64)
        local.get 0
        i64.eqz
        br_if 0
        local.get 0
        return_call $g
    )
    (func $g (param i64)
        local.get 0
        i64.const 1
        i64.sub
        i64.const 2
        i64.const 6
        i64.const 3
        i64.const 4
        i64.const 1
        i64.const 2
        i64.const 6
        i64.const 3
        return_call $f
    )
    (func (export "run") (param i64)
        local.get 0
        call $g
    )
)`);

for (var i = 0; i < 10; i++) {
    ins.exports.run(100n);
}

// Also when trampoline is used.
var ins0 = wasmEvalText(`(module (func (export "t")))`);
var ins = wasmEvalText(`
(module
    (import "" "t" (func $g))
    (func $f (return_call_indirect $t (i32.const 0)))
    (table $t 1 1 funcref)
  
    (func (export "run") (param i64)
     loop
       local.get 0
       i64.eqz
       br_if 1
       call $f
       local.get 0
       i64.const 1
       i64.sub
       local.set 0
       br 0
     end
    )
    (elem (i32.const 0) $g)
)`, {"": {t: ins0.exports.t},});

ins.exports.run(10n);