From d623fcae9cad5cb56475b7f1065a0a1adc2cf432 Mon Sep 17 00:00:00 2001 From: Michael Starzinger Date: Fri, 2 Mar 2018 10:57:56 +0100 Subject: [PATCH] [wasm] Turn {WasmSharedModuleData} into a proper {Struct}. This makes sure that the object can be identified by a unique instance type and hence is not accidentally confused with other FixedArrays on the heap. R=clemensh@chromium.org BUG=v8:7509 Change-Id: Ib3dcdb4559821d0ad9ca8cced37754e0e3c1d578 Reviewed-on: https://chromium-review.googlesource.com/943781 Commit-Queue: Michael Starzinger Reviewed-by: Clemens Hammacher Cr-Commit-Position: refs/heads/master@{#51687} --- src/compiler/types.cc | 1 + src/objects-debug.cc | 11 +++ src/objects-printer.cc | 7 ++ src/objects.h | 3 + src/wasm/wasm-objects-inl.h | 6 ++ src/wasm/wasm-objects.cc | 57 ++++----------- src/wasm/wasm-objects.h | 53 +++++++------- tools/v8heapconst.py | 134 ++++++++++++++++++------------------ 8 files changed, 133 insertions(+), 139 deletions(-) diff --git a/src/compiler/types.cc b/src/compiler/types.cc index ded220f5aa..e0647bb8d9 100644 --- a/src/compiler/types.cc +++ b/src/compiler/types.cc @@ -312,6 +312,7 @@ Type::bitset BitsetType::Lub(i::Map* map) { case TUPLE2_TYPE: case TUPLE3_TYPE: case WASM_DEBUG_INFO_TYPE: + case WASM_SHARED_MODULE_DATA_TYPE: case LOAD_HANDLER_TYPE: case STORE_HANDLER_TYPE: case CONTEXT_EXTENSION_TYPE: diff --git a/src/objects-debug.cc b/src/objects-debug.cc index 956472f0a3..049c4db9f8 100644 --- a/src/objects-debug.cc +++ b/src/objects-debug.cc @@ -1437,6 +1437,17 @@ void WasmDebugInfo::WasmDebugInfoVerify() { VerifyObjectField(kCWasmEntryMapOffset); } +void WasmSharedModuleData::WasmSharedModuleDataVerify() { + CHECK(IsWasmSharedModuleData()); + VerifyObjectField(kModuleWrapperOffset); + CHECK(module_wrapper()->IsForeign()); + VerifyObjectField(kModuleBytesOffset); + VerifyObjectField(kScriptOffset); + VerifyObjectField(kAsmJsOffsetTableOffset); + VerifyObjectField(kBreakPointInfosOffset); + VerifyObjectField(kLazyCompilationOrchestratorOffset); +} + void DataHandler::DataHandlerVerify() { CHECK(IsDataHandler()); CHECK_IMPLIES(!smi_handler()->IsSmi(), diff --git a/src/objects-printer.cc b/src/objects-printer.cc index d8df02d217..e680a91ec9 100644 --- a/src/objects-printer.cc +++ b/src/objects-printer.cc @@ -1470,6 +1470,13 @@ void WasmDebugInfo::WasmDebugInfoPrint(std::ostream& os) { // NOLINT os << "\n"; } +void WasmSharedModuleData::WasmSharedModuleDataPrint( + std::ostream& os) { // NOLINT + HeapObject::PrintHeader(os, "WasmSharedModuleData"); + os << "\n - module: " << module(); + os << "\n"; +} + void LoadHandler::LoadHandlerPrint(std::ostream& os) { // NOLINT HeapObject::PrintHeader(os, "LoadHandler"); // TODO(ishell): implement printing based on handler kind diff --git a/src/objects.h b/src/objects.h index 128e48fa38..48060a0005 100644 --- a/src/objects.h +++ b/src/objects.h @@ -384,6 +384,7 @@ const int kStubMinorKeyBits = kSmiValueSize - kStubMajorKeyBits - 1; V(TUPLE2_TYPE) \ V(TUPLE3_TYPE) \ V(WASM_DEBUG_INFO_TYPE) \ + V(WASM_SHARED_MODULE_DATA_TYPE) \ \ V(CALLABLE_TASK_TYPE) \ V(CALLBACK_TASK_TYPE) \ @@ -585,6 +586,7 @@ const int kStubMinorKeyBits = kSmiValueSize - kStubMajorKeyBits - 1; V(TUPLE2, Tuple2, tuple2) \ V(TUPLE3, Tuple3, tuple3) \ V(WASM_DEBUG_INFO, WasmDebugInfo, wasm_debug_info) \ + V(WASM_SHARED_MODULE_DATA, WasmSharedModuleData, wasm_shared_module_data) \ V(CALLABLE_TASK, CallableTask, callable_task) \ V(CALLBACK_TASK, CallbackTask, callback_task) \ V(PROMISE_FULFILL_REACTION_JOB_TASK, PromiseFulfillReactionJobTask, \ @@ -776,6 +778,7 @@ enum InstanceType : uint16_t { TUPLE2_TYPE, TUPLE3_TYPE, WASM_DEBUG_INFO_TYPE, + WASM_SHARED_MODULE_DATA_TYPE, CALLABLE_TASK_TYPE, // FIRST_MICROTASK_TYPE CALLBACK_TASK_TYPE, diff --git a/src/wasm/wasm-objects-inl.h b/src/wasm/wasm-objects-inl.h index b81c4db7e9..f7edf936de 100644 --- a/src/wasm/wasm-objects-inl.h +++ b/src/wasm/wasm-objects-inl.h @@ -18,6 +18,7 @@ CAST_ACCESSOR(WasmDebugInfo) CAST_ACCESSOR(WasmInstanceObject) CAST_ACCESSOR(WasmMemoryObject) CAST_ACCESSOR(WasmModuleObject) +CAST_ACCESSOR(WasmSharedModuleData) CAST_ACCESSOR(WasmTableObject) #define OPTIONAL_ACCESSORS(holder, name, type, offset) \ @@ -63,6 +64,7 @@ ACCESSORS(WasmInstanceObject, js_imports_table, FixedArray, kJsImportsTableOffset) // WasmSharedModuleData +ACCESSORS(WasmSharedModuleData, module_wrapper, Object, kModuleWrapperOffset) ACCESSORS(WasmSharedModuleData, module_bytes, SeqOneByteString, kModuleBytesOffset) ACCESSORS(WasmSharedModuleData, script, Script, kScriptOffset) @@ -72,6 +74,10 @@ OPTIONAL_ACCESSORS(WasmSharedModuleData, breakpoint_infos, FixedArray, kBreakPointInfosOffset) OPTIONAL_ACCESSORS(WasmSharedModuleData, lazy_compilation_orchestrator, Foreign, kLazyCompilationOrchestratorOffset) +void WasmSharedModuleData::reset_breakpoint_infos() { + DCHECK(IsWasmSharedModuleData()); + WRITE_FIELD(this, kBreakPointInfosOffset, GetHeap()->undefined_value()); +} // WasmDebugInfo ACCESSORS(WasmDebugInfo, wasm_instance, WasmInstanceObject, kInstanceOffset) diff --git a/src/wasm/wasm-objects.cc b/src/wasm/wasm-objects.cc index ae6fc665de..e034bc1c3a 100644 --- a/src/wasm/wasm-objects.cc +++ b/src/wasm/wasm-objects.cc @@ -915,59 +915,33 @@ WasmCodeWrapper WasmExportedFunction::GetWasmCode() { UNREACHABLE(); } -bool WasmSharedModuleData::IsWasmSharedModuleData(Object* object) { - if (!object->IsFixedArray()) return false; - FixedArray* arr = FixedArray::cast(object); - if (arr->length() != kFieldCount) return false; - Isolate* isolate = arr->GetIsolate(); - if (!arr->get(kModuleWrapperIndex)->IsForeign()) return false; - if (!arr->get(kModuleBytesIndex)->IsUndefined(isolate) && - !arr->get(kModuleBytesIndex)->IsSeqOneByteString()) - return false; - if (!arr->get(kScriptIndex)->IsScript()) return false; - if (!arr->get(kAsmJsOffsetTableIndex)->IsUndefined(isolate) && - !arr->get(kAsmJsOffsetTableIndex)->IsByteArray()) - return false; - if (!arr->get(kBreakPointInfosIndex)->IsUndefined(isolate) && - !arr->get(kBreakPointInfosIndex)->IsFixedArray()) - return false; - return true; -} - -WasmSharedModuleData* WasmSharedModuleData::cast(Object* object) { - DCHECK(IsWasmSharedModuleData(object)); - return reinterpret_cast(object); -} - -WasmModule* WasmSharedModuleData::module() { +WasmModule* WasmSharedModuleData::module() const { // We populate the kModuleWrapper field with a Foreign holding the // address to the address of a WasmModule. This is because we can // handle both cases when the WasmModule's lifetime is managed through // a Managed object, as well as cases when it's managed // by the embedder. CcTests fall into the latter case. return *(reinterpret_cast( - Foreign::cast(get(kModuleWrapperIndex))->foreign_address())); + Foreign::cast(module_wrapper())->foreign_address())); } Handle WasmSharedModuleData::New( Isolate* isolate, Handle module_wrapper, Handle module_bytes, Handle