Bumping manifests a=b2g-bump
[gecko.git] / tools / profiler / tests / test_enterjit_osr.js
blob2595b28ec8d1709033373c63f9081b8b483a7df4
1 // Check that the EnterJIT frame, added by the JIT trampoline and
2 // usable by a native unwinder to resume unwinding after encountering
3 // JIT code, is pushed as expected.
4 function run_test() {
5     let p = Cc["@mozilla.org/tools/profiler;1"];
6     // Just skip the test if the profiler component isn't present.
7     if (!p)
8         return;
9     p = p.getService(Ci.nsIProfiler);
10     if (!p)
11         return;
13     // This test assumes that it's starting on an empty SPS stack.
14     // (Note that the other profiler tests also assume the profiler
15     // isn't already started.)
16     do_check_true(!p.IsActive());
18     const ms = 5;
19     p.StartProfiler(100, ms, ["js"], 1);
21     function arbitrary_name(){
22         // A frame for |arbitrary_name| has been pushed.  Do a sequence of
23         // increasingly long spins until we get a sample.
24         var delayMS = 5;
25         while (1) {
26             do_print("loop: ms = " + delayMS);
27             let then = Date.now();
28             do {
29                 let n = 10000;
30                 while (--n); // OSR happens here
31                 // Spin in the hope of getting a sample.
32             } while (Date.now() - then < delayMS);
33             let pr = p.getProfileData().threads[0].samples;
34             if (pr.length > 0 || delayMS > 30000)
35                 return pr;
36             delayMS *= 2;
37         }
38     };
40     var profile = arbitrary_name();
42     do_check_neq(profile.length, 0);
43     let stack = profile[profile.length - 1].frames.map(f => f.location);
44     stack = stack.slice(stack.lastIndexOf("js::RunScript") + 1);
46     do_print(stack);
47     // This test needs to not break on platforms and configurations
48     // where IonMonkey isn't available / enabled.
49     if (stack.length < 2 || stack[1] != "EnterJIT") {
50         do_print("No JIT?");
51         // Try to check what we can....
52         do_check_eq(Math.min(stack.length, 1), 1);
53         let thisInterp = stack[0];
54         do_check_eq(thisInterp.split(" ")[0], "arbitrary_name");
55         if (stack.length >= 2) {
56             let nextFrame = stack[1];
57             do_check_neq(nextFrame.split(" ")[0], "arbitrary_name");
58         }
59     } else {
60         do_check_eq(Math.min(stack.length, 3), 3);
61         let thisInterp = stack[0];
62         let enterJit = stack[1];
63         let thisBC = stack[2];
64         do_check_eq(thisInterp.split(" ")[0], "arbitrary_name");
65         do_check_eq(enterJit, "EnterJIT");
66         do_check_eq(thisBC.split(" ")[0], "arbitrary_name");
67     }
69     p.StopProfiler();