Commit 67770d61 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Call via jump table after lazy compile

The WasmCompileLazy runtime function used to return the start of the
instructions of the newly compiled function. With garbage collection of
wasm code, it would be tricky to keep this wasm code object alive until
it is being called. Thus make the runtime function not return anything,
and call via the jump table instead. The jump table was patched as part
of lazy compilation to point to the compiled code.

Drive-by: Merge {LazyCompileFunction} into single caller {CompileLazy}.

R=mstarzinger@chromium.org

Bug: v8:8217
Change-Id: Id3c02f4dfe2c536e335af2e7e1b9700203d48675
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1509472
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60163}
parent ca0b91b0
......@@ -244,8 +244,10 @@ RUNTIME_FUNCTION(Runtime_WasmCompileLazy) {
DCHECK_EQ(*instance, WasmCompileLazyFrame::cast(it.frame())->wasm_instance());
#endif
Address entrypoint = wasm::CompileLazy(
isolate, instance->module_object()->native_module(), func_index);
auto* native_module = instance->module_object()->native_module();
wasm::CompileLazy(isolate, native_module, func_index);
Address entrypoint = native_module->GetCallTargetForFunction(func_index);
return Object(entrypoint);
}
......
......@@ -318,9 +318,17 @@ std::unique_ptr<CompilationState> CompilationState::New(
// End of PIMPL implementation of {CompilationState}.
//////////////////////////////////////////////////////
WasmCode* LazyCompileFunction(Isolate* isolate, NativeModule* native_module,
int func_index) {
void CompileLazy(Isolate* isolate, NativeModule* native_module,
uint32_t func_index) {
Counters* counters = isolate->counters();
HistogramTimerScope lazy_time_scope(counters->wasm_lazy_compilation_time());
DCHECK(!native_module->lazy_compile_frozen());
base::ElapsedTimer compilation_timer;
NativeModuleModificationScope native_module_modification_scope(native_module);
DCHECK(!native_module->has_code(static_cast<uint32_t>(func_index)));
compilation_timer.Start();
......@@ -351,36 +359,20 @@ WasmCode* LazyCompileFunction(Isolate* isolate, NativeModule* native_module,
// module creation time, and return a function that always traps here.
CHECK(!native_module->compilation_state()->failed());
// The code we just produced should be the one that was requested.
DCHECK_EQ(func_index, code->index());
if (WasmCode::ShouldBeLogged(isolate)) code->LogCode(isolate);
int64_t func_size =
static_cast<int64_t>(func->code.end_offset() - func->code.offset());
int64_t compilation_time = compilation_timer.Elapsed().InMicroseconds();
auto counters = isolate->counters();
counters->wasm_lazily_compiled_functions()->Increment();
counters->wasm_lazy_compilation_throughput()->AddSample(
compilation_time != 0 ? static_cast<int>(func_size / compilation_time)
: 0);
return code;
}
Address CompileLazy(Isolate* isolate, NativeModule* native_module,
uint32_t func_index) {
HistogramTimerScope lazy_time_scope(
isolate->counters()->wasm_lazy_compilation_time());
DCHECK(!native_module->lazy_compile_frozen());
NativeModuleModificationScope native_module_modification_scope(native_module);
WasmCode* result = LazyCompileFunction(isolate, native_module, func_index);
DCHECK_NOT_NULL(result);
DCHECK_EQ(func_index, result->index());
return result->instruction_start();
}
namespace {
......
......@@ -56,8 +56,7 @@ V8_EXPORT_PRIVATE Handle<Script> CreateWasmScript(
const std::string& source_map_url);
// Triggered by the WasmCompileLazy builtin.
// Returns the instruction start of the compiled code object.
Address CompileLazy(Isolate*, NativeModule*, uint32_t func_index);
void CompileLazy(Isolate*, NativeModule*, uint32_t func_index);
// Encapsulates all the state and steps of an asynchronous compilation.
// An asynchronous compile job consists of a number of tasks that are executed
......
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