Commit 69f264f5 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Refactor code installation in NativeModule

Whenever we insert new code in the module, we call {set_code} and
{PatchJumpTable}. This CL refactors these two calls into a new
{InstallCode} method. This method will be extended in a future CL to
maintain a counter of potentially dead code and trigger GC.

R=mstarzinger@chromium.org

Bug: v8:8217
Change-Id: I1a1421806c8518cf7b6b78fe4aa2e969d4e4dde6
Reviewed-on: https://chromium-review.googlesource.com/1243003
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56214}
parent 1a5a6c36
......@@ -425,8 +425,7 @@ WasmCode* NativeModule::AddInterpreterEntry(Handle<Code> code, uint32_t index) {
WasmCode* ret = AddAnonymousCode(code, WasmCode::kInterpreterEntry);
ret->index_ = Just(index);
base::LockGuard<base::Mutex> lock(&allocation_mutex_);
PatchJumpTable(index, ret->instruction_start(), WasmCode::kFlushICache);
set_code(index, ret);
InstallCode(ret);
return ret;
}
......@@ -591,8 +590,8 @@ WasmCode* NativeModule::AddDeserializedCode(
if (!code->protected_instructions_.is_empty()) {
code->RegisterTrapHandlerData();
}
set_code(index, code);
PatchJumpTable(index, code->instruction_start(), WasmCode::kFlushICache);
base::LockGuard<base::Mutex> lock(&allocation_mutex_);
InstallCode(code);
// Note: we do not flush the i-cache here, since the code needs to be
// relocated anyway. The caller is responsible for flushing the i-cache later.
return code;
......@@ -609,10 +608,7 @@ void NativeModule::PublishCode(WasmCode* code) {
if (!code->protected_instructions_.is_empty()) {
code->RegisterTrapHandlerData();
}
DCHECK(!code->IsAnonymous());
set_code(code->index(), code);
PatchJumpTable(code->index(), code->instruction_start(),
WasmCode::kFlushICache);
InstallCode(code);
}
std::vector<WasmCode*> NativeModule::SnapshotCodeTable() const {
......@@ -642,12 +638,18 @@ WasmCode* NativeModule::CreateEmptyJumpTable(uint32_t num_wasm_functions) {
WasmCode::kOther); // tier
}
void NativeModule::PatchJumpTable(uint32_t func_index, Address target,
WasmCode::FlushICache flush_icache) {
DCHECK_LE(module_->num_imported_functions, func_index);
uint32_t slot_idx = func_index - module_->num_imported_functions;
void NativeModule::InstallCode(WasmCode* code) {
DCHECK_LT(code->index(), num_functions());
DCHECK_LE(module_->num_imported_functions, code->index());
// Update code table.
code_table_[code->index() - module_->num_imported_functions] = code;
// Patch jump table.
uint32_t slot_idx = code->index() - module_->num_imported_functions;
JumpTableAssembler::PatchJumpTableSlot(jump_table_->instruction_start(),
slot_idx, target, flush_icache);
slot_idx, code->instruction_start(),
WasmCode::kFlushICache);
}
Address NativeModule::AllocateForCode(size_t size) {
......
......@@ -371,18 +371,12 @@ class V8_EXPORT_PRIVATE NativeModule final {
WasmCode* CreateEmptyJumpTable(uint32_t num_wasm_functions);
void PatchJumpTable(uint32_t func_index, Address target,
WasmCode::FlushICache);
// Hold the {allocation_mutex_} when calling this method.
void InstallCode(WasmCode* code);
Vector<WasmCode*> code_table() const {
return {code_table_.get(), module_->num_declared_functions};
}
void set_code(uint32_t index, WasmCode* code) {
DCHECK_LT(index, num_functions());
DCHECK_LE(module_->num_imported_functions, index);
DCHECK_EQ(code->index(), index);
code_table_[index - module_->num_imported_functions] = code;
}
// Features enabled for this module. We keep a copy of the features that
// were enabled at the time of the creation of this native module,
......
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