Index: src/wasm/wasm-module.cc |
diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc |
index 5b4b8e0f2895bab32b4e6402663e9b1bf7ae7157..33113c39669eb68506c2e739bdd9e8356cead246 100644 |
--- a/src/wasm/wasm-module.cc |
+++ b/src/wasm/wasm-module.cc |
@@ -19,6 +19,7 @@ |
#include "src/wasm/wasm-debug.h" |
#include "src/wasm/wasm-js.h" |
#include "src/wasm/wasm-module.h" |
+#include "src/wasm/wasm-objects.h" |
#include "src/wasm/wasm-result.h" |
#include "src/compiler/wasm-compiler.h" |
@@ -1101,7 +1102,7 @@ class WasmInstanceBuilder { |
static_cast<int>(module_->function_tables.size()); |
table_instances_.reserve(module_->function_tables.size()); |
for (int index = 0; index < function_table_count; ++index) { |
- table_instances_.push_back({Handle<JSObject>::null(), |
+ table_instances_.push_back({Handle<WasmTableObject>::null(), |
Handle<FixedArray>::null(), |
Handle<FixedArray>::null()}); |
} |
@@ -1272,7 +1273,7 @@ class WasmInstanceBuilder { |
private: |
// Represents the initialized state of a table. |
struct TableInstance { |
- Handle<JSObject> table_object; // WebAssembly.Table instance |
+ Handle<WasmTableObject> table_object; // WebAssembly.Table instance |
Handle<FixedArray> js_wrappers; // JSFunctions exported |
Handle<FixedArray> dispatch_table; // internal (code, sig) pairs |
}; |
@@ -1460,7 +1461,7 @@ class WasmInstanceBuilder { |
WasmIndirectFunctionTable& table = |
module_->function_tables[num_imported_tables]; |
TableInstance& table_instance = table_instances_[num_imported_tables]; |
- table_instance.table_object = Handle<JSObject>::cast(value); |
+ table_instance.table_object = Handle<WasmTableObject>::cast(value); |
table_instance.js_wrappers = WasmJs::GetWasmTableFunctions( |
isolate_, table_instance.table_object); |
@@ -1508,8 +1509,9 @@ class WasmInstanceBuilder { |
index, module_name, function_name); |
return -1; |
} |
+ auto memory = Handle<WasmMemoryObject>::cast(object); |
ahaas
2016/11/10 09:51:13
Can you not just use the type here instead of auto
titzer
2016/11/10 10:33:24
I think that's redundant, since a Handle<X>::cast(
|
instance->SetInternalField(kWasmMemObject, *object); |
- memory_ = WasmJs::GetWasmMemoryArrayBuffer(isolate_, object); |
+ memory_ = Handle<JSArrayBuffer>(memory->get_buffer(), isolate_); |
break; |
} |
case kExternalGlobal: { |
@@ -1665,7 +1667,7 @@ class WasmInstanceBuilder { |
WasmIndirectFunctionTable& table = |
module_->function_tables[exp.index]; |
if (table_instance.table_object.is_null()) { |
- table_instance.table_object = WasmJs::CreateWasmTableObject( |
+ table_instance.table_object = WasmTableObject::New( |
isolate_, table.min_size, table.has_max, table.max_size, |
&table_instance.js_wrappers); |
} |
@@ -1682,9 +1684,9 @@ class WasmInstanceBuilder { |
JSArrayBuffer::cast( |
instance->GetInternalField(kWasmMemArrayBuffer)), |
isolate_); |
- memory_object = WasmJs::CreateWasmMemoryObject( |
- isolate_, buffer, (module_->max_mem_pages != 0), |
- module_->max_mem_pages); |
+ memory_object = WasmMemoryObject::New( |
+ isolate_, buffer, |
+ (module_->max_mem_pages != 0) ? module_->max_mem_pages : -1); |
ahaas
2016/11/10 09:51:13
Could you do this check also in {WasmMemoryObject:
titzer
2016/11/10 10:33:24
WasmMemoryObject::New() is just a constructor, so
|
instance->SetInternalField(kWasmMemObject, *memory_object); |
} |
@@ -1756,9 +1758,10 @@ class WasmInstanceBuilder { |
Handle<FixedArray> all_dispatch_tables; |
if (!table_instance.table_object.is_null()) { |
// Get the existing dispatch table(s) with the WebAssembly.Table object. |
- all_dispatch_tables = WasmJs::AddWasmTableDispatchTable( |
- isolate_, table_instance.table_object, Handle<JSObject>::null(), |
- index, Handle<FixedArray>::null()); |
+ all_dispatch_tables = WasmTableObject::AddDispatchTable( |
+ isolate_, table_instance.table_object, |
+ Handle<WasmInstanceObject>::null(), index, |
+ Handle<FixedArray>::null()); |
} |
// TODO(titzer): this does redundant work if there are multiple tables, |
@@ -1822,8 +1825,11 @@ class WasmInstanceBuilder { |
// initialized. |
if (!table_instance.table_object.is_null()) { |
// Add the new dispatch table to the WebAssembly.Table object. |
- all_dispatch_tables = WasmJs::AddWasmTableDispatchTable( |
- isolate_, table_instance.table_object, instance, index, |
+ // TODO: remove the cast of WasmInstanceObject |
+ Handle<WasmInstanceObject> handle( |
+ reinterpret_cast<WasmInstanceObject*>(*instance), isolate_); |
+ all_dispatch_tables = WasmTableObject::AddDispatchTable( |
+ isolate_, table_instance.table_object, handle, index, |
table_instance.dispatch_table); |
} |
} |
@@ -1852,61 +1858,6 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate, |
return builder.Build(); |
} |
-Handle<WasmCompiledModule> WasmCompiledModule::New( |
- Isolate* isolate, Handle<WasmModuleWrapper> module_wrapper) { |
- Handle<FixedArray> ret = |
- isolate->factory()->NewFixedArray(PropertyIndices::Count, TENURED); |
- // WasmCompiledModule::cast would fail since module bytes are not set yet. |
- Handle<WasmCompiledModule> compiled_module( |
- reinterpret_cast<WasmCompiledModule*>(*ret), isolate); |
- compiled_module->InitId(); |
- compiled_module->set_module_wrapper(module_wrapper); |
- return compiled_module; |
-} |
- |
-void WasmCompiledModule::InitId() { |
-#if DEBUG |
- static uint32_t instance_id_counter = 0; |
- set(kID_instance_id, Smi::FromInt(instance_id_counter++)); |
- TRACE("New compiled module id: %d\n", instance_id()); |
-#endif |
-} |
- |
-bool WasmCompiledModule::IsWasmCompiledModule(Object* obj) { |
- if (!obj->IsFixedArray()) return false; |
- FixedArray* arr = FixedArray::cast(obj); |
- if (arr->length() != PropertyIndices::Count) return false; |
- Isolate* isolate = arr->GetIsolate(); |
-#define WCM_CHECK_SMALL_NUMBER(TYPE, NAME) \ |
- if (!arr->get(kID_##NAME)->IsSmi()) return false; |
-#define WCM_CHECK_OBJECT_OR_WEAK(TYPE, NAME) \ |
- if (!arr->get(kID_##NAME)->IsUndefined(isolate) && \ |
- !arr->get(kID_##NAME)->Is##TYPE()) \ |
- return false; |
-#define WCM_CHECK_OBJECT(TYPE, NAME) WCM_CHECK_OBJECT_OR_WEAK(TYPE, NAME) |
-#define WCM_CHECK_WEAK_LINK(TYPE, NAME) WCM_CHECK_OBJECT_OR_WEAK(WeakCell, NAME) |
-#define WCM_CHECK(KIND, TYPE, NAME) WCM_CHECK_##KIND(TYPE, NAME) |
- WCM_PROPERTY_TABLE(WCM_CHECK) |
-#undef WCM_CHECK |
- |
- // All checks passed. |
- return true; |
-} |
- |
-void WasmCompiledModule::PrintInstancesChain() { |
-#if DEBUG |
- if (!FLAG_trace_wasm_instances) return; |
- for (WasmCompiledModule* current = this; current != nullptr;) { |
- PrintF("->%d", current->instance_id()); |
- if (current->ptr_to_weak_next_instance() == nullptr) break; |
- CHECK(!current->ptr_to_weak_next_instance()->cleared()); |
- current = |
- WasmCompiledModule::cast(current->ptr_to_weak_next_instance()->value()); |
- } |
- PrintF("\n"); |
-#endif |
-} |
- |
Handle<Object> wasm::GetWasmFunctionNameOrNull(Isolate* isolate, |
Handle<Object> instance, |
uint32_t func_index) { |
@@ -2023,12 +1974,12 @@ Handle<JSObject> wasm::CreateWasmModuleObject( |
} |
// TODO(clemensh): origin can be inferred from asm_js_script; remove it. |
-MaybeHandle<JSObject> wasm::CreateModuleObjectFromBytes( |
+MaybeHandle<WasmModuleObject> wasm::CreateModuleObjectFromBytes( |
Isolate* isolate, const byte* start, const byte* end, ErrorThrower* thrower, |
ModuleOrigin origin, Handle<Script> asm_js_script, |
const byte* asm_js_offset_tables_start, |
const byte* asm_js_offset_tables_end) { |
- MaybeHandle<JSObject> nothing; |
+ MaybeHandle<WasmModuleObject> nothing; |
ModuleResult result = DecodeWasmModule(isolate, start, end, false, origin); |
if (result.failed()) { |
if (result.val) delete result.val; |
@@ -2064,7 +2015,7 @@ MaybeHandle<JSObject> wasm::CreateModuleObjectFromBytes( |
compiled_module->set_asm_js_offset_tables(offset_tables); |
} |
- return CreateWasmModuleObject(isolate, compiled_module, origin); |
+ return WasmModuleObject::New(isolate, compiled_module); |
} |
bool wasm::ValidateModuleBytes(Isolate* isolate, const byte* start, |
@@ -2111,9 +2062,9 @@ uint32_t GetMaxInstanceMemorySize(Isolate* isolate, Handle<JSObject> instance) { |
Handle<Object> memory_object(instance->GetInternalField(kWasmMemObject), |
isolate); |
if (!memory_object->IsUndefined(isolate)) { |
- uint32_t mem_obj_max = |
- WasmJs::GetWasmMemoryMaximumSize(isolate, memory_object); |
- if (mem_obj_max != 0) return mem_obj_max; |
+ int maximum = |
+ Handle<WasmMemoryObject>::cast(memory_object)->maximum_pages(); |
+ if (maximum > 0) return static_cast<uint32_t>(maximum); |
} |
uint32_t compiled_max_pages = GetCompiledModule(*instance)->max_mem_pages(); |
isolate->counters()->wasm_max_mem_pages_count()->AddSample( |
@@ -2168,7 +2119,7 @@ int32_t wasm::GrowInstanceMemory(Isolate* isolate, Handle<JSObject> instance, |
Handle<Object> memory_object(instance->GetInternalField(kWasmMemObject), |
isolate); |
if (!memory_object->IsUndefined(isolate)) { |
- WasmJs::SetWasmMemoryArrayBuffer(isolate, memory_object, buffer); |
+ Handle<WasmMemoryObject>::cast(memory_object)->set_buffer(*buffer); |
} |
DCHECK(old_size % WasmModule::kPageSize == 0); |