Commit 37ca8c3d authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Remove friendship between NativeModule and (de)serializer

This CL removes the friendship between {NativeModule} and
{NativeModuleSerializer}/{NativeModuleDeserializer}.
Instead, it adds a new public method ({AddDeserializedCode}) which is
being called from the deserializer.

Drive-by: Unify the argument order to {AddCode}, {AddOwnedCode} and
{WasmCode}.

R=mstarzinger@chromium.org

Bug: chromium:856938
Change-Id: I88943c90c45650e21ae6bc17395a17f86319c046
Reviewed-on: https://chromium-review.googlesource.com/1117075Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54084}
parent 38ea6697
......@@ -1048,8 +1048,9 @@ PipelineWasmCompilationJob::Status PipelineWasmCompilationJob::FinalizeJobImpl(
code_generator->tasm()->GetCode(isolate, &code_desc);
wasm::WasmCode* code = native_module_->AddCode(
code_desc, code_generator->frame()->GetTotalFrameSlotCount(),
data_.wasm_function_index(), code_generator->GetSafepointTableOffset(),
data_.wasm_function_index(), code_desc,
code_generator->frame()->GetTotalFrameSlotCount(),
code_generator->GetSafepointTableOffset(),
code_generator->GetHandlerTableOffset(),
data_.wasm_compilation_data()->GetProtectedInstructions(),
code_generator->GetSourcePositionTable(), wasm::WasmCode::kTurbofan);
......
......@@ -1880,7 +1880,7 @@ wasm::WasmCode* LiftoffCompilationUnit::FinishCompilation(
OwnedVector<trap_handler::ProtectedInstructionData>::Of(
protected_instructions_);
wasm::WasmCode* code = wasm_unit_->native_module_->AddCode(
desc, asm_.GetTotalFrameSlotCount(), wasm_unit_->func_index_,
wasm_unit_->func_index_, desc, asm_.GetTotalFrameSlotCount(),
safepoint_table_offset_, 0, std::move(protected_instructions_copy),
std::move(source_positions), wasm::WasmCode::kLiftoff);
......
This diff is collapsed.
......@@ -159,17 +159,17 @@ class V8_EXPORT_PRIVATE WasmCode final {
private:
friend class NativeModule;
WasmCode(Vector<byte> instructions, OwnedVector<const byte> reloc_info,
OwnedVector<const byte> source_pos, NativeModule* native_module,
Maybe<uint32_t> index, Kind kind, size_t constant_pool_offset,
uint32_t stack_slots, size_t safepoint_table_offset,
size_t handler_table_offset,
WasmCode(NativeModule* native_module, Maybe<uint32_t> index,
Vector<byte> instructions, uint32_t stack_slots,
size_t safepoint_table_offset, size_t handler_table_offset,
size_t constant_pool_offset,
OwnedVector<trap_handler::ProtectedInstructionData>
protected_instructions,
Tier tier)
OwnedVector<const byte> reloc_info,
OwnedVector<const byte> source_position_table, Kind kind, Tier tier)
: instructions_(instructions),
reloc_info_(std::move(reloc_info)),
source_position_table_(std::move(source_pos)),
source_position_table_(std::move(source_position_table)),
native_module_(native_module),
index_(index),
kind_(kind),
......@@ -219,13 +219,22 @@ const char* GetWasmCodeKindAsString(WasmCode::Kind);
class V8_EXPORT_PRIVATE NativeModule final {
public:
WasmCode* AddCode(const CodeDesc& desc, uint32_t frame_count, uint32_t index,
WasmCode* AddCode(uint32_t index, const CodeDesc& desc, uint32_t stack_slots,
size_t safepoint_table_offset, size_t handler_table_offset,
OwnedVector<trap_handler::ProtectedInstructionData>
protected_instructions,
OwnedVector<byte> source_position_table,
OwnedVector<const byte> source_position_table,
WasmCode::Tier tier);
WasmCode* AddDeserializedCode(
uint32_t index, Vector<const byte> instructions, uint32_t stack_slots,
size_t safepoint_table_offset, size_t handler_table_offset,
size_t constant_pool_offset,
OwnedVector<trap_handler::ProtectedInstructionData>
protected_instructions,
OwnedVector<const byte> reloc_info,
OwnedVector<const byte> source_position_table, WasmCode::Tier tier);
// A way to copy over JS-allocated code. This is because we compile
// certain wrappers using a different pipeline.
WasmCode* AddCodeCopy(Handle<Code> code, WasmCode::Kind kind, uint32_t index);
......@@ -233,7 +242,7 @@ class V8_EXPORT_PRIVATE NativeModule final {
// Add an interpreter entry. For the same reason as AddCodeCopy, we
// currently compile these using a different pipeline and we can't get a
// CodeDesc here. When adding interpreter wrappers, we do not insert them in
// the code_table, however, we let them self-identify as the {index} function
// the code_table, however, we let them self-identify as the {index} function.
WasmCode* AddInterpreterEntry(Handle<Code> code, uint32_t index);
// When starting lazy compilation, provide the WasmLazyCompile builtin by
......@@ -319,8 +328,6 @@ class V8_EXPORT_PRIVATE NativeModule final {
private:
friend class WasmCode;
friend class WasmCodeManager;
friend class NativeModuleSerializer;
friend class NativeModuleDeserializer;
friend class NativeModuleModificationScope;
NativeModule(Isolate* isolate, uint32_t num_functions,
......@@ -335,15 +342,14 @@ class V8_EXPORT_PRIVATE NativeModule final {
// module is owned by that module. Various callers get to decide on how the
// code is obtained (CodeDesc vs, as a point in time, Code*), the kind,
// whether it has an index or is anonymous, etc.
WasmCode* AddOwnedCode(Vector<const byte> orig_instructions,
OwnedVector<const byte> reloc_info,
OwnedVector<const byte> source_pos,
Maybe<uint32_t> index, WasmCode::Kind kind,
size_t constant_pool_offset, uint32_t stack_slots,
size_t safepoint_table_offset,
WasmCode* AddOwnedCode(Maybe<uint32_t> index, Vector<const byte> instructions,
uint32_t stack_slots, size_t safepoint_table_offset,
size_t handler_table_offset,
size_t constant_pool_offset,
OwnedVector<trap_handler::ProtectedInstructionData>,
WasmCode::Tier, WasmCode::FlushICache);
OwnedVector<const byte> reloc_info,
OwnedVector<const byte> source_position_table,
WasmCode::Kind, WasmCode::Tier, WasmCode::FlushICache);
WasmCode* CreateEmptyJumpTable(uint32_t num_wasm_functions);
......
......@@ -453,21 +453,19 @@ bool NativeModuleDeserializer::ReadCode(uint32_t fn_index, Reader* reader) {
OwnedVector<trap_handler::ProtectedInstructionData>::New(
protected_instructions_size);
reader->ReadVector(Vector<byte>::cast(protected_instructions.as_vector()));
WasmCode* ret = native_module_->AddOwnedCode(
code_buffer, std::move(reloc_info), std::move(source_pos), Just(fn_index),
WasmCode::kFunction, constant_pool_offset, stack_slot_count,
safepoint_table_offset, handler_table_offset,
std::move(protected_instructions), tier, WasmCode::kNoFlushICache);
native_module_->set_code(fn_index, ret);
native_module_->PatchJumpTable(fn_index, ret->instruction_start(),
WasmCode::kFlushICache);
WasmCode* code = native_module_->AddDeserializedCode(
fn_index, code_buffer, stack_slot_count, safepoint_table_offset,
handler_table_offset, constant_pool_offset,
std::move(protected_instructions), std::move(reloc_info),
std::move(source_pos), tier);
// Relocate the code.
int mask = RelocInfo::ModeMask(RelocInfo::WASM_CALL) |
RelocInfo::ModeMask(RelocInfo::WASM_STUB_CALL) |
RelocInfo::ModeMask(RelocInfo::EXTERNAL_REFERENCE);
for (RelocIterator iter(ret->instructions(), ret->reloc_info(),
ret->constant_pool(), mask);
for (RelocIterator iter(code->instructions(), code->reloc_info(),
code->constant_pool(), mask);
!iter.done(); iter.next()) {
RelocInfo::Mode mode = iter.rinfo()->rmode();
switch (mode) {
......@@ -499,12 +497,13 @@ bool NativeModuleDeserializer::ReadCode(uint32_t fn_index, Reader* reader) {
}
}
// Flush the i-cache here instead of in AddOwnedCode, to include the changes
// made while iterating over the RelocInfo above.
Assembler::FlushICache(ret->instructions().start(),
ret->instructions().size());
if (FLAG_print_code || FLAG_print_wasm_code) ret->Print();
ret->Validate();
if (FLAG_print_code || FLAG_print_wasm_code) code->Print();
code->Validate();
// Finally, flush the icache for that code.
Assembler::FlushICache(code->instructions().start(),
code->instructions().size());
return true;
}
......
......@@ -3438,7 +3438,7 @@ TEST(Liftoff_tier_up) {
memcpy(buffer.get(), sub_code->instructions().start(), sub_size);
desc.buffer = buffer.get();
desc.instr_size = static_cast<int>(sub_size);
native_module->AddCode(desc, 0, add.function_index(), 0, 0, {},
native_module->AddCode(add.function_index(), desc, 0, 0, 0, {},
OwnedVector<byte>(), WasmCode::kOther);
// Second run should now execute {sub}.
......
......@@ -176,7 +176,7 @@ class WasmCodeManagerTest : public TestWithContext,
std::unique_ptr<byte[]> exec_buff(new byte[size]);
desc.buffer = exec_buff.get();
desc.instr_size = static_cast<int>(size);
return native_module->AddCode(desc, 0, index, 0, 0, {}, OwnedVector<byte>(),
return native_module->AddCode(index, desc, 0, 0, 0, {}, OwnedVector<byte>(),
WasmCode::kOther);
}
......
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