Index: src/wasm/wasm-objects.cc |
diff --git a/src/wasm/wasm-objects.cc b/src/wasm/wasm-objects.cc |
index feddfaf2d27b7498a347646b221d157e9307149d..d57aa519e1467669a0b724cda79e69a30c4d7bbd 100644 |
--- a/src/wasm/wasm-objects.cc |
+++ b/src/wasm/wasm-objects.cc |
@@ -461,6 +461,14 @@ bool WasmCompiledModule::GetPositionInfo(uint32_t position, |
} |
namespace { |
+ |
+enum AsmJsOffsetTableEntryLayout { |
+ kOTEByteOffset, |
+ kOTECallPosition, |
+ kOTENumberConvPosition, |
+ kOTESize |
+}; |
+ |
Handle<ByteArray> GetDecodedAsmJsOffsetTable( |
Handle<WasmCompiledModule> compiled_module, Isolate* isolate) { |
DCHECK(compiled_module->has_asm_js_offset_table()); |
@@ -488,13 +496,16 @@ Handle<ByteArray> GetDecodedAsmJsOffsetTable( |
static_cast<int>(compiled_module->module()->num_imported_functions); |
DCHECK_EQ(compiled_module->module()->functions.size(), |
static_cast<size_t>(num_functions) + num_imported_functions); |
- // One byte to encode that this is a decoded table. |
- int total_size = 1; |
+ int num_entries = 0; |
for (int func = 0; func < num_functions; ++func) { |
- size_t new_size = asm_offsets.val[func].size() * 2 * kIntSize; |
- DCHECK_LE(new_size, static_cast<size_t>(kMaxInt) - total_size); |
- total_size += static_cast<int>(new_size); |
+ size_t new_size = asm_offsets.val[func].size(); |
+ DCHECK_LE(new_size, static_cast<size_t>(kMaxInt) - num_entries); |
+ num_entries += static_cast<int>(new_size); |
} |
+ // One byte to encode that this is a decoded table. |
+ DCHECK_GE(kMaxInt, |
+ 1 + static_cast<uint64_t>(num_entries) * kOTESize * kIntSize); |
+ int total_size = 1 + num_entries * kOTESize * kIntSize; |
Handle<ByteArray> decoded_table = |
isolate->factory()->NewByteArray(total_size, TENURED); |
decoded_table->set(total_size - 1, AsmJsTableType::Decoded); |
@@ -503,16 +514,19 @@ Handle<ByteArray> GetDecodedAsmJsOffsetTable( |
int idx = 0; |
std::vector<WasmFunction>& wasm_funs = compiled_module->module()->functions; |
for (int func = 0; func < num_functions; ++func) { |
- std::vector<std::pair<int, int>>& func_asm_offsets = asm_offsets.val[func]; |
+ std::vector<AsmJsOffsetEntry>& func_asm_offsets = asm_offsets.val[func]; |
if (func_asm_offsets.empty()) continue; |
int func_offset = |
wasm_funs[num_imported_functions + func].code_start_offset; |
- for (std::pair<int, int> p : func_asm_offsets) { |
+ for (AsmJsOffsetEntry& e : func_asm_offsets) { |
// Byte offsets must be strictly monotonously increasing: |
- DCHECK(idx == 0 || |
- func_offset + p.first > decoded_table->get_int(idx - 2)); |
- decoded_table->set_int(idx++, func_offset + p.first); |
- decoded_table->set_int(idx++, p.second); |
+ DCHECK_IMPLIES(idx > 0, func_offset + e.byte_offset > |
+ decoded_table->get_int(idx - kOTESize)); |
+ decoded_table->set_int(idx + kOTEByteOffset, func_offset + e.byte_offset); |
+ decoded_table->set_int(idx + kOTECallPosition, e.source_position_call); |
+ decoded_table->set_int(idx + kOTENumberConvPosition, |
+ e.source_position_number_conversion); |
+ idx += kOTESize; |
} |
} |
DCHECK_EQ(total_size, idx * kIntSize + 1); |
@@ -522,7 +536,7 @@ Handle<ByteArray> GetDecodedAsmJsOffsetTable( |
int WasmCompiledModule::GetAsmJsSourcePosition( |
Handle<WasmCompiledModule> compiled_module, uint32_t func_index, |
- uint32_t byte_offset) { |
+ uint32_t byte_offset, bool is_at_number_conversion) { |
Isolate* isolate = compiled_module->GetIsolate(); |
Handle<ByteArray> offset_table = |
GetDecodedAsmJsOffsetTable(compiled_module, isolate); |
@@ -533,12 +547,12 @@ int WasmCompiledModule::GetAsmJsSourcePosition( |
uint32_t total_offset = func_code_offset + byte_offset; |
// Binary search for the total byte offset. |
- int left = 0; // inclusive |
- int right = offset_table->length() / kIntSize / 2; // exclusive |
+ int left = 0; // inclusive |
+ int right = offset_table->length() / kIntSize / kOTESize; // exclusive |
DCHECK_LT(left, right); |
while (right - left > 1) { |
int mid = left + (right - left) / 2; |
- int mid_entry = offset_table->get_int(2 * mid); |
+ int mid_entry = offset_table->get_int(kOTESize * mid); |
DCHECK_GE(kMaxInt, mid_entry); |
if (static_cast<uint32_t>(mid_entry) <= total_offset) { |
left = mid; |
@@ -548,9 +562,9 @@ int WasmCompiledModule::GetAsmJsSourcePosition( |
} |
// There should be an entry for each position that could show up on the stack |
// trace: |
- DCHECK_EQ(total_offset, |
- static_cast<uint32_t>(offset_table->get_int(2 * left))); |
- return offset_table->get_int(2 * left + 1); |
+ DCHECK_EQ(total_offset, offset_table->get_int(kOTESize * left)); |
+ int idx = is_at_number_conversion ? kOTENumberConvPosition : kOTECallPosition; |
+ return offset_table->get_int(kOTESize * left + idx); |
} |
v8::debug::WasmDisassembly WasmCompiledModule::DisassembleFunction( |