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