Commit 6b145575 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm][cleanup] Fix field names in CodeSpecialization

The fields are private, so prepend them with "_".
Drive-by: Replace std::map by std::unordered_map and avoid one
redundant lookup in this map.

R=titzer@chromium.org

Change-Id: Id4aad9bb36ec84daf581a79852d56895fc05429d
Reviewed-on: https://chromium-review.googlesource.com/877882
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50742}
parent f921f749
......@@ -90,25 +90,27 @@ CodeSpecialization::~CodeSpecialization() {}
void CodeSpecialization::RelocateWasmContextReferences(Address new_context) {
DCHECK_NOT_NULL(new_context);
DCHECK_NULL(new_wasm_context_address);
new_wasm_context_address = new_context;
DCHECK_NULL(new_wasm_context_address_);
new_wasm_context_address_ = new_context;
}
void CodeSpecialization::PatchTableSize(uint32_t old_size, uint32_t new_size) {
DCHECK(old_function_table_size == 0 && new_function_table_size == 0);
old_function_table_size = old_size;
new_function_table_size = new_size;
DCHECK(old_function_table_size_ == 0 && new_function_table_size_ == 0);
old_function_table_size_ = old_size;
new_function_table_size_ = new_size;
}
void CodeSpecialization::RelocateDirectCalls(
Handle<WasmInstanceObject> instance) {
DCHECK(relocate_direct_calls_instance.is_null());
DCHECK(relocate_direct_calls_instance_.is_null());
DCHECK(!instance.is_null());
relocate_direct_calls_instance = instance;
relocate_direct_calls_instance_ = instance;
}
void CodeSpecialization::RelocatePointer(Address old_ptr, Address new_ptr) {
pointers_to_relocate.insert(std::make_pair(old_ptr, new_ptr));
DCHECK_EQ(0, pointers_to_relocate_.count(old_ptr));
DCHECK_EQ(0, pointers_to_relocate_.count(new_ptr));
pointers_to_relocate_.insert(std::make_pair(old_ptr, new_ptr));
}
bool CodeSpecialization::ApplyToWholeInstance(
......@@ -147,14 +149,14 @@ bool CodeSpecialization::ApplyToWholeInstance(
// Patch all exported functions (JS_TO_WASM_FUNCTION).
int reloc_mode = 0;
// We need to patch WASM_CONTEXT_REFERENCE to put the correct address.
if (new_wasm_context_address) {
if (new_wasm_context_address_) {
reloc_mode |= RelocInfo::ModeMask(RelocInfo::WASM_CONTEXT_REFERENCE);
}
// Patch CODE_TARGET if we shall relocate direct calls. If we patch direct
// calls, the instance registered for that (relocate_direct_calls_instance)
// calls, the instance registered for that (relocate_direct_calls_instance_)
// should match the instance we currently patch (instance).
if (!relocate_direct_calls_instance.is_null()) {
DCHECK_EQ(instance, *relocate_direct_calls_instance);
if (!relocate_direct_calls_instance_.is_null()) {
DCHECK_EQ(instance, *relocate_direct_calls_instance_);
reloc_mode |=
RelocInfo::ModeMask(FLAG_wasm_jit_to_native ? RelocInfo::JS_TO_WASM_CALL
: RelocInfo::CODE_TARGET);
......@@ -171,7 +173,7 @@ bool CodeSpecialization::ApplyToWholeInstance(
switch (mode) {
case RelocInfo::WASM_CONTEXT_REFERENCE:
it.rinfo()->set_wasm_context_reference(export_wrapper->GetIsolate(),
new_wasm_context_address,
new_wasm_context_address_,
icache_flush_mode);
break;
case RelocInfo::JS_TO_WASM_CALL: {
......@@ -210,9 +212,9 @@ bool CodeSpecialization::ApplyToWasmCode(WasmCodeWrapper code,
DCHECK_EQ(wasm::WasmCode::kFunction, code.GetWasmCode()->kind());
}
bool patch_table_size = old_function_table_size || new_function_table_size;
bool reloc_direct_calls = !relocate_direct_calls_instance.is_null();
bool reloc_pointers = pointers_to_relocate.size() > 0;
bool patch_table_size = old_function_table_size_ || new_function_table_size_;
bool reloc_direct_calls = !relocate_direct_calls_instance_.is_null();
bool reloc_pointers = pointers_to_relocate_.size() > 0;
int reloc_mode = 0;
auto add_mode = [&reloc_mode](bool cond, RelocInfo::Mode mode) {
......@@ -253,7 +255,7 @@ bool CodeSpecialization::ApplyToWasmCode(WasmCodeWrapper code,
// bytes to find the new compiled function.
size_t offset = it.rinfo()->pc() - code.GetCode()->instruction_start();
if (!patch_direct_calls_helper) {
patch_direct_calls_helper.emplace(*relocate_direct_calls_instance,
patch_direct_calls_helper.emplace(*relocate_direct_calls_instance_,
*code.GetCode());
}
int byte_pos = AdvanceSourcePositionTableIterator(
......@@ -262,7 +264,7 @@ bool CodeSpecialization::ApplyToWasmCode(WasmCodeWrapper code,
patch_direct_calls_helper->decoder,
patch_direct_calls_helper->func_bytes + byte_pos);
FixedArray* code_table =
relocate_direct_calls_instance->compiled_module()->code_table();
relocate_direct_calls_instance_->compiled_module()->code_table();
Code* new_code = Code::cast(code_table->get(called_func_index));
it.rinfo()->set_target_address(new_code->GetIsolate(),
new_code->instruction_start(),
......@@ -280,7 +282,7 @@ bool CodeSpecialization::ApplyToWasmCode(WasmCodeWrapper code,
size_t offset =
it.rinfo()->pc() - code.GetWasmCode()->instructions().start();
if (!patch_direct_calls_helper) {
patch_direct_calls_helper.emplace(*relocate_direct_calls_instance,
patch_direct_calls_helper.emplace(*relocate_direct_calls_instance_,
code.GetWasmCode());
}
int byte_pos = AdvanceSourcePositionTableIterator(
......@@ -296,8 +298,9 @@ bool CodeSpecialization::ApplyToWasmCode(WasmCodeWrapper code,
case RelocInfo::WASM_GLOBAL_HANDLE: {
DCHECK(reloc_pointers);
Address old_ptr = it.rinfo()->global_handle();
if (pointers_to_relocate.count(old_ptr) == 1) {
Address new_ptr = pointers_to_relocate[old_ptr];
auto entry = pointers_to_relocate_.find(old_ptr);
if (entry != pointers_to_relocate_.end()) {
Address new_ptr = entry->second;
it.rinfo()->set_global_handle(isolate_, new_ptr, icache_flush_mode);
changed = true;
}
......@@ -305,7 +308,7 @@ bool CodeSpecialization::ApplyToWasmCode(WasmCodeWrapper code,
case RelocInfo::WASM_FUNCTION_TABLE_SIZE_REFERENCE:
DCHECK(patch_table_size);
it.rinfo()->update_wasm_function_table_size_reference(
isolate_, old_function_table_size, new_function_table_size,
isolate_, old_function_table_size_, new_function_table_size_,
icache_flush_mode);
changed = true;
break;
......
......@@ -48,14 +48,14 @@ class CodeSpecialization {
private:
Isolate* isolate_;
Address new_wasm_context_address = 0;
Address new_wasm_context_address_ = 0;
uint32_t old_function_table_size = 0;
uint32_t new_function_table_size = 0;
uint32_t old_function_table_size_ = 0;
uint32_t new_function_table_size_ = 0;
Handle<WasmInstanceObject> relocate_direct_calls_instance;
Handle<WasmInstanceObject> relocate_direct_calls_instance_;
std::map<Address, Address> pointers_to_relocate;
std::unordered_map<Address, Address> pointers_to_relocate_;
};
} // namespace wasm
......
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