Commit 62546505 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Avoid specializing code on instance finalization.

Now that {WasmCode} objects are no longer specific to an instance, it is
no longer needed to patch code when the last instance is finalized. The
code specialization in {WasmCompiledModule::Reset} is no longer needed.

R=clemensh@chromium.org

Change-Id: I430e7f7258d309916de1188d47677c7feb8123b0
Reviewed-on: https://chromium-review.googlesource.com/1057488Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53155}
parent ac357002
...@@ -136,14 +136,10 @@ bool CodeSpecialization::ApplyToWasmCode(wasm::WasmCode* code, ...@@ -136,14 +136,10 @@ bool CodeSpecialization::ApplyToWasmCode(wasm::WasmCode* code,
bool reloc_direct_calls = relocate_direct_calls_module_ != nullptr; bool reloc_direct_calls = relocate_direct_calls_module_ != nullptr;
int reloc_mode = 0; int reloc_mode = 0;
auto add_mode = [&reloc_mode](bool cond, RelocInfo::Mode mode) { if (reloc_direct_calls) {
if (cond) reloc_mode |= RelocInfo::ModeMask(mode); reloc_mode |= RelocInfo::ModeMask(RelocInfo::WASM_CALL);
}; }
add_mode(reloc_direct_calls, RelocInfo::WASM_CALL); if (!reloc_mode) return false;
// Always patch the code table entry address which is used in Liftoff
// prologue to jump to optimized code if existent.
reloc_mode |= RelocInfo::ModeMask(RelocInfo::WASM_CODE_TABLE_ENTRY);
base::Optional<PatchDirectCallsHelper> patch_direct_calls_helper; base::Optional<PatchDirectCallsHelper> patch_direct_calls_helper;
bool changed = false; bool changed = false;
...@@ -177,14 +173,6 @@ bool CodeSpecialization::ApplyToWasmCode(wasm::WasmCode* code, ...@@ -177,14 +173,6 @@ bool CodeSpecialization::ApplyToWasmCode(wasm::WasmCode* code,
icache_flush_mode); icache_flush_mode);
changed = true; changed = true;
} break; } break;
case RelocInfo::WASM_CODE_TABLE_ENTRY: {
DCHECK(FLAG_wasm_tier_up);
DCHECK(code->is_liftoff());
WasmCode* const* code_table_entry =
native_module->code_table().data() + code->index();
it.rinfo()->set_wasm_code_table_entry(
reinterpret_cast<Address>(code_table_entry), icache_flush_mode);
} break;
default: default:
UNREACHABLE(); UNREACHABLE();
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "src/wasm/module-compiler.h" #include "src/wasm/module-compiler.h"
#include "src/wasm/module-decoder.h" #include "src/wasm/module-decoder.h"
#include "src/wasm/wasm-code-manager.h" #include "src/wasm/wasm-code-manager.h"
#include "src/wasm/wasm-code-specialization.h"
#include "src/wasm/wasm-engine.h" #include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-limits.h" #include "src/wasm/wasm-limits.h"
#include "src/wasm/wasm-memory.h" #include "src/wasm/wasm-memory.h"
...@@ -1407,25 +1406,6 @@ void WasmCompiledModule::Reset(Isolate* isolate, ...@@ -1407,25 +1406,6 @@ void WasmCompiledModule::Reset(Isolate* isolate,
if (native_module->use_trap_handler()) { if (native_module->use_trap_handler()) {
native_module->ReleaseProtectedInstructions(); native_module->ReleaseProtectedInstructions();
} }
// Patch code to update memory references, global references, and function
// table references.
wasm::CodeSpecialization code_specialization;
for (uint32_t i = native_module->num_imported_functions(),
end = native_module->function_count();
i < end; ++i) {
wasm::WasmCode* code = native_module->code(i);
// Skip lazy compile stubs.
if (code == nullptr || code->kind() != wasm::WasmCode::kFunction) continue;
bool changed = code_specialization.ApplyToWasmCode(code, SKIP_ICACHE_FLUSH);
// TODO(wasm): Check if this is faster than passing FLUSH_ICACHE_IF_NEEDED
// above.
if (changed) {
Assembler::FlushICache(code->instructions().start(),
code->instructions().size());
}
}
} }
MaybeHandle<String> WasmSharedModuleData::ExtractUtf8StringFromModuleBytes( MaybeHandle<String> WasmSharedModuleData::ExtractUtf8StringFromModuleBytes(
...@@ -1486,13 +1466,6 @@ void WasmCompiledModule::RemoveFromChain() { ...@@ -1486,13 +1466,6 @@ void WasmCompiledModule::RemoveFromChain() {
} }
} }
void WasmCompiledModule::ReinitializeAfterDeserialization(
Isolate* isolate, Handle<WasmCompiledModule> compiled_module) {
// Reset, but don't delete any global handles, because their owning instance
// may still be active.
WasmCompiledModule::Reset(isolate, *compiled_module);
}
MaybeHandle<String> WasmSharedModuleData::GetModuleNameOrNull( MaybeHandle<String> WasmSharedModuleData::GetModuleNameOrNull(
Isolate* isolate, Handle<WasmSharedModuleData> shared) { Isolate* isolate, Handle<WasmSharedModuleData> shared) {
WasmModule* module = shared->module(); WasmModule* module = shared->module();
......
...@@ -598,9 +598,6 @@ class WasmCompiledModule : public Struct { ...@@ -598,9 +598,6 @@ class WasmCompiledModule : public Struct {
void PrintInstancesChain(); void PrintInstancesChain();
static void ReinitializeAfterDeserialization(Isolate*,
Handle<WasmCompiledModule>);
void LogWasmCodes(Isolate* isolate); void LogWasmCodes(Isolate* isolate);
private: private:
......
...@@ -557,7 +557,8 @@ bool NativeModuleDeserializer::ReadCode(uint32_t fn_index, Reader* reader) { ...@@ -557,7 +557,8 @@ bool NativeModuleDeserializer::ReadCode(uint32_t fn_index, Reader* reader) {
int mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) | int mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) |
RelocInfo::ModeMask(RelocInfo::CODE_TARGET) | RelocInfo::ModeMask(RelocInfo::CODE_TARGET) |
RelocInfo::ModeMask(RelocInfo::RUNTIME_ENTRY) | RelocInfo::ModeMask(RelocInfo::RUNTIME_ENTRY) |
RelocInfo::ModeMask(RelocInfo::EXTERNAL_REFERENCE); RelocInfo::ModeMask(RelocInfo::EXTERNAL_REFERENCE) |
RelocInfo::ModeMask(RelocInfo::WASM_CODE_TABLE_ENTRY);
for (RelocIterator iter(ret->instructions(), ret->reloc_info(), for (RelocIterator iter(ret->instructions(), ret->reloc_info(),
ret->constant_pool(), mask); ret->constant_pool(), mask);
!iter.done(); iter.next()) { !iter.done(); iter.next()) {
...@@ -591,6 +592,15 @@ bool NativeModuleDeserializer::ReadCode(uint32_t fn_index, Reader* reader) { ...@@ -591,6 +592,15 @@ bool NativeModuleDeserializer::ReadCode(uint32_t fn_index, Reader* reader) {
iter.rinfo()->set_target_external_reference(address, SKIP_ICACHE_FLUSH); iter.rinfo()->set_target_external_reference(address, SKIP_ICACHE_FLUSH);
break; break;
} }
case RelocInfo::WASM_CODE_TABLE_ENTRY: {
DCHECK(FLAG_wasm_tier_up);
DCHECK(ret->is_liftoff());
WasmCode* const* code_table_entry =
native_module_->code_table().data() + ret->index();
iter.rinfo()->set_wasm_code_table_entry(
reinterpret_cast<Address>(code_table_entry), SKIP_ICACHE_FLUSH);
break;
}
default: default:
UNREACHABLE(); UNREACHABLE();
} }
...@@ -671,8 +681,11 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule( ...@@ -671,8 +681,11 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
// into the allocator. // into the allocator.
CodeSpaceMemoryModificationScope modification_scope(isolate->heap()); CodeSpaceMemoryModificationScope modification_scope(isolate->heap());
CompileJsToWasmWrappers(isolate, module_object, isolate->counters()); CompileJsToWasmWrappers(isolate, module_object, isolate->counters());
WasmCompiledModule::ReinitializeAfterDeserialization(isolate,
compiled_module); // There are no instances for this module yet, which means we need to reset
// the module into a state as if the last instance was collected.
WasmCompiledModule::Reset(isolate, *compiled_module);
return module_object; return module_object;
} }
......
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