tools/profiler/tests/test_enterjit_osr.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/profiler/tests/test_enterjit_osr.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,58 @@
     1.4 +// Check that the EnterJIT frame, added by the JIT trampoline and
     1.5 +// usable by a native unwinder to resume unwinding after encountering
     1.6 +// JIT code, is pushed as expected.
     1.7 +function run_test() {
     1.8 +    let p = Cc["@mozilla.org/tools/profiler;1"];
     1.9 +    // Just skip the test if the profiler component isn't present.
    1.10 +    if (!p)
    1.11 +	return;
    1.12 +    p = p.getService(Ci.nsIProfiler);
    1.13 +    if (!p)
    1.14 +	return;
    1.15 +
    1.16 +    // This test assumes that it's starting on an empty SPS stack.
    1.17 +    // (Note that the other profiler tests also assume the profiler
    1.18 +    // isn't already started.)
    1.19 +    do_check_true(!p.IsActive());
    1.20 +
    1.21 +    const ms = 5;
    1.22 +    p.StartProfiler(100, ms, ["js"], 1);
    1.23 +    let profile = (function arbitrary_name(){
    1.24 +	// A frame for |arbitrary_name| has been pushed.
    1.25 +	let then = Date.now();
    1.26 +	do {
    1.27 +	    let n = 10000;
    1.28 +	    while (--n); // OSR happens here
    1.29 +	    // Spin until we're sure we have a sample.
    1.30 +	} while (Date.now() - then < ms * 2.5);
    1.31 +	return p.getProfileData().threads[0].samples;
    1.32 +    })();
    1.33 +    do_check_neq(profile.length, 0);
    1.34 +    let stack = profile[profile.length - 1].frames.map(f => f.location);
    1.35 +    stack = stack.slice(stack.indexOf("js::RunScript") + 1);
    1.36 +
    1.37 +    do_print(stack);
    1.38 +    // This test needs to not break on platforms and configurations
    1.39 +    // where IonMonkey isn't available / enabled.
    1.40 +    if (stack.length < 2 || stack[1] != "EnterJIT") {
    1.41 +	do_print("No JIT?");
    1.42 +	// Try to check what we can....
    1.43 +	do_check_eq(Math.min(stack.length, 1), 1);
    1.44 +	let thisInterp = stack[0];
    1.45 +	do_check_eq(thisInterp.split(" ")[0], "arbitrary_name");
    1.46 +	if (stack.length >= 2) {
    1.47 +	    let nextFrame = stack[1];
    1.48 +	    do_check_neq(nextFrame.split(" ")[0], "arbitrary_name");
    1.49 +	}
    1.50 +    } else {
    1.51 +	do_check_eq(Math.min(stack.length, 3), 3);
    1.52 +	let thisInterp = stack[0];
    1.53 +	let enterJit = stack[1];
    1.54 +	let thisBC = stack[2];
    1.55 +	do_check_eq(thisInterp.split(" ")[0], "arbitrary_name");
    1.56 +	do_check_eq(enterJit, "EnterJIT");
    1.57 +	do_check_eq(thisBC.split(" ")[0], "arbitrary_name");
    1.58 +    }
    1.59 +
    1.60 +    p.StopProfiler();
    1.61 +}

mercurial