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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 // column. | 319 // column. |
325 static Handle<FixedArray> GetFunctionOffsetTable( | 320 static Handle<FixedArray> GetFunctionOffsetTable( |
326 Handle<WasmDebugInfo> debug_info, int func_index); | 321 Handle<WasmDebugInfo> debug_info, int func_index); |
327 | 322 |
328 // Get the asm.js source position from a byte offset. | 323 // Get the asm.js source position from a byte offset. |
329 // Must only be called if the associated wasm object was created from asm.js. | 324 // Must only be called if the associated wasm object was created from asm.js. |
330 static int GetAsmJsSourcePosition(Handle<WasmDebugInfo> debug_info, | 325 static int GetAsmJsSourcePosition(Handle<WasmDebugInfo> debug_info, |
331 int func_index, int byte_offset); | 326 int func_index, int byte_offset); |
332 }; | 327 }; |
333 | 328 |
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 | |
389 #undef DECLARE_ACCESSORS | 329 #undef DECLARE_ACCESSORS |
390 #undef DECLARE_OPTIONAL_ACCESSORS | 330 #undef DECLARE_OPTIONAL_ACCESSORS |
391 | 331 |
392 } // namespace internal | 332 } // namespace internal |
393 } // namespace v8 | 333 } // namespace v8 |
394 | 334 |
395 #endif // V8_WASM_OBJECTS_H_ | 335 #endif // V8_WASM_OBJECTS_H_ |
OLD | NEW |