Commit 39fcb540 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Make {NativeModule::compiled_module} a phantom reference.

This reduces time it takes for the compiled module to be reclaimed. It
switches the reference in question from a weak reference with finalizer
to a phantom reference, because the finalizer was only clearing the
reference by now anyways.

R=ahaas@chromium.org
BUG=chromium:824443

Change-Id: I51f0dbd487281184f82fd6c79fcf27514721b819
Reviewed-on: https://chromium-review.googlesource.com/978243
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52247}
parent be5dbd8f
...@@ -520,13 +520,18 @@ void NativeModule::SetLazyBuiltin(Handle<Code> code) { ...@@ -520,13 +520,18 @@ void NativeModule::SetLazyBuiltin(Handle<Code> code) {
} }
WasmCompiledModule* NativeModule::compiled_module() const { WasmCompiledModule* NativeModule::compiled_module() const {
DCHECK_NOT_NULL(compiled_module_);
return *compiled_module_; return *compiled_module_;
} }
void NativeModule::SetCompiledModule( void NativeModule::SetCompiledModule(
Handle<WasmCompiledModule> compiled_module) { Handle<WasmCompiledModule> compiled_module) {
DCHECK(compiled_module_.is_null()); DCHECK_NULL(compiled_module_);
compiled_module_ = compiled_module; compiled_module_ = compiled_module->GetIsolate()
->global_handles()
->Create(*compiled_module)
.location();
GlobalHandles::MakeWeak(reinterpret_cast<Object***>(&compiled_module_));
} }
WasmCode* NativeModule::AddAnonymousCode(Handle<Code> code, WasmCode* NativeModule::AddAnonymousCode(Handle<Code> code,
...@@ -862,6 +867,12 @@ WasmCode* NativeModule::CloneCode(const WasmCode* original_code, ...@@ -862,6 +867,12 @@ WasmCode* NativeModule::CloneCode(const WasmCode* original_code,
NativeModule::~NativeModule() { NativeModule::~NativeModule() {
TRACE_HEAP("Deleting native module: %p\n", reinterpret_cast<void*>(this)); TRACE_HEAP("Deleting native module: %p\n", reinterpret_cast<void*>(this));
wasm_code_manager_->FreeNativeModuleMemories(this); wasm_code_manager_->FreeNativeModuleMemories(this);
if (compiled_module_ != nullptr) {
Isolate* isolate = compiled_module()->GetIsolate();
isolate->global_handles()->Destroy(
reinterpret_cast<Object**>(compiled_module_));
compiled_module_ = nullptr;
}
} }
WasmCodeManager::WasmCodeManager(v8::Isolate* isolate, size_t max_committed) WasmCodeManager::WasmCodeManager(v8::Isolate* isolate, size_t max_committed)
......
...@@ -278,8 +278,8 @@ class V8_EXPORT_PRIVATE NativeModule final { ...@@ -278,8 +278,8 @@ class V8_EXPORT_PRIVATE NativeModule final {
CompilationState* compilation_state() { return compilation_state_.get(); } CompilationState* compilation_state() { return compilation_state_.get(); }
// TODO(mstarzinger): needed until we sort out source positions, which are // TODO(mstarzinger): The link to the {compiled_module} is deprecated and all
// still on the GC-heap. // uses should vanish to make {NativeModule} independent of the Isolate.
WasmCompiledModule* compiled_module() const; WasmCompiledModule* compiled_module() const;
void SetCompiledModule(Handle<WasmCompiledModule>); void SetCompiledModule(Handle<WasmCompiledModule>);
...@@ -340,12 +340,16 @@ class V8_EXPORT_PRIVATE NativeModule final { ...@@ -340,12 +340,16 @@ class V8_EXPORT_PRIVATE NativeModule final {
std::unique_ptr<CompilationState, CompilationStateDeleter> compilation_state_; std::unique_ptr<CompilationState, CompilationStateDeleter> compilation_state_;
// A phantom reference to the {WasmCompiledModule}. It is intentionally not
// typed {Handle<WasmCompiledModule>} because this location will be cleared
// when the phantom reference is cleared.
WasmCompiledModule** compiled_module_ = nullptr;
DisjointAllocationPool free_memory_; DisjointAllocationPool free_memory_;
DisjointAllocationPool allocated_memory_; DisjointAllocationPool allocated_memory_;
std::list<VirtualMemory> owned_memory_; std::list<VirtualMemory> owned_memory_;
WasmCodeManager* wasm_code_manager_; WasmCodeManager* wasm_code_manager_;
base::Mutex allocation_mutex_; base::Mutex allocation_mutex_;
Handle<WasmCompiledModule> compiled_module_;
size_t committed_memory_ = 0; size_t committed_memory_ = 0;
bool can_request_more_memory_; bool can_request_more_memory_;
bool is_executable_ = false; bool is_executable_ = false;
......
...@@ -155,14 +155,6 @@ bool IsBreakablePosition(WasmSharedModuleData* shared, int func_index, ...@@ -155,14 +155,6 @@ bool IsBreakablePosition(WasmSharedModuleData* shared, int func_index,
} }
#endif // DEBUG #endif // DEBUG
void CompiledModuleFinalizer(const v8::WeakCallbackInfo<void>& data) {
DisallowHeapAllocation no_gc;
JSObject** p = reinterpret_cast<JSObject**>(data.GetParameter());
WasmCompiledModule* compiled_module = WasmCompiledModule::cast(*p);
compiled_module->reset_native_module();
GlobalHandles::Destroy(reinterpret_cast<Object**>(p));
}
enum DispatchTableElements : int { enum DispatchTableElements : int {
kDispatchTableInstanceOffset, kDispatchTableInstanceOffset,
kDispatchTableIndexOffset, kDispatchTableIndexOffset,
...@@ -1252,13 +1244,7 @@ Handle<WasmCompiledModule> WasmCompiledModule::New( ...@@ -1252,13 +1244,7 @@ Handle<WasmCompiledModule> WasmCompiledModule::New(
Handle<Foreign> native_module_wrapper = Handle<Foreign> native_module_wrapper =
Managed<wasm::NativeModule>::From(isolate, native_module); Managed<wasm::NativeModule>::From(isolate, native_module);
compiled_module->set_native_module(*native_module_wrapper); compiled_module->set_native_module(*native_module_wrapper);
Handle<WasmCompiledModule> weak_link = compiled_module->GetNativeModule()->SetCompiledModule(compiled_module);
isolate->global_handles()->Create(*compiled_module);
GlobalHandles::MakeWeak(Handle<Object>::cast(weak_link).location(),
Handle<Object>::cast(weak_link).location(),
&CompiledModuleFinalizer,
v8::WeakCallbackType::kFinalizer);
compiled_module->GetNativeModule()->SetCompiledModule(weak_link);
} }
// TODO(mtrofin): copy the rest of the specialization parameters over. // TODO(mtrofin): copy the rest of the specialization parameters over.
...@@ -1292,13 +1278,7 @@ Handle<WasmCompiledModule> WasmCompiledModule::Clone( ...@@ -1292,13 +1278,7 @@ Handle<WasmCompiledModule> WasmCompiledModule::Clone(
Handle<Foreign> native_module_wrapper = Handle<Foreign> native_module_wrapper =
Managed<wasm::NativeModule>::From(isolate, native_module.release()); Managed<wasm::NativeModule>::From(isolate, native_module.release());
ret->set_native_module(*native_module_wrapper); ret->set_native_module(*native_module_wrapper);
Handle<WasmCompiledModule> weak_link = ret->GetNativeModule()->SetCompiledModule(ret);
isolate->global_handles()->Create(*ret);
GlobalHandles::MakeWeak(Handle<Object>::cast(weak_link).location(),
Handle<Object>::cast(weak_link).location(),
&CompiledModuleFinalizer,
v8::WeakCallbackType::kFinalizer);
ret->GetNativeModule()->SetCompiledModule(weak_link);
if (module->has_lazy_compile_data()) { if (module->has_lazy_compile_data()) {
Handle<FixedArray> lazy_comp_data = isolate->factory()->NewFixedArray( Handle<FixedArray> lazy_comp_data = isolate->factory()->NewFixedArray(
......
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