tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

speculative-inlining.js (2367B)


      1 // |jit-test| test-also=--setpref=wasm_lazy_tiering --setpref=wasm_lazy_tiering_synchronous; skip-if: !wasmLazyTieringEnabled() || !getPrefValue("wasm_lazy_tiering_synchronous")
      2 
      3 // Needs to be at least 13500 in order for test functions to tier up.
      4 // See Instance::computeInitialHotnessCounter.
      5 const tierUpThreshold = 14000;
      6 
      7 let {importFunc} = wasmEvalText(`
      8  (module (func (export "importFunc") (result i32) i32.const 2))
      9 `).exports;
     10 let testFuncs = [
     11  [importFunc, 2],
     12  ["trueFunc", 1],
     13  ["falseFunc", 0],
     14  ["trapFunc", WebAssembly.RuntimeError],
     15  [null, WebAssembly.RuntimeError],
     16 ];
     17 function invokeTestWith(exports, exportThing, expected) {
     18  let targetFunc;
     19  if (exportThing instanceof Function) {
     20    targetFunc = exportThing;
     21  } else if (exportThing === null) {
     22    targetFunc = null;
     23  } else {
     24    targetFunc = exports[exportThing];
     25  }
     26 
     27  if (expected === WebAssembly.RuntimeError) {
     28    assertErrorMessage(() => exports.test(targetFunc), WebAssembly.RuntimeError, /./);
     29  } else {
     30    assertEq(exports.test(targetFunc), expected);
     31  }
     32 }
     33 
     34 for ([funcToInline, funcToInlineExpected] of testFuncs) {
     35  let exports = wasmEvalText(`
     36  (module
     37    (type $booleanFunc (func (result i32)))
     38 
     39    (func $importFunc (import "" "importFunc") (result i32))
     40    (func $trueFunc (export "trueFunc") (result i32)
     41      i32.const 1
     42    )
     43    (func $falseFunc (export "falseFunc") (result i32)
     44      i32.const 0
     45    )
     46    (func $trapFunc (export "trapFunc") (result i32)
     47      unreachable
     48    )
     49 
     50    (func (export "test") (param (ref null $booleanFunc)) (result i32)
     51      local.get 0
     52      call_ref $booleanFunc
     53    )
     54  )`, {"": {importFunc}}).exports;
     55  let test = exports["test"];
     56 
     57  // Force a tier-up of the function, calling the same function every time
     58  assertEq(wasmFunctionTier(test), "baseline");
     59  for (let i = 0; i <= tierUpThreshold; i++) {
     60    invokeTestWith(exports, funcToInline, funcToInlineExpected);
     61  }
     62  // We are running in "synchronous" lazy-tiering mode, so there's no race here
     63  // -- the optimized version should be available at this point.
     64  assertEq(wasmFunctionTier(test), "optimized");
     65 
     66  // Now that we've inlined something, try calling it with every test function
     67  // and double check we get the expected behavior
     68  for ([testFunc, testFuncExpected] of testFuncs) {
     69    invokeTestWith(exports, testFunc, testFuncExpected);
     70  }
     71 }