Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1622)

Side by Side Diff: src/wasm/wasm-debug.cc

Issue 2522953002: [wasm] Move asm.js offset table to compiled module (Closed)
Patch Set: rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/messages.cc ('k') | src/wasm/wasm-module.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/assert-scope.h" 5 #include "src/assert-scope.h"
6 #include "src/debug/debug.h" 6 #include "src/debug/debug.h"
7 #include "src/factory.h" 7 #include "src/factory.h"
8 #include "src/isolate.h" 8 #include "src/isolate.h"
9 #include "src/wasm/module-decoder.h" 9 #include "src/wasm/module-decoder.h"
10 #include "src/wasm/wasm-module.h" 10 #include "src/wasm/wasm-module.h"
11 #include "src/wasm/wasm-objects.h" 11 #include "src/wasm/wasm-objects.h"
12 12
13 using namespace v8::internal; 13 using namespace v8::internal;
14 using namespace v8::internal::wasm; 14 using namespace v8::internal::wasm;
15 15
16 namespace { 16 namespace {
17 17
18 enum { 18 enum {
19 kWasmDebugInfoWasmObj, 19 kWasmDebugInfoWasmObj,
20 kWasmDebugInfoWasmBytesHash, 20 kWasmDebugInfoWasmBytesHash,
21 kWasmDebugInfoAsmJsOffsets, 21 kWasmDebugInfoAsmJsOffsets,
22 kWasmDebugInfoNumEntries 22 kWasmDebugInfoNumEntries
23 }; 23 };
24 24
25 // TODO(clemensh): Move asm.js offset tables to the compiled module.
26 FixedArray *GetAsmJsOffsetTables(Handle<WasmDebugInfo> debug_info,
27 Isolate *isolate) {
28 Object *offset_tables = debug_info->get(kWasmDebugInfoAsmJsOffsets);
29 if (!offset_tables->IsUndefined(isolate)) {
30 return FixedArray::cast(offset_tables);
31 }
32
33 Handle<WasmInstanceObject> wasm_instance(debug_info->wasm_instance(),
34 isolate);
35 Handle<WasmCompiledModule> compiled_module(
36 wasm_instance->get_compiled_module(), isolate);
37 DCHECK(compiled_module->has_asm_js_offset_tables());
38
39 AsmJsOffsetsResult asm_offsets;
40 {
41 Handle<ByteArray> asm_offset_tables =
42 compiled_module->asm_js_offset_tables();
43 DisallowHeapAllocation no_gc;
44 const byte *bytes_start = asm_offset_tables->GetDataStartAddress();
45 const byte *bytes_end = bytes_start + asm_offset_tables->length();
46 asm_offsets = wasm::DecodeAsmJsOffsets(bytes_start, bytes_end);
47 }
48 // Wasm bytes must be valid and must contain asm.js offset table.
49 DCHECK(asm_offsets.ok());
50 DCHECK_GE(static_cast<size_t>(kMaxInt), asm_offsets.val.size());
51 int num_functions = static_cast<int>(asm_offsets.val.size());
52 DCHECK_EQ(
53 wasm::GetNumberOfFunctions(handle(debug_info->wasm_instance())),
54 static_cast<int>(num_functions +
55 compiled_module->module()->num_imported_functions));
56 Handle<FixedArray> all_tables =
57 isolate->factory()->NewFixedArray(num_functions);
58 debug_info->set(kWasmDebugInfoAsmJsOffsets, *all_tables);
59 for (int func = 0; func < num_functions; ++func) {
60 std::vector<std::pair<int, int>> &func_asm_offsets = asm_offsets.val[func];
61 if (func_asm_offsets.empty()) continue;
62 size_t array_size = 2 * kIntSize * func_asm_offsets.size();
63 CHECK_LE(array_size, static_cast<size_t>(kMaxInt));
64 ByteArray *arr =
65 *isolate->factory()->NewByteArray(static_cast<int>(array_size));
66 all_tables->set(func, arr);
67 int idx = 0;
68 for (std::pair<int, int> p : func_asm_offsets) {
69 // Byte offsets must be strictly monotonously increasing:
70 DCHECK(idx == 0 || p.first > arr->get_int(idx - 2));
71 arr->set_int(idx++, p.first);
72 arr->set_int(idx++, p.second);
73 }
74 DCHECK_EQ(arr->length(), idx * kIntSize);
75 }
76 return *all_tables;
77 }
78 } // namespace 25 } // namespace
79 26
80 Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) { 27 Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) {
81 Isolate *isolate = instance->GetIsolate(); 28 Isolate *isolate = instance->GetIsolate();
82 Factory *factory = isolate->factory(); 29 Factory *factory = isolate->factory();
83 Handle<FixedArray> arr = 30 Handle<FixedArray> arr =
84 factory->NewFixedArray(kWasmDebugInfoNumEntries, TENURED); 31 factory->NewFixedArray(kWasmDebugInfoNumEntries, TENURED);
85 arr->set(kWasmDebugInfoWasmObj, *instance); 32 arr->set(kWasmDebugInfoWasmObj, *instance);
86 int hash = 0; 33 int hash = 0;
87 Handle<SeqOneByteString> wasm_bytes = 34 Handle<SeqOneByteString> wasm_bytes =
(...skipping 18 matching lines...) Expand all
106 } 53 }
107 54
108 WasmDebugInfo *WasmDebugInfo::cast(Object *object) { 55 WasmDebugInfo *WasmDebugInfo::cast(Object *object) {
109 DCHECK(IsDebugInfo(object)); 56 DCHECK(IsDebugInfo(object));
110 return reinterpret_cast<WasmDebugInfo *>(object); 57 return reinterpret_cast<WasmDebugInfo *>(object);
111 } 58 }
112 59
113 WasmInstanceObject *WasmDebugInfo::wasm_instance() { 60 WasmInstanceObject *WasmDebugInfo::wasm_instance() {
114 return WasmInstanceObject::cast(get(kWasmDebugInfoWasmObj)); 61 return WasmInstanceObject::cast(get(kWasmDebugInfoWasmObj));
115 } 62 }
116
117 int WasmDebugInfo::GetAsmJsSourcePosition(Handle<WasmDebugInfo> debug_info,
118 int func_index, int byte_offset) {
119 Isolate *isolate = debug_info->GetIsolate();
120 Handle<WasmInstanceObject> instance(debug_info->wasm_instance(), isolate);
121 FixedArray *offset_tables = GetAsmJsOffsetTables(debug_info, isolate);
122
123 WasmCompiledModule *compiled_module = instance->get_compiled_module();
124 int num_imported_functions =
125 compiled_module->module()->num_imported_functions;
126 DCHECK_LE(num_imported_functions, func_index);
127 func_index -= num_imported_functions;
128 DCHECK_LT(func_index, offset_tables->length());
129 ByteArray *offset_table = ByteArray::cast(offset_tables->get(func_index));
130
131 // Binary search for the current byte offset.
132 int left = 0; // inclusive
133 int right = offset_table->length() / kIntSize / 2; // exclusive
134 DCHECK_LT(left, right);
135 while (right - left > 1) {
136 int mid = left + (right - left) / 2;
137 if (offset_table->get_int(2 * mid) <= byte_offset) {
138 left = mid;
139 } else {
140 right = mid;
141 }
142 }
143 // There should be an entry for each position that could show up on the stack
144 // trace:
145 DCHECK_EQ(byte_offset, offset_table->get_int(2 * left));
146 return offset_table->get_int(2 * left + 1);
147 }
OLDNEW
« no previous file with comments | « src/messages.cc ('k') | src/wasm/wasm-module.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698