ion-error-ool.js (2679B)
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 FAST_OOL_ENTRY_STACK = ['', '>', '<,>', 'ool>,>', '<,>', '>', '0,>', '>', '']; 15 const EXCEPTION_ENTRY_STACK = ['', '>', '<,>', 'ool>,>', '<,>', '>', '']; 16 17 enableGeckoProfiling(); 18 19 for (let type of ['i32', 'f32', 'f64']) { 20 var instance = wasmEvalText(`(module 21 (func (export "add") (param ${type}) (param ${type}) (result ${type}) 22 local.get 0 23 local.get 1 24 ${type}.add 25 ) 26 )`).exports; 27 28 function loopBody(a, b) { 29 var caught = null; 30 try { 31 instance.add(a, b); 32 } catch(e) { 33 assertEq(e.message, "ph34r"); 34 assertStackTrace(e, ['innerValueOf', 'outerValueOf', 'loopBody', 'main', '']); 35 caught = e; 36 } 37 assertEq(!!caught, b === EXCEPTION_ITER); 38 } 39 40 var x = 0; 41 function main() { 42 let observedStacks = [0, 0, 0]; 43 for (var i = 0; i < ITER; i++) { 44 startProfiling(); 45 loopBody(i + 1, i + EXCEPTION_ITER + 1); 46 assertEqPreciseStacks(endProfiling(), [INLINED_CALL_STACK, FAST_ENTRY_STACK, SLOW_ENTRY_STACK]); 47 48 if (i === EXCEPTION_ITER) { 49 x = { valueOf: function innerValueOf() { throw new Error("ph34r"); }}; 50 } else { 51 x = i; 52 } 53 54 startProfiling(); 55 loopBody({valueOf: function outerValueOf() { return x|0; }}, i); 56 let stack = endProfiling(); 57 let which = assertEqPreciseStacks(stack, [FAST_OOL_ENTRY_STACK, SLOW_ENTRY_STACK, EXCEPTION_ENTRY_STACK]); 58 if (which !== null) { 59 if (i === EXCEPTION_ITER) { 60 assertEq(which, 2); 61 } 62 observedStacks[which]++; 63 } 64 } 65 66 let sum = observedStacks.reduce((acc, x) => acc + x); 67 assertEq(sum === 0 || sum === ITER, true); 68 if (sum === ITER) { 69 assertEq(observedStacks[0] > 0, true, "the fast entry should have been taken at least once"); 70 assertEq(observedStacks[2], 1, "the error path should have been taken exactly once"); 71 } 72 } 73 74 main(); 75 } 76 77 disableGeckoProfiling();