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

[wasm] Move source position tables off-heap.

This moves source position tables associated with WasmCode objects to be
located outside the garbage-collected heap. There now is a clear link to
the source position table from code, making the one-to-one relationship
and its lifetime explicit.

R=ahaas@chromium.org
BUG=v8:7424

Change-Id: I9d0b332732508c302ba525059ef02559f45aa2f6
Reviewed-on: https://chromium-review.googlesource.com/975565
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52178}
parent 32d0e026
......@@ -5292,7 +5292,9 @@ wasm::WasmCode* WasmCompilationUnit::FinishTurbofanCompilation(
func_index_,
tf_.job_->compilation_info()->wasm_code_desc()->safepoint_table_offset,
tf_.job_->compilation_info()->wasm_code_desc()->handler_table_offset,
std::move(protected_instructions_), wasm::WasmCode::kTurbofan);
std::move(protected_instructions_),
tf_.job_->compilation_info()->wasm_code_desc()->source_positions_table,
wasm::WasmCode::kTurbofan);
if (!code) return code;
if (FLAG_trace_wasm_decode_time) {
double codegen_ms = codegen_timer.Elapsed().InMillisecondsF();
......@@ -5301,11 +5303,6 @@ wasm::WasmCode* WasmCompilationUnit::FinishTurbofanCompilation(
codegen_ms);
}
Handle<ByteArray> source_positions =
tf_.job_->compilation_info()->wasm_code_desc()->source_positions_table;
native_module_->compiled_module()->source_positions()->set(func_index_,
*source_positions);
return code;
}
......@@ -5317,12 +5314,10 @@ wasm::WasmCode* WasmCompilationUnit::FinishLiftoffCompilation(
Handle<ByteArray> source_positions =
liftoff_.source_position_table_builder_.ToSourcePositionTable(isolate_);
native_module_->compiled_module()->source_positions()->set(func_index_,
*source_positions);
wasm::WasmCode* code = native_module_->AddCode(
desc, liftoff_.asm_.GetTotalFrameSlotCount(), func_index_,
liftoff_.safepoint_table_offset_, 0, std::move(protected_instructions_),
wasm::WasmCode::kLiftoff);
source_positions, wasm::WasmCode::kLiftoff);
return code;
}
......
......@@ -1324,10 +1324,7 @@ int FrameSummary::WasmCompiledFrameSummary::GetWasmSourcePosition(
int position = 0;
// Subtract one because the current PC is one instruction after the call site.
offset--;
Handle<ByteArray> source_position_table(ByteArray::cast(
code->native_module()->compiled_module()->source_positions()->get(
code->index())));
for (SourcePositionTableIterator iterator(source_position_table);
for (SourcePositionTableIterator iterator(code->source_positions());
!iterator.done() && iterator.code_offset() <= offset;
iterator.Advance()) {
position = iterator.source_position().ScriptOffset();
......
......@@ -1285,26 +1285,41 @@ void Logger::CodeMoveEvent(AbstractCode* from, Address to) {
MoveEventInternal(CodeEventListener::CODE_MOVE_EVENT, from->address(), to);
}
void Logger::CodeLinePosInfoRecordEvent(Address code_start,
ByteArray* source_position_table) {
if (jit_logger_) {
void* jit_handler_data = jit_logger_->StartCodePosInfoEvent();
for (SourcePositionTableIterator iter(source_position_table); !iter.done();
iter.Advance()) {
namespace {
void CodeLinePosEvent(JitLogger* jit_logger, Address code_start,
SourcePositionTableIterator& iter) {
if (jit_logger) {
void* jit_handler_data = jit_logger->StartCodePosInfoEvent();
for (; !iter.done(); iter.Advance()) {
if (iter.is_statement()) {
jit_logger_->AddCodeLinePosInfoEvent(
jit_logger->AddCodeLinePosInfoEvent(
jit_handler_data, iter.code_offset(),
iter.source_position().ScriptOffset(),
JitCodeEvent::STATEMENT_POSITION);
}
jit_logger_->AddCodeLinePosInfoEvent(
jit_handler_data, iter.code_offset(),
iter.source_position().ScriptOffset(), JitCodeEvent::POSITION);
jit_logger->AddCodeLinePosInfoEvent(jit_handler_data, iter.code_offset(),
iter.source_position().ScriptOffset(),
JitCodeEvent::POSITION);
}
jit_logger_->EndCodePosInfoEvent(code_start, jit_handler_data);
jit_logger->EndCodePosInfoEvent(code_start, jit_handler_data);
}
}
} // namespace
void Logger::CodeLinePosInfoRecordEvent(Address code_start,
ByteArray* source_position_table) {
SourcePositionTableIterator iter(source_position_table);
CodeLinePosEvent(jit_logger_, code_start, iter);
}
void Logger::CodeLinePosInfoRecordEvent(
Address code_start, Vector<const byte> source_position_table) {
SourcePositionTableIterator iter(source_position_table);
CodeLinePosEvent(jit_logger_, code_start, iter);
}
void Logger::CodeNameEvent(Address addr, int pos, const char* code_name) {
if (code_name == nullptr) return; // Not a code object.
Log::MessageBuilder msg(log_);
......
......@@ -193,6 +193,8 @@ class Logger : public CodeEventListener {
// Emits a code line info record event.
void CodeLinePosInfoRecordEvent(Address code_start,
ByteArray* source_position_table);
void CodeLinePosInfoRecordEvent(Address code_start,
Vector<const byte> source_position_table);
void SharedFunctionInfoMoveEvent(Address from, Address to);
......
......@@ -1450,7 +1450,6 @@ void WasmCompiledModule::WasmCompiledModuleVerify() {
VerifyObjectField(kPrevInstanceOffset);
VerifyObjectField(kOwningInstanceOffset);
VerifyObjectField(kWasmModuleOffset);
VerifyObjectField(kSourcePositionsOffset);
VerifyObjectField(kNativeModuleOffset);
VerifyObjectField(kLazyCompileDataOffset);
VerifyObjectField(kUseTrapHandlerOffset);
......
......@@ -75,13 +75,13 @@ void EncodeEntry(std::vector<byte>& bytes, const PositionTableEntry& entry) {
// Helper: Decode an integer.
template <typename T>
T DecodeInt(ByteArray* bytes, int* index) {
T DecodeInt(Vector<const byte> bytes, int* index) {
byte current;
int shift = 0;
T decoded = 0;
bool more;
do {
current = bytes->get((*index)++);
current = bytes[(*index)++];
decoded |= static_cast<typename std::make_unsigned<T>::type>(
ValueBits::decode(current))
<< shift;
......@@ -93,7 +93,8 @@ T DecodeInt(ByteArray* bytes, int* index) {
return decoded;
}
void DecodeEntry(ByteArray* bytes, int* index, PositionTableEntry* entry) {
void DecodeEntry(Vector<const byte> bytes, int* index,
PositionTableEntry* entry) {
int tmp = DecodeInt<int>(bytes, index);
if (tmp >= 0) {
entry->is_statement = true;
......@@ -105,6 +106,11 @@ void DecodeEntry(ByteArray* bytes, int* index, PositionTableEntry* entry) {
entry->source_position = DecodeInt<int64_t>(bytes, index);
}
Vector<const byte> VectorFromByteArray(ByteArray* byte_array) {
return Vector<const byte>(byte_array->GetDataStartAddress(),
byte_array->length());
}
} // namespace
SourcePositionTableBuilder::SourcePositionTableBuilder(
......@@ -159,7 +165,7 @@ Handle<ByteArray> SourcePositionTableBuilder::ToSourcePositionTable(
}
SourcePositionTableIterator::SourcePositionTableIterator(ByteArray* byte_array)
: raw_table_(byte_array) {
: raw_table_(VectorFromByteArray(byte_array)) {
Advance();
}
......@@ -171,15 +177,24 @@ SourcePositionTableIterator::SourcePositionTableIterator(
no_gc.Release();
}
SourcePositionTableIterator::SourcePositionTableIterator(
Vector<const byte> bytes)
: raw_table_(bytes) {
Advance();
// We can enable allocation because the underlying vector does not move.
no_gc.Release();
}
void SourcePositionTableIterator::Advance() {
ByteArray* table = raw_table_ ? raw_table_ : *table_;
Vector<const byte> bytes =
table_.is_null() ? raw_table_ : VectorFromByteArray(*table_);
DCHECK(!done());
DCHECK(index_ >= 0 && index_ <= table->length());
if (index_ >= table->length()) {
DCHECK(index_ >= 0 && index_ <= bytes.length());
if (index_ >= bytes.length()) {
index_ = kDone;
} else {
PositionTableEntry tmp;
DecodeEntry(table, &index_, &tmp);
DecodeEntry(bytes, &index_, &tmp);
AddAndSetEntry(current_, tmp);
}
}
......
......@@ -64,7 +64,7 @@ class V8_EXPORT_PRIVATE SourcePositionTableIterator {
PositionTableEntry position_;
};
// We expose two flavours of the iterator, depending on the argument passed
// We expose three flavours of the iterator, depending on the argument passed
// to the constructor:
// Handlified iterator allows allocation, but it needs a handle (and thus
......@@ -76,6 +76,10 @@ class V8_EXPORT_PRIVATE SourcePositionTableIterator {
// scope around.
explicit SourcePositionTableIterator(ByteArray* byte_array);
// Handle-safe iterator based on an a vector located outside the garbage
// collected heap, allows allocation during its lifetime.
explicit SourcePositionTableIterator(Vector<const byte> bytes);
void Advance();
int code_offset() const {
......@@ -102,7 +106,7 @@ class V8_EXPORT_PRIVATE SourcePositionTableIterator {
private:
static const int kDone = -1;
ByteArray* raw_table_ = nullptr;
Vector<const byte> raw_table_;
Handle<ByteArray> table_;
int index_ = 0;
PositionTableEntry current_;
......
......@@ -738,8 +738,7 @@ const wasm::WasmCode* LazyCompilationOrchestrator::CompileDirectCall(
SeqOneByteString* module_bytes = caller_module->shared()->module_bytes();
uint32_t caller_func_index = wasm_caller->index();
SourcePositionTableIterator source_pos_iterator(
Handle<ByteArray>(ByteArray::cast(
caller_module->source_positions()->get(caller_func_index))));
wasm_caller->source_positions());
const byte* func_bytes =
module_bytes->GetChars() + caller_module->shared()
......
......@@ -253,13 +253,9 @@ void WasmCode::LogCode(Isolate* isolate) const {
}
#endif
MaybeHandle<ByteArray> src_pos = native_module_->compiled_module()
->source_positions()
->GetValue<ByteArray>(isolate, index);
if (!src_pos.is_null()) {
LOG_CODE_EVENT(isolate,
CodeLinePosInfoRecordEvent(this->instructions().start(),
*src_pos.ToHandleChecked()));
if (!source_positions().is_empty()) {
LOG_CODE_EVENT(isolate, CodeLinePosInfoRecordEvent(instructions().start(),
source_positions()));
}
}
}
......@@ -295,21 +291,15 @@ void WasmCode::Disassemble(const char* name, Isolate* isolate,
instructions().start() + instruction_size, nullptr);
os << "\n";
// Anonymous functions don't have source positions.
if (!IsAnonymous()) {
Object* source_positions_or_undef =
native_module_->compiled_module()->source_positions()->get(index());
if (!source_positions_or_undef->IsUndefined(isolate)) {
os << "Source positions:\n pc offset position\n";
for (SourcePositionTableIterator it(
ByteArray::cast(source_positions_or_undef));
!it.done(); it.Advance()) {
os << std::setw(10) << std::hex << it.code_offset() << std::dec
<< std::setw(10) << it.source_position().ScriptOffset()
<< (it.is_statement() ? " statement" : "") << "\n";
}
os << "\n";
if (!source_positions().is_empty()) {
os << "Source positions:\n pc offset position\n";
for (SourcePositionTableIterator it(source_positions()); !it.done();
it.Advance()) {
os << std::setw(10) << std::hex << it.code_offset() << std::dec
<< std::setw(10) << it.source_position().ScriptOffset()
<< (it.is_statement() ? " statement" : "") << "\n";
}
os << "\n";
}
os << "RelocInfo (size = " << reloc_size_ << ")\n";
......@@ -454,15 +444,7 @@ NativeModule::NativeModule(uint32_t num_functions, uint32_t num_imports,
void NativeModule::ResizeCodeTableForTest(size_t last_index) {
size_t new_size = last_index + 1;
if (new_size > FunctionCount()) {
Isolate* isolate = compiled_module()->GetIsolate();
code_table_.resize(new_size);
int grow_by = static_cast<int>(new_size) -
compiled_module()->source_positions()->length();
Handle<FixedArray> source_positions(compiled_module()->source_positions(),
isolate);
source_positions = isolate->factory()->CopyFixedArrayAndGrow(
source_positions, grow_by, TENURED);
compiled_module()->set_source_positions(*source_positions);
}
}
......@@ -478,6 +460,7 @@ uint32_t NativeModule::FunctionCount() const {
WasmCode* NativeModule::AddOwnedCode(
Vector<const byte> orig_instructions,
std::unique_ptr<const byte[]> reloc_info, size_t reloc_size,
std::unique_ptr<const byte[]> source_pos, size_t source_pos_size,
Maybe<uint32_t> index, WasmCode::Kind kind, size_t constant_pool_offset,
uint32_t stack_slots, size_t safepoint_table_offset,
size_t handler_table_offset,
......@@ -495,9 +478,9 @@ WasmCode* NativeModule::AddOwnedCode(
orig_instructions.size());
std::unique_ptr<WasmCode> code(new WasmCode(
{executable_buffer, orig_instructions.size()}, std::move(reloc_info),
reloc_size, this, index, kind, constant_pool_offset, stack_slots,
safepoint_table_offset, handler_table_offset,
std::move(protected_instructions), tier));
reloc_size, std::move(source_pos), source_pos_size, this, index, kind,
constant_pool_offset, stack_slots, safepoint_table_offset,
handler_table_offset, std::move(protected_instructions), tier));
WasmCode* ret = code.get();
// TODO(mtrofin): We allocate in increasing address order, and
......@@ -519,8 +502,6 @@ WasmCode* NativeModule::AddCodeCopy(Handle<Code> code, WasmCode::Kind kind,
WasmCode* ret = AddAnonymousCode(code, kind);
code_table_[index] = ret;
ret->index_ = Just(index);
compiled_module()->source_positions()->set(static_cast<int>(index),
code->source_position_table());
return ret;
}
......@@ -555,6 +536,12 @@ WasmCode* NativeModule::AddAnonymousCode(Handle<Code> code,
reloc_info.reset(new byte[code->relocation_size()]);
memcpy(reloc_info.get(), code->relocation_start(), code->relocation_size());
}
std::unique_ptr<byte[]> source_pos;
Handle<ByteArray> source_pos_table(code->SourcePositionTable());
if (source_pos_table->length() > 0) {
source_pos.reset(new byte[source_pos_table->length()]);
source_pos_table->copy_out(0, source_pos.get(), source_pos_table->length());
}
std::shared_ptr<ProtectedInstructions> protected_instructions(
new ProtectedInstructions(0));
Vector<const byte> orig_instructions(
......@@ -566,8 +553,10 @@ WasmCode* NativeModule::AddAnonymousCode(Handle<Code> code,
AddOwnedCode(orig_instructions, // instructions
std::move(reloc_info), // reloc_info
static_cast<size_t>(code->relocation_size()), // reloc_size
Nothing<uint32_t>(), // index
kind, // kind
std::move(source_pos), // source positions
static_cast<size_t>(source_pos_table->length()),
Nothing<uint32_t>(), // index
kind, // kind
code->constant_pool_offset(), // constant_pool_offset
stack_slots, // stack_slots
safepoint_table_offset, // safepoint_table_offset
......@@ -607,19 +596,26 @@ WasmCode* NativeModule::AddCode(
const CodeDesc& desc, uint32_t frame_slots, uint32_t index,
size_t safepoint_table_offset, size_t handler_table_offset,
std::unique_ptr<ProtectedInstructions> protected_instructions,
WasmCode::Tier tier) {
Handle<ByteArray> source_pos_table, WasmCode::Tier tier) {
std::unique_ptr<byte[]> reloc_info;
if (desc.reloc_size) {
reloc_info.reset(new byte[desc.reloc_size]);
memcpy(reloc_info.get(), desc.buffer + desc.buffer_size - desc.reloc_size,
desc.reloc_size);
}
std::unique_ptr<byte[]> source_pos;
if (source_pos_table->length() > 0) {
source_pos.reset(new byte[source_pos_table->length()]);
source_pos_table->copy_out(0, source_pos.get(), source_pos_table->length());
}
TurboAssembler* origin = reinterpret_cast<TurboAssembler*>(desc.origin);
WasmCode* ret = AddOwnedCode(
{desc.buffer, static_cast<size_t>(desc.instr_size)},
std::move(reloc_info), static_cast<size_t>(desc.reloc_size), Just(index),
WasmCode::kFunction, desc.instr_size - desc.constant_pool_size,
frame_slots, safepoint_table_offset, handler_table_offset,
std::move(reloc_info), static_cast<size_t>(desc.reloc_size),
std::move(source_pos), static_cast<size_t>(source_pos_table->length()),
Just(index), WasmCode::kFunction,
desc.instr_size - desc.constant_pool_size, frame_slots,
safepoint_table_offset, handler_table_offset,
std::move(protected_instructions), tier, WasmCode::kNoFlushICache);
code_table_[index] = ret;
......@@ -674,6 +670,8 @@ Address NativeModule::CreateTrampolineTo(Handle<Code> code) {
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
......@@ -840,9 +838,16 @@ WasmCode* NativeModule::CloneCode(const WasmCode* original_code,
memcpy(reloc_info.get(), original_code->reloc_info().start(),
original_code->reloc_info().size());
}
std::unique_ptr<byte[]> source_pos;
if (original_code->source_positions().size() > 0) {
source_pos.reset(new byte[original_code->source_positions().size()]);
memcpy(source_pos.get(), original_code->source_positions().start(),
original_code->source_positions().size());
}
WasmCode* ret = AddOwnedCode(
original_code->instructions(), std::move(reloc_info),
original_code->reloc_info().size(), original_code->index_,
original_code->reloc_info().size(), std::move(source_pos),
original_code->source_positions().size(), original_code->index_,
original_code->kind(), original_code->constant_pool_offset_,
original_code->stack_slots(), original_code->safepoint_table_offset_,
original_code->handler_table_offset_,
......
......@@ -106,6 +106,9 @@ class V8_EXPORT_PRIVATE WasmCode final {
Vector<const byte> reloc_info() const {
return {reloc_info_.get(), reloc_size_};
}
Vector<const byte> source_positions() const {
return {source_position_table_.get(), source_position_size_};
}
uint32_t index() const { return index_.ToChecked(); }
// Anonymous functions are functions that don't carry an index, like
......@@ -148,6 +151,7 @@ class V8_EXPORT_PRIVATE WasmCode final {
WasmCode(Vector<byte> instructions,
std::unique_ptr<const byte[]>&& reloc_info, size_t reloc_size,
std::unique_ptr<const byte[]>&& source_pos, size_t source_pos_size,
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,
......@@ -156,6 +160,8 @@ class V8_EXPORT_PRIVATE WasmCode final {
: instructions_(instructions),
reloc_info_(std::move(reloc_info)),
reloc_size_(reloc_size),
source_position_table_(std::move(source_pos)),
source_position_size_(source_pos_size),
native_module_(native_module),
index_(index),
kind_(kind),
......@@ -173,6 +179,8 @@ class V8_EXPORT_PRIVATE WasmCode final {
Vector<byte> instructions_;
std::unique_ptr<const byte[]> reloc_info_;
size_t reloc_size_ = 0;
std::unique_ptr<const byte[]> source_position_table_;
size_t source_position_size_ = 0;
NativeModule* native_module_ = nullptr;
Maybe<uint32_t> index_;
Kind kind_;
......@@ -227,6 +235,7 @@ class V8_EXPORT_PRIVATE NativeModule final {
WasmCode* AddCode(const CodeDesc& desc, uint32_t frame_count, uint32_t index,
size_t safepoint_table_offset, size_t handler_table_offset,
std::unique_ptr<ProtectedInstructions>,
Handle<ByteArray> source_position_table,
WasmCode::Tier tier);
// A way to copy over JS-allocated code. This is because we compile
......@@ -300,7 +309,9 @@ class V8_EXPORT_PRIVATE NativeModule final {
// whether it has an index or is anonymous, etc.
WasmCode* AddOwnedCode(Vector<const byte> orig_instructions,
std::unique_ptr<const byte[]> reloc_info,
size_t reloc_size, Maybe<uint32_t> index,
size_t reloc_size,
std::unique_ptr<const byte[]> source_pos,
size_t source_pos_size, Maybe<uint32_t> index,
WasmCode::Kind kind, size_t constant_pool_offset,
uint32_t stack_slots, size_t safepoint_table_offset,
size_t handler_table_offset,
......
......@@ -44,10 +44,7 @@ int AdvanceSourcePositionTableIterator(SourcePositionTableIterator& iterator,
class PatchDirectCallsHelper {
public:
PatchDirectCallsHelper(NativeModule* native_module, const WasmCode* code)
: source_pos_it(ByteArray::cast(
native_module->compiled_module()->source_positions()->get(
static_cast<int>(code->index())))),
decoder(nullptr, nullptr) {
: source_pos_it(code->source_positions()), decoder(nullptr, nullptr) {
uint32_t func_index = code->index();
WasmCompiledModule* comp_mod = native_module->compiled_module();
func_bytes =
......
......@@ -160,7 +160,6 @@ WCM_OBJECT(WasmCompiledModule, next_instance, kNextInstanceOffset)
WCM_OBJECT(WasmCompiledModule, prev_instance, kPrevInstanceOffset)
WCM_WEAK_LINK(WasmInstanceObject, owning_instance, kOwningInstanceOffset)
WCM_WEAK_LINK(WasmModuleObject, wasm_module, kWasmModuleOffset)
WCM_OBJECT(FixedArray, source_positions, kSourcePositionsOffset)
WCM_OBJECT(Foreign, native_module, kNativeModuleOffset)
WCM_OBJECT(FixedArray, lazy_compile_data, kLazyCompileDataOffset)
WCM_SMALL_CONST_NUMBER(bool, use_trap_handler, kUseTrapHandlerOffset)
......
......@@ -1260,10 +1260,6 @@ Handle<WasmCompiledModule> WasmCompiledModule::New(
compiled_module->GetNativeModule()->SetCompiledModule(weak_link);
}
int function_count = static_cast<int>(module->functions.size());
Handle<FixedArray> source_positions =
isolate->factory()->NewFixedArray(function_count, TENURED);
compiled_module->set_source_positions(*source_positions);
// TODO(mtrofin): copy the rest of the specialization parameters over.
// We're currently OK because we're only using defaults.
return compiled_module;
......@@ -1278,7 +1274,6 @@ Handle<WasmCompiledModule> WasmCompiledModule::Clone(
ret->set_weak_native_context(module->weak_native_context());
ret->set_export_wrappers(module->export_wrappers());
ret->set_weak_wasm_module(module->weak_wasm_module());
ret->set_source_positions(module->source_positions());
ret->set_native_module(module->native_module());
if (module->has_lazy_compile_data()) {
ret->set_lazy_compile_data(module->lazy_compile_data());
......
......@@ -451,7 +451,6 @@ class WasmCompiledModule : public Struct {
V(kPrevInstanceOffset, kPointerSize) \
V(kOwningInstanceOffset, kPointerSize) \
V(kWasmModuleOffset, kPointerSize) \
V(kSourcePositionsOffset, kPointerSize) \
V(kNativeModuleOffset, kPointerSize) \
V(kLazyCompileDataOffset, kPointerSize) \
V(kUseTrapHandlerOffset, kPointerSize) \
......@@ -500,7 +499,6 @@ class WasmCompiledModule : public Struct {
WCM_CONST_OBJECT(WasmCompiledModule, prev_instance)
WCM_WEAK_LINK(WasmInstanceObject, owning_instance)
WCM_WEAK_LINK(WasmModuleObject, wasm_module)
WCM_OBJECT(FixedArray, source_positions)
WCM_OBJECT(Foreign, native_module)
WCM_OBJECT(FixedArray, lazy_compile_data)
// TODO(mstarzinger): Make {use_trap_handler} smaller.
......
......@@ -157,7 +157,6 @@ class V8_EXPORT_PRIVATE NativeModuleSerializer {
static size_t GetCodeHeaderSize();
size_t MeasureCode(const WasmCode*) const;
size_t MeasureCopiedStubs() const;
ByteArray* GetSourcePositions(const WasmCode*) const;
void BufferHeader();
// we buffer all the stubs because they are small
......@@ -252,20 +251,16 @@ size_t NativeModuleSerializer::GetCodeHeaderSize() {
sizeof(uint32_t) + // stack slots
sizeof(size_t) + // code size
sizeof(size_t) + // reloc size
sizeof(uint32_t) + // source positions size
sizeof(size_t) + // source positions size
sizeof(size_t) + // protected instructions size
sizeof(WasmCode::Tier); // tier
}
size_t NativeModuleSerializer::MeasureCode(const WasmCode* code) const {
ByteArray* source_positions = GetSourcePositions(code);
return GetCodeHeaderSize() + code->instructions().size() + // code
code->reloc_info().size() + // reloc info
(source_positions == nullptr
? 0
: static_cast<uint32_t>(
source_positions->length())) + // source positions
code->protected_instructions().size() *
code->source_positions().size() + // source pos.
code->protected_instructions().size() * // protected inst.
sizeof(trap_handler::ProtectedInstructionData);
}
......@@ -330,19 +325,6 @@ void NativeModuleSerializer::BufferCopiedStubs() {
}
}
ByteArray* NativeModuleSerializer::GetSourcePositions(
const WasmCode* code) const {
if (code->kind() != WasmCode::kFunction) return nullptr;
uint32_t index = code->index();
Object* source_positions_entry =
native_module_->compiled_module()->source_positions()->get(
static_cast<int>(index));
if (source_positions_entry->IsByteArray()) {
return ByteArray::cast(source_positions_entry);
}
return nullptr;
}
void NativeModuleSerializer::BufferCurrentWasmCode() {
const WasmCode* code = native_module_->GetCode(index_);
size_t size = MeasureCode(code);
......@@ -355,14 +337,6 @@ void NativeModuleSerializer::BufferCodeInAllocatedScratch(
const WasmCode* code) {
// We write the address, the size, and then copy the code as-is, followed
// by reloc info, followed by source positions.
ByteArray* source_positions_entry = GetSourcePositions(code);
Address source_positions = nullptr;
uint32_t source_positions_size = 0;
if (source_positions_entry != nullptr) {
source_positions = source_positions_entry->GetDataStartAddress();
source_positions_size =
static_cast<uint32_t>(source_positions_entry->length());
}
Writer writer(remaining_);
// write the header
writer.Write(MeasureCode(code));
......@@ -372,7 +346,7 @@ void NativeModuleSerializer::BufferCodeInAllocatedScratch(
writer.Write(code->stack_slots());
writer.Write(code->instructions().size());
writer.Write(code->reloc_info().size());
writer.Write(source_positions_size);
writer.Write(code->source_positions().size());
writer.Write(code->protected_instructions().size());
writer.Write(code->tier());
// next is the code, which we have to reloc.
......@@ -381,7 +355,7 @@ void NativeModuleSerializer::BufferCodeInAllocatedScratch(
// write the code and everything else
writer.WriteVector(code->instructions());
writer.WriteVector(code->reloc_info());
writer.WriteVector({source_positions, source_positions_size});
writer.WriteVector(code->source_positions());
writer.WriteVector(
{reinterpret_cast<const byte*>(code->protected_instructions().data()),
sizeof(trap_handler::ProtectedInstructionData) *
......@@ -559,7 +533,7 @@ bool NativeModuleDeserializer::ReadCode() {
uint32_t stack_slot_count = reader.Read<uint32_t>();
size_t code_size = reader.Read<size_t>();
size_t reloc_size = reader.Read<size_t>();
uint32_t source_position_size = reader.Read<uint32_t>();
size_t source_position_size = reader.Read<size_t>();
size_t protected_instructions_size = reader.Read<size_t>();
WasmCode::Tier tier = reader.Read<WasmCode::Tier>();
......@@ -573,11 +547,17 @@ bool NativeModuleDeserializer::ReadCode() {
reloc_info.reset(new byte[reloc_size]);
reader.ReadIntoVector({reloc_info.get(), reloc_size});
}
std::unique_ptr<byte[]> source_pos;
if (source_position_size > 0) {
source_pos.reset(new byte[source_position_size]);
reader.ReadIntoVector({source_pos.get(), source_position_size});
}
WasmCode* ret = native_module_->AddOwnedCode(
code_buffer, std::move(reloc_info), reloc_size, Just(index_),
WasmCode::kFunction, constant_pool_offset, stack_slot_count,
safepoint_table_offset, handler_table_offset, protected_instructions,
tier, WasmCode::kNoFlushICache);
code_buffer, std::move(reloc_info), reloc_size, std::move(source_pos),
source_position_size, Just(index_), WasmCode::kFunction,
constant_pool_offset, stack_slot_count, safepoint_table_offset,
handler_table_offset, protected_instructions, tier,
WasmCode::kNoFlushICache);
native_module_->code_table_[index_] = ret;
// now relocate the code
......@@ -619,14 +599,6 @@ bool NativeModuleDeserializer::ReadCode() {
Assembler::FlushICache(ret->instructions().start(),
ret->instructions().size());
if (source_position_size > 0) {
Handle<ByteArray> source_positions = isolate_->factory()->NewByteArray(
static_cast<int>(source_position_size), TENURED);
reader.ReadIntoVector(
{source_positions->GetDataStartAddress(), source_position_size});
native_module_->compiled_module()->source_positions()->set(
static_cast<int>(index_), *source_positions);
}
if (protected_instructions_size > 0) {
reader.ReadIntoVector(
{reinterpret_cast<byte*>(protected_instructions->data()),
......
......@@ -128,15 +128,6 @@ std::unique_ptr<wasm::NativeModule> AllocateNativeModule(Isolate* isolate,
std::unique_ptr<wasm::NativeModule> module =
isolate->wasm_engine()->code_manager()->NewNativeModule(code_size, 1, 0,
false);
// TODO(mstarzinger): Remove the WasmCompiledModule here as soon as source
// positions are stored in the WasmCode directly.
Handle<WasmCompiledModule> compiled_module = Handle<WasmCompiledModule>::cast(
isolate->factory()->NewStruct(WASM_COMPILED_MODULE_TYPE, TENURED));
Handle<FixedArray> source_positions =
isolate->factory()->NewFixedArray(1, TENURED);
compiled_module->set_source_positions(*source_positions);
module->SetCompiledModule(compiled_module);
return module;
}
......
......@@ -155,15 +155,6 @@ std::unique_ptr<wasm::NativeModule> AllocateNativeModule(i::Isolate* isolate,
std::unique_ptr<wasm::NativeModule> module =
isolate->wasm_engine()->code_manager()->NewNativeModule(code_size, 1, 0,
false);
// TODO(mstarzinger): Remove the WasmCompiledModule here as soon as source
// positions are stored in the WasmCode directly.
Handle<WasmCompiledModule> compiled_module = Handle<WasmCompiledModule>::cast(
isolate->factory()->NewStruct(WASM_COMPILED_MODULE_TYPE, TENURED));
Handle<FixedArray> source_positions =
isolate->factory()->NewFixedArray(1, TENURED);
compiled_module->set_source_positions(*source_positions);
module->SetCompiledModule(compiled_module);
return module;
}
......
......@@ -186,7 +186,9 @@ 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, {}, WasmCode::kOther);
Handle<ByteArray> source_pos = i_isolate()->factory()->empty_byte_array();
return native_module->AddCode(desc, 0, index, 0, 0, {}, source_pos,
WasmCode::kOther);
}
size_t page() const { return AllocatePageSize(); }
......
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