tier-down-to-liftoff.js 1.73 KB
Newer Older
1 2 3 4
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
// Flags: --allow-natives-syntax
6 7 8

load('test/mjsunit/wasm/wasm-module-builder.js');

9
const num_functions = 200;
10

11
function create_builder(delta = 0) {
12 13 14
  const builder = new WasmModuleBuilder();
  for (let i = 0; i < num_functions; ++i) {
    builder.addFunction('f' + i, kSig_i_v)
15
        .addBody(wasmI32Const(i + delta))
16 17 18 19 20
        .exportFunc();
  }
  return builder;
}

21
function checkTieredDown(instance) {
22 23 24
  for (let i = 0; i < num_functions; ++i) {
    assertTrue(%IsLiftoffFunction(instance.exports['f' + i]));
  }
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
}

function checkTieredUp(instance) {
  // Busy waiting until all functions are tiered up.
  let num_liftoff_functions;
  while (true) {
    num_liftoff_functions = 0;
    for (let i = 0; i < num_functions; ++i) {
      if (%IsLiftoffFunction(instance.exports['f' + i])) {
        num_liftoff_functions++;
      }
    }
    if (num_liftoff_functions == 0) return;
  }
}

function check(instance) {
  %WasmTierDownModule(instance);
  checkTieredDown(instance);
44 45 46 47

  for (let i = 0; i < num_functions; ++i) {
    %WasmTierUpFunction(instance, i);
  }
48
  checkTieredDown(instance);
49 50

  %WasmTierUpModule(instance);
51
  checkTieredUp(instance);
52 53 54 55 56 57 58 59
}

(function testTierDownToLiftoff() {
  print(arguments.callee.name);
  const instance = create_builder().instantiate();
  check(instance);
})();

60
// Use slightly different module for this test to avoid sharing native module.
61 62
async function testTierDownToLiftoffAsync() {
  print(arguments.callee.name);
63
  const instance = await create_builder(num_functions).asyncInstantiate();
64 65 66 67
  check(instance);
}

assertPromiseResult(testTierDownToLiftoffAsync());