| 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" |
| 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 { | |
| 17 | |
| 18 enum { | |
| 19 kWasmDebugInfoWasmObj, | |
| 20 kWasmDebugInfoWasmBytesHash, | |
| 21 kWasmDebugInfoAsmJsOffsets, | |
| 22 kWasmDebugInfoNumEntries | |
| 23 }; | |
| 24 | |
| 25 } // namespace | |
| 26 | |
| 27 Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) { | 16 Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) { |
| 28 Isolate *isolate = instance->GetIsolate(); | 17 Isolate *isolate = instance->GetIsolate(); |
| 29 Factory *factory = isolate->factory(); | 18 Factory *factory = isolate->factory(); |
| 30 Handle<FixedArray> arr = | 19 Handle<FixedArray> arr = factory->NewFixedArray(kFieldCount, TENURED); |
| 31 factory->NewFixedArray(kWasmDebugInfoNumEntries, TENURED); | 20 arr->set(kInstance, *instance); |
| 32 arr->set(kWasmDebugInfoWasmObj, *instance); | |
| 33 int hash = 0; | |
| 34 Handle<SeqOneByteString> wasm_bytes = | |
| 35 instance->get_compiled_module()->module_bytes(); | |
| 36 { | |
| 37 DisallowHeapAllocation no_gc; | |
| 38 hash = StringHasher::HashSequentialString( | |
| 39 wasm_bytes->GetChars(), wasm_bytes->length(), kZeroHashSeed); | |
| 40 } | |
| 41 Handle<Object> hash_obj = factory->NewNumberFromInt(hash, TENURED); | |
| 42 arr->set(kWasmDebugInfoWasmBytesHash, *hash_obj); | |
| 43 | 21 |
| 44 return Handle<WasmDebugInfo>::cast(arr); | 22 return Handle<WasmDebugInfo>::cast(arr); |
| 45 } | 23 } |
| 46 | 24 |
| 47 bool WasmDebugInfo::IsDebugInfo(Object *object) { | 25 bool WasmDebugInfo::IsDebugInfo(Object *object) { |
| 48 if (!object->IsFixedArray()) return false; | 26 if (!object->IsFixedArray()) return false; |
| 49 FixedArray *arr = FixedArray::cast(object); | 27 FixedArray *arr = FixedArray::cast(object); |
| 50 return arr->length() == kWasmDebugInfoNumEntries && | 28 return arr->length() == kFieldCount && IsWasmInstance(arr->get(kInstance)); |
| 51 IsWasmInstance(arr->get(kWasmDebugInfoWasmObj)) && | |
| 52 arr->get(kWasmDebugInfoWasmBytesHash)->IsNumber(); | |
| 53 } | 29 } |
| 54 | 30 |
| 55 WasmDebugInfo *WasmDebugInfo::cast(Object *object) { | 31 WasmDebugInfo *WasmDebugInfo::cast(Object *object) { |
| 56 DCHECK(IsDebugInfo(object)); | 32 DCHECK(IsDebugInfo(object)); |
| 57 return reinterpret_cast<WasmDebugInfo *>(object); | 33 return reinterpret_cast<WasmDebugInfo *>(object); |
| 58 } | 34 } |
| 59 | 35 |
| 60 WasmInstanceObject *WasmDebugInfo::wasm_instance() { | 36 WasmInstanceObject *WasmDebugInfo::wasm_instance() { |
| 61 return WasmInstanceObject::cast(get(kWasmDebugInfoWasmObj)); | 37 return WasmInstanceObject::cast(get(kInstance)); |
| 62 } | 38 } |
| OLD | NEW |