Commit 6d20218e authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Remove {WasmCompiledModule} object type.

R=clemensh@chromium.org

Change-Id: I01b0b4948973ebbe0386ae8ae08e722ad16bcab8
Reviewed-on: https://chromium-review.googlesource.com/1114616Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54058}
parent ded61e98
...@@ -316,7 +316,6 @@ Type::bitset BitsetType::Lub(HeapObjectType const& type) { ...@@ -316,7 +316,6 @@ Type::bitset BitsetType::Lub(HeapObjectType const& type) {
case INTERPRETER_DATA_TYPE: case INTERPRETER_DATA_TYPE:
case TUPLE2_TYPE: case TUPLE2_TYPE:
case TUPLE3_TYPE: case TUPLE3_TYPE:
case WASM_COMPILED_MODULE_TYPE:
case WASM_DEBUG_INFO_TYPE: case WASM_DEBUG_INFO_TYPE:
case WASM_EXPORTED_FUNCTION_DATA_TYPE: case WASM_EXPORTED_FUNCTION_DATA_TYPE:
case LOAD_HANDLER_TYPE: case LOAD_HANDLER_TYPE:
......
...@@ -548,7 +548,7 @@ class WasmInstanceObject::BodyDescriptor final : public BodyDescriptorBase { ...@@ -548,7 +548,7 @@ class WasmInstanceObject::BodyDescriptor final : public BodyDescriptorBase {
public: public:
static bool IsValidSlot(Map* map, HeapObject* obj, int offset) { static bool IsValidSlot(Map* map, HeapObject* obj, int offset) {
if (offset < kMemoryStartOffset) return true; if (offset < kMemoryStartOffset) return true;
if (offset < kCompiledModuleOffset) return false; if (offset < kModuleObjectOffset) return false;
return IsValidSlotImpl(map, obj, offset); return IsValidSlotImpl(map, obj, offset);
} }
......
...@@ -1540,13 +1540,6 @@ void Tuple3::Tuple3Verify(Isolate* isolate) { ...@@ -1540,13 +1540,6 @@ void Tuple3::Tuple3Verify(Isolate* isolate) {
VerifyObjectField(kValue3Offset); VerifyObjectField(kValue3Offset);
} }
void WasmCompiledModule::WasmCompiledModuleVerify(Isolate* isolate) {
CHECK(IsWasmCompiledModule());
VerifyObjectField(kNextInstanceOffset);
VerifyObjectField(kPrevInstanceOffset);
VerifyObjectField(kOwningInstanceOffset);
}
void WasmDebugInfo::WasmDebugInfoVerify(Isolate* isolate) { void WasmDebugInfo::WasmDebugInfoVerify(Isolate* isolate) {
CHECK(IsWasmDebugInfo()); CHECK(IsWasmDebugInfo());
VerifyObjectField(kInstanceOffset); VerifyObjectField(kInstanceOffset);
...@@ -1586,7 +1579,6 @@ void WasmExportedFunctionData::WasmExportedFunctionDataVerify( ...@@ -1586,7 +1579,6 @@ void WasmExportedFunctionData::WasmExportedFunctionDataVerify(
void WasmModuleObject::WasmModuleObjectVerify(Isolate* isolate) { void WasmModuleObject::WasmModuleObjectVerify(Isolate* isolate) {
CHECK(IsWasmModuleObject()); CHECK(IsWasmModuleObject());
VerifyObjectField(kNativeModuleOffset); VerifyObjectField(kNativeModuleOffset);
VerifyObjectField(kCompiledModuleOffset);
VerifyObjectField(kExportWrappersOffset); VerifyObjectField(kExportWrappersOffset);
VerifyObjectField(kManagedModuleOffset); VerifyObjectField(kManagedModuleOffset);
CHECK(managed_module()->IsForeign()); CHECK(managed_module()->IsForeign());
......
...@@ -1672,11 +1672,6 @@ void Tuple3::Tuple3Print(std::ostream& os) { // NOLINT ...@@ -1672,11 +1672,6 @@ void Tuple3::Tuple3Print(std::ostream& os) { // NOLINT
os << "\n"; os << "\n";
} }
void WasmCompiledModule::WasmCompiledModulePrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "WasmCompiledModule");
os << "\n";
}
void WasmDebugInfo::WasmDebugInfoPrint(std::ostream& os) { // NOLINT void WasmDebugInfo::WasmDebugInfoPrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "WasmDebugInfo"); HeapObject::PrintHeader(os, "WasmDebugInfo");
os << "\n - wasm_instance: " << Brief(wasm_instance()); os << "\n - wasm_instance: " << Brief(wasm_instance());
...@@ -1685,7 +1680,6 @@ void WasmDebugInfo::WasmDebugInfoPrint(std::ostream& os) { // NOLINT ...@@ -1685,7 +1680,6 @@ void WasmDebugInfo::WasmDebugInfoPrint(std::ostream& os) { // NOLINT
void WasmInstanceObject::WasmInstanceObjectPrint(std::ostream& os) { // NOLINT void WasmInstanceObject::WasmInstanceObjectPrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "WasmInstanceObject"); HeapObject::PrintHeader(os, "WasmInstanceObject");
os << "\n - compiled_module: " << Brief(compiled_module());
os << "\n - module_object: " << Brief(module_object()); os << "\n - module_object: " << Brief(module_object());
os << "\n - exports_object: " << Brief(exports_object()); os << "\n - exports_object: " << Brief(exports_object());
os << "\n - native_context: " << Brief(native_context()); os << "\n - native_context: " << Brief(native_context());
......
...@@ -103,7 +103,6 @@ ...@@ -103,7 +103,6 @@
// - ModuleInfo // - ModuleInfo
// - ScriptContextTable // - ScriptContextTable
// - FixedArrayOfWeakCells // - FixedArrayOfWeakCells
// - WasmCompiledModule
// - FixedDoubleArray // - FixedDoubleArray
// - Name // - Name
// - String // - String
...@@ -400,7 +399,6 @@ const int kStubMinorKeyBits = kSmiValueSize - kStubMajorKeyBits - 1; ...@@ -400,7 +399,6 @@ const int kStubMinorKeyBits = kSmiValueSize - kStubMajorKeyBits - 1;
V(STACK_FRAME_INFO_TYPE) \ V(STACK_FRAME_INFO_TYPE) \
V(TUPLE2_TYPE) \ V(TUPLE2_TYPE) \
V(TUPLE3_TYPE) \ V(TUPLE3_TYPE) \
V(WASM_COMPILED_MODULE_TYPE) \
V(WASM_DEBUG_INFO_TYPE) \ V(WASM_DEBUG_INFO_TYPE) \
V(WASM_EXPORTED_FUNCTION_DATA_TYPE) \ V(WASM_EXPORTED_FUNCTION_DATA_TYPE) \
\ \
...@@ -587,7 +585,6 @@ const int kStubMinorKeyBits = kSmiValueSize - kStubMajorKeyBits - 1; ...@@ -587,7 +585,6 @@ const int kStubMinorKeyBits = kSmiValueSize - kStubMajorKeyBits - 1;
V(STACK_FRAME_INFO, StackFrameInfo, stack_frame_info) \ V(STACK_FRAME_INFO, StackFrameInfo, stack_frame_info) \
V(TUPLE2, Tuple2, tuple2) \ V(TUPLE2, Tuple2, tuple2) \
V(TUPLE3, Tuple3, tuple3) \ V(TUPLE3, Tuple3, tuple3) \
V(WASM_COMPILED_MODULE, WasmCompiledModule, wasm_compiled_module) \
V(WASM_DEBUG_INFO, WasmDebugInfo, wasm_debug_info) \ V(WASM_DEBUG_INFO, WasmDebugInfo, wasm_debug_info) \
V(WASM_EXPORTED_FUNCTION_DATA, WasmExportedFunctionData, \ V(WASM_EXPORTED_FUNCTION_DATA, WasmExportedFunctionData, \
wasm_exported_function_data) \ wasm_exported_function_data) \
...@@ -786,7 +783,6 @@ enum InstanceType : uint16_t { ...@@ -786,7 +783,6 @@ enum InstanceType : uint16_t {
STACK_FRAME_INFO_TYPE, STACK_FRAME_INFO_TYPE,
TUPLE2_TYPE, TUPLE2_TYPE,
TUPLE3_TYPE, TUPLE3_TYPE,
WASM_COMPILED_MODULE_TYPE,
WASM_DEBUG_INFO_TYPE, WASM_DEBUG_INFO_TYPE,
WASM_EXPORTED_FUNCTION_DATA_TYPE, WASM_EXPORTED_FUNCTION_DATA_TYPE,
......
...@@ -959,24 +959,6 @@ RUNTIME_FUNCTION(Runtime_DeserializeWasmModule) { ...@@ -959,24 +959,6 @@ RUNTIME_FUNCTION(Runtime_DeserializeWasmModule) {
return *module_object; return *module_object;
} }
RUNTIME_FUNCTION(Runtime_ValidateWasmInstancesChain) {
HandleScope shs(isolate);
DCHECK_EQ(2, args.length());
CONVERT_ARG_HANDLE_CHECKED(WasmModuleObject, module_obj, 0);
CONVERT_ARG_HANDLE_CHECKED(Smi, instance_count, 1);
WasmInstanceObject::ValidateInstancesChainForTesting(isolate, module_obj,
instance_count->value());
return isolate->heap()->ToBoolean(true);
}
RUNTIME_FUNCTION(Runtime_ValidateWasmModuleState) {
HandleScope shs(isolate);
DCHECK_EQ(1, args.length());
CONVERT_ARG_HANDLE_CHECKED(WasmModuleObject, module_obj, 0);
WasmModuleObject::ValidateStateForTesting(isolate, module_obj);
return isolate->heap()->ToBoolean(true);
}
RUNTIME_FUNCTION(Runtime_HeapObjectVerify) { RUNTIME_FUNCTION(Runtime_HeapObjectVerify) {
HandleScope shs(isolate); HandleScope shs(isolate);
DCHECK_EQ(1, args.length()); DCHECK_EQ(1, args.length());
...@@ -994,6 +976,18 @@ RUNTIME_FUNCTION(Runtime_HeapObjectVerify) { ...@@ -994,6 +976,18 @@ RUNTIME_FUNCTION(Runtime_HeapObjectVerify) {
return isolate->heap()->ToBoolean(true); return isolate->heap()->ToBoolean(true);
} }
RUNTIME_FUNCTION(Runtime_WasmGetNumberOfInstances) {
SealHandleScope shs(isolate);
DCHECK_EQ(1, args.length());
CONVERT_ARG_HANDLE_CHECKED(WasmModuleObject, module_obj, 0);
int instance_count = 0;
WeakArrayList* weak_instance_list = module_obj->weak_instance_list();
for (int i = 0; i < weak_instance_list->length(); ++i) {
if (weak_instance_list->Get(i)->IsWeakHeapObject()) instance_count++;
}
return Smi::FromInt(instance_count);
}
RUNTIME_FUNCTION(Runtime_WasmNumInterpretedCalls) { RUNTIME_FUNCTION(Runtime_WasmNumInterpretedCalls) {
DCHECK_EQ(1, args.length()); DCHECK_EQ(1, args.length());
HandleScope scope(isolate); HandleScope scope(isolate);
......
...@@ -556,8 +556,7 @@ namespace internal { ...@@ -556,8 +556,7 @@ namespace internal {
F(TraceEnter, 0, 1) \ F(TraceEnter, 0, 1) \
F(TraceExit, 1, 1) \ F(TraceExit, 1, 1) \
F(UnblockConcurrentRecompilation, 0, 1) \ F(UnblockConcurrentRecompilation, 0, 1) \
F(ValidateWasmInstancesChain, 2, 1) \ F(WasmGetNumberOfInstances, 1, 1) \
F(ValidateWasmModuleState, 1, 1) \
F(WasmNumInterpretedCalls, 1, 1) \ F(WasmNumInterpretedCalls, 1, 1) \
F(WasmTraceMemory, 1, 1) \ F(WasmTraceMemory, 1, 1) \
F(WasmMemoryHasFullGuardRegion, 1, 1) F(WasmMemoryHasFullGuardRegion, 1, 1)
......
...@@ -229,9 +229,8 @@ class JSToWasmWrapperCache { ...@@ -229,9 +229,8 @@ class JSToWasmWrapperCache {
std::vector<Handle<Code>> code_cache_; std::vector<Handle<Code>> code_cache_;
}; };
// A helper class to simplify instantiating a module from a compiled module. // A helper class to simplify instantiating a module from a module object.
// It closes over the {Isolate}, the {ErrorThrower}, the {WasmCompiledModule}, // It closes over the {Isolate}, the {ErrorThrower}, etc.
// etc.
class InstanceBuilder { class InstanceBuilder {
public: public:
InstanceBuilder(Isolate* isolate, ErrorThrower* thrower, InstanceBuilder(Isolate* isolate, ErrorThrower* thrower,
...@@ -1046,7 +1045,6 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() { ...@@ -1046,7 +1045,6 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
// Record build time into correct bucket, then build instance. // Record build time into correct bucket, then build instance.
TimedHistogramScope wasm_instantiate_module_time_scope(SELECT_WASM_COUNTER( TimedHistogramScope wasm_instantiate_module_time_scope(SELECT_WASM_COUNTER(
counters(), module_->origin, wasm_instantiate, module_time)); counters(), module_->origin, wasm_instantiate, module_time));
Factory* factory = isolate_->factory();
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// Allocate the memory array buffer. // Allocate the memory array buffer.
...@@ -1082,6 +1080,7 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() { ...@@ -1082,6 +1080,7 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
memory_ = AllocateMemory(initial_pages); memory_ = AllocateMemory(initial_pages);
if (memory_.is_null()) return {}; // failed to allocate memory if (memory_.is_null()) return {}; // failed to allocate memory
} }
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// Recompile module if using trap handlers but could not get guarded memory // Recompile module if using trap handlers but could not get guarded memory
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
...@@ -1113,42 +1112,14 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() { ...@@ -1113,42 +1112,14 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
} }
} }
//--------------------------------------------------------------------------
// Reuse the compiled module (if no owner), otherwise clone.
//--------------------------------------------------------------------------
wasm::NativeModule* native_module = module_object_->native_module();
// Root the old instance, if any, in case later allocation causes GC,
// to prevent the finalizer running for the old instance.
MaybeHandle<WasmInstanceObject> old_instance;
TRACE("Starting new module instantiation\n");
Handle<WasmCompiledModule> new_compiled_module;
{
Handle<WasmCompiledModule> original =
handle(module_object_->compiled_module(), isolate_);
if (original->has_instance()) {
old_instance = handle(original->owning_instance(), isolate_);
// Clone, but don't insert yet the clone in the instances chain.
// We do that last. Since we are holding on to the old instance,
// the owner + original state used for cloning and patching
// won't be mutated by possible finalizer runs.
TRACE("Cloning from %zu\n", native_module->instance_id);
new_compiled_module = WasmCompiledModule::Clone(isolate_, original);
RecordStats(module_object_->native_module(), counters());
} else {
// No instance owned the original compiled module.
new_compiled_module = original;
TRACE("Reusing existing instance %zu\n", native_module->instance_id);
}
}
wasm::NativeModuleModificationScope native_modification_scope(native_module);
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// Create the WebAssembly.Instance object. // Create the WebAssembly.Instance object.
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
wasm::NativeModule* native_module = module_object_->native_module();
TRACE("New module instantiation for %zu\n", native_module->instance_id);
Handle<WasmInstanceObject> instance = Handle<WasmInstanceObject> instance =
WasmInstanceObject::New(isolate_, module_object_, new_compiled_module); WasmInstanceObject::New(isolate_, module_object_);
Handle<WeakCell> weak_instance = factory->NewWeakCell(instance); wasm::NativeModuleModificationScope native_modification_scope(native_module);
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// Set up the globals for the new instance. // Set up the globals for the new instance.
...@@ -1294,18 +1265,9 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() { ...@@ -1294,18 +1265,9 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
FlushICache(native_module); FlushICache(native_module);
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// Insert the compiled module into the weak list of compiled modules. // Install a finalizer on the new instance object.
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
{ WasmInstanceObject::InstallFinalizer(isolate_, instance);
if (!old_instance.is_null()) {
// Publish the new instance to the instances chain.
DisallowHeapAllocation no_gc;
new_compiled_module->InsertInChain(*module_object_);
}
module_object_->set_compiled_module(*new_compiled_module);
new_compiled_module->set_weak_owning_instance(*weak_instance);
WasmInstanceObject::InstallFinalizer(isolate_, instance);
}
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// Debugging support. // Debugging support.
......
...@@ -290,11 +290,6 @@ const char* GetWasmCodeKindAsString(WasmCode::Kind kind) { ...@@ -290,11 +290,6 @@ const char* GetWasmCodeKindAsString(WasmCode::Kind kind) {
} }
WasmCode::~WasmCode() { WasmCode::~WasmCode() {
// Depending on finalizer order, the WasmCompiledModule finalizer may be
// called first, case in which we release here. If the InstanceFinalizer is
// called first, the handlers will be cleared in Reset, as-if the NativeModule
// may be later used again (which would be the case if the WasmCompiledModule
// were still held by a WasmModuleObject)
if (HasTrapHandlerIndex()) { if (HasTrapHandlerIndex()) {
CHECK_LT(trap_handler_index(), CHECK_LT(trap_handler_index(),
static_cast<size_t>(std::numeric_limits<int>::max())); static_cast<size_t>(std::numeric_limits<int>::max()));
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
CAST_ACCESSOR(WasmCompiledModule)
CAST_ACCESSOR(WasmDebugInfo) CAST_ACCESSOR(WasmDebugInfo)
CAST_ACCESSOR(WasmExportedFunctionData) CAST_ACCESSOR(WasmExportedFunctionData)
CAST_ACCESSOR(WasmGlobalObject) CAST_ACCESSOR(WasmGlobalObject)
...@@ -52,12 +51,12 @@ CAST_ACCESSOR(WasmTableObject) ...@@ -52,12 +51,12 @@ CAST_ACCESSOR(WasmTableObject)
// WasmModuleObject // WasmModuleObject
ACCESSORS(WasmModuleObject, managed_native_module, Managed<wasm::NativeModule>, ACCESSORS(WasmModuleObject, managed_native_module, Managed<wasm::NativeModule>,
kNativeModuleOffset) kNativeModuleOffset)
ACCESSORS(WasmModuleObject, compiled_module, WasmCompiledModule,
kCompiledModuleOffset)
ACCESSORS(WasmModuleObject, export_wrappers, FixedArray, kExportWrappersOffset) ACCESSORS(WasmModuleObject, export_wrappers, FixedArray, kExportWrappersOffset)
ACCESSORS(WasmModuleObject, managed_module, Managed<wasm::WasmModule>, ACCESSORS(WasmModuleObject, managed_module, Managed<wasm::WasmModule>,
kManagedModuleOffset) kManagedModuleOffset)
ACCESSORS(WasmModuleObject, script, Script, kScriptOffset) ACCESSORS(WasmModuleObject, script, Script, kScriptOffset)
ACCESSORS(WasmModuleObject, weak_instance_list, WeakArrayList,
kWeakInstanceListOffset)
OPTIONAL_ACCESSORS(WasmModuleObject, asm_js_offset_table, ByteArray, OPTIONAL_ACCESSORS(WasmModuleObject, asm_js_offset_table, ByteArray,
kAsmJsOffsetTableOffset) kAsmJsOffsetTableOffset)
OPTIONAL_ACCESSORS(WasmModuleObject, breakpoint_infos, FixedArray, OPTIONAL_ACCESSORS(WasmModuleObject, breakpoint_infos, FixedArray,
...@@ -156,8 +155,6 @@ PRIMITIVE_ACCESSORS(WasmInstanceObject, indirect_function_table_sig_ids, ...@@ -156,8 +155,6 @@ PRIMITIVE_ACCESSORS(WasmInstanceObject, indirect_function_table_sig_ids,
PRIMITIVE_ACCESSORS(WasmInstanceObject, indirect_function_table_targets, PRIMITIVE_ACCESSORS(WasmInstanceObject, indirect_function_table_targets,
Address*, kIndirectFunctionTableTargetsOffset) Address*, kIndirectFunctionTableTargetsOffset)
ACCESSORS(WasmInstanceObject, compiled_module, WasmCompiledModule,
kCompiledModuleOffset)
ACCESSORS(WasmInstanceObject, module_object, WasmModuleObject, ACCESSORS(WasmInstanceObject, module_object, WasmModuleObject,
kModuleObjectOffset) kModuleObjectOffset)
ACCESSORS(WasmInstanceObject, exports_object, JSObject, kExportsObjectOffset) ACCESSORS(WasmInstanceObject, exports_object, JSObject, kExportsObjectOffset)
...@@ -220,40 +217,6 @@ OPTIONAL_ACCESSORS(WasmDebugInfo, c_wasm_entry_map, Managed<wasm::SignatureMap>, ...@@ -220,40 +217,6 @@ OPTIONAL_ACCESSORS(WasmDebugInfo, c_wasm_entry_map, Managed<wasm::SignatureMap>,
kCWasmEntryMapOffset) kCWasmEntryMapOffset)
#undef OPTIONAL_ACCESSORS #undef OPTIONAL_ACCESSORS
#define WCM_OBJECT_OR_WEAK(TYPE, NAME, OFFSET, TYPE_CHECK) \
bool WasmCompiledModule::has_##NAME() const { \
Object* value = READ_FIELD(this, OFFSET); \
return TYPE_CHECK; \
} \
\
void WasmCompiledModule::reset_##NAME() { \
WRITE_FIELD(this, OFFSET, GetHeap()->undefined_value()); \
} \
\
ACCESSORS_CHECKED2(WasmCompiledModule, NAME, TYPE, OFFSET, TYPE_CHECK, true)
#define WCM_OBJECT(TYPE, NAME, OFFSET) \
WCM_OBJECT_OR_WEAK(TYPE, NAME, OFFSET, value->Is##TYPE())
#define WCM_WEAK_LINK(TYPE, NAME, OFFSET) \
WCM_OBJECT_OR_WEAK(WeakCell, weak_##NAME, OFFSET, value->IsWeakCell()) \
\
TYPE* WasmCompiledModule::NAME() const { \
DCHECK(!weak_##NAME()->cleared()); \
return TYPE::cast(weak_##NAME()->value()); \
}
// WasmCompiledModule
WCM_OBJECT(WasmCompiledModule, next_instance, kNextInstanceOffset)
WCM_OBJECT(WasmCompiledModule, prev_instance, kPrevInstanceOffset)
WCM_WEAK_LINK(WasmInstanceObject, owning_instance, kOwningInstanceOffset)
ACCESSORS(WasmCompiledModule, raw_next_instance, Object, kNextInstanceOffset);
ACCESSORS(WasmCompiledModule, raw_prev_instance, Object, kPrevInstanceOffset);
#undef WCM_OBJECT_OR_WEAK
#undef WCM_OBJECT
#undef WCM_WEAK_LINK
#undef READ_PRIMITIVE_FIELD #undef READ_PRIMITIVE_FIELD
#undef WRITE_PRIMITIVE_FIELD #undef WRITE_PRIMITIVE_FIELD
#undef PRIMITIVE_ACCESSORS #undef PRIMITIVE_ACCESSORS
...@@ -262,10 +225,6 @@ uint32_t WasmTableObject::current_length() { return functions()->length(); } ...@@ -262,10 +225,6 @@ uint32_t WasmTableObject::current_length() { return functions()->length(); }
bool WasmMemoryObject::has_maximum_pages() { return maximum_pages() >= 0; } bool WasmMemoryObject::has_maximum_pages() { return maximum_pages() >= 0; }
inline bool WasmCompiledModule::has_instance() const {
return !weak_owning_instance()->cleared();
}
#include "src/objects/object-macros-undef.h" #include "src/objects/object-macros-undef.h"
} // namespace internal } // namespace internal
......
This diff is collapsed.
...@@ -36,7 +36,6 @@ class BreakPoint; ...@@ -36,7 +36,6 @@ class BreakPoint;
class JSArrayBuffer; class JSArrayBuffer;
class FixedArrayOfWeakCells; class FixedArrayOfWeakCells;
class SeqOneByteString; class SeqOneByteString;
class WasmCompiledModule;
class WasmDebugInfo; class WasmDebugInfo;
class WasmInstanceObject; class WasmInstanceObject;
...@@ -107,11 +106,11 @@ class WasmModuleObject : public JSObject { ...@@ -107,11 +106,11 @@ class WasmModuleObject : public JSObject {
DECL_ACCESSORS(managed_native_module, Managed<wasm::NativeModule>) DECL_ACCESSORS(managed_native_module, Managed<wasm::NativeModule>)
inline wasm::NativeModule* native_module(); inline wasm::NativeModule* native_module();
DECL_ACCESSORS(compiled_module, WasmCompiledModule)
DECL_ACCESSORS(export_wrappers, FixedArray) DECL_ACCESSORS(export_wrappers, FixedArray)
DECL_ACCESSORS(managed_module, Managed<wasm::WasmModule>) DECL_ACCESSORS(managed_module, Managed<wasm::WasmModule>)
inline wasm::WasmModule* module() const; inline wasm::WasmModule* module() const;
DECL_ACCESSORS(script, Script) DECL_ACCESSORS(script, Script)
DECL_ACCESSORS(weak_instance_list, WeakArrayList)
DECL_OPTIONAL_ACCESSORS(asm_js_offset_table, ByteArray) DECL_OPTIONAL_ACCESSORS(asm_js_offset_table, ByteArray)
DECL_OPTIONAL_ACCESSORS(breakpoint_infos, FixedArray) DECL_OPTIONAL_ACCESSORS(breakpoint_infos, FixedArray)
inline void reset_breakpoint_infos(); inline void reset_breakpoint_infos();
...@@ -123,10 +122,10 @@ class WasmModuleObject : public JSObject { ...@@ -123,10 +122,10 @@ class WasmModuleObject : public JSObject {
// Layout description. // Layout description.
#define WASM_MODULE_OBJECT_FIELDS(V) \ #define WASM_MODULE_OBJECT_FIELDS(V) \
V(kNativeModuleOffset, kPointerSize) \ V(kNativeModuleOffset, kPointerSize) \
V(kCompiledModuleOffset, kPointerSize) \
V(kExportWrappersOffset, kPointerSize) \ V(kExportWrappersOffset, kPointerSize) \
V(kManagedModuleOffset, kPointerSize) \ V(kManagedModuleOffset, kPointerSize) \
V(kScriptOffset, kPointerSize) \ V(kScriptOffset, kPointerSize) \
V(kWeakInstanceListOffset, kPointerSize) \
V(kAsmJsOffsetTableOffset, kPointerSize) \ V(kAsmJsOffsetTableOffset, kPointerSize) \
V(kBreakPointInfosOffset, kPointerSize) \ V(kBreakPointInfosOffset, kPointerSize) \
V(kSize, 0) V(kSize, 0)
...@@ -150,9 +149,6 @@ class WasmModuleObject : public JSObject { ...@@ -150,9 +149,6 @@ class WasmModuleObject : public JSObject {
static bool SetBreakPoint(Handle<WasmModuleObject>, int* position, static bool SetBreakPoint(Handle<WasmModuleObject>, int* position,
Handle<BreakPoint> break_point); Handle<BreakPoint> break_point);
static void ValidateStateForTesting(Isolate* isolate,
Handle<WasmModuleObject> module);
// Check whether this module was generated from asm.js source. // Check whether this module was generated from asm.js source.
inline bool is_asm_js(); inline bool is_asm_js();
...@@ -374,7 +370,6 @@ class WasmInstanceObject : public JSObject { ...@@ -374,7 +370,6 @@ class WasmInstanceObject : public JSObject {
public: public:
DECL_CAST(WasmInstanceObject) DECL_CAST(WasmInstanceObject)
DECL_ACCESSORS(compiled_module, WasmCompiledModule)
DECL_ACCESSORS(module_object, WasmModuleObject) DECL_ACCESSORS(module_object, WasmModuleObject)
DECL_ACCESSORS(exports_object, JSObject) DECL_ACCESSORS(exports_object, JSObject)
DECL_ACCESSORS(native_context, Context) DECL_ACCESSORS(native_context, Context)
...@@ -408,7 +403,6 @@ class WasmInstanceObject : public JSObject { ...@@ -408,7 +403,6 @@ class WasmInstanceObject : public JSObject {
// Layout description. // Layout description.
#define WASM_INSTANCE_OBJECT_FIELDS(V) \ #define WASM_INSTANCE_OBJECT_FIELDS(V) \
V(kCompiledModuleOffset, kPointerSize) \
V(kModuleObjectOffset, kPointerSize) \ V(kModuleObjectOffset, kPointerSize) \
V(kExportsObjectOffset, kPointerSize) \ V(kExportsObjectOffset, kPointerSize) \
V(kNativeContextOffset, kPointerSize) \ V(kNativeContextOffset, kPointerSize) \
...@@ -456,12 +450,7 @@ class WasmInstanceObject : public JSObject { ...@@ -456,12 +450,7 @@ class WasmInstanceObject : public JSObject {
// If no debug info exists yet, it is created automatically. // If no debug info exists yet, it is created automatically.
static Handle<WasmDebugInfo> GetOrCreateDebugInfo(Handle<WasmInstanceObject>); static Handle<WasmDebugInfo> GetOrCreateDebugInfo(Handle<WasmInstanceObject>);
static Handle<WasmInstanceObject> New(Isolate*, Handle<WasmModuleObject>, static Handle<WasmInstanceObject> New(Isolate*, Handle<WasmModuleObject>);
Handle<WasmCompiledModule>);
static void ValidateInstancesChainForTesting(
Isolate* isolate, Handle<WasmModuleObject> module_obj,
int instance_count);
static void InstallFinalizer(Isolate* isolate, static void InstallFinalizer(Isolate* isolate,
Handle<WasmInstanceObject> instance); Handle<WasmInstanceObject> instance);
...@@ -519,73 +508,6 @@ class WasmExportedFunctionData : public Struct { ...@@ -519,73 +508,6 @@ class WasmExportedFunctionData : public Struct {
#undef WASM_EXPORTED_FUNCTION_DATA_FIELDS #undef WASM_EXPORTED_FUNCTION_DATA_FIELDS
}; };
// This represents the set of wasm compiled functions, together
// with all the information necessary for re-specializing them.
class WasmCompiledModule : public Struct {
public:
DECL_CAST(WasmCompiledModule)
// Dispatched behavior.
DECL_PRINTER(WasmCompiledModule)
DECL_VERIFIER(WasmCompiledModule)
// Layout description.
#define WASM_COMPILED_MODULE_FIELDS(V) \
V(kNextInstanceOffset, kPointerSize) \
V(kPrevInstanceOffset, kPointerSize) \
V(kOwningInstanceOffset, kPointerSize) \
V(kSize, 0)
DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
WASM_COMPILED_MODULE_FIELDS)
#undef WASM_COMPILED_MODULE_FIELDS
#define WCM_OBJECT_OR_WEAK(TYPE, NAME, SETTER_MODIFIER) \
public: \
inline TYPE* NAME() const; \
inline bool has_##NAME() const; \
inline void reset_##NAME(); \
\
SETTER_MODIFIER: \
inline void set_##NAME(TYPE* value, \
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
#define WCM_OBJECT(TYPE, NAME) WCM_OBJECT_OR_WEAK(TYPE, NAME, public)
#define WCM_CONST_OBJECT(TYPE, NAME) WCM_OBJECT_OR_WEAK(TYPE, NAME, private)
#define WCM_WEAK_LINK(TYPE, NAME) \
WCM_OBJECT_OR_WEAK(WeakCell, weak_##NAME, public) \
\
public: \
inline TYPE* NAME() const;
// Add values here if they are required for creating new instances or
// for deserialization, and if they are serializable.
// By default, instance values go to WasmInstanceObject, however, if
// we embed the generated code with a value, then we track that value here.
WCM_CONST_OBJECT(WasmCompiledModule, next_instance)
WCM_CONST_OBJECT(WasmCompiledModule, prev_instance)
WCM_WEAK_LINK(WasmInstanceObject, owning_instance)
public:
static Handle<WasmCompiledModule> New(Isolate* isolate);
static Handle<WasmCompiledModule> Clone(Isolate* isolate,
Handle<WasmCompiledModule> module);
bool has_instance() const;
void InsertInChain(WasmModuleObject*);
void RemoveFromChain(Isolate* isolate);
DECL_ACCESSORS(raw_next_instance, Object);
DECL_ACCESSORS(raw_prev_instance, Object);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(WasmCompiledModule);
};
class WasmDebugInfo : public Struct { class WasmDebugInfo : public Struct {
public: public:
DECL_ACCESSORS(wasm_instance, WasmInstanceObject) DECL_ACCESSORS(wasm_instance, WasmInstanceObject)
...@@ -681,11 +603,6 @@ class WasmDebugInfo : public Struct { ...@@ -681,11 +603,6 @@ class WasmDebugInfo : public Struct {
}; };
#undef DECL_OPTIONAL_ACCESSORS #undef DECL_OPTIONAL_ACCESSORS
#undef WCM_CONST_OBJECT
#undef WCM_LARGE_NUMBER
#undef WCM_OBJECT
#undef WCM_OBJECT_OR_WEAK
#undef WCM_WEAK_LINK
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
...@@ -120,8 +120,6 @@ void SetBreakpoint(WasmRunnerBase& runner, int function_index, int byte_offset, ...@@ -120,8 +120,6 @@ void SetBreakpoint(WasmRunnerBase& runner, int function_index, int byte_offset,
int code_offset = func_offset + byte_offset; int code_offset = func_offset + byte_offset;
if (expected_set_byte_offset == -1) expected_set_byte_offset = byte_offset; if (expected_set_byte_offset == -1) expected_set_byte_offset = byte_offset;
Handle<WasmInstanceObject> instance = runner.builder().instance_object(); Handle<WasmInstanceObject> instance = runner.builder().instance_object();
Handle<WasmCompiledModule> compiled_module(instance->compiled_module(),
runner.main_isolate());
Handle<WasmModuleObject> module_object(instance->module_object(), Handle<WasmModuleObject> module_object(instance->module_object(),
runner.main_isolate()); runner.main_isolate());
static int break_index = 0; static int break_index = 0;
......
...@@ -154,10 +154,6 @@ class WasmSerializationTest { ...@@ -154,10 +154,6 @@ class WasmSerializationTest {
Handle<WasmModuleObject> module_object = Handle<WasmModuleObject> module_object =
maybe_module_object.ToHandleChecked(); maybe_module_object.ToHandleChecked();
Handle<WasmCompiledModule> compiled_module(
module_object->compiled_module(), serialization_isolate);
Handle<FixedArray> export_wrappers(module_object->export_wrappers(),
serialization_isolate);
v8::Local<v8::Object> v8_module_obj = v8::Local<v8::Object> v8_module_obj =
v8::Utils::ToLocal(Handle<JSObject>::cast(module_object)); v8::Utils::ToLocal(Handle<JSObject>::cast(module_object));
CHECK(v8_module_obj->IsWebAssemblyCompiledModule()); CHECK(v8_module_obj->IsWebAssemblyCompiledModule());
......
...@@ -224,20 +224,14 @@ Handle<WasmInstanceObject> TestingModuleBuilder::InitInstanceObject() { ...@@ -224,20 +224,14 @@ Handle<WasmInstanceObject> TestingModuleBuilder::InitInstanceObject() {
Handle<WasmModuleObject> module_object = Handle<WasmModuleObject> module_object =
WasmModuleObject::New(isolate_, export_wrappers, test_module_, env, WasmModuleObject::New(isolate_, export_wrappers, test_module_, env,
nullptr, 0, script, Handle<ByteArray>::null()); nullptr, 0, script, Handle<ByteArray>::null());
Handle<WasmCompiledModule> compiled_module(module_object->compiled_module(),
isolate_);
// This method is called when we initialize TestEnvironment. We don't // This method is called when we initialize TestEnvironment. We don't
// have a memory yet, so we won't create it here. We'll update the // have a memory yet, so we won't create it here. We'll update the
// interpreter when we get a memory. We do have globals, though. // interpreter when we get a memory. We do have globals, though.
native_module_ = module_object->native_module(); native_module_ = module_object->native_module();
native_module_->ReserveCodeTableForTesting(kMaxFunctions); native_module_->ReserveCodeTableForTesting(kMaxFunctions);
DCHECK(compiled_module->IsWasmCompiledModule()); auto instance = WasmInstanceObject::New(isolate_, module_object);
auto instance =
WasmInstanceObject::New(isolate_, module_object, compiled_module);
instance->set_globals_start(globals_data_); instance->set_globals_start(globals_data_);
Handle<WeakCell> weak_instance = isolate()->factory()->NewWeakCell(instance);
compiled_module->set_weak_owning_instance(*weak_instance);
return instance; return instance;
} }
......
...@@ -86,7 +86,7 @@ struct ManuallyImportedJSFunction { ...@@ -86,7 +86,7 @@ struct ManuallyImportedJSFunction {
// A Wasm module builder. Globals are pre-set, however, memory and code may be // A Wasm module builder. Globals are pre-set, however, memory and code may be
// progressively added by a test. In turn, we piecemeal update the runtime // progressively added by a test. In turn, we piecemeal update the runtime
// objects, i.e. {WasmInstanceObject}, {WasmCompiledModule} and, if necessary, // objects, i.e. {WasmInstanceObject}, {WasmModuleObject} and, if necessary,
// the interpreter. // the interpreter.
class TestingModuleBuilder { class TestingModuleBuilder {
public: public:
......
...@@ -27,23 +27,21 @@ var instance4; ...@@ -27,23 +27,21 @@ var instance4;
]).exportFunc(); ]).exportFunc();
module = new WebAssembly.Module(builder.toBuffer()); module = new WebAssembly.Module(builder.toBuffer());
print("Initial module");
%ValidateWasmModuleState(module);
print("Initial instances=0"); print("Initial instances=0");
%ValidateWasmInstancesChain(module, 0); assertEquals(0, %WasmGetNumberOfInstances(module));
instance1 = new WebAssembly.Instance(module, {"": {getValue: () => 1}}); instance1 = new WebAssembly.Instance(module, {"": {getValue: () => 1}});
print("Initial instances=1"); print("Initial instances=1");
%ValidateWasmInstancesChain(module, 1); assertEquals(1, %WasmGetNumberOfInstances(module));
instance2 = new WebAssembly.Instance(module, {"": {getValue: () => 2}}); instance2 = new WebAssembly.Instance(module, {"": {getValue: () => 2}});
print("Initial instances=2"); print("Initial instances=2");
%ValidateWasmInstancesChain(module, 2); assertEquals(2, %WasmGetNumberOfInstances(module));
instance3 = new WebAssembly.Instance(module, {"": {getValue: () => 3}}); instance3 = new WebAssembly.Instance(module, {"": {getValue: () => 3}});
print("Initial instances=3"); print("Initial instances=3");
%ValidateWasmInstancesChain(module, 3); assertEquals(3, %WasmGetNumberOfInstances(module));
})(); })();
(function CompiledModuleInstancesClear1() { (function CompiledModuleInstancesClear1() {
...@@ -51,30 +49,33 @@ var instance4; ...@@ -51,30 +49,33 @@ var instance4;
instance1 = null; instance1 = null;
})(); })();
// Note that two GC's are required because weak slots clearing is deferred.
gc();
gc(); gc();
print("After gc instances=2"); print("After gc instances=2");
%ValidateWasmInstancesChain(module, 2); assertEquals(2, %WasmGetNumberOfInstances(module));
(function CompiledModuleInstancesClear3() { (function CompiledModuleInstancesClear3() {
assertEquals(3, instance3.exports.f()); assertEquals(3, instance3.exports.f());
instance3 = null; instance3 = null;
})(); })();
// Note that two GC's are required because weak slots clearing is deferred.
gc();
gc(); gc();
print("After gc instances=1"); print("After gc instances=1");
%ValidateWasmInstancesChain(module, 1); assertEquals(1, %WasmGetNumberOfInstances(module));
(function CompiledModuleInstancesClear2() { (function CompiledModuleInstancesClear2() {
assertEquals(2, instance2.exports.f()); assertEquals(2, instance2.exports.f());
instance2 = null; instance2 = null;
})(); })();
// Note that two GC's are required because weak cells are not cleared // Note that two GC's are required because weak slots clearing is deferred.
// in the same cycle that the instance finalizer is run.
gc(); gc();
gc(); gc();
print("After gc module state"); print("After gc instances=0");
%ValidateWasmModuleState(module); assertEquals(0, %WasmGetNumberOfInstances(module));
(function CompiledModuleInstancesInitialize4AndClearModule() { (function CompiledModuleInstancesInitialize4AndClearModule() {
instance4 = new WebAssembly.Instance(module, {"": {getValue: () => 4}}); instance4 = new WebAssembly.Instance(module, {"": {getValue: () => 4}});
...@@ -82,6 +83,6 @@ print("After gc module state"); ...@@ -82,6 +83,6 @@ print("After gc module state");
module = null; module = null;
})(); })();
// Note that the first GC will clear the module, the second the instance. // Note that two GC's are required because weak slots clearing is deferred.
gc(); gc();
gc(); gc();
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment