Commit bb64e34f authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Add "freeze" flag to test lazy compilation

In order to test that we don't repeatedly go through the
WasmCompileLazy runtime function, add a flag to the
LazyCompilationOrchestrator to "freeze" it, i.e. disallow any further
lazy compilation.
In tests, use this flag to first call a method, then freeze lazy
compilation, then call the method again to assert that no further lazy
compilation is triggered.

This test currently fails with --wasm-jit-to-native, so disable it for
that variant.

R=titzer@chromium.org
CC=mtrofin@chromium.org

Bug: v8:7140, chromium:788441, v8:5991
Change-Id: I18a40d302c24041740d8a54351d06ed968f4beec
Reviewed-on: https://chromium-review.googlesource.com/796430Reviewed-by: 's avatarMircea Trofin <mtrofin@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49734}
parent b15be58f
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "src/snapshot/natives.h" #include "src/snapshot/natives.h"
#include "src/trap-handler/trap-handler.h" #include "src/trap-handler/trap-handler.h"
#include "src/wasm/memory-tracing.h" #include "src/wasm/memory-tracing.h"
#include "src/wasm/module-compiler.h"
#include "src/wasm/wasm-module.h" #include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-objects-inl.h" #include "src/wasm/wasm-objects-inl.h"
#include "src/wasm/wasm-serialization.h" #include "src/wasm/wasm-serialization.h"
...@@ -1180,5 +1181,19 @@ RUNTIME_FUNCTION(Runtime_CompleteInobjectSlackTracking) { ...@@ -1180,5 +1181,19 @@ RUNTIME_FUNCTION(Runtime_CompleteInobjectSlackTracking) {
return isolate->heap()->undefined_value(); return isolate->heap()->undefined_value();
} }
RUNTIME_FUNCTION(Runtime_FreezeWasmLazyCompilation) {
DCHECK_EQ(1, args.length());
DisallowHeapAllocation no_gc;
CONVERT_ARG_CHECKED(WasmInstanceObject, instance, 0);
WasmSharedModuleData* shared = instance->compiled_module()->ptr_to_shared();
CHECK(shared->has_lazy_compilation_orchestrator());
auto* orchestrator = Managed<wasm::LazyCompilationOrchestrator>::cast(
shared->lazy_compilation_orchestrator())
->get();
orchestrator->FreezeLazyCompilationForTesting();
return isolate->heap()->undefined_value();
}
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -631,7 +631,8 @@ namespace internal { ...@@ -631,7 +631,8 @@ namespace internal {
F(RedirectToWasmInterpreter, 2, 1) \ F(RedirectToWasmInterpreter, 2, 1) \
F(WasmTraceMemory, 4, 1) \ F(WasmTraceMemory, 4, 1) \
F(CompleteInobjectSlackTracking, 1, 1) \ F(CompleteInobjectSlackTracking, 1, 1) \
F(IsLiftoffFunction, 1, 1) F(IsLiftoffFunction, 1, 1) \
F(FreezeWasmLazyCompilation, 1, 1)
#define FOR_EACH_INTRINSIC_TYPEDARRAY(F) \ #define FOR_EACH_INTRINSIC_TYPEDARRAY(F) \
F(ArrayBufferGetByteLength, 1, 1) \ F(ArrayBufferGetByteLength, 1, 1) \
......
...@@ -692,6 +692,8 @@ Handle<Code> CompileLazyOnGCHeap(Isolate* isolate) { ...@@ -692,6 +692,8 @@ Handle<Code> CompileLazyOnGCHeap(Isolate* isolate) {
->shared() ->shared()
->lazy_compilation_orchestrator()) ->lazy_compilation_orchestrator())
->get(); ->get();
DCHECK(!orchestrator->IsFrozenForTesting());
Handle<Code> compiled_code = orchestrator->CompileLazyOnGCHeap( Handle<Code> compiled_code = orchestrator->CompileLazyOnGCHeap(
isolate, instance, caller_code, offset, func_index, patch_caller); isolate, instance, caller_code, offset, func_index, patch_caller);
if (!exp_deopt_data.is_null() && exp_deopt_data->length() > 2) { if (!exp_deopt_data.is_null() && exp_deopt_data->length() > 2) {
...@@ -779,6 +781,8 @@ Address CompileLazy(Isolate* isolate) { ...@@ -779,6 +781,8 @@ Address CompileLazy(Isolate* isolate) {
Managed<wasm::LazyCompilationOrchestrator>::cast( Managed<wasm::LazyCompilationOrchestrator>::cast(
compiled_module->shared()->lazy_compilation_orchestrator()) compiled_module->shared()->lazy_compilation_orchestrator())
->get(); ->get();
DCHECK(!orchestrator->IsFrozenForTesting());
const wasm::WasmCode* result = nullptr; const wasm::WasmCode* result = nullptr;
// The caller may be js to wasm calling a function // The caller may be js to wasm calling a function
// also available for indirect calls. // also available for indirect calls.
......
...@@ -95,6 +95,20 @@ class LazyCompilationOrchestrator { ...@@ -95,6 +95,20 @@ class LazyCompilationOrchestrator {
const wasm::WasmCode* CompileIndirectCall(Isolate*, const wasm::WasmCode* CompileIndirectCall(Isolate*,
Handle<WasmInstanceObject>, Handle<WasmInstanceObject>,
uint32_t func_index); uint32_t func_index);
#ifdef DEBUG
// Call this method in tests to disallow any further lazy compilation; then
// call into the wasm instance again to verify that no lazy compilation is
// triggered.
void FreezeLazyCompilationForTesting() { frozen_ = true; }
bool IsFrozenForTesting() const { return frozen_; }
private:
bool frozen_;
#else
void FreezeLazyCompilationForTesting() {}
bool IsFrozenForTesting() { return false; }
#endif
}; };
// Encapsulates all the state and steps of an asynchronous compilation. // Encapsulates all the state and steps of an asynchronous compilation.
......
...@@ -706,6 +706,10 @@ ...@@ -706,6 +706,10 @@
'math-*': [SKIP], 'math-*': [SKIP],
'unicode-test': [SKIP], 'unicode-test': [SKIP],
'whitespaces': [SKIP], 'whitespaces': [SKIP],
# Lazy compilation is currently broken for --wasm-jit-to-native
# (crbug.com/v8/7140).
'wasm/lazy-compilation': [SKIP],
}], # variant == wasm_traps }], # variant == wasm_traps
['variant == wasm_traps and gc_stress == True', { ['variant == wasm_traps and gc_stress == True', {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// Flags: --wasm-lazy-compilation // Flags: --wasm-lazy-compilation --allow-natives-syntax
load('test/mjsunit/wasm/wasm-constants.js'); load('test/mjsunit/wasm/wasm-constants.js');
load('test/mjsunit/wasm/wasm-module-builder.js'); load('test/mjsunit/wasm/wasm-module-builder.js');
...@@ -46,6 +46,10 @@ load('test/mjsunit/wasm/wasm-module-builder.js'); ...@@ -46,6 +46,10 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
instance2.exports.call_store(3); instance2.exports.call_store(3);
assertEquals(3, mem1[0]); assertEquals(3, mem1[0]);
assertEquals(0, mem2[0]); assertEquals(0, mem2[0]);
%FreezeWasmLazyCompilation(instance1);
%FreezeWasmLazyCompilation(instance2);
instance2.exports.call_store(7);
assertEquals(7, mem1[0]);
})(); })();
(function exportImportedFunction() { (function exportImportedFunction() {
...@@ -60,4 +64,37 @@ load('test/mjsunit/wasm/wasm-module-builder.js'); ...@@ -60,4 +64,37 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
const instance2 = builder2.instantiate({A: instance1.exports}); const instance2 = builder2.instantiate({A: instance1.exports});
instance2.exports.foo(); instance2.exports.foo();
%FreezeWasmLazyCompilation(instance1);
%FreezeWasmLazyCompilation(instance2);
instance2.exports.foo();
})();
(function exportImportedFunctionWithDifferentMemory() {
print(arguments.callee.name);
const builder1 = new WasmModuleBuilder();
builder1.addMemory(1, 1, true);
builder1.addFunction('store', kSig_v_i)
.addBody([
kExprI32Const, 0, // i32.const 1
kExprGetLocal, 0, // get_local 0
kExprI32StoreMem, 0, 0, // i32.store offset=0 align=0
])
.exportFunc();
const instance1 = builder1.instantiate();
const mem1 = new Int32Array(instance1.exports.memory.buffer);
const builder2 = new WasmModuleBuilder();
builder2.addMemory(1, 1, true);
const imp_idx = builder2.addImport('A', 'store', kSig_v_i);
builder2.addExport('exp_store', imp_idx);
const instance2 = builder2.instantiate({A: instance1.exports});
const mem2 = new Int32Array(instance2.exports.memory.buffer);
instance2.exports.exp_store(3);
assertEquals(3, mem1[0]);
assertEquals(0, mem2[0]);
%FreezeWasmLazyCompilation(instance1);
%FreezeWasmLazyCompilation(instance2);
instance2.exports.exp_store(7);
assertEquals(7, mem1[0]);
})(); })();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment