tor-browser

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

test_wasm_tailcalls_profiler.js (3825B)


      1 Services.prefs.setBoolPref("javascript.options.wasm_tail_calls", true);
      2 registerCleanupFunction(() => {
      3  Services.prefs.clearUserPref("javascript.options.wasm_tail_calls");
      4 });
      5 
      6 // The tests runs code in tight loop with the profiler enabled. It is testing
      7 // behavoir of MacroAssembler::wasmCollapseFrameXXXX methods.
      8 // It is not guarantee 100% hit since the profiler probes stacks every 1ms,
      9 // but it will happen often enough.
     10 add_task(async () => {
     11  await Services.profiler.StartProfiler(10, 1, ["js"], ["GeckoMain"]);
     12  Assert.ok(Services.profiler.IsActive());
     13 
     14 /* Wasm module that is tested:
     15 (module
     16    (func $f (param i64 i64 i64 i64 i64 i64 i64 i64 i64)
     17        local.get 0
     18        i64.eqz
     19        br_if 0
     20        local.get 0
     21        return_call $g
     22    )
     23    (func $g (param i64)
     24        local.get 0
     25        i64.const 1
     26        i64.sub
     27        i64.const 2
     28        i64.const 6
     29        i64.const 3
     30        i64.const 4
     31        i64.const 1
     32        i64.const 2
     33        i64.const 6
     34        i64.const 3
     35        return_call $f
     36    )
     37    (func (export "run")
     38        i64.const 0x100000
     39        call $g
     40    )
     41 )
     42 */
     43 
     44  const b = new Uint8Array([
     45    0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x14, 0x03, 0x60,
     46    0x09, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x60,
     47    0x01, 0x7e, 0x00, 0x60, 0x00, 0x00, 0x03, 0x04, 0x03, 0x00, 0x01, 0x02,
     48    0x07, 0x07, 0x01, 0x03, 0x72, 0x75, 0x6e, 0x00, 0x02, 0x0a, 0x31, 0x03,
     49    0x0b, 0x00, 0x20, 0x00, 0x50, 0x0d, 0x00, 0x20, 0x00, 0x12, 0x01, 0x0b,
     50    0x19, 0x00, 0x20, 0x00, 0x42, 0x01, 0x7d, 0x42, 0x02, 0x42, 0x06, 0x42,
     51    0x03, 0x42, 0x04, 0x42, 0x01, 0x42, 0x02, 0x42, 0x06, 0x42, 0x03, 0x12,
     52    0x00, 0x0b, 0x09, 0x00, 0x42, 0x80, 0x80, 0xc0, 0x00, 0x10, 0x01, 0x0b
     53  ]);
     54  const ins = new WebAssembly.Instance(new WebAssembly.Module(b));
     55  for (var i = 0; i < 100; i++) {
     56    ins.exports.run();
     57  }
     58  
     59  Assert.ok(true, "Done");
     60  await Services.profiler.StopProfiler();
     61 });
     62 
     63 add_task(async () => {
     64  await Services.profiler.StartProfiler(10, 1, ["js"], ["GeckoMain"]);
     65  Assert.ok(Services.profiler.IsActive());
     66 
     67 /* Wasm modules that are tested:
     68 (module (func (export "t")))
     69 
     70 (module
     71    (import "" "t" (func $g))
     72    (table $t 1 1 funcref)
     73 
     74    (func $f (return_call_indirect $t (i32.const 0)))  
     75    (func (export "run") (param i64)
     76     loop
     77       local.get 0
     78       i64.eqz
     79       br_if 1
     80       call $f
     81       local.get 0
     82       i64.const 1
     83       i64.sub
     84       local.set 0
     85       br 0
     86     end
     87    )
     88    (elem (i32.const 0) $g)
     89 )
     90 */
     91  const b0 = new Uint8Array([
     92    0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x04, 0x01, 0x60,
     93    0x00, 0x00, 0x03, 0x02, 0x01, 0x00, 0x07, 0x05, 0x01, 0x01, 0x74, 0x00,
     94    0x00, 0x0a, 0x04, 0x01, 0x02, 0x00, 0x0b  
     95  ]);
     96  const ins0 = new WebAssembly.Instance(new WebAssembly.Module(b0));
     97  const b = new Uint8Array([
     98    0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x02, 0x60,
     99    0x00, 0x00, 0x60, 0x01, 0x7e, 0x00, 0x02, 0x06, 0x01, 0x00, 0x01, 0x74,
    100    0x00, 0x00, 0x03, 0x03, 0x02, 0x00, 0x01, 0x04, 0x05, 0x01, 0x70, 0x01,
    101    0x01, 0x01, 0x07, 0x07, 0x01, 0x03, 0x72, 0x75, 0x6e, 0x00, 0x02, 0x09,
    102    0x07, 0x01, 0x00, 0x41, 0x00, 0x0b, 0x01, 0x00, 0x0a, 0x1f, 0x02, 0x07,
    103    0x00, 0x41, 0x00, 0x13, 0x00, 0x00, 0x0b, 0x15, 0x00, 0x03, 0x40, 0x20,
    104    0x00, 0x50, 0x0d, 0x01, 0x10, 0x01, 0x20, 0x00, 0x42, 0x01, 0x7d, 0x21,
    105    0x00, 0x0c, 0x00, 0x0b, 0x0b
    106  ]);
    107  const ins = new WebAssembly.Instance(new WebAssembly.Module(b), {"": {t: ins0.exports.t,},});
    108  for (var i = 0; i < 100; i++) {
    109    ins.exports.run(0x100000n);
    110  }
    111 
    112  Assert.ok(true, "Done");
    113  await Services.profiler.StopProfiler();
    114 });
    115 
    116 /**
    117 * All the tests are implemented with add_task, this starts them automatically.
    118 */
    119 function run_test() {
    120  do_get_profile();
    121  run_next_test();
    122 }