Commit 0feff465 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Turn {WasmCompileLazy} stub into a runtime stub.

This removes the special casing for the lazy compilation stub which used
to have its own code kind, just so that the stack walker would properly
recognize its frame.

Also, by re-using the existing machinery for runtime stubs we no longer
need to copy this stub into the native module and get all the niceties
that come with embedded builtins for free.

Thirdly this will make it easier to start lazy compilation from the
background or to do it on a per-function basis without requiring yet
more special machinery, since {NativeModule::SetLazyBuiltin} no longer
requires access to the Isolate.

Kudos for the inspiration for this cleanup go to Frederik, I merely did
some of the legwork.

R=clemensh@chromium.org
BUG=v8:8834

Change-Id: Iac2b51a2e33fb0e88d25d3632fa18998123ee6c3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1532064Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60365}
parent 1ca08865
......@@ -1422,6 +1422,7 @@ namespace internal {
// elements of the list coincide with {compiler::TrapId}, order matters.
#define WASM_RUNTIME_STUB_LIST(V, VTRAP) \
FOREACH_WASM_TRAPREASON(VTRAP) \
V(WasmCompileLazy) \
V(WasmAllocateHeapNumber) \
V(WasmAtomicNotify) \
V(WasmI32AtomicWait) \
......
......@@ -488,9 +488,13 @@ StackFrame::Type StackFrame::ComputeType(const StackFrameIteratorBase* iterator,
return WASM_COMPILED;
case wasm::WasmCode::kWasmToJsWrapper:
return WASM_TO_JS;
case wasm::WasmCode::kLazyStub:
return WASM_COMPILE_LAZY;
case wasm::WasmCode::kRuntimeStub:
// Some stubs, like e.g. {WasmCode::kWasmCompileLazy} build their own
// specialized frame which already carries a type marker.
// TODO(mstarzinger): This is only needed for the case where embedded
// builtins are disabled. It can be removed once all non-embedded
// builtins are gone.
if (StackFrame::IsTypeMarker(marker)) break;
return STUB;
case wasm::WasmCode::kInterpreterEntry:
return WASM_INTERPRETER_ENTRY;
......@@ -552,6 +556,7 @@ StackFrame::Type StackFrame::ComputeType(const StackFrameIteratorBase* iterator,
case ARGUMENTS_ADAPTOR:
case WASM_TO_JS:
case WASM_COMPILED:
case WASM_COMPILE_LAZY:
return candidate;
case JS_TO_WASM:
case OPTIMIZED:
......
......@@ -628,7 +628,7 @@ void CompileNativeModule(Isolate* isolate, ErrorThrower* thrower,
if (thrower->error()) return;
}
native_module->SetLazyBuiltin(BUILTIN_CODE(isolate, WasmCompileLazy));
native_module->SetLazyBuiltin();
} else {
size_t funcs_to_compile =
wasm_module->functions.size() - wasm_module->num_imported_functions;
......
......@@ -349,8 +349,6 @@ const char* GetWasmCodeKindAsString(WasmCode::Kind kind) {
return "wasm function";
case WasmCode::kWasmToJsWrapper:
return "wasm-to-js";
case WasmCode::kLazyStub:
return "lazy-compile";
case WasmCode::kRuntimeStub:
return "runtime-stub";
case WasmCode::kInterpreterEntry:
......@@ -486,12 +484,11 @@ WasmCode* NativeModule::AddCodeForTesting(Handle<Code> code) {
return ret;
}
void NativeModule::SetLazyBuiltin(Handle<Code> code) {
void NativeModule::SetLazyBuiltin() {
uint32_t num_wasm_functions = module_->num_declared_functions;
if (num_wasm_functions == 0) return;
WasmCode* lazy_builtin = AddAnonymousCode(code, WasmCode::kLazyStub);
// Fill the jump table with jumps to the lazy compile stub.
Address lazy_compile_target = lazy_builtin->instruction_start();
Address lazy_compile_target = runtime_stub_entry(WasmCode::kWasmCompileLazy);
for (uint32_t i = 0; i < num_wasm_functions; ++i) {
JumpTableAssembler::EmitLazyCompileJumpSlot(
jump_table_->instruction_start(), i,
......
......@@ -76,7 +76,6 @@ class V8_EXPORT_PRIVATE WasmCode final {
enum Kind {
kFunction,
kWasmToJsWrapper,
kLazyStub,
kRuntimeStub,
kInterpreterEntry,
kJumpTable
......@@ -256,10 +255,10 @@ class V8_EXPORT_PRIVATE NativeModule final {
// Adds anonymous code for testing purposes.
WasmCode* AddCodeForTesting(Handle<Code> code);
// When starting lazy compilation, provide the WasmLazyCompile builtin by
// calling SetLazyBuiltin. It will be copied into this NativeModule and the
// jump table will be populated with that copy.
void SetLazyBuiltin(Handle<Code> code);
// Use this to start lazy compilation for the entire module. It will use the
// existing {WasmCode::kWasmCompileLazy} runtime stub and populate the jump
// table with trampolines to that runtime stub.
void SetLazyBuiltin();
// Initializes all runtime stubs by setting up entry addresses in the runtime
// stub table. It must be called exactly once per native module before adding
......
......@@ -626,7 +626,7 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
NativeModule* native_module = module_object->native_module();
if (FLAG_wasm_lazy_compilation) {
native_module->SetLazyBuiltin(BUILTIN_CODE(isolate, WasmCompileLazy));
native_module->SetLazyBuiltin();
}
NativeModuleDeserializer deserializer(native_module);
......
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