[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/1057488 Reviewed-by: Clemens Hammacher <clemensh@chromium.org> Commit-Queue: Michael Starzinger <mstarzinger@chromium.org> Cr-Commit-Position: refs/heads/master@{#53155}
This commit is contained in:
parent
ac357002ad
commit
6254650566
@ -136,14 +136,10 @@ bool CodeSpecialization::ApplyToWasmCode(wasm::WasmCode* code,
|
||||
bool reloc_direct_calls = relocate_direct_calls_module_ != nullptr;
|
||||
|
||||
int reloc_mode = 0;
|
||||
auto add_mode = [&reloc_mode](bool cond, RelocInfo::Mode mode) {
|
||||
if (cond) reloc_mode |= RelocInfo::ModeMask(mode);
|
||||
};
|
||||
add_mode(reloc_direct_calls, RelocInfo::WASM_CALL);
|
||||
|
||||
// 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);
|
||||
if (reloc_direct_calls) {
|
||||
reloc_mode |= RelocInfo::ModeMask(RelocInfo::WASM_CALL);
|
||||
}
|
||||
if (!reloc_mode) return false;
|
||||
|
||||
base::Optional<PatchDirectCallsHelper> patch_direct_calls_helper;
|
||||
bool changed = false;
|
||||
@ -177,14 +173,6 @@ bool CodeSpecialization::ApplyToWasmCode(wasm::WasmCode* code,
|
||||
icache_flush_mode);
|
||||
changed = true;
|
||||
} 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:
|
||||
UNREACHABLE();
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include "src/wasm/module-compiler.h"
|
||||
#include "src/wasm/module-decoder.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-limits.h"
|
||||
#include "src/wasm/wasm-memory.h"
|
||||
@ -1407,25 +1406,6 @@ void WasmCompiledModule::Reset(Isolate* isolate,
|
||||
if (native_module->use_trap_handler()) {
|
||||
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(
|
||||
@ -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(
|
||||
Isolate* isolate, Handle<WasmSharedModuleData> shared) {
|
||||
WasmModule* module = shared->module();
|
||||
|
@ -598,9 +598,6 @@ class WasmCompiledModule : public Struct {
|
||||
|
||||
void PrintInstancesChain();
|
||||
|
||||
static void ReinitializeAfterDeserialization(Isolate*,
|
||||
Handle<WasmCompiledModule>);
|
||||
|
||||
void LogWasmCodes(Isolate* isolate);
|
||||
|
||||
private:
|
||||
|
@ -557,7 +557,8 @@ bool NativeModuleDeserializer::ReadCode(uint32_t fn_index, Reader* reader) {
|
||||
int mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) |
|
||||
RelocInfo::ModeMask(RelocInfo::CODE_TARGET) |
|
||||
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(),
|
||||
ret->constant_pool(), mask);
|
||||
!iter.done(); iter.next()) {
|
||||
@ -591,6 +592,15 @@ bool NativeModuleDeserializer::ReadCode(uint32_t fn_index, Reader* reader) {
|
||||
iter.rinfo()->set_target_external_reference(address, SKIP_ICACHE_FLUSH);
|
||||
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:
|
||||
UNREACHABLE();
|
||||
}
|
||||
@ -671,8 +681,11 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
|
||||
// into the allocator.
|
||||
CodeSpaceMemoryModificationScope modification_scope(isolate->heap());
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user