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

[wasm] Remove obsolete stub call serialization support.

By now we no longer call {CodeStub} targets directly from WebAssembly
code and hence can remove support for serializing and deserializing such
call sites.

R=clemensh@chromium.org

Change-Id: Ibfea9fce178d49f4e739a049a6767031da3c9569
Reviewed-on: https://chromium-review.googlesource.com/1066013
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53299}
parent ecae80cd
......@@ -5,7 +5,6 @@
#include "src/wasm/function-compiler.h"
#include "src/code-factory.h"
#include "src/code-stubs.h"
#include "src/compiler/wasm-compiler.h"
#include "src/counters.h"
#include "src/macro-assembler-inl.h"
......
......@@ -11,7 +11,6 @@
#include "src/base/template-utils.h"
#include "src/base/utils/random-number-generator.h"
#include "src/code-factory.h"
#include "src/code-stubs.h"
#include "src/compiler/wasm-compiler.h"
#include "src/counters.h"
#include "src/identity-map.h"
......
......@@ -10,7 +10,6 @@
#include "src/base/atomic-utils.h"
#include "src/base/macros.h"
#include "src/base/platform/platform.h"
#include "src/code-stubs.h"
#include "src/codegen.h"
#include "src/disassembler.h"
#include "src/globals.h"
......@@ -625,6 +624,10 @@ Address NativeModule::CreateTrampolineTo(Handle<Code> code) {
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()) {
......
......@@ -7,7 +7,6 @@
#include "src/api.h"
#include "src/assembler-inl.h"
#include "src/code-stubs.h"
#include "src/compiler/wasm-compiler.h"
#include "src/debug/interface-types.h"
#include "src/frames-inl.h"
......
......@@ -5,7 +5,6 @@
#include "src/wasm/wasm-serialization.h"
#include "src/assembler-inl.h"
#include "src/code-stubs.h"
#include "src/external-reference-table.h"
#include "src/objects-inl.h"
#include "src/objects.h"
......@@ -200,14 +199,6 @@ constexpr size_t kCodeHeaderSize =
sizeof(size_t) + // protected instructions size
sizeof(WasmCode::Tier); // tier
// Bitfields used for encoding stub and builtin ids in a tag. We only use 26
// bits total as ARM64 can only encode 26 bits in branch immediate instructions.
class IsStubIdField : public BitField<bool, 0, 1> {};
class StubOrBuiltinIdField
: public BitField<uint32_t, IsStubIdField::kNext, 25> {};
static_assert(StubOrBuiltinIdField::kNext == 26,
"ARM64 only supports 26 bits for this field");
} // namespace
class V8_EXPORT_PRIVATE NativeModuleSerializer {
......@@ -219,24 +210,21 @@ class V8_EXPORT_PRIVATE NativeModuleSerializer {
bool Write(Writer* writer);
private:
size_t MeasureCopiedStubs() const;
size_t MeasureCode(const WasmCode*) const;
void WriteHeader(Writer* writer);
void WriteCopiedStubs(Writer* writer);
void WriteCode(const WasmCode*, Writer* writer);
uint32_t EncodeBuiltinOrStub(Address);
uint32_t EncodeBuiltin(Address);
Isolate* const isolate_;
const NativeModule* const native_module_;
bool write_called_;
// wasm and copied stubs reverse lookup
// wasm code targets reverse lookup
std::map<Address, uint32_t> wasm_targets_lookup_;
// immovable builtins and runtime entries lookup
std::map<Address, uint32_t> reference_table_lookup_;
std::map<Address, uint32_t> stub_lookup_;
std::map<Address, uint32_t> builtin_lookup_;
DISALLOW_COPY_AND_ASSIGN(NativeModuleSerializer);
......@@ -258,23 +246,14 @@ NativeModuleSerializer::NativeModuleSerializer(Isolate* isolate,
for (auto pair : native_module_->trampolines_) {
v8::internal::Code* code = Code::GetCodeFromTargetAddress(pair.first);
int builtin_index = code->builtin_index();
if (builtin_index >= 0) {
uint32_t tag = static_cast<uint32_t>(builtin_index);
builtin_lookup_.insert(std::make_pair(pair.second, tag));
}
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::MeasureCopiedStubs() const {
size_t size = sizeof(uint32_t); // number of stubs
for (auto pair : native_module_->trampolines_) {
v8::internal::Code* code = Code::GetCodeFromTargetAddress(pair.first);
int builtin_index = code->builtin_index();
if (builtin_index < 0) size += sizeof(uint32_t); // stub key
}
return size;
}
size_t NativeModuleSerializer::MeasureCode(const WasmCode* code) const {
return code->instructions().size() + code->reloc_info().size() +
code->source_positions().size() +
......@@ -283,7 +262,7 @@ size_t NativeModuleSerializer::MeasureCode(const WasmCode* code) const {
}
size_t NativeModuleSerializer::Measure() const {
size_t size = kHeaderSize + MeasureCopiedStubs();
size_t size = kHeaderSize;
uint32_t first_wasm_fn = native_module_->num_imported_functions();
uint32_t total_fns = native_module_->function_count();
for (uint32_t i = first_wasm_fn; i < total_fns; ++i) {
......@@ -298,26 +277,6 @@ void NativeModuleSerializer::WriteHeader(Writer* writer) {
writer->Write(native_module_->num_imported_functions());
}
void NativeModuleSerializer::WriteCopiedStubs(Writer* writer) {
// Write the number of stubs and their keys.
// TODO(all) Serialize the stubs as WasmCode.
size_t stubs_size = MeasureCopiedStubs();
// Get the stub count from the number of keys.
size_t num_stubs = (stubs_size - sizeof(uint32_t)) / sizeof(uint32_t);
writer->Write(static_cast<uint32_t>(num_stubs));
uint32_t stub_id = 0;
for (auto pair : native_module_->trampolines_) {
v8::internal::Code* code = Code::GetCodeFromTargetAddress(pair.first);
int builtin_index = code->builtin_index();
if (builtin_index < 0) {
stub_lookup_.insert(std::make_pair(pair.second, stub_id));
writer->Write(code->stub_key());
++stub_id;
}
}
}
void NativeModuleSerializer::WriteCode(const WasmCode* code, Writer* writer) {
// Write the size of the entire code section, followed by the code header.
writer->Write(MeasureCode(code));
......@@ -370,7 +329,7 @@ void NativeModuleSerializer::WriteCode(const WasmCode* code, Writer* writer) {
switch (mode) {
case RelocInfo::CODE_TARGET: {
Address orig_target = orig_iter.rinfo()->target_address();
uint32_t tag = EncodeBuiltinOrStub(orig_target);
uint32_t tag = EncodeBuiltin(orig_target);
SetWasmCalleeTag(iter.rinfo(), tag);
} break;
case RelocInfo::WASM_CALL: {
......@@ -402,20 +361,9 @@ void NativeModuleSerializer::WriteCode(const WasmCode* code, Writer* writer) {
}
}
uint32_t NativeModuleSerializer::EncodeBuiltinOrStub(Address address) {
auto builtin_iter = builtin_lookup_.find(address);
uint32_t tag = 0;
if (builtin_iter != builtin_lookup_.end()) {
uint32_t id = builtin_iter->second;
DCHECK_LT(id, std::numeric_limits<uint16_t>::max());
tag = IsStubIdField::encode(false) | StubOrBuiltinIdField::encode(id);
} else {
auto stub_iter = stub_lookup_.find(address);
DCHECK(stub_iter != stub_lookup_.end());
uint32_t id = stub_iter->second;
tag = IsStubIdField::encode(true) | StubOrBuiltinIdField::encode(id);
}
return tag;
uint32_t NativeModuleSerializer::EncodeBuiltin(Address address) {
DCHECK_EQ(1, builtin_lookup_.count(address));
return builtin_lookup_.find(address)->second;
}
bool NativeModuleSerializer::Write(Writer* writer) {
......@@ -423,7 +371,6 @@ bool NativeModuleSerializer::Write(Writer* writer) {
write_called_ = true;
WriteHeader(writer);
WriteCopiedStubs(writer);
uint32_t total_fns = native_module_->function_count();
uint32_t first_wasm_fn = native_module_->num_imported_functions();
......@@ -465,13 +412,10 @@ class V8_EXPORT_PRIVATE NativeModuleDeserializer {
private:
bool ReadHeader(Reader* reader);
bool ReadCode(uint32_t fn_index, Reader* reader);
bool ReadStubs(Reader* reader);
Address GetTrampolineOrStubFromTag(uint32_t);
Address GetBuiltinTrampolineFromTag(uint32_t);
Isolate* const isolate_;
NativeModule* const native_module_;
std::vector<Address> stubs_;
bool read_called_;
DISALLOW_COPY_AND_ASSIGN(NativeModuleDeserializer);
......@@ -486,7 +430,6 @@ bool NativeModuleDeserializer::Read(Reader* reader) {
read_called_ = true;
if (!ReadHeader(reader)) return false;
if (!ReadStubs(reader)) return false;
uint32_t total_fns = native_module_->function_count();
uint32_t first_wasm_fn = native_module_->num_imported_functions();
for (uint32_t i = first_wasm_fn; i < total_fns; ++i) {
......@@ -502,18 +445,6 @@ bool NativeModuleDeserializer::ReadHeader(Reader* reader) {
imports == native_module_->num_imported_functions();
}
bool NativeModuleDeserializer::ReadStubs(Reader* reader) {
size_t num_stubs = reader->Read<uint32_t>();
stubs_.reserve(num_stubs);
for (size_t i = 0; i < num_stubs; ++i) {
uint32_t key = reader->Read<uint32_t>();
v8::internal::Code* stub =
*(v8::internal::CodeStub::GetCode(isolate_, key).ToHandleChecked());
stubs_.push_back(native_module_->GetLocalAddressFor(handle(stub)));
}
return true;
}
bool NativeModuleDeserializer::ReadCode(uint32_t fn_index, Reader* reader) {
size_t code_section_size = reader->Read<size_t>();
USE(code_section_size);
......@@ -576,7 +507,7 @@ bool NativeModuleDeserializer::ReadCode(uint32_t fn_index, Reader* reader) {
}
case RelocInfo::CODE_TARGET: {
uint32_t tag = GetWasmCalleeTag(iter.rinfo());
Address target = GetTrampolineOrStubFromTag(tag);
Address target = GetBuiltinTrampolineFromTag(tag);
iter.rinfo()->set_target_address(target, SKIP_WRITE_BARRIER,
SKIP_ICACHE_FLUSH);
break;
......@@ -617,14 +548,10 @@ bool NativeModuleDeserializer::ReadCode(uint32_t fn_index, Reader* reader) {
return true;
}
Address NativeModuleDeserializer::GetTrampolineOrStubFromTag(uint32_t tag) {
uint32_t id = StubOrBuiltinIdField::decode(tag);
if (IsStubIdField::decode(tag)) {
return stubs_[id];
} else {
v8::internal::Code* builtin = isolate_->builtins()->builtin(id);
return native_module_->GetLocalAddressFor(handle(builtin));
}
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));
}
MaybeHandle<WasmModuleObject> DeserializeNativeModule(
......
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