diff --git a/src/compiler/backend/code-generator.cc b/src/compiler/backend/code-generator.cc index a8e3b38e80..a441a36496 100644 --- a/src/compiler/backend/code-generator.cc +++ b/src/compiler/backend/code-generator.cc @@ -432,9 +432,10 @@ OwnedVector CodeGenerator::GetSourcePositionTable() { return source_position_table_builder_.ToSourcePositionTableVector(); } -OwnedVector CodeGenerator::GetProtectedInstructionsData() { - return OwnedVector::Of( - Vector::cast(VectorOf(protected_instructions_))); +OwnedVector +CodeGenerator::GetProtectedInstructions() { + return OwnedVector::Of( + protected_instructions_); } MaybeHandle CodeGenerator::FinalizeCode() { diff --git a/src/compiler/backend/code-generator.h b/src/compiler/backend/code-generator.h index 425250ef9b..7695cc16a4 100644 --- a/src/compiler/backend/code-generator.h +++ b/src/compiler/backend/code-generator.h @@ -125,7 +125,8 @@ class V8_EXPORT_PRIVATE CodeGenerator final : public GapResolver::Assembler { MaybeHandle FinalizeCode(); OwnedVector GetSourcePositionTable(); - OwnedVector GetProtectedInstructionsData(); + OwnedVector + GetProtectedInstructions(); InstructionSequence* instructions() const { return instructions_; } FrameAccessState* frame_access_state() const { return frame_access_state_; } diff --git a/src/compiler/pipeline.cc b/src/compiler/pipeline.cc index 2c97e1ab51..e7285f0074 100644 --- a/src/compiler/pipeline.cc +++ b/src/compiler/pipeline.cc @@ -2765,8 +2765,7 @@ wasm::WasmCompilationResult Pipeline::GenerateCodeForWasmNativeStub( static_cast(code_generator->GetHandlerTableOffset())); result.instr_buffer = instruction_buffer->ReleaseBuffer(); result.source_positions = code_generator->GetSourcePositionTable(); - result.protected_instructions_data = - code_generator->GetProtectedInstructionsData(); + result.protected_instructions = code_generator->GetProtectedInstructions(); result.frame_slot_count = code_generator->frame()->GetTotalFrameSlotCount(); result.tagged_parameter_slots = call_descriptor->GetTaggedParameterSlots(); result.result_tier = wasm::ExecutionTier::kTurbofan; @@ -2973,8 +2972,7 @@ void Pipeline::GenerateCodeForWasmFunction( result->frame_slot_count = code_generator->frame()->GetTotalFrameSlotCount(); result->tagged_parameter_slots = call_descriptor->GetTaggedParameterSlots(); result->source_positions = code_generator->GetSourcePositionTable(); - result->protected_instructions_data = - code_generator->GetProtectedInstructionsData(); + result->protected_instructions = code_generator->GetProtectedInstructions(); result->result_tier = wasm::ExecutionTier::kTurbofan; if (data.info()->trace_turbo_json_enabled()) { diff --git a/src/compiler/wasm-compiler.cc b/src/compiler/wasm-compiler.cc index 7c8de5ee16..c41deac9a7 100644 --- a/src/compiler/wasm-compiler.cc +++ b/src/compiler/wasm-compiler.cc @@ -6666,9 +6666,8 @@ wasm::WasmCode* CompileWasmCapiCallWrapper(wasm::WasmEngine* wasm_engine, WasmStubAssemblerOptions(), source_positions); std::unique_ptr wasm_code = native_module->AddCode( wasm::kAnonymousFuncIndex, result.code_desc, result.frame_slot_count, - result.tagged_parameter_slots, - result.protected_instructions_data.as_vector(), - result.source_positions.as_vector(), wasm::WasmCode::kWasmToCapiWrapper, + result.tagged_parameter_slots, std::move(result.protected_instructions), + std::move(result.source_positions), wasm::WasmCode::kWasmToCapiWrapper, wasm::ExecutionTier::kNone); return native_module->PublishCode(std::move(wasm_code)); } diff --git a/src/utils/vector.h b/src/utils/vector.h index 71dadc6c0e..2398ddaeca 100644 --- a/src/utils/vector.h +++ b/src/utils/vector.h @@ -9,7 +9,6 @@ #include #include #include -#include #include "src/common/checks.h" #include "src/common/globals.h" @@ -117,14 +116,6 @@ class Vector { template static constexpr Vector cast(Vector input) { - // Casting is potentially dangerous, so be really restrictive here. This - // might be lifted once we have use cases for that. - STATIC_ASSERT(std::is_pod::value); - STATIC_ASSERT(std::is_pod::value); -#if V8_HAS_CXX14_CONSTEXPR - DCHECK_EQ(0, (input.length() * sizeof(S)) % sizeof(T)); - DCHECK_EQ(0, reinterpret_cast(input.begin()) % alignof(T)); -#endif return Vector(reinterpret_cast(input.begin()), input.length() * sizeof(S) / sizeof(T)); } diff --git a/src/wasm/baseline/liftoff-compiler.cc b/src/wasm/baseline/liftoff-compiler.cc index 60b1dd6255..026933e452 100644 --- a/src/wasm/baseline/liftoff-compiler.cc +++ b/src/wasm/baseline/liftoff-compiler.cc @@ -321,9 +321,10 @@ class LiftoffCompiler { return source_position_table_builder_.ToSourcePositionTableVector(); } - OwnedVector GetProtectedInstructionsData() const { - return OwnedVector::Of( - Vector::cast(VectorOf(protected_instructions_))); + OwnedVector GetProtectedInstructions() + const { + return OwnedVector::Of( + protected_instructions_); } uint32_t GetTotalFrameSlotCount() const { @@ -2795,7 +2796,7 @@ WasmCompilationResult ExecuteLiftoffCompilation( compiler->GetCode(&result.code_desc); result.instr_buffer = instruction_buffer->ReleaseBuffer(); result.source_positions = compiler->GetSourcePositionTable(); - result.protected_instructions_data = compiler->GetProtectedInstructionsData(); + result.protected_instructions = compiler->GetProtectedInstructions(); result.frame_slot_count = compiler->GetTotalFrameSlotCount(); result.tagged_parameter_slots = call_descriptor->GetTaggedParameterSlots(); result.func_index = func_index; diff --git a/src/wasm/function-compiler.h b/src/wasm/function-compiler.h index a511f19b76..e382c1b310 100644 --- a/src/wasm/function-compiler.h +++ b/src/wasm/function-compiler.h @@ -67,7 +67,7 @@ struct WasmCompilationResult { uint32_t frame_slot_count = 0; uint32_t tagged_parameter_slots = 0; OwnedVector source_positions; - OwnedVector protected_instructions_data; + OwnedVector protected_instructions; int func_index = kAnonymousFuncIndex; ExecutionTier requested_tier; ExecutionTier result_tier; diff --git a/src/wasm/module-compiler.cc b/src/wasm/module-compiler.cc index 5174f51faa..7ca162ddc9 100644 --- a/src/wasm/module-compiler.cc +++ b/src/wasm/module-compiler.cc @@ -2972,9 +2972,8 @@ WasmCode* CompileImportWrapper( wasm_engine, &env, kind, sig, source_positions); std::unique_ptr wasm_code = native_module->AddCode( result.func_index, result.code_desc, result.frame_slot_count, - result.tagged_parameter_slots, - result.protected_instructions_data.as_vector(), - result.source_positions.as_vector(), GetCodeKind(result), + result.tagged_parameter_slots, std::move(result.protected_instructions), + std::move(result.source_positions), GetCodeKind(result), ExecutionTier::kNone); WasmCode* published_code = native_module->PublishCode(std::move(wasm_code)); (*cache_scope)[key] = published_code; diff --git a/src/wasm/wasm-code-manager.cc b/src/wasm/wasm-code-manager.cc index 1b1ed3eb1e..be0217ee8c 100644 --- a/src/wasm/wasm-code-manager.cc +++ b/src/wasm/wasm-code-manager.cc @@ -147,32 +147,17 @@ int WasmCode::code_comments_size() const { return static_cast(unpadded_binary_size_ - code_comments_offset_); } -std::unique_ptr WasmCode::ConcatenateBytes( - std::initializer_list> vectors) { - size_t total_size = 0; - for (auto& vec : vectors) total_size += vec.size(); - // Use default-initialization (== no initialization). - std::unique_ptr result{new byte[total_size]}; - byte* ptr = result.get(); - for (auto& vec : vectors) { - memcpy(ptr, vec.begin(), vec.size()); - ptr += vec.size(); - } - return result; -} - void WasmCode::RegisterTrapHandlerData() { DCHECK(!has_trap_handler_index()); if (kind() != WasmCode::kFunction) return; - if (protected_instructions_size_ == 0) return; + if (protected_instructions_.empty()) return; Address base = instruction_start(); size_t size = instructions().size(); - auto protected_instruction_data = this->protected_instructions(); const int index = - RegisterHandlerData(base, size, protected_instruction_data.size(), - protected_instruction_data.begin()); + RegisterHandlerData(base, size, protected_instructions().size(), + protected_instructions().begin()); // TODO(eholk): if index is negative, fail. CHECK_LE(0, index); @@ -337,7 +322,7 @@ void WasmCode::Disassemble(const char* name, std::ostream& os, os << "\n"; } - if (protected_instructions_size_ > 0) { + if (!protected_instructions_.empty()) { os << "Protected instructions:\n pc offset land pad\n"; for (auto& data : protected_instructions()) { os << std::setw(10) << std::hex << data.instr_offset << std::setw(10) @@ -379,7 +364,7 @@ void WasmCode::Disassemble(const char* name, std::ostream& os, os << "\n"; } - os << "RelocInfo (size = " << reloc_info().size() << ")\n"; + os << "RelocInfo (size = " << reloc_info_.size() << ")\n"; for (RelocIterator it(instructions(), reloc_info(), constant_pool()); !it.done(); it.next()) { it.rinfo()->Print(nullptr, os); @@ -870,22 +855,22 @@ WasmCode* NativeModule::AddCodeForTesting(Handle code) { // Flush the i-cache after relocation. FlushInstructionCache(dst_code_bytes.begin(), dst_code_bytes.size()); - std::unique_ptr new_code{ - new WasmCode{this, // native_module - kAnonymousFuncIndex, // index - dst_code_bytes, // instructions - stack_slots, // stack_slots - 0, // tagged_parameter_slots - safepoint_table_offset, // safepoint_table_offset - handler_table_offset, // handler_table_offset - constant_pool_offset, // constant_pool_offset - code_comments_offset, // code_comments_offset - instructions.length(), // unpadded_binary_size - {}, // protected_instructions - reloc_info.as_vector(), // reloc_info - source_pos.as_vector(), // source positions - WasmCode::kFunction, // kind - ExecutionTier::kNone}}; // tier + std::unique_ptr new_code{new WasmCode{ + this, // native_module + kAnonymousFuncIndex, // index + dst_code_bytes, // instructions + stack_slots, // stack_slots + 0, // tagged_parameter_slots + safepoint_table_offset, // safepoint_table_offset + handler_table_offset, // handler_table_offset + constant_pool_offset, // constant_pool_offset + code_comments_offset, // code_comments_offset + instructions.length(), // unpadded_binary_size + OwnedVector{}, // protected_instructions + std::move(reloc_info), // reloc_info + std::move(source_pos), // source positions + WasmCode::kFunction, // kind + ExecutionTier::kNone}}; // tier new_code->MaybePrint(nullptr); new_code->Validate(); @@ -929,27 +914,33 @@ void NativeModule::UseLazyStub(uint32_t func_index) { std::unique_ptr NativeModule::AddCode( int index, const CodeDesc& desc, int stack_slots, - int tagged_parameter_slots, Vector protected_instructions_data, - Vector source_position_table, WasmCode::Kind kind, + int tagged_parameter_slots, + OwnedVector protected_instructions, + OwnedVector source_position_table, WasmCode::Kind kind, ExecutionTier tier) { Vector code_space = code_allocator_.AllocateForCode(this, desc.instr_size); auto jump_table_ref = FindJumpTablesForRegion(base::AddressRegionOf(code_space)); return AddCodeWithCodeSpace(index, desc, stack_slots, tagged_parameter_slots, - protected_instructions_data, - source_position_table, kind, tier, code_space, - jump_table_ref); + std::move(protected_instructions), + std::move(source_position_table), kind, tier, + code_space, jump_table_ref); } std::unique_ptr NativeModule::AddCodeWithCodeSpace( int index, const CodeDesc& desc, int stack_slots, - int tagged_parameter_slots, Vector protected_instructions_data, - Vector source_position_table, WasmCode::Kind kind, + int tagged_parameter_slots, + OwnedVector protected_instructions, + OwnedVector source_position_table, WasmCode::Kind kind, ExecutionTier tier, Vector dst_code_bytes, const JumpTablesRef& jump_tables) { - Vector reloc_info{desc.buffer + desc.buffer_size - desc.reloc_size, - static_cast(desc.reloc_size)}; + OwnedVector reloc_info; + if (desc.reloc_size > 0) { + reloc_info = OwnedVector::New(desc.reloc_size); + memcpy(reloc_info.start(), desc.buffer + desc.buffer_size - desc.reloc_size, + desc.reloc_size); + } // TODO(jgruber,v8:8758): Remove this translation. It exists only because // CodeDesc contains real offsets but WasmCode expects an offset of 0 to mean @@ -971,8 +962,8 @@ std::unique_ptr NativeModule::AddCodeWithCodeSpace( RelocInfo::ModeMask(RelocInfo::WASM_STUB_CALL); Address code_start = reinterpret_cast
(dst_code_bytes.begin()); Address constant_pool_start = code_start + constant_pool_offset; - for (RelocIterator it(dst_code_bytes, reloc_info, constant_pool_start, - mode_mask); + for (RelocIterator it(dst_code_bytes, reloc_info.as_vector(), + constant_pool_start, mode_mask); !it.done(); it.next()) { RelocInfo::Mode mode = it.rinfo()->rmode(); if (RelocInfo::IsWasmCall(mode)) { @@ -996,8 +987,8 @@ std::unique_ptr NativeModule::AddCodeWithCodeSpace( std::unique_ptr code{new WasmCode{ this, index, dst_code_bytes, stack_slots, tagged_parameter_slots, safepoint_table_offset, handler_table_offset, constant_pool_offset, - code_comments_offset, instr_size, protected_instructions_data, reloc_info, - source_position_table, kind, tier}}; + code_comments_offset, instr_size, std::move(protected_instructions), + std::move(reloc_info), std::move(source_position_table), kind, tier}}; code->MaybePrint(); code->Validate(); @@ -1086,9 +1077,10 @@ WasmCode* NativeModule::AddDeserializedCode( int tagged_parameter_slots, int safepoint_table_offset, int handler_table_offset, int constant_pool_offset, int code_comments_offset, int unpadded_binary_size, - Vector protected_instructions_data, - Vector reloc_info, Vector source_position_table, - WasmCode::Kind kind, ExecutionTier tier) { + OwnedVector protected_instructions, + OwnedVector reloc_info, + OwnedVector source_position_table, WasmCode::Kind kind, + ExecutionTier tier) { Vector dst_code_bytes = code_allocator_.AllocateForCode(this, instructions.size()); memcpy(dst_code_bytes.begin(), instructions.begin(), instructions.size()); @@ -1096,8 +1088,9 @@ WasmCode* NativeModule::AddDeserializedCode( std::unique_ptr code{new WasmCode{ this, index, dst_code_bytes, stack_slots, tagged_parameter_slots, safepoint_table_offset, handler_table_offset, constant_pool_offset, - code_comments_offset, unpadded_binary_size, protected_instructions_data, - reloc_info, source_position_table, kind, tier}}; + code_comments_offset, unpadded_binary_size, + std::move(protected_instructions), std::move(reloc_info), + std::move(source_position_table), kind, tier}}; // 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. @@ -1148,22 +1141,22 @@ WasmCode* NativeModule::CreateEmptyJumpTableInRegion( this, jump_table_size, region, allocator_lock); DCHECK(!code_space.empty()); ZapCode(reinterpret_cast
(code_space.begin()), code_space.size()); - std::unique_ptr code{ - new WasmCode{this, // native_module - kAnonymousFuncIndex, // index - code_space, // instructions - 0, // stack_slots - 0, // tagged_parameter_slots - 0, // safepoint_table_offset - jump_table_size, // handler_table_offset - jump_table_size, // constant_pool_offset - jump_table_size, // code_comments_offset - jump_table_size, // unpadded_binary_size - {}, // protected_instructions - {}, // reloc_info - {}, // source_pos - WasmCode::kJumpTable, // kind - ExecutionTier::kNone}}; // tier + std::unique_ptr code{new WasmCode{ + this, // native_module + kAnonymousFuncIndex, // index + code_space, // instructions + 0, // stack_slots + 0, // tagged_parameter_slots + 0, // safepoint_table_offset + jump_table_size, // handler_table_offset + jump_table_size, // constant_pool_offset + jump_table_size, // code_comments_offset + jump_table_size, // unpadded_binary_size + OwnedVector{}, // protected_instructions + OwnedVector{}, // reloc_info + OwnedVector{}, // source_pos + WasmCode::kJumpTable, // kind + ExecutionTier::kNone}}; // tier return PublishCode(std::move(code)); } @@ -1789,9 +1782,8 @@ std::vector NativeModule::AddCompiledCode( code_space += code_size; generated_code.emplace_back(AddCodeWithCodeSpace( result.func_index, result.code_desc, result.frame_slot_count, - result.tagged_parameter_slots, - result.protected_instructions_data.as_vector(), - result.source_positions.as_vector(), GetCodeKind(result), + result.tagged_parameter_slots, std::move(result.protected_instructions), + std::move(result.source_positions), GetCodeKind(result), result.result_tier, this_code_space, jump_tables)); } DCHECK_EQ(0, code_space.size()); diff --git a/src/wasm/wasm-code-manager.h b/src/wasm/wasm-code-manager.h index 17e108983a..aab8998d82 100644 --- a/src/wasm/wasm-code-manager.h +++ b/src/wasm/wasm-code-manager.h @@ -127,12 +127,9 @@ class V8_EXPORT_PRIVATE WasmCode final { Address instruction_start() const { return reinterpret_cast
(instructions_.begin()); } - Vector reloc_info() const { - return {protected_instructions_data().end(), - static_cast(reloc_info_size_)}; - } + Vector reloc_info() const { return reloc_info_.as_vector(); } Vector source_positions() const { - return {reloc_info().end(), static_cast(source_positions_size_)}; + return source_position_table_.as_vector(); } // TODO(clemensb): Make this return int. @@ -163,15 +160,9 @@ class V8_EXPORT_PRIVATE WasmCode final { pc < reinterpret_cast
(instructions_.end()); } - Vector protected_instructions_data() const { - return {meta_data_.get(), - static_cast(protected_instructions_size_)}; - } - - Vector protected_instructions() + Vector protected_instructions() const { - return Vector::cast( - protected_instructions_data()); + return protected_instructions_.as_vector(); } void Validate() const; @@ -227,17 +218,15 @@ class V8_EXPORT_PRIVATE WasmCode final { int safepoint_table_offset, int handler_table_offset, int constant_pool_offset, int code_comments_offset, int unpadded_binary_size, - Vector protected_instructions_data, - Vector reloc_info, - Vector source_position_table, Kind kind, + OwnedVector + protected_instructions, + OwnedVector reloc_info, + OwnedVector source_position_table, Kind kind, ExecutionTier tier) : instructions_(instructions), + reloc_info_(std::move(reloc_info)), + source_position_table_(std::move(source_position_table)), native_module_(native_module), - meta_data_(ConcatenateBytes( - {protected_instructions_data, reloc_info, source_position_table})), - reloc_info_size_(reloc_info.length()), - source_positions_size_(source_position_table.length()), - protected_instructions_size_(protected_instructions_data.length()), index_(index), kind_(kind), constant_pool_offset_(constant_pool_offset), @@ -247,6 +236,7 @@ class V8_EXPORT_PRIVATE WasmCode final { handler_table_offset_(handler_table_offset), code_comments_offset_(code_comments_offset), unpadded_binary_size_(unpadded_binary_size), + protected_instructions_(std::move(protected_instructions)), tier_(tier) { DCHECK_LE(safepoint_table_offset, unpadded_binary_size); DCHECK_LE(handler_table_offset, unpadded_binary_size); @@ -254,9 +244,6 @@ class V8_EXPORT_PRIVATE WasmCode final { DCHECK_LE(constant_pool_offset, unpadded_binary_size); } - std::unique_ptr ConcatenateBytes( - std::initializer_list>); - // Code objects that have been registered with the global trap handler within // this process, will have a {trap_handler_index} associated with them. int trap_handler_index() const { @@ -278,16 +265,9 @@ class V8_EXPORT_PRIVATE WasmCode final { V8_NOINLINE bool DecRefOnPotentiallyDeadCode(); Vector instructions_; + OwnedVector reloc_info_; + OwnedVector source_position_table_; NativeModule* native_module_ = nullptr; - // {meta_data_} contains several byte vectors concatenated into one: - // - protected instructions data of size {protected_instructions_size_} - // - relocation info of size {reloc_info_size_} - // - source positions of size {source_positions_size_} - // Note that the protected instructions come first to ensure alignment. - std::unique_ptr meta_data_; - const int reloc_info_size_; - const int source_positions_size_; - const int protected_instructions_size_; int index_; Kind kind_; int constant_pool_offset_ = 0; @@ -302,6 +282,7 @@ class V8_EXPORT_PRIVATE WasmCode final { int code_comments_offset_ = 0; int unpadded_binary_size_ = 0; int trap_handler_index_ = -1; + OwnedVector protected_instructions_; ExecutionTier tier_; // WasmCode is ref counted. Counters are held by: @@ -323,7 +304,7 @@ class V8_EXPORT_PRIVATE WasmCode final { // often for rather small functions. // Increase the limit if needed, but first check if the size increase is // justified. -STATIC_ASSERT(sizeof(WasmCode) <= 96); +STATIC_ASSERT(sizeof(WasmCode) <= 120); WasmCode::Kind GetCodeKind(const WasmCompilationResult& result); @@ -430,11 +411,13 @@ class V8_EXPORT_PRIVATE NativeModule final { // {AddCode} is thread safe w.r.t. other calls to {AddCode} or methods adding // code below, i.e. it can be called concurrently from background threads. // The returned code still needs to be published via {PublishCode}. - std::unique_ptr AddCode(int index, const CodeDesc& desc, - int stack_slots, int tagged_parameter_slots, - Vector protected_instructions, - Vector source_position_table, - WasmCode::Kind kind, ExecutionTier tier); + std::unique_ptr AddCode( + int index, const CodeDesc& desc, int stack_slots, + int tagged_parameter_slots, + OwnedVector + protected_instructions, + OwnedVector source_position_table, WasmCode::Kind kind, + ExecutionTier tier); // {PublishCode} makes the code available to the system by entering it into // the code table and patching the jump table. It returns a raw pointer to the @@ -448,9 +431,11 @@ class V8_EXPORT_PRIVATE NativeModule final { int tagged_parameter_slots, int safepoint_table_offset, int handler_table_offset, int constant_pool_offset, int code_comments_offset, int unpadded_binary_size, - Vector protected_instructions_data, - Vector reloc_info, Vector source_position_table, - WasmCode::Kind kind, ExecutionTier tier); + OwnedVector + protected_instructions, + OwnedVector reloc_info, + OwnedVector source_position_table, WasmCode::Kind kind, + ExecutionTier tier); // Adds anonymous code for testing purposes. WasmCode* AddCodeForTesting(Handle code); @@ -616,8 +601,9 @@ class V8_EXPORT_PRIVATE NativeModule final { std::unique_ptr AddCodeWithCodeSpace( int index, const CodeDesc& desc, int stack_slots, int tagged_parameter_slots, - Vector protected_instructions_data, - Vector source_position_table, WasmCode::Kind kind, + OwnedVector + protected_instructions, + OwnedVector source_position_table, WasmCode::Kind kind, ExecutionTier tier, Vector code_space, const JumpTablesRef& jump_tables_ref); diff --git a/src/wasm/wasm-debug.cc b/src/wasm/wasm-debug.cc index 09f9d6110c..3b0b73bb2a 100644 --- a/src/wasm/wasm-debug.cc +++ b/src/wasm/wasm-debug.cc @@ -900,9 +900,8 @@ void WasmDebugInfo::RedirectToInterpreter(Handle debug_info, module->functions[func_index].sig); std::unique_ptr wasm_code = native_module->AddCode( func_index, result.code_desc, result.frame_slot_count, - result.tagged_parameter_slots, - result.protected_instructions_data.as_vector(), - result.source_positions.as_vector(), wasm::WasmCode::kInterpreterEntry, + result.tagged_parameter_slots, std::move(result.protected_instructions), + std::move(result.source_positions), wasm::WasmCode::kInterpreterEntry, wasm::ExecutionTier::kInterpreter); native_module->PublishCode(std::move(wasm_code)); DCHECK(native_module->IsRedirectedToInterpreter(func_index)); diff --git a/src/wasm/wasm-objects.cc b/src/wasm/wasm-objects.cc index 5272d87b26..16e64651b1 100644 --- a/src/wasm/wasm-objects.cc +++ b/src/wasm/wasm-objects.cc @@ -1460,9 +1460,8 @@ void WasmInstanceObject::ImportWasmJSFunctionIntoTable( isolate->wasm_engine(), &env, kind, sig, false); std::unique_ptr wasm_code = native_module->AddCode( result.func_index, result.code_desc, result.frame_slot_count, - result.tagged_parameter_slots, - result.protected_instructions_data.as_vector(), - result.source_positions.as_vector(), GetCodeKind(result), + result.tagged_parameter_slots, std::move(result.protected_instructions), + std::move(result.source_positions), GetCodeKind(result), wasm::ExecutionTier::kNone); wasm::WasmCode* published_code = native_module->PublishCode(std::move(wasm_code)); diff --git a/src/wasm/wasm-serialization.cc b/src/wasm/wasm-serialization.cc index 4adab58355..e4cf8102e6 100644 --- a/src/wasm/wasm-serialization.cc +++ b/src/wasm/wasm-serialization.cc @@ -99,17 +99,16 @@ class Reader { return value; } - template - Vector ReadVector(size_t size) { - DCHECK_GE(current_size(), size); - Vector bytes{pos_, size * sizeof(T)}; - pos_ += size * sizeof(T); + void ReadVector(Vector v) { + if (v.size() > 0) { + DCHECK_GE(current_size(), v.size()); + memcpy(v.begin(), current_location(), v.size()); + pos_ += v.size(); + } if (FLAG_trace_wasm_serialization) { - StdoutStream{} << "read vector of " << size << " elements of size " - << sizeof(T) << " (total size " << size * sizeof(T) << ")" + StdoutStream{} << "read vector of " << v.size() << " elements" << std::endl; } - return Vector::cast(bytes); } void Skip(size_t size) { pos_ += size; } @@ -305,7 +304,8 @@ size_t NativeModuleSerializer::MeasureCode(const WasmCode* code) const { code->kind() == WasmCode::kInterpreterEntry); return kCodeHeaderSize + code->instructions().size() + code->reloc_info().size() + code->source_positions().size() + - code->protected_instructions_data().size(); + code->protected_instructions().size() * + sizeof(trap_handler::ProtectedInstructionData); } size_t NativeModuleSerializer::Measure() const { @@ -343,7 +343,7 @@ void NativeModuleSerializer::WriteCode(const WasmCode* code, Writer* writer) { writer->Write(code->instructions().length()); writer->Write(code->reloc_info().length()); writer->Write(code->source_positions().length()); - writer->Write(code->protected_instructions_data().length()); + writer->Write(code->protected_instructions().length()); writer->Write(code->kind()); writer->Write(code->tier()); @@ -355,7 +355,7 @@ void NativeModuleSerializer::WriteCode(const WasmCode* code, Writer* writer) { // Write the reloc info, source positions, and protected code. writer->WriteVector(code->reloc_info()); writer->WriteVector(code->source_positions()); - writer->WriteVector(code->protected_instructions_data()); + writer->WriteVector(Vector::cast(code->protected_instructions())); #if V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_ARM || \ V8_TARGET_ARCH_PPC || V8_TARGET_ARCH_PPC64 || V8_TARGET_ARCH_S390X // On platforms that don't support misaligned word stores, copy to an aligned @@ -516,17 +516,25 @@ bool NativeModuleDeserializer::ReadCode(int fn_index, Reader* reader) { WasmCode::Kind kind = reader->Read(); ExecutionTier tier = reader->Read(); - auto code_buffer = reader->ReadVector(code_size); - auto reloc_info = reader->ReadVector(reloc_size); - auto source_pos = reader->ReadVector(source_position_size); + Vector code_buffer{reader->current_location(), + static_cast(code_size)}; + reader->Skip(code_size); + + OwnedVector reloc_info = OwnedVector::New(reloc_size); + reader->ReadVector(reloc_info.as_vector()); + OwnedVector source_pos = OwnedVector::New(source_position_size); + reader->ReadVector(source_pos.as_vector()); auto protected_instructions = - reader->ReadVector(protected_instructions_size); + OwnedVector::New( + protected_instructions_size); + reader->ReadVector(Vector::cast(protected_instructions.as_vector())); WasmCode* code = native_module_->AddDeserializedCode( fn_index, code_buffer, stack_slot_count, tagged_parameter_slots, safepoint_table_offset, handler_table_offset, constant_pool_offset, - code_comment_offset, unpadded_binary_size, protected_instructions, - std::move(reloc_info), std::move(source_pos), kind, tier); + code_comment_offset, unpadded_binary_size, + std::move(protected_instructions), std::move(reloc_info), + std::move(source_pos), kind, tier); // Relocate the code. int mask = RelocInfo::ModeMask(RelocInfo::WASM_CALL) | diff --git a/test/cctest/wasm/test-run-wasm.cc b/test/cctest/wasm/test-run-wasm.cc index b3b58a8092..e625b5d90f 100644 --- a/test/cctest/wasm/test-run-wasm.cc +++ b/test/cctest/wasm/test-run-wasm.cc @@ -3753,9 +3753,9 @@ TEST(Liftoff_tier_up) { memcpy(buffer.get(), sub_code->instructions().begin(), sub_size); desc.buffer = buffer.get(); desc.instr_size = static_cast(sub_size); - std::unique_ptr new_code = - native_module->AddCode(add.function_index(), desc, 0, 0, {}, {}, - WasmCode::kFunction, ExecutionTier::kTurbofan); + std::unique_ptr new_code = native_module->AddCode( + add.function_index(), desc, 0, 0, {}, OwnedVector(), + WasmCode::kFunction, ExecutionTier::kTurbofan); native_module->PublishCode(std::move(new_code)); // Second run should now execute {sub}. diff --git a/test/cctest/wasm/wasm-run-utils.cc b/test/cctest/wasm/wasm-run-utils.cc index 186807ed91..993bec0245 100644 --- a/test/cctest/wasm/wasm-run-utils.cc +++ b/test/cctest/wasm/wasm-run-utils.cc @@ -144,9 +144,8 @@ uint32_t TestingModuleBuilder::AddFunction(const FunctionSig* sig, sig); std::unique_ptr code = native_module_->AddCode( index, result.code_desc, result.frame_slot_count, - result.tagged_parameter_slots, - result.protected_instructions_data.as_vector(), - result.source_positions.as_vector(), wasm::WasmCode::kInterpreterEntry, + result.tagged_parameter_slots, std::move(result.protected_instructions), + std::move(result.source_positions), wasm::WasmCode::kInterpreterEntry, wasm::ExecutionTier::kInterpreter); native_module_->PublishCode(std::move(code)); }