Commit 7913a2a7 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Remove support for trampolines from WasmCodeManager.

R=clemensh@chromium.org

Change-Id: Ic16e1da4ca50070ceff7f9a441250db2d20a868f
Reviewed-on: https://chromium-review.googlesource.com/1104471
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53871}
parent 0f80a21c
......@@ -49,8 +49,6 @@ constexpr bool kModuleCanAllocateMoreMemory = false;
constexpr bool kModuleCanAllocateMoreMemory = true;
#endif
constexpr bool kNeedsTrampoline = !kModuleCanAllocateMoreMemory;
} // namespace
void DisjointAllocationPool::Merge(AddressRange range) {
......@@ -269,8 +267,6 @@ const char* GetWasmCodeKindAsString(WasmCode::Kind kind) {
return "runtime-stub";
case WasmCode::kInterpreterEntry:
return "interpreter entry";
case WasmCode::kTrampoline:
return "trampoline";
case WasmCode::kJumpTable:
return "jump table";
}
......@@ -592,37 +588,6 @@ WasmCode* NativeModule::AddCode(
return ret;
}
Address NativeModule::CreateTrampolineTo(Handle<Code> code) {
Address dest = code->raw_instruction_start();
Address ret = dest;
if (kNeedsTrampoline) {
JumpTableAssembler jtasm;
jtasm.EmitJumpTrampoline(dest);
CodeDesc code_desc;
jtasm.GetCode(nullptr, &code_desc);
Vector<const byte> instructions(code_desc.buffer,
static_cast<size_t>(code_desc.instr_size));
WasmCode* wasm_code = AddOwnedCode(instructions, // instructions
nullptr, // reloc_info
0, // reloc_size
nullptr, // source_pos
0, // source_pos_size
Nothing<uint32_t>(), // index
WasmCode::kTrampoline, // kind
0, // constant_pool_offset
0, // stack_slots
0, // safepoint_table_offset
0, // handler_table_offset
{}, // protected_instructions
WasmCode::kOther, // tier
WasmCode::kFlushICache); // flush_icache
ret = wasm_code->instruction_start();
}
DCHECK_EQ(0, trampolines_.count(dest));
trampolines_.emplace(std::make_pair(dest, ret));
return ret;
}
WasmCode* NativeModule::CreateEmptyJumpTable(uint32_t num_wasm_functions) {
// Only call this if we really need a jump table.
DCHECK_LT(0, num_wasm_functions);
......@@ -655,22 +620,6 @@ void NativeModule::PatchJumpTable(uint32_t func_index, Address target,
JumpTableAssembler::PatchJumpTableSlot(jump_table_slot, target, flush_icache);
}
Address NativeModule::GetLocalAddressFor(Handle<Code> code) {
DCHECK(Heap::IsImmovable(*code));
// Limit calls of {Code} objects on the GC heap to builtins (i.e. disallow
// calls to {CodeStub} or dynamic code). The serializer depends on this.
DCHECK(code->is_builtin());
Address index = code->raw_instruction_start();
auto trampoline_iter = trampolines_.find(index);
if (trampoline_iter == trampolines_.end()) {
return CreateTrampolineTo(code);
} else {
return trampoline_iter->second;
}
}
Address NativeModule::AllocateForCode(size_t size) {
// This happens under a lock assumed by the caller.
size = RoundUp(size, kCodeAlignment);
......
......@@ -96,7 +96,6 @@ class V8_EXPORT_PRIVATE WasmCode final {
kLazyStub,
kRuntimeStub,
kInterpreterEntry,
kTrampoline,
kJumpTable
};
......@@ -128,8 +127,7 @@ class V8_EXPORT_PRIVATE WasmCode final {
}
uint32_t index() const { return index_.ToChecked(); }
// Anonymous functions are functions that don't carry an index, like
// trampolines.
// Anonymous functions are functions that don't carry an index.
bool IsAnonymous() const { return index_.IsNothing(); }
Kind kind() const { return kind_; }
NativeModule* native_module() const { return native_module_; }
......@@ -362,8 +360,6 @@ class V8_EXPORT_PRIVATE NativeModule final {
size_t handler_table_offset,
std::unique_ptr<ProtectedInstructions>, WasmCode::Tier,
WasmCode::FlushICache);
Address GetLocalAddressFor(Handle<Code>);
Address CreateTrampolineTo(Handle<Code>);
WasmCode* CreateEmptyJumpTable(uint32_t num_wasm_functions);
......@@ -387,11 +383,6 @@ class V8_EXPORT_PRIVATE NativeModule final {
WasmCode* runtime_stub_table_[WasmCode::kRuntimeStubCount] = {nullptr};
// Maps from instruction start of an immovable code object to instruction
// start of the trampoline.
// TODO(mstarzinger): By now trampolines are unused. Remove.
std::unordered_map<Address, Address> trampolines_;
// Jump table used to easily redirect wasm function calls.
WasmCode* jump_table_ = nullptr;
......
......@@ -218,12 +218,9 @@ class V8_EXPORT_PRIVATE NativeModuleSerializer {
private:
size_t MeasureCode(const WasmCode*) const;
void WriteHeader(Writer* writer);
void WriteCode(const WasmCode*, Writer* writer);
uint32_t EncodeBuiltin(Address);
Isolate* const isolate_;
const NativeModule* const native_module_;
bool write_called_;
......@@ -231,9 +228,7 @@ class V8_EXPORT_PRIVATE NativeModuleSerializer {
// wasm code targets reverse lookup
std::map<Address, uint32_t> wasm_targets_lookup_;
std::map<Address, uint32_t> wasm_stub_targets_lookup_;
// immovable builtins and runtime entries lookup
std::map<Address, uint32_t> reference_table_lookup_;
std::map<Address, uint32_t> builtin_lookup_;
DISALLOW_COPY_AND_ASSIGN(NativeModuleSerializer);
};
......@@ -256,15 +251,6 @@ NativeModuleSerializer::NativeModuleSerializer(Isolate* isolate,
Address addr = table->address(i);
reference_table_lookup_.insert(std::make_pair(addr, i));
}
for (auto pair : native_module_->trampolines_) {
v8::internal::Code* code = Code::GetCodeFromTargetAddress(pair.first);
int builtin_index = code->builtin_index();
DCHECK_GE(builtin_index, 0);
// Note that ARM64 can only encode 26 bits in branch immediate instructions.
DCHECK_LT(builtin_index, 1 << 26);
uint32_t tag = static_cast<uint32_t>(builtin_index);
builtin_lookup_.insert(std::make_pair(pair.second, tag));
}
}
size_t NativeModuleSerializer::MeasureCode(const WasmCode* code) const {
......@@ -331,8 +317,7 @@ void NativeModuleSerializer::WriteCode(const WasmCode* code, Writer* writer) {
#endif
memcpy(code_start, code->instructions().start(), code_size);
// Relocate the code.
int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET) |
RelocInfo::ModeMask(RelocInfo::WASM_CALL) |
int mask = RelocInfo::ModeMask(RelocInfo::WASM_CALL) |
RelocInfo::ModeMask(RelocInfo::WASM_STUB_CALL) |
RelocInfo::ModeMask(RelocInfo::EXTERNAL_REFERENCE);
RelocIterator orig_iter(code->instructions(), code->reloc_info(),
......@@ -344,11 +329,6 @@ void NativeModuleSerializer::WriteCode(const WasmCode* code, Writer* writer) {
!iter.done(); iter.next(), orig_iter.next()) {
RelocInfo::Mode mode = orig_iter.rinfo()->rmode();
switch (mode) {
case RelocInfo::CODE_TARGET: {
Address orig_target = orig_iter.rinfo()->target_address();
uint32_t tag = EncodeBuiltin(orig_target);
SetWasmCalleeTag(iter.rinfo(), tag);
} break;
case RelocInfo::WASM_CALL: {
Address orig_target = orig_iter.rinfo()->wasm_call_address();
uint32_t tag = wasm_targets_lookup_[orig_target];
......@@ -378,11 +358,6 @@ void NativeModuleSerializer::WriteCode(const WasmCode* code, Writer* writer) {
}
}
uint32_t NativeModuleSerializer::EncodeBuiltin(Address address) {
DCHECK_EQ(1, builtin_lookup_.count(address));
return builtin_lookup_.find(address)->second;
}
bool NativeModuleSerializer::Write(Writer* writer) {
DCHECK(!write_called_);
write_called_ = true;
......@@ -425,7 +400,6 @@ class V8_EXPORT_PRIVATE NativeModuleDeserializer {
private:
bool ReadHeader(Reader* reader);
bool ReadCode(uint32_t fn_index, Reader* reader);
Address GetBuiltinTrampolineFromTag(uint32_t);
Isolate* const isolate_;
NativeModule* const native_module_;
......@@ -504,8 +478,7 @@ bool NativeModuleDeserializer::ReadCode(uint32_t fn_index, Reader* reader) {
WasmCode::kFlushICache);
// Relocate the code.
int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET) |
RelocInfo::ModeMask(RelocInfo::WASM_STUB_CALL) |
int mask = RelocInfo::ModeMask(RelocInfo::WASM_STUB_CALL) |
RelocInfo::ModeMask(RelocInfo::EXTERNAL_REFERENCE) |
RelocInfo::ModeMask(RelocInfo::WASM_CODE_TABLE_ENTRY);
for (RelocIterator iter(ret->instructions(), ret->reloc_info(),
......@@ -513,13 +486,6 @@ bool NativeModuleDeserializer::ReadCode(uint32_t fn_index, Reader* reader) {
!iter.done(); iter.next()) {
RelocInfo::Mode mode = iter.rinfo()->rmode();
switch (mode) {
case RelocInfo::CODE_TARGET: {
uint32_t tag = GetWasmCalleeTag(iter.rinfo());
Address target = GetBuiltinTrampolineFromTag(tag);
iter.rinfo()->set_target_address(target, SKIP_WRITE_BARRIER,
SKIP_ICACHE_FLUSH);
break;
}
case RelocInfo::WASM_STUB_CALL: {
uint32_t tag = GetWasmCalleeTag(iter.rinfo());
DCHECK_LT(tag, WasmCode::kRuntimeStubCount);
......@@ -564,12 +530,6 @@ bool NativeModuleDeserializer::ReadCode(uint32_t fn_index, Reader* reader) {
return true;
}
Address NativeModuleDeserializer::GetBuiltinTrampolineFromTag(uint32_t tag) {
int builtin_id = static_cast<int>(tag);
v8::internal::Code* builtin = isolate_->builtins()->builtin(builtin_id);
return native_module_->GetLocalAddressFor(handle(builtin, isolate_));
}
MaybeHandle<WasmModuleObject> DeserializeNativeModule(
Isolate* isolate, Vector<const byte> data, Vector<const byte> wire_bytes) {
if (!IsWasmCodegenAllowed(isolate, isolate->native_context())) {
......
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