| OLD | NEW |
| 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" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 // TODO(clemensh): Move asm.js offset tables to the compiled module. | 25 // TODO(clemensh): Move asm.js offset tables to the compiled module. |
| 26 FixedArray *GetAsmJsOffsetTables(Handle<WasmDebugInfo> debug_info, | 26 FixedArray *GetAsmJsOffsetTables(Handle<WasmDebugInfo> debug_info, |
| 27 Isolate *isolate) { | 27 Isolate *isolate) { |
| 28 Object *offset_tables = debug_info->get(kWasmDebugInfoAsmJsOffsets); | 28 Object *offset_tables = debug_info->get(kWasmDebugInfoAsmJsOffsets); |
| 29 if (!offset_tables->IsUndefined(isolate)) { | 29 if (!offset_tables->IsUndefined(isolate)) { |
| 30 return FixedArray::cast(offset_tables); | 30 return FixedArray::cast(offset_tables); |
| 31 } | 31 } |
| 32 | 32 |
| 33 Handle<JSObject> wasm_instance(debug_info->wasm_instance(), isolate); | 33 Handle<WasmInstanceObject> wasm_instance(debug_info->wasm_instance(), |
| 34 Handle<WasmCompiledModule> compiled_module(GetCompiledModule(*wasm_instance), | 34 isolate); |
| 35 isolate); | 35 Handle<WasmCompiledModule> compiled_module( |
| 36 wasm_instance->get_compiled_module(), isolate); |
| 36 DCHECK(compiled_module->has_asm_js_offset_tables()); | 37 DCHECK(compiled_module->has_asm_js_offset_tables()); |
| 37 | 38 |
| 38 AsmJsOffsetsResult asm_offsets; | 39 AsmJsOffsetsResult asm_offsets; |
| 39 { | 40 { |
| 40 Handle<ByteArray> asm_offset_tables = | 41 Handle<ByteArray> asm_offset_tables = |
| 41 compiled_module->asm_js_offset_tables(); | 42 compiled_module->asm_js_offset_tables(); |
| 42 DisallowHeapAllocation no_gc; | 43 DisallowHeapAllocation no_gc; |
| 43 const byte *bytes_start = asm_offset_tables->GetDataStartAddress(); | 44 const byte *bytes_start = asm_offset_tables->GetDataStartAddress(); |
| 44 const byte *bytes_end = bytes_start + asm_offset_tables->length(); | 45 const byte *bytes_end = bytes_start + asm_offset_tables->length(); |
| 45 asm_offsets = wasm::DecodeAsmJsOffsets(bytes_start, bytes_end); | 46 asm_offsets = wasm::DecodeAsmJsOffsets(bytes_start, bytes_end); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 69 DCHECK(idx == 0 || p.first > arr->get_int(idx - 2)); | 70 DCHECK(idx == 0 || p.first > arr->get_int(idx - 2)); |
| 70 arr->set_int(idx++, p.first); | 71 arr->set_int(idx++, p.first); |
| 71 arr->set_int(idx++, p.second); | 72 arr->set_int(idx++, p.second); |
| 72 } | 73 } |
| 73 DCHECK_EQ(arr->length(), idx * kIntSize); | 74 DCHECK_EQ(arr->length(), idx * kIntSize); |
| 74 } | 75 } |
| 75 return *all_tables; | 76 return *all_tables; |
| 76 } | 77 } |
| 77 } // namespace | 78 } // namespace |
| 78 | 79 |
| 79 Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<JSObject> wasm) { | 80 Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) { |
| 80 Isolate *isolate = wasm->GetIsolate(); | 81 Isolate *isolate = instance->GetIsolate(); |
| 81 Factory *factory = isolate->factory(); | 82 Factory *factory = isolate->factory(); |
| 82 Handle<FixedArray> arr = | 83 Handle<FixedArray> arr = |
| 83 factory->NewFixedArray(kWasmDebugInfoNumEntries, TENURED); | 84 factory->NewFixedArray(kWasmDebugInfoNumEntries, TENURED); |
| 84 arr->set(kWasmDebugInfoWasmObj, *wasm); | 85 arr->set(kWasmDebugInfoWasmObj, *instance); |
| 85 int hash = 0; | 86 int hash = 0; |
| 86 Handle<SeqOneByteString> wasm_bytes = GetWasmBytes(wasm); | 87 Handle<SeqOneByteString> wasm_bytes = |
| 88 instance->get_compiled_module()->module_bytes(); |
| 87 { | 89 { |
| 88 DisallowHeapAllocation no_gc; | 90 DisallowHeapAllocation no_gc; |
| 89 hash = StringHasher::HashSequentialString( | 91 hash = StringHasher::HashSequentialString( |
| 90 wasm_bytes->GetChars(), wasm_bytes->length(), kZeroHashSeed); | 92 wasm_bytes->GetChars(), wasm_bytes->length(), kZeroHashSeed); |
| 91 } | 93 } |
| 92 Handle<Object> hash_obj = factory->NewNumberFromInt(hash, TENURED); | 94 Handle<Object> hash_obj = factory->NewNumberFromInt(hash, TENURED); |
| 93 arr->set(kWasmDebugInfoWasmBytesHash, *hash_obj); | 95 arr->set(kWasmDebugInfoWasmBytesHash, *hash_obj); |
| 94 | 96 |
| 95 return Handle<WasmDebugInfo>::cast(arr); | 97 return Handle<WasmDebugInfo>::cast(arr); |
| 96 } | 98 } |
| 97 | 99 |
| 98 bool WasmDebugInfo::IsDebugInfo(Object *object) { | 100 bool WasmDebugInfo::IsDebugInfo(Object *object) { |
| 99 if (!object->IsFixedArray()) return false; | 101 if (!object->IsFixedArray()) return false; |
| 100 FixedArray *arr = FixedArray::cast(object); | 102 FixedArray *arr = FixedArray::cast(object); |
| 101 return arr->length() == kWasmDebugInfoNumEntries && | 103 return arr->length() == kWasmDebugInfoNumEntries && |
| 102 IsWasmInstance(arr->get(kWasmDebugInfoWasmObj)) && | 104 IsWasmInstance(arr->get(kWasmDebugInfoWasmObj)) && |
| 103 arr->get(kWasmDebugInfoWasmBytesHash)->IsNumber(); | 105 arr->get(kWasmDebugInfoWasmBytesHash)->IsNumber(); |
| 104 } | 106 } |
| 105 | 107 |
| 106 WasmDebugInfo *WasmDebugInfo::cast(Object *object) { | 108 WasmDebugInfo *WasmDebugInfo::cast(Object *object) { |
| 107 DCHECK(IsDebugInfo(object)); | 109 DCHECK(IsDebugInfo(object)); |
| 108 return reinterpret_cast<WasmDebugInfo *>(object); | 110 return reinterpret_cast<WasmDebugInfo *>(object); |
| 109 } | 111 } |
| 110 | 112 |
| 111 JSObject *WasmDebugInfo::wasm_instance() { | 113 WasmInstanceObject *WasmDebugInfo::wasm_instance() { |
| 112 return JSObject::cast(get(kWasmDebugInfoWasmObj)); | 114 return WasmInstanceObject::cast(get(kWasmDebugInfoWasmObj)); |
| 113 } | 115 } |
| 114 | 116 |
| 115 int WasmDebugInfo::GetAsmJsSourcePosition(Handle<WasmDebugInfo> debug_info, | 117 int WasmDebugInfo::GetAsmJsSourcePosition(Handle<WasmDebugInfo> debug_info, |
| 116 int func_index, int byte_offset) { | 118 int func_index, int byte_offset) { |
| 117 Isolate *isolate = debug_info->GetIsolate(); | 119 Isolate *isolate = debug_info->GetIsolate(); |
| 118 Handle<JSObject> instance(debug_info->wasm_instance(), isolate); | 120 Handle<WasmInstanceObject> instance(debug_info->wasm_instance(), isolate); |
| 119 FixedArray *offset_tables = GetAsmJsOffsetTables(debug_info, isolate); | 121 FixedArray *offset_tables = GetAsmJsOffsetTables(debug_info, isolate); |
| 120 | 122 |
| 121 WasmCompiledModule *compiled_module = wasm::GetCompiledModule(*instance); | 123 WasmCompiledModule *compiled_module = instance->get_compiled_module(); |
| 122 int num_imported_functions = | 124 int num_imported_functions = |
| 123 compiled_module->module()->num_imported_functions; | 125 compiled_module->module()->num_imported_functions; |
| 124 DCHECK_LE(num_imported_functions, func_index); | 126 DCHECK_LE(num_imported_functions, func_index); |
| 125 func_index -= num_imported_functions; | 127 func_index -= num_imported_functions; |
| 126 DCHECK_LT(func_index, offset_tables->length()); | 128 DCHECK_LT(func_index, offset_tables->length()); |
| 127 ByteArray *offset_table = ByteArray::cast(offset_tables->get(func_index)); | 129 ByteArray *offset_table = ByteArray::cast(offset_tables->get(func_index)); |
| 128 | 130 |
| 129 // Binary search for the current byte offset. | 131 // Binary search for the current byte offset. |
| 130 int left = 0; // inclusive | 132 int left = 0; // inclusive |
| 131 int right = offset_table->length() / kIntSize / 2; // exclusive | 133 int right = offset_table->length() / kIntSize / 2; // exclusive |
| 132 DCHECK_LT(left, right); | 134 DCHECK_LT(left, right); |
| 133 while (right - left > 1) { | 135 while (right - left > 1) { |
| 134 int mid = left + (right - left) / 2; | 136 int mid = left + (right - left) / 2; |
| 135 if (offset_table->get_int(2 * mid) <= byte_offset) { | 137 if (offset_table->get_int(2 * mid) <= byte_offset) { |
| 136 left = mid; | 138 left = mid; |
| 137 } else { | 139 } else { |
| 138 right = mid; | 140 right = mid; |
| 139 } | 141 } |
| 140 } | 142 } |
| 141 // There should be an entry for each position that could show up on the stack | 143 // There should be an entry for each position that could show up on the stack |
| 142 // trace: | 144 // trace: |
| 143 DCHECK_EQ(byte_offset, offset_table->get_int(2 * left)); | 145 DCHECK_EQ(byte_offset, offset_table->get_int(2 * left)); |
| 144 return offset_table->get_int(2 * left + 1); | 146 return offset_table->get_int(2 * left + 1); |
| 145 } | 147 } |
| OLD | NEW |