summaryrefslogtreecommitdiffstats
path: root/tools/profiler/tests/test_enterjit_osr.js
blob: a4bca590f895721b2b96394374a05ac4da00b904 (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
// Check that the EnterJIT frame, added by the JIT trampoline and
// usable by a native unwinder to resume unwinding after encountering
// JIT code, is pushed as expected.
function run_test() {
    let p = Cc["@mozilla.org/tools/profiler;1"];
    // Just skip the test if the profiler component isn't present.
    if (!p)
        return;
    p = p.getService(Ci.nsIProfiler);
    if (!p)
        return;

    // This test assumes that it's starting on an empty SPS stack.
    // (Note that the other profiler tests also assume the profiler
    // isn't already started.)
    do_check_true(!p.IsActive());

    const ms = 5;
    p.StartProfiler(100, ms, ["js"], 1);

    function arbitrary_name(){
        // A frame for |arbitrary_name| has been pushed.  Do a sequence of
        // increasingly long spins until we get a sample.
        var delayMS = 5;
        while (1) {
            do_print("loop: ms = " + delayMS);
            let then = Date.now();
            do {
                let n = 10000;
                while (--n); // OSR happens here
                // Spin in the hope of getting a sample.
            } while (Date.now() - then < delayMS);
            let pr = p.getProfileData().threads[0];
            if (pr.samples.data.length > 0 || delayMS > 30000)
                return pr;
            delayMS *= 2;
        }
    };

    var profile = arbitrary_name();

    do_check_neq(profile.samples.data.length, 0);
    var lastSample = profile.samples.data[profile.samples.data.length - 1];
    var stack = getInflatedStackLocations(profile, lastSample);
    do_print(stack);

    // All we can really check here is ensure that there is exactly
    // one arbitrary_name frame in the list.
    var gotName = false;
    for (var i = 0; i < stack.length; i++) {
        if (stack[i].match(/arbitrary_name/)) {
            do_check_eq(gotName, false);
            gotName = true;
        }
    }
    do_check_eq(gotName, true);

    p.StopProfiler();
}