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

Unified Diff: src/wasm/wasm-module.cc

Issue 2383623003: Revert of [wasm] Strongly typed compiled module (Closed)
Patch Set: Created 4 years, 3 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/wasm/wasm-module.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/wasm-module.cc
diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc
index 9f6e37843e0d3ac8b6797bbb04608c16e5f6977e..0dd53d22c826673279d3c6ebc4cb64bfcbfaa05b 100644
--- a/src/wasm/wasm-module.cc
+++ b/src/wasm/wasm-module.cc
@@ -154,6 +154,41 @@
kWasmModuleInternalFieldCount
};
+// TODO(mtrofin): Unnecessary once we stop using JS Heap for wasm code.
+// For now, each field is expected to have the type commented by its side.
+// The elements typed as "maybe" are optional. The others are mandatory. Since
+// the compiled module is either obtained from the current v8 instance, or from
+// a snapshot produced by a compatible (==identical) v8 instance, we simply
+// fail at instantiation time, in the face of invalid data.
+enum WasmCompiledModule {
+ kCodeTable, // FixedArray of Code
+ kImportData, // maybe FixedArray of FixedArray respecting the
+ // WasmImportData structure.
+ kExportData, // maybe FixedArray of FixedArray of WasmExportData
+ // structure
+ kStartupData, // maybe FixedArray of WasmExportData structure
+ kTableOfIndirectFunctionTables, // maybe FixedArray of FixedArray of
+ // WasmIndirectFunctionTableData
+ kModuleBytes, // maybe String
+ kFunctionNameTable, // maybe ByteArray
+ kMinRequiredMemory, // Smi. an uint32_t
+ // The following 2 are either together present or absent:
+ kDataSegmentsInfo, // maybe FixedArray of FixedArray respecting the
+ // WasmSegmentInfo structure
+ kDataSegments, // maybe ByteArray.
+
+ kGlobalsSize, // Smi. an uint32_t
+ kMemSize, // Smi.an uint32_t
+ kMemStart, // MaybeHandle<ArrayBuffer>
+ kExportMem, // Smi. bool
+ kOrigin, // Smi. ModuleOrigin
+ kNextInstance, // WeakCell. See compiled code cloning.
+ kPrevInstance, // WeakCell. See compiled code cloning.
+ kOwningInstance, // WeakCell, pointing to the owning instance.
+ kModuleObject, // WeakCell, pointing to the module object.
+ kWasmCompiledModuleSize // Sentinel value.
+};
+
enum WasmImportData {
kModuleName, // String
kFunctionName, // maybe String
@@ -186,16 +221,21 @@
return WasmModule::kPageSize * module->min_mem_pages;
}
-void LoadDataSegments(Handle<WasmCompiledModule> compiled_module,
- Address mem_addr, size_t mem_size) {
- CHECK(compiled_module->has_data_segments() ==
- compiled_module->has_data_segments_info());
-
+void LoadDataSegments(Handle<FixedArray> compiled_module, Address mem_addr,
+ size_t mem_size) {
+ Isolate* isolate = compiled_module->GetIsolate();
+ MaybeHandle<ByteArray> maybe_data =
+ compiled_module->GetValue<ByteArray>(isolate, kDataSegments);
+ MaybeHandle<FixedArray> maybe_segments =
+ compiled_module->GetValue<FixedArray>(isolate, kDataSegmentsInfo);
+
+ // We either have both or neither.
+ CHECK(maybe_data.is_null() == maybe_segments.is_null());
// If we have neither, we're done.
- if (!compiled_module->has_data_segments()) return;
-
- Handle<ByteArray> data = compiled_module->data_segments();
- Handle<FixedArray> segments = compiled_module->data_segments_info();
+ if (maybe_data.is_null()) return;
+
+ Handle<ByteArray> data = maybe_data.ToHandleChecked();
+ Handle<FixedArray> segments = maybe_segments.ToHandleChecked();
uint32_t last_extraction_pos = 0;
for (int i = 0; i < segments->length(); ++i) {
@@ -213,7 +253,7 @@
}
void SaveDataSegmentInfo(Factory* factory, const WasmModule* module,
- Handle<WasmCompiledModule> compiled_module) {
+ Handle<FixedArray> compiled_module) {
Handle<FixedArray> segments = factory->NewFixedArray(
static_cast<int>(module->data_segments.size()), TENURED);
uint32_t data_size = 0;
@@ -239,8 +279,8 @@
segment.source_size);
last_insertion_pos += segment.source_size;
}
- compiled_module->set_data_segments_info(segments);
- compiled_module->set_data_segments(data);
+ compiled_module->set(kDataSegmentsInfo, *segments);
+ compiled_module->set(kDataSegments, *data);
}
void PatchFunctionTable(Handle<Code> code,
@@ -848,11 +888,30 @@
}
}
+#define GET_COMPILED_MODULE_WEAK_RELATION_OR_NULL(Field) \
+ WeakCell* Get##Field(const FixedArray* compiled_module) { \
+ Object* obj = compiled_module->get(k##Field); \
+ DCHECK_NOT_NULL(obj); \
+ if (obj->IsWeakCell()) { \
+ return WeakCell::cast(obj); \
+ } else { \
+ return nullptr; \
+ } \
+ }
+
+GET_COMPILED_MODULE_WEAK_RELATION_OR_NULL(NextInstance)
+GET_COMPILED_MODULE_WEAK_RELATION_OR_NULL(PrevInstance)
+GET_COMPILED_MODULE_WEAK_RELATION_OR_NULL(OwningInstance)
+GET_COMPILED_MODULE_WEAK_RELATION_OR_NULL(ModuleObject)
+
static void ResetCompiledModule(Isolate* isolate, JSObject* owner,
- WasmCompiledModule* compiled_module) {
+ FixedArray* compiled_module) {
Object* undefined = *isolate->factory()->undefined_value();
- uint32_t old_mem_size = compiled_module->mem_size();
- Object* mem_start = compiled_module->ptr_to_mem_start();
+ Object* mem_size_obj = compiled_module->get(kMemSize);
+ DCHECK(mem_size_obj->IsMutableHeapNumber());
+ uint32_t old_mem_size =
+ static_cast<uint32_t>(HeapNumber::cast(mem_size_obj)->value());
+ Object* mem_start = compiled_module->get(kMemStart);
Address old_mem_address = nullptr;
Address globals_start =
GetGlobalStartAddressFromCodeTemplate(undefined, owner);
@@ -866,7 +925,7 @@
RelocInfo::ModeMask(RelocInfo::WASM_MEMORY_SIZE_REFERENCE) |
RelocInfo::ModeMask(RelocInfo::WASM_GLOBAL_REFERENCE);
- Object* fct_obj = compiled_module->ptr_to_code_table();
+ Object* fct_obj = compiled_module->get(kCodeTable);
if (fct_obj != nullptr && fct_obj != undefined &&
(old_mem_size > 0 || globals_start != nullptr)) {
FixedArray* functions = FixedArray::cast(fct_obj);
@@ -892,29 +951,29 @@
}
}
}
- compiled_module->reset_weak_owning_instance();
- compiled_module->reset_mem_start();
+ compiled_module->set(kOwningInstance, undefined);
+ compiled_module->set(kMemStart, undefined);
}
static void InstanceFinalizer(const v8::WeakCallbackInfo<void>& data) {
JSObject** p = reinterpret_cast<JSObject**>(data.GetParameter());
JSObject* owner = *p;
- WasmCompiledModule* compiled_module =
- WasmCompiledModule::cast(owner->GetInternalField(kWasmCompiledModule));
+ FixedArray* compiled_module =
+ FixedArray::cast(owner->GetInternalField(kWasmCompiledModule));
Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate());
- DCHECK(compiled_module->has_weak_module_object());
- WeakCell* weak_module_obj = compiled_module->ptr_to_weak_module_object();
-
+ Object* undefined = *isolate->factory()->undefined_value();
+ WeakCell* weak_module_obj = GetModuleObject(compiled_module);
+ DCHECK_NOT_NULL(weak_module_obj);
// weak_module_obj may have been cleared, meaning the module object
// was GC-ed. In that case, there won't be any new instances created,
// and we don't need to maintain the links between instances.
if (!weak_module_obj->cleared()) {
JSObject* module_obj = JSObject::cast(weak_module_obj->value());
- WasmCompiledModule* current_template =
- WasmCompiledModule::cast(module_obj->GetInternalField(0));
- DCHECK(!current_template->has_weak_prev_instance());
- WeakCell* next = compiled_module->ptr_to_weak_next_instance();
- WeakCell* prev = compiled_module->ptr_to_weak_prev_instance();
+ FixedArray* current_template =
+ FixedArray::cast(module_obj->GetInternalField(0));
+ DCHECK_NULL(GetPrevInstance(current_template));
+ WeakCell* next = GetNextInstance(compiled_module);
+ WeakCell* prev = GetPrevInstance(compiled_module);
if (current_template == compiled_module) {
if (next == nullptr) {
@@ -923,7 +982,7 @@
DCHECK(next->value()->IsFixedArray());
module_obj->SetInternalField(0, next->value());
DCHECK_NULL(prev);
- WasmCompiledModule::cast(next->value())->reset_weak_prev_instance();
+ FixedArray::cast(next->value())->set(kPrevInstance, undefined);
}
} else {
DCHECK(!(prev == nullptr && next == nullptr));
@@ -932,21 +991,13 @@
// we would have relinked the list.
if (prev != nullptr) {
DCHECK(!prev->cleared());
- if (next == nullptr) {
- WasmCompiledModule::cast(prev->value())->reset_weak_next_instance();
- } else {
- WasmCompiledModule::cast(prev->value())
- ->set_ptr_to_weak_next_instance(next);
- }
+ FixedArray::cast(prev->value())
+ ->set(kNextInstance, next == nullptr ? undefined : next);
}
if (next != nullptr) {
DCHECK(!next->cleared());
- if (prev == nullptr) {
- WasmCompiledModule::cast(next->value())->reset_weak_prev_instance();
- } else {
- WasmCompiledModule::cast(next->value())
- ->set_ptr_to_weak_prev_instance(prev);
- }
+ FixedArray::cast(next->value())
+ ->set(kPrevInstance, prev == nullptr ? undefined : prev);
}
}
}
@@ -955,11 +1006,11 @@
} // namespace
-MaybeHandle<WasmCompiledModule> WasmModule::CompileFunctions(
+MaybeHandle<FixedArray> WasmModule::CompileFunctions(
Isolate* isolate, ErrorThrower* thrower) const {
Factory* factory = isolate->factory();
- MaybeHandle<WasmCompiledModule> nothing;
+ MaybeHandle<FixedArray> nothing;
WasmModuleInstance temp_instance(this);
temp_instance.context = isolate->native_context();
@@ -1050,13 +1101,14 @@
// and information needed at instantiation time. This object needs to be
// serializable. Instantiation may occur off a deserialized version of this
// object.
- Handle<WasmCompiledModule> ret = WasmCompiledModule::New(isolate);
- ret->set_code_table(code_table);
+ Handle<FixedArray> ret =
+ factory->NewFixedArray(kWasmCompiledModuleSize, TENURED);
+ ret->set(kCodeTable, *code_table);
if (!indirect_table.is_null()) {
- ret->set_indirect_function_tables(indirect_table.ToHandleChecked());
+ ret->set(kTableOfIndirectFunctionTables, *indirect_table.ToHandleChecked());
}
Handle<FixedArray> import_data = GetImportsData(factory, this);
- ret->set_import_data(import_data);
+ ret->set(kImportData, *import_data);
// Compile exported function wrappers.
int export_size = static_cast<int>(num_exported_functions);
@@ -1094,7 +1146,7 @@
exports->set(index, *export_data);
code_table->set(static_cast<int>(functions.size() + index), *export_code);
}
- ret->set_exports(exports);
+ ret->set(kExportData, *exports);
}
// Record data for startup function.
@@ -1105,7 +1157,7 @@
startup_data->set(kExportArity, Smi::FromInt(0));
startup_data->set(kExportedFunctionIndex,
Smi::FromInt(start_function_index));
- ret->set_startup_function(startup_data);
+ ret->set(kStartupData, *startup_data);
}
// TODO(wasm): saving the module bytes for debugging is wasteful. We should
@@ -1118,18 +1170,20 @@
Handle<String> module_bytes_string =
factory->NewStringFromOneByte(module_bytes_vec, TENURED)
.ToHandleChecked();
- ret->set_module_bytes(module_bytes_string);
+ ret->set(kModuleBytes, *module_bytes_string);
}
Handle<ByteArray> function_name_table =
BuildFunctionNamesTable(isolate, module_env.module);
- ret->set_function_names(function_name_table);
- ret->set_min_required_memory(min_mem_pages);
+ ret->set(kFunctionNameTable, *function_name_table);
+ ret->set(kMinRequiredMemory, Smi::FromInt(min_mem_pages));
if (data_segments.size() > 0) SaveDataSegmentInfo(factory, this, ret);
- ret->set_globals_size(globals_size);
- ret->set_export_memory(mem_export);
- ret->set_origin(origin);
- ret->set_mem_size(temp_instance.mem_size);
+ ret->set(kGlobalsSize, Smi::FromInt(globals_size));
+ ret->set(kExportMem, Smi::FromInt(mem_export));
+ ret->set(kOrigin, Smi::FromInt(origin));
+ Handle<HeapNumber> size_as_object = factory->NewHeapNumber(
+ static_cast<double>(temp_instance.mem_size), MUTABLE, TENURED);
+ ret->set(kMemSize, *size_as_object);
return ret;
}
@@ -1197,7 +1251,7 @@
//--------------------------------------------------------------------------
// Reuse the compiled module (if no owner), otherwise clone.
//--------------------------------------------------------------------------
- Handle<WasmCompiledModule> compiled_module;
+ Handle<FixedArray> compiled_module;
Handle<FixedArray> code_table;
Handle<FixedArray> old_code_table;
Handle<JSObject> owner;
@@ -1207,31 +1261,33 @@
MaybeHandle<WeakCell> link_to_original;
{
- Handle<WasmCompiledModule> original(
- WasmCompiledModule::cast(module_object->GetInternalField(0)), isolate);
+ Handle<FixedArray> original(
+ FixedArray::cast(module_object->GetInternalField(0)), isolate);
// Always make a new copy of the code_table, since the old_code_table
// may still have placeholders for imports.
- old_code_table = original->code_table();
+ old_code_table = original->GetValueChecked<FixedArray>(isolate, kCodeTable);
code_table = factory->CopyFixedArray(old_code_table);
- if (original->has_weak_owning_instance()) {
- WeakCell* tmp = original->ptr_to_weak_owning_instance();
+ WeakCell* tmp = GetOwningInstance(*original);
+ if (tmp != nullptr) {
DCHECK(!tmp->cleared());
// There is already an owner, clone everything.
owner = Handle<JSObject>(JSObject::cast(tmp->value()), isolate);
// Insert the latest clone in front.
- compiled_module =
- handle(WasmCompiledModule::cast(*factory->CopyFixedArray(original)));
+ compiled_module = factory->CopyFixedArray(original);
// Replace the strong reference to point to the new instance here.
// This allows any of the other instances, including the original,
// to be collected.
module_object->SetInternalField(0, *compiled_module);
- compiled_module->set_weak_module_object(original->weak_module_object());
+ Handle<WeakCell> weak_link_to_wasm_obj =
+ original->GetValueChecked<WeakCell>(isolate, kModuleObject);
+
+ compiled_module->set(kModuleObject, *weak_link_to_wasm_obj);
link_to_original = factory->NewWeakCell(original);
// Don't link to original here. We remember the original
// as a weak link. If that link isn't clear by the time we finish
// instantiating this instance, then we link it at that time.
- compiled_module->reset_weak_next_instance();
+ compiled_module->set(kNextInstance, *factory->undefined_value());
// Clone the code for WASM functions and exports.
for (int i = 0; i < code_table->length(); ++i) {
@@ -1250,13 +1306,18 @@
UNREACHABLE();
}
}
- compiled_module->set_mem_size(original->mem_size());
+ Handle<HeapNumber> size_as_object = factory->NewHeapNumber(
+ static_cast<double>(
+ compiled_module->GetValueChecked<HeapNumber>(isolate, kMemSize)
+ ->value()),
+ MUTABLE, TENURED);
+ compiled_module->set(kMemSize, *size_as_object);
RecordStats(isolate, code_table);
} else {
// There was no owner, so we can reuse the original.
compiled_module = original;
}
- compiled_module->set_code_table(code_table);
+ compiled_module->set(kCodeTable, *code_table);
}
//--------------------------------------------------------------------------
@@ -1274,7 +1335,8 @@
MaybeHandle<JSArrayBuffer> old_memory;
// TODO(titzer): handle imported memory properly.
- uint32_t min_mem_pages = compiled_module->min_required_memory();
+ uint32_t min_mem_pages = static_cast<uint32_t>(
+ Smi::cast(compiled_module->get(kMinRequiredMemory))->value());
isolate->counters()->wasm_min_mem_pages_count()->AddSample(min_mem_pages);
// TODO(wasm): re-enable counter for max_mem_pages when we use that field.
@@ -1289,16 +1351,20 @@
uint32_t mem_size = static_cast<uint32_t>(memory->byte_length()->Number());
LoadDataSegments(compiled_module, mem_start, mem_size);
- uint32_t old_mem_size = compiled_module->mem_size();
+ uint32_t old_mem_size = static_cast<uint32_t>(
+ compiled_module->GetValueChecked<HeapNumber>(isolate, kMemSize)
+ ->value());
+ MaybeHandle<JSArrayBuffer> old_mem =
+ compiled_module->GetValue<JSArrayBuffer>(isolate, kMemStart);
Address old_mem_start =
- compiled_module->has_mem_start()
- ? static_cast<Address>(
- compiled_module->mem_start()->backing_store())
- : nullptr;
+ old_mem.is_null()
+ ? nullptr
+ : static_cast<Address>(old_mem.ToHandleChecked()->backing_store());
RelocateInstanceCode(instance, old_mem_start, mem_start, old_mem_size,
mem_size);
- compiled_module->set_mem_size(mem_size);
- compiled_module->set_mem_start(memory);
+ compiled_module->GetValueChecked<HeapNumber>(isolate, kMemSize)
+ ->set_value(static_cast<double>(mem_size));
+ compiled_module->set(kMemStart, *memory);
}
//--------------------------------------------------------------------------
@@ -1306,7 +1372,8 @@
//--------------------------------------------------------------------------
MaybeHandle<JSArrayBuffer> old_globals;
MaybeHandle<JSArrayBuffer> globals;
- uint32_t globals_size = compiled_module->globals_size();
+ uint32_t globals_size = static_cast<uint32_t>(
+ Smi::cast(compiled_module->get(kGlobalsSize))->value());
if (globals_size > 0) {
Handle<JSArrayBuffer> global_buffer = NewArrayBuffer(isolate, globals_size);
globals = global_buffer;
@@ -1327,9 +1394,10 @@
// Compile the import wrappers for the new instance.
//--------------------------------------------------------------------------
// TODO(titzer): handle imported globals and function tables.
+ Handle<FixedArray> import_data;
int num_imported_functions = 0;
- if (compiled_module->has_import_data()) {
- Handle<FixedArray> import_data = compiled_module->import_data();
+ if (compiled_module->GetValue<FixedArray>(isolate, kImportData)
+ .ToHandle(&import_data)) {
num_imported_functions = import_data->length();
for (int index = 0; index < num_imported_functions; index++) {
Handle<Code> import_wrapper =
@@ -1343,16 +1411,18 @@
//--------------------------------------------------------------------------
// Set up the debug support for the new instance.
//--------------------------------------------------------------------------
- // TODO(wasm): avoid referencing this stuff from the instance, use it off
- // the compiled module instead. See the following 3 assignments:
- if (compiled_module->has_module_bytes()) {
+ MaybeHandle<String> module_bytes_string =
+ compiled_module->GetValue<String>(isolate, kModuleBytes);
+ if (!module_bytes_string.is_null()) {
instance->SetInternalField(kWasmModuleBytesString,
- compiled_module->ptr_to_module_bytes());
- }
-
- if (compiled_module->has_function_names()) {
- instance->SetInternalField(kWasmFunctionNamesArray,
- compiled_module->ptr_to_function_names());
+ *module_bytes_string.ToHandleChecked());
+ }
+
+ MaybeHandle<ByteArray> function_name_table =
+ compiled_module->GetValue<ByteArray>(isolate, kFunctionNameTable);
+ if (!function_name_table.is_null()) {
+ Handle<ByteArray> handle = function_name_table.ToHandleChecked();
+ instance->SetInternalField(kWasmFunctionNamesArray, *handle);
}
{
@@ -1388,9 +1458,11 @@
functions[i] = code_table->GetValueChecked<Code>(isolate, i);
}
- if (compiled_module->has_indirect_function_tables()) {
- Handle<FixedArray> indirect_tables_template =
- compiled_module->indirect_function_tables();
+ MaybeHandle<FixedArray> maybe_indirect_tables =
+ compiled_module->GetValue<FixedArray>(isolate,
+ kTableOfIndirectFunctionTables);
+ Handle<FixedArray> indirect_tables_template;
+ if (maybe_indirect_tables.ToHandle(&indirect_tables_template)) {
Handle<FixedArray> to_replace =
owner.is_null() ? indirect_tables_template
: handle(FixedArray::cast(owner->GetInternalField(
@@ -1412,10 +1484,14 @@
//--------------------------------------------------------------------------
// Set up the exports object for the new instance.
//--------------------------------------------------------------------------
- bool mem_export = compiled_module->export_memory();
- ModuleOrigin origin = compiled_module->origin();
-
- if (compiled_module->has_exports() || mem_export) {
+ bool mem_export =
+ static_cast<bool>(Smi::cast(compiled_module->get(kExportMem))->value());
+ ModuleOrigin origin = static_cast<ModuleOrigin>(
+ Smi::cast(compiled_module->get(kOrigin))->value());
+
+ MaybeHandle<FixedArray> maybe_exports =
+ compiled_module->GetValue<FixedArray>(isolate, kExportData);
+ if (!maybe_exports.is_null() || mem_export) {
PropertyDescriptor desc;
desc.set_writable(false);
@@ -1428,6 +1504,7 @@
Handle<String> exports_name = factory->InternalizeUtf8String("exports");
JSObject::AddProperty(instance, exports_name, exports_object, READ_ONLY);
}
+ Handle<FixedArray> exports;
int first_export = -1;
// TODO(wasm): another iteration over the code objects.
for (int i = 0; i < code_table->length(); i++) {
@@ -1437,8 +1514,7 @@
break;
}
}
- if (compiled_module->has_exports()) {
- Handle<FixedArray> exports = compiled_module->exports();
+ if (maybe_exports.ToHandle(&exports)) {
int export_size = exports->length();
for (int i = 0; i < export_size; ++i) {
Handle<FixedArray> export_data =
@@ -1484,8 +1560,9 @@
//--------------------------------------------------------------------------
// Run the start function if one was specified.
//--------------------------------------------------------------------------
- if (compiled_module->has_startup_function()) {
- Handle<FixedArray> startup_data = compiled_module->startup_function();
+ Handle<FixedArray> startup_data;
+ if (compiled_module->GetValue<FixedArray>(isolate, kStartupData)
+ .ToHandle(&startup_data)) {
HandleScope scope(isolate);
int32_t start_index =
startup_data->GetValueChecked<Smi>(isolate, kExportedFunctionIndex)
@@ -1512,7 +1589,7 @@
DCHECK(wasm::IsWasmObject(*instance));
- if (compiled_module->has_weak_module_object()) {
+ if (!compiled_module->GetValue<WeakCell>(isolate, kModuleObject).is_null()) {
instance->SetInternalField(kWasmCompiledModule, *compiled_module);
Handle<WeakCell> link_to_owner = factory->NewWeakCell(instance);
@@ -1520,14 +1597,14 @@
Handle<WeakCell> link_to_clone = factory->NewWeakCell(compiled_module);
{
DisallowHeapAllocation no_gc;
- compiled_module->set_weak_owning_instance(link_to_owner);
+ compiled_module->set(kOwningInstance, *link_to_owner);
Handle<WeakCell> next;
if (link_to_original.ToHandle(&next) && !next->cleared()) {
- WasmCompiledModule* original = WasmCompiledModule::cast(next->value());
- DCHECK(original->has_weak_owning_instance());
- DCHECK(!original->weak_owning_instance()->cleared());
- compiled_module->set_weak_next_instance(next);
- original->set_weak_prev_instance(link_to_clone);
+ FixedArray* original = FixedArray::cast(next->value());
+ DCHECK_NOT_NULL(GetOwningInstance(original));
+ DCHECK(!GetOwningInstance(original)->cleared());
+ compiled_module->set(kNextInstance, *next);
+ original->set(kPrevInstance, *link_to_clone);
}
GlobalHandles::MakeWeak(global_handle.location(),
global_handle.location(), &InstanceFinalizer,
@@ -1710,8 +1787,7 @@
Object::SetProperty(module_obj, module_sym, module_obj, STRICT).Check();
}
Handle<WeakCell> link_to_module = isolate->factory()->NewWeakCell(module_obj);
- WasmCompiledModule::cast(*compiled_module)
- ->set_weak_module_object(link_to_module);
+ compiled_module->set(kModuleObject, *link_to_module);
return module_obj;
}
@@ -1764,8 +1840,8 @@
instance->SetInternalField(kWasmMemArrayBuffer, buffer);
Object* module = instance->GetInternalField(kWasmCompiledModule);
if (module->IsFixedArray()) {
- WasmCompiledModule::cast(module)->set_mem_size(
- buffer->byte_length()->Number());
+ HeapNumber::cast(FixedArray::cast(module)->get(kMemSize))
+ ->set_value(buffer->byte_length()->Number());
}
}
@@ -1775,24 +1851,21 @@
int instance_count) {
CHECK_GE(instance_count, 0);
DisallowHeapAllocation no_gc;
- WasmCompiledModule* compiled_module =
- WasmCompiledModule::cast(module_obj->GetInternalField(0));
- CHECK_EQ(
- JSObject::cast(compiled_module->ptr_to_weak_module_object()->value()),
- *module_obj);
+ FixedArray* compiled_module =
+ FixedArray::cast(module_obj->GetInternalField(0));
+ CHECK_EQ(JSObject::cast(GetModuleObject(compiled_module)->value()),
+ *module_obj);
Object* prev = nullptr;
- int found_instances = compiled_module->has_weak_owning_instance() ? 1 : 0;
- WasmCompiledModule* current_instance = compiled_module;
- while (current_instance->has_weak_next_instance()) {
- CHECK((prev == nullptr && !current_instance->has_weak_prev_instance()) ||
- current_instance->ptr_to_weak_prev_instance()->value() == prev);
- CHECK_EQ(current_instance->ptr_to_weak_module_object()->value(),
- *module_obj);
- CHECK(
- IsWasmObject(current_instance->ptr_to_weak_owning_instance()->value()));
+ int found_instances = GetOwningInstance(compiled_module) == nullptr ? 0 : 1;
+ FixedArray* current_instance = compiled_module;
+ while (GetNextInstance(current_instance) != nullptr) {
+ CHECK((prev == nullptr && GetPrevInstance(current_instance) == nullptr) ||
+ GetPrevInstance(current_instance)->value() == prev);
+ CHECK_EQ(GetModuleObject(current_instance)->value(), *module_obj);
+ CHECK(IsWasmObject(GetOwningInstance(current_instance)->value()));
prev = current_instance;
- current_instance = WasmCompiledModule::cast(
- current_instance->ptr_to_weak_next_instance()->value());
+ current_instance =
+ FixedArray::cast(GetNextInstance(current_instance)->value());
++found_instances;
CHECK_LE(found_instances, instance_count);
}
@@ -1801,22 +1874,22 @@
void ValidateModuleState(Isolate* isolate, Handle<JSObject> module_obj) {
DisallowHeapAllocation no_gc;
- WasmCompiledModule* compiled_module =
- WasmCompiledModule::cast(module_obj->GetInternalField(0));
- CHECK(compiled_module->has_weak_module_object());
- CHECK_EQ(compiled_module->ptr_to_weak_module_object()->value(), *module_obj);
- CHECK(!compiled_module->has_weak_prev_instance());
- CHECK(!compiled_module->has_weak_next_instance());
- CHECK(!compiled_module->has_weak_owning_instance());
+ FixedArray* compiled_module =
+ FixedArray::cast(module_obj->GetInternalField(0));
+ CHECK_NOT_NULL(GetModuleObject(compiled_module));
+ CHECK_EQ(GetModuleObject(compiled_module)->value(), *module_obj);
+ CHECK_NULL(GetPrevInstance(compiled_module));
+ CHECK_NULL(GetNextInstance(compiled_module));
+ CHECK_NULL(GetOwningInstance(compiled_module));
}
void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance) {
DisallowHeapAllocation no_gc;
CHECK(IsWasmObject(*instance));
- WasmCompiledModule* compiled_module =
- WasmCompiledModule::cast(instance->GetInternalField(kWasmCompiledModule));
- CHECK(compiled_module->has_weak_module_object());
- CHECK(compiled_module->ptr_to_weak_module_object()->cleared());
+ FixedArray* compiled_module =
+ FixedArray::cast(instance->GetInternalField(kWasmCompiledModule));
+ CHECK_NOT_NULL(GetModuleObject(compiled_module));
+ CHECK(GetModuleObject(compiled_module)->cleared());
}
} // namespace testing
« no previous file with comments | « src/wasm/wasm-module.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698