Commit a6f84875 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Simplify offset declaration of WebAssembly objects.

R=clemensh@chromium.org
BUG=v8:7509

Change-Id: If4c199535f9a039f648c54bc72094dbc4218607d
Reviewed-on: https://chromium-review.googlesource.com/945731Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51689}
parent 3ea2d6b0
...@@ -981,9 +981,8 @@ void WasmJs::Install(Isolate* isolate, bool exposed_on_global_object) { ...@@ -981,9 +981,8 @@ void WasmJs::Install(Isolate* isolate, bool exposed_on_global_object) {
JSFunction::EnsureHasInitialMap(module_constructor); JSFunction::EnsureHasInitialMap(module_constructor);
Handle<JSObject> module_proto( Handle<JSObject> module_proto(
JSObject::cast(module_constructor->instance_prototype())); JSObject::cast(module_constructor->instance_prototype()));
i::Handle<i::Map> module_map = isolate->factory()->NewMap( i::Handle<i::Map> module_map =
i::WASM_MODULE_TYPE, i::JSObject::kHeaderSize + isolate->factory()->NewMap(i::WASM_MODULE_TYPE, WasmModuleObject::kSize);
WasmModuleObject::kFieldCount * i::kPointerSize);
JSFunction::SetInitialMap(module_constructor, module_map, module_proto); JSFunction::SetInitialMap(module_constructor, module_map, module_proto);
InstallFunc(isolate, module_constructor, "imports", WebAssemblyModuleImports, InstallFunc(isolate, module_constructor, "imports", WebAssemblyModuleImports,
1); 1);
......
...@@ -44,14 +44,6 @@ class WasmInstanceObject; ...@@ -44,14 +44,6 @@ class WasmInstanceObject;
INLINE(bool has_##name()); \ INLINE(bool has_##name()); \
DECL_ACCESSORS(name, type) DECL_ACCESSORS(name, type)
#define DEF_SIZE(parent) \
static const int kSize = parent::kHeaderSize + kFieldCount * kPointerSize; \
static const int kParentSize = parent::kHeaderSize; \
static const int kHeaderSize = kSize;
#define DEF_OFFSET(name) \
static const int k##name##Offset = \
kSize + (k##name##Index - kFieldCount) * kPointerSize;
// An entry in an indirect dispatch table. // An entry in an indirect dispatch table.
struct IndirectFunctionTableEntry { struct IndirectFunctionTableEntry {
int32_t sig_id = 0; int32_t sig_id = 0;
...@@ -104,13 +96,14 @@ class WasmModuleObject : public JSObject { ...@@ -104,13 +96,14 @@ class WasmModuleObject : public JSObject {
// Shared compiled code between multiple WebAssembly.Module objects. // Shared compiled code between multiple WebAssembly.Module objects.
DECL_ACCESSORS(compiled_module, WasmCompiledModule) DECL_ACCESSORS(compiled_module, WasmCompiledModule)
enum { // -- // Layout description.
kCompiledModuleIndex, #define WASM_MODULE_OBJECT_FIELDS(V) \
kFieldCount V(kCompiledModuleOffset, kPointerSize) \
}; V(kSize, 0)
DEF_SIZE(JSObject) DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize,
DEF_OFFSET(CompiledModule) WASM_MODULE_OBJECT_FIELDS)
#undef WASM_MODULE_OBJECT_FIELDS
static Handle<WasmModuleObject> New( static Handle<WasmModuleObject> New(
Isolate* isolate, Handle<WasmCompiledModule> compiled_module); Isolate* isolate, Handle<WasmCompiledModule> compiled_module);
...@@ -129,17 +122,15 @@ class WasmTableObject : public JSObject { ...@@ -129,17 +122,15 @@ class WasmTableObject : public JSObject {
DECL_ACCESSORS(maximum_length, Object) DECL_ACCESSORS(maximum_length, Object)
DECL_ACCESSORS(dispatch_tables, FixedArray) DECL_ACCESSORS(dispatch_tables, FixedArray)
enum { // -- // Layout description.
kFunctionsIndex, #define WASM_TABLE_OBJECT_FIELDS(V) \
kMaximumLengthIndex, V(kFunctionsOffset, kPointerSize) \
kDispatchTablesIndex, V(kMaximumLengthOffset, kPointerSize) \
kFieldCount V(kDispatchTablesOffset, kPointerSize) \
}; V(kSize, 0)
DEF_SIZE(JSObject) DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize, WASM_TABLE_OBJECT_FIELDS)
DEF_OFFSET(Functions) #undef WASM_TABLE_OBJECT_FIELDS
DEF_OFFSET(MaximumLength)
DEF_OFFSET(DispatchTables)
inline uint32_t current_length(); inline uint32_t current_length();
inline bool has_maximum_length(); inline bool has_maximum_length();
...@@ -175,19 +166,17 @@ class WasmMemoryObject : public JSObject { ...@@ -175,19 +166,17 @@ class WasmMemoryObject : public JSObject {
DECL_OPTIONAL_ACCESSORS(instances, WeakFixedArray) DECL_OPTIONAL_ACCESSORS(instances, WeakFixedArray)
DECL_ACCESSORS(wasm_context, Managed<WasmContext>) DECL_ACCESSORS(wasm_context, Managed<WasmContext>)
enum { // -- // Layout description.
kArrayBufferIndex, #define WASM_MEMORY_OBJECT_FIELDS(V) \
kMaximumPagesIndex, V(kArrayBufferOffset, kPointerSize) \
kInstancesIndex, V(kMaximumPagesOffset, kPointerSize) \
kWasmContextIndex, V(kInstancesOffset, kPointerSize) \
kFieldCount V(kWasmContextOffset, kPointerSize) \
}; V(kSize, 0)
DEF_SIZE(JSObject) DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize,
DEF_OFFSET(ArrayBuffer) WASM_MEMORY_OBJECT_FIELDS)
DEF_OFFSET(MaximumPages) #undef WASM_MEMORY_OBJECT_FIELDS
DEF_OFFSET(Instances)
DEF_OFFSET(WasmContext)
// Add an instance to the internal (weak) list. amortized O(n). // Add an instance to the internal (weak) list. amortized O(n).
static void AddInstance(Isolate* isolate, Handle<WasmMemoryObject> memory, static void AddInstance(Isolate* isolate, Handle<WasmMemoryObject> memory,
...@@ -222,31 +211,23 @@ class WasmInstanceObject : public JSObject { ...@@ -222,31 +211,23 @@ class WasmInstanceObject : public JSObject {
DECL_OPTIONAL_ACCESSORS(directly_called_instances, FixedArray) DECL_OPTIONAL_ACCESSORS(directly_called_instances, FixedArray)
DECL_ACCESSORS(js_imports_table, FixedArray) DECL_ACCESSORS(js_imports_table, FixedArray)
enum { // -- // Layout description.
kWasmContextIndex, #define WASM_INSTANCE_OBJECT_FIELDS(V) \
kCompiledModuleIndex, V(kWasmContextOffset, kPointerSize) \
kExportsObjectIndex, V(kCompiledModuleOffset, kPointerSize) \
kMemoryObjectIndex, V(kExportsObjectOffset, kPointerSize) \
kGlobalsBufferIndex, V(kMemoryObjectOffset, kPointerSize) \
kDebugInfoIndex, V(kGlobalsBufferOffset, kPointerSize) \
kTableObjectIndex, V(kDebugInfoOffset, kPointerSize) \
kFunctionTablesIndex, V(kTableObjectOffset, kPointerSize) \
kDirectlyCalledInstancesIndex, V(kFunctionTablesOffset, kPointerSize) \
kJsImportsTableIndex, V(kDirectlyCalledInstancesOffset, kPointerSize) \
kFieldCount V(kJsImportsTableOffset, kPointerSize) \
}; V(kSize, 0)
DEF_SIZE(JSObject) DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize,
DEF_OFFSET(WasmContext) WASM_INSTANCE_OBJECT_FIELDS)
DEF_OFFSET(CompiledModule) #undef WASM_INSTANCE_OBJECT_FIELDS
DEF_OFFSET(ExportsObject)
DEF_OFFSET(MemoryObject)
DEF_OFFSET(GlobalsBuffer)
DEF_OFFSET(DebugInfo)
DEF_OFFSET(TableObject)
DEF_OFFSET(FunctionTables)
DEF_OFFSET(DirectlyCalledInstances)
DEF_OFFSET(JsImportsTable)
WasmModuleObject* module_object(); WasmModuleObject* module_object();
V8_EXPORT_PRIVATE wasm::WasmModule* module(); V8_EXPORT_PRIVATE wasm::WasmModule* module();
......
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