Commit 0045718a authored by Mircea Trofin's avatar Mircea Trofin Committed by Commit Bot

[wasm] Factor JS wrapper compilation (sync and async)

The logic for wrapper compilation is the same in the sync and
async cases. Moreover, when moving wasm off the GC heap, we'll
initially skip serializing the wrappers, and regenerate them,
using the same logic, at deserialization.

Longer term, we intend to make the serialization format for wasm
more resilient wrt V8 versioning, time at which this separation
will continue playing a role: cross-v8 versions, wrappers will
be recompiled (instead of deserialzied), while wasm code may just
be deserialized.

Bug: v8:6876
Change-Id: I8d9ba835e7c83bb8d1f47163f62396a6fa17661d
Reviewed-on: https://chromium-review.googlesource.com/755542Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49198}
parent ac48a9bd
...@@ -1577,18 +1577,7 @@ MaybeHandle<WasmModuleObject> ModuleCompiler::CompileToModuleObjectInternal( ...@@ -1577,18 +1577,7 @@ MaybeHandle<WasmModuleObject> ModuleCompiler::CompileToModuleObjectInternal(
} }
// Compile JS->wasm wrappers for exported functions. // Compile JS->wasm wrappers for exported functions.
JSToWasmWrapperCache js_to_wasm_cache; CompileJsToWasmWrappers(isolate_, compiled_module, counters());
int wrapper_index = 0;
for (auto exp : module_->export_table) {
if (exp.kind != kExternalFunction) continue;
Handle<Code> wasm_code = EnsureExportedLazyDeoptData(
isolate_, Handle<WasmInstanceObject>::null(), code_table, exp.index);
Handle<Code> wrapper_code = js_to_wasm_cache.CloneOrCompileJSToWasmWrapper(
isolate_, module_, wasm_code, exp.index);
export_wrappers->set(wrapper_index, *wrapper_code);
RecordStats(*wrapper_code, counters());
++wrapper_index;
}
return WasmModuleObject::New(isolate_, compiled_module); return WasmModuleObject::New(isolate_, compiled_module);
} }
...@@ -3332,21 +3321,8 @@ class AsyncCompileJob::CompileWrappers : public CompileStep { ...@@ -3332,21 +3321,8 @@ class AsyncCompileJob::CompileWrappers : public CompileStep {
void RunInForeground() override { void RunInForeground() override {
TRACE_COMPILE("(6) Compile wrappers...\n"); TRACE_COMPILE("(6) Compile wrappers...\n");
// Compile JS->wasm wrappers for exported functions. // Compile JS->wasm wrappers for exported functions.
JSToWasmWrapperCache js_to_wasm_cache; CompileJsToWasmWrappers(job_->isolate_, job_->compiled_module_,
int wrapper_index = 0; job_->counters());
WasmModule* module = job_->compiled_module_->module();
for (auto exp : module->export_table) {
if (exp.kind != kExternalFunction) continue;
Handle<Code> wasm_code(Code::cast(job_->code_table_->get(exp.index)),
job_->isolate_);
Handle<Code> wrapper_code =
js_to_wasm_cache.CloneOrCompileJSToWasmWrapper(job_->isolate_, module,
wasm_code, exp.index);
job_->export_wrappers_->set(wrapper_index, *wrapper_code);
RecordStats(*wrapper_code, job_->counters());
++wrapper_index;
}
job_->DoSync<FinishModule>(); job_->DoSync<FinishModule>();
} }
}; };
...@@ -3518,6 +3494,25 @@ void AsyncStreamingProcessor::OnAbort() { ...@@ -3518,6 +3494,25 @@ void AsyncStreamingProcessor::OnAbort() {
job_->Abort(); job_->Abort();
} }
void CompileJsToWasmWrappers(Isolate* isolate,
Handle<WasmCompiledModule> compiled_module,
Counters* counters) {
JSToWasmWrapperCache js_to_wasm_cache;
int wrapper_index = 0;
Handle<FixedArray> export_wrappers = compiled_module->export_wrappers();
for (auto exp : compiled_module->module()->export_table) {
if (exp.kind != kExternalFunction) continue;
Handle<Code> wasm_code =
EnsureExportedLazyDeoptData(isolate, Handle<WasmInstanceObject>::null(),
compiled_module->code_table(), exp.index);
Handle<Code> wrapper_code = js_to_wasm_cache.CloneOrCompileJSToWasmWrapper(
isolate, compiled_module->module(), wasm_code, exp.index);
export_wrappers->set(wrapper_index, *wrapper_code);
RecordStats(*wrapper_code, counters);
++wrapper_index;
}
}
} // namespace wasm } // namespace wasm
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
...@@ -49,6 +49,10 @@ V8_EXPORT_PRIVATE void AsyncInstantiate(Isolate* isolate, ...@@ -49,6 +49,10 @@ V8_EXPORT_PRIVATE void AsyncInstantiate(Isolate* isolate,
Handle<WasmModuleObject> module_object, Handle<WasmModuleObject> module_object,
MaybeHandle<JSReceiver> imports); MaybeHandle<JSReceiver> imports);
V8_EXPORT_PRIVATE void CompileJsToWasmWrappers(
Isolate* isolate, Handle<WasmCompiledModule> compiled_module,
Counters* counters);
// Triggered by the WasmCompileLazy builtin. // Triggered by the WasmCompileLazy builtin.
// Walks the stack (top three frames) to determine the wasm instance involved // Walks the stack (top three frames) to determine the wasm instance involved
// and which function to compile. // and which function to compile.
......
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