| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_WASM_OBJECTS_H_ | 5 #ifndef V8_WASM_OBJECTS_H_ |
| 6 #define V8_WASM_OBJECTS_H_ | 6 #define V8_WASM_OBJECTS_H_ |
| 7 | 7 |
| 8 #include "src/objects-inl.h" | 8 #include "src/objects-inl.h" |
| 9 #include "src/wasm/managed.h" | 9 #include "src/wasm/managed.h" |
| 10 | 10 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 namespace wasm { | 13 namespace wasm { |
| 14 struct WasmModule; | 14 struct WasmModule; |
| 15 } | 15 } |
| 16 | 16 |
| 17 class WasmCompiledModule; | 17 class WasmCompiledModule; |
| 18 class WasmDebugInfo; | 18 class WasmDebugInfo; |
| 19 class WasmInstanceObject; | 19 class WasmInstanceObject; |
| 20 class WasmInstanceWrapper; | |
| 21 | 20 |
| 22 #define DECLARE_CASTS(name) \ | 21 #define DECLARE_CASTS(name) \ |
| 23 static bool Is##name(Object* object); \ | 22 static bool Is##name(Object* object); \ |
| 24 static name* cast(Object* object) | 23 static name* cast(Object* object) |
| 25 | 24 |
| 26 #define DECLARE_ACCESSORS(name, type) \ | 25 #define DECLARE_ACCESSORS(name, type) \ |
| 27 type* get_##name(); \ | 26 type* get_##name(); \ |
| 28 void set_##name(type* value) | 27 void set_##name(type* value) |
| 29 | 28 |
| 30 #define DECLARE_OPTIONAL_ACCESSORS(name, type) \ | 29 #define DECLARE_OPTIONAL_ACCESSORS(name, type) \ |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 static Handle<FixedArray> AddDispatchTable( | 72 static Handle<FixedArray> AddDispatchTable( |
| 74 Isolate* isolate, Handle<WasmTableObject> table, | 73 Isolate* isolate, Handle<WasmTableObject> table, |
| 75 Handle<WasmInstanceObject> instance, int table_index, | 74 Handle<WasmInstanceObject> instance, int table_index, |
| 76 Handle<FixedArray> dispatch_table); | 75 Handle<FixedArray> dispatch_table); |
| 77 }; | 76 }; |
| 78 | 77 |
| 79 // Representation of a WebAssembly.Memory JavaScript-level object. | 78 // Representation of a WebAssembly.Memory JavaScript-level object. |
| 80 class WasmMemoryObject : public JSObject { | 79 class WasmMemoryObject : public JSObject { |
| 81 public: | 80 public: |
| 82 // TODO(titzer): add the brand as an internal field instead of a property. | 81 // TODO(titzer): add the brand as an internal field instead of a property. |
| 83 enum Fields : uint8_t { kArrayBuffer, kMaximum, kInstancesLink, kFieldCount }; | 82 enum Fields : uint8_t { kArrayBuffer, kMaximum, kInstance, kFieldCount }; |
| 84 | 83 |
| 85 DECLARE_CASTS(WasmMemoryObject); | 84 DECLARE_CASTS(WasmMemoryObject); |
| 86 DECLARE_ACCESSORS(buffer, JSArrayBuffer); | 85 DECLARE_ACCESSORS(buffer, JSArrayBuffer); |
| 87 DECLARE_OPTIONAL_ACCESSORS(instances_link, WasmInstanceWrapper); | |
| 88 | 86 |
| 89 void AddInstance(Isolate* isolate, Handle<WasmInstanceObject> object); | 87 void AddInstance(WasmInstanceObject* object); |
| 90 void ResetInstancesLink(Isolate* isolate); | |
| 91 uint32_t current_pages(); | 88 uint32_t current_pages(); |
| 92 int32_t maximum_pages(); // returns < 0 if there is no maximum | 89 int32_t maximum_pages(); // returns < 0 if there is no maximum |
| 93 | 90 |
| 94 static Handle<WasmMemoryObject> New(Isolate* isolate, | 91 static Handle<WasmMemoryObject> New(Isolate* isolate, |
| 95 Handle<JSArrayBuffer> buffer, | 92 Handle<JSArrayBuffer> buffer, |
| 96 int maximum); | 93 int maximum); |
| 97 | 94 |
| 98 static bool Grow(Handle<WasmMemoryObject> memory, uint32_t count); | 95 static bool Grow(Handle<WasmMemoryObject> memory, uint32_t count); |
| 99 }; | 96 }; |
| 100 | 97 |
| 101 // Representation of a WebAssembly.Instance JavaScript-level object. | 98 // Representation of a WebAssembly.Instance JavaScript-level object. |
| 102 class WasmInstanceObject : public JSObject { | 99 class WasmInstanceObject : public JSObject { |
| 103 public: | 100 public: |
| 104 // TODO(titzer): add the brand as an internal field instead of a property. | 101 // TODO(titzer): add the brand as an internal field instead of a property. |
| 105 enum Fields { | 102 enum Fields { |
| 106 kCompiledModule, | 103 kCompiledModule, |
| 107 kMemoryObject, | 104 kMemoryObject, |
| 108 kMemoryArrayBuffer, | 105 kMemoryArrayBuffer, |
| 109 kGlobalsArrayBuffer, | 106 kGlobalsArrayBuffer, |
| 110 kDebugInfo, | 107 kDebugInfo, |
| 111 kWasmMemInstanceWrapper, | |
| 112 kFieldCount | 108 kFieldCount |
| 113 }; | 109 }; |
| 114 | 110 |
| 115 DECLARE_CASTS(WasmInstanceObject); | 111 DECLARE_CASTS(WasmInstanceObject); |
| 116 | 112 |
| 117 DECLARE_ACCESSORS(compiled_module, WasmCompiledModule); | 113 DECLARE_ACCESSORS(compiled_module, WasmCompiledModule); |
| 118 DECLARE_OPTIONAL_ACCESSORS(globals_buffer, JSArrayBuffer); | 114 DECLARE_OPTIONAL_ACCESSORS(globals_buffer, JSArrayBuffer); |
| 119 DECLARE_OPTIONAL_ACCESSORS(memory_buffer, JSArrayBuffer); | 115 DECLARE_OPTIONAL_ACCESSORS(memory_buffer, JSArrayBuffer); |
| 120 DECLARE_OPTIONAL_ACCESSORS(memory_object, WasmMemoryObject); | 116 DECLARE_OPTIONAL_ACCESSORS(memory_object, WasmMemoryObject); |
| 121 DECLARE_OPTIONAL_ACCESSORS(debug_info, WasmDebugInfo); | 117 DECLARE_OPTIONAL_ACCESSORS(debug_info, WasmDebugInfo); |
| 122 DECLARE_OPTIONAL_ACCESSORS(instance_wrapper, WasmInstanceWrapper); | |
| 123 | 118 |
| 124 WasmModuleObject* module_object(); | 119 WasmModuleObject* module_object(); |
| 125 wasm::WasmModule* module(); | 120 wasm::WasmModule* module(); |
| 126 | 121 |
| 127 static Handle<WasmInstanceObject> New( | 122 static Handle<WasmInstanceObject> New( |
| 128 Isolate* isolate, Handle<WasmCompiledModule> compiled_module); | 123 Isolate* isolate, Handle<WasmCompiledModule> compiled_module); |
| 129 }; | 124 }; |
| 130 | 125 |
| 131 // Representation of an exported WASM function. | 126 // Representation of an exported WASM function. |
| 132 class WasmExportedFunction : public JSFunction { | 127 class WasmExportedFunction : public JSFunction { |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 // column. | 309 // column. |
| 315 static Handle<FixedArray> GetFunctionOffsetTable( | 310 static Handle<FixedArray> GetFunctionOffsetTable( |
| 316 Handle<WasmDebugInfo> debug_info, int func_index); | 311 Handle<WasmDebugInfo> debug_info, int func_index); |
| 317 | 312 |
| 318 // Get the asm.js source position from a byte offset. | 313 // Get the asm.js source position from a byte offset. |
| 319 // Must only be called if the associated wasm object was created from asm.js. | 314 // Must only be called if the associated wasm object was created from asm.js. |
| 320 static int GetAsmJsSourcePosition(Handle<WasmDebugInfo> debug_info, | 315 static int GetAsmJsSourcePosition(Handle<WasmDebugInfo> debug_info, |
| 321 int func_index, int byte_offset); | 316 int func_index, int byte_offset); |
| 322 }; | 317 }; |
| 323 | 318 |
| 324 class WasmInstanceWrapper : public FixedArray { | |
| 325 public: | |
| 326 static Handle<WasmInstanceWrapper> New(Isolate* isolate, | |
| 327 Handle<WasmInstanceObject> instance); | |
| 328 static WasmInstanceWrapper* cast(Object* fixed_array) { | |
| 329 SLOW_DCHECK(IsWasmInstanceWrapper(fixed_array)); | |
| 330 return reinterpret_cast<WasmInstanceWrapper*>(fixed_array); | |
| 331 } | |
| 332 static bool IsWasmInstanceWrapper(Object* obj); | |
| 333 bool has_instance() { return get(kWrapperInstanceObject)->IsWeakCell(); } | |
| 334 Handle<WasmInstanceObject> instance_object() { | |
| 335 Object* obj = get(kWrapperInstanceObject); | |
| 336 DCHECK(obj->IsWeakCell()); | |
| 337 WeakCell* cell = WeakCell::cast(obj); | |
| 338 DCHECK(cell->value()->IsJSObject()); | |
| 339 return handle(WasmInstanceObject::cast(cell->value())); | |
| 340 } | |
| 341 bool has_next() { return IsWasmInstanceWrapper(get(kNextInstanceWrapper)); } | |
| 342 bool has_previous() { | |
| 343 return IsWasmInstanceWrapper(get(kPreviousInstanceWrapper)); | |
| 344 } | |
| 345 void set_instance_object(Handle<JSObject> instance, Isolate* isolate); | |
| 346 void set_next_wrapper(Object* obj) { | |
| 347 DCHECK(IsWasmInstanceWrapper(obj)); | |
| 348 set(kNextInstanceWrapper, obj); | |
| 349 } | |
| 350 void set_previous_wrapper(Object* obj) { | |
| 351 DCHECK(IsWasmInstanceWrapper(obj)); | |
| 352 set(kPreviousInstanceWrapper, obj); | |
| 353 } | |
| 354 Handle<WasmInstanceWrapper> next_wrapper() { | |
| 355 Object* obj = get(kNextInstanceWrapper); | |
| 356 DCHECK(IsWasmInstanceWrapper(obj)); | |
| 357 return handle(WasmInstanceWrapper::cast(obj)); | |
| 358 } | |
| 359 Handle<WasmInstanceWrapper> previous_wrapper() { | |
| 360 Object* obj = get(kPreviousInstanceWrapper); | |
| 361 DCHECK(IsWasmInstanceWrapper(obj)); | |
| 362 return handle(WasmInstanceWrapper::cast(obj)); | |
| 363 } | |
| 364 void reset_next_wrapper() { set_undefined(kNextInstanceWrapper); } | |
| 365 void reset_previous_wrapper() { set_undefined(kPreviousInstanceWrapper); } | |
| 366 void reset() { | |
| 367 for (int kID = 0; kID < kWrapperPropertyCount; kID++) set_undefined(kID); | |
| 368 } | |
| 369 | |
| 370 private: | |
| 371 enum { | |
| 372 kWrapperInstanceObject, | |
| 373 kNextInstanceWrapper, | |
| 374 kPreviousInstanceWrapper, | |
| 375 kWrapperPropertyCount | |
| 376 }; | |
| 377 }; | |
| 378 | |
| 379 #undef DECLARE_ACCESSORS | 319 #undef DECLARE_ACCESSORS |
| 380 #undef DECLARE_OPTIONAL_ACCESSORS | 320 #undef DECLARE_OPTIONAL_ACCESSORS |
| 381 | 321 |
| 382 } // namespace internal | 322 } // namespace internal |
| 383 } // namespace v8 | 323 } // namespace v8 |
| 384 | 324 |
| 385 #endif // V8_WASM_OBJECTS_H_ | 325 #endif // V8_WASM_OBJECTS_H_ |
| OLD | NEW |