Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: src/wasm/wasm-objects.h

Issue 2972803002: [wasm] Use WeakFixedArray for list of instances sharing a WasmMemoryObject. (Closed)
Patch Set: Rebase Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/debug/debug.h" 8 #include "src/debug/debug.h"
9 #include "src/debug/interface-types.h" 9 #include "src/debug/interface-types.h"
10 #include "src/objects.h" 10 #include "src/objects.h"
(...skipping 11 matching lines...) Expand all
22 namespace v8 { 22 namespace v8 {
23 namespace internal { 23 namespace internal {
24 namespace wasm { 24 namespace wasm {
25 class InterpretedFrame; 25 class InterpretedFrame;
26 class WasmInterpreter; 26 class WasmInterpreter;
27 } 27 }
28 28
29 class WasmCompiledModule; 29 class WasmCompiledModule;
30 class WasmDebugInfo; 30 class WasmDebugInfo;
31 class WasmInstanceObject; 31 class WasmInstanceObject;
32 class WasmInstanceWrapper;
33 32
34 #define DECL_OOL_QUERY(type) static bool Is##type(Object* object); 33 #define DECL_OOL_QUERY(type) static bool Is##type(Object* object);
35 #define DECL_OOL_CAST(type) static type* cast(Object* object); 34 #define DECL_OOL_CAST(type) static type* cast(Object* object);
36 35
37 #define DECL_GETTER(name, type) type* name(); 36 #define DECL_GETTER(name, type) type* name();
38 37
39 #define DECL_OPTIONAL_ACCESSORS(name, type) \ 38 #define DECL_OPTIONAL_ACCESSORS(name, type) \
40 INLINE(bool has_##name()); \ 39 INLINE(bool has_##name()); \
41 DECL_ACCESSORS(name, type) 40 DECL_ACCESSORS(name, type)
42 41
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 Handle<FixedArray> function_table, Handle<FixedArray> signature_table); 105 Handle<FixedArray> function_table, Handle<FixedArray> signature_table);
107 }; 106 };
108 107
109 // Representation of a WebAssembly.Memory JavaScript-level object. 108 // Representation of a WebAssembly.Memory JavaScript-level object.
110 class WasmMemoryObject : public JSObject { 109 class WasmMemoryObject : public JSObject {
111 public: 110 public:
112 DECL_CAST(WasmMemoryObject) 111 DECL_CAST(WasmMemoryObject)
113 112
114 DECL_ACCESSORS(array_buffer, JSArrayBuffer) 113 DECL_ACCESSORS(array_buffer, JSArrayBuffer)
115 DECL_INT_ACCESSORS(maximum_pages) 114 DECL_INT_ACCESSORS(maximum_pages)
116 DECL_OPTIONAL_ACCESSORS(instances_link, WasmInstanceWrapper) 115 DECL_OPTIONAL_ACCESSORS(instances, WeakFixedArray)
117 116
118 enum { // -- 117 enum { // --
119 kArrayBufferIndex, 118 kArrayBufferIndex,
120 kMaximumPagesIndex, 119 kMaximumPagesIndex,
121 kInstancesLinkIndex, 120 kInstancesIndex,
122 kFieldCount 121 kFieldCount
123 }; 122 };
124 123
125 DEF_SIZE(JSObject) 124 DEF_SIZE(JSObject)
126 DEF_OFFSET(ArrayBuffer) 125 DEF_OFFSET(ArrayBuffer)
127 DEF_OFFSET(MaximumPages) 126 DEF_OFFSET(MaximumPages)
128 DEF_OFFSET(InstancesLink) 127 DEF_OFFSET(Instances)
129 128
130 void AddInstance(Isolate* isolate, Handle<WasmInstanceObject> object); 129 static void AddInstance(Isolate* isolate, Handle<WasmMemoryObject> memory,
131 inline void ResetInstancesLink(Isolate* isolate); 130 Handle<WasmInstanceObject> object);
131 static void RemoveInstance(Isolate* isolate, Handle<WasmMemoryObject> memory,
132 Handle<WasmInstanceObject> object);
132 uint32_t current_pages(); 133 uint32_t current_pages();
133 inline bool has_maximum_pages() { return maximum_pages() >= 0; } 134 inline bool has_maximum_pages() { return maximum_pages() >= 0; }
134 135
135 static Handle<WasmMemoryObject> New(Isolate* isolate, 136 static Handle<WasmMemoryObject> New(Isolate* isolate,
136 Handle<JSArrayBuffer> buffer, 137 Handle<JSArrayBuffer> buffer,
137 int32_t maximum); 138 int32_t maximum);
138 139
139 static int32_t Grow(Isolate*, Handle<WasmMemoryObject>, uint32_t pages); 140 static int32_t Grow(Isolate*, Handle<WasmMemoryObject>, uint32_t pages);
140 }; 141 };
141 142
142 // A WebAssembly.Instance JavaScript-level object. 143 // A WebAssembly.Instance JavaScript-level object.
143 class WasmInstanceObject : public JSObject { 144 class WasmInstanceObject : public JSObject {
144 public: 145 public:
145 DECL_CAST(WasmInstanceObject) 146 DECL_CAST(WasmInstanceObject)
146 147
147 DECL_ACCESSORS(compiled_module, WasmCompiledModule) 148 DECL_ACCESSORS(compiled_module, WasmCompiledModule)
148 DECL_OPTIONAL_ACCESSORS(memory_object, WasmMemoryObject) 149 DECL_OPTIONAL_ACCESSORS(memory_object, WasmMemoryObject)
149 DECL_OPTIONAL_ACCESSORS(memory_buffer, JSArrayBuffer) 150 DECL_OPTIONAL_ACCESSORS(memory_buffer, JSArrayBuffer)
150 DECL_OPTIONAL_ACCESSORS(globals_buffer, JSArrayBuffer) 151 DECL_OPTIONAL_ACCESSORS(globals_buffer, JSArrayBuffer)
151 DECL_OPTIONAL_ACCESSORS(debug_info, WasmDebugInfo) 152 DECL_OPTIONAL_ACCESSORS(debug_info, WasmDebugInfo)
152 DECL_OPTIONAL_ACCESSORS(instance_wrapper, WasmInstanceWrapper)
153 // FixedArray of all instances whose code was imported 153 // FixedArray of all instances whose code was imported
154 DECL_OPTIONAL_ACCESSORS(directly_called_instances, FixedArray) 154 DECL_OPTIONAL_ACCESSORS(directly_called_instances, FixedArray)
155 155
156 enum { // -- 156 enum { // --
157 kCompiledModuleIndex, 157 kCompiledModuleIndex,
158 kMemoryObjectIndex, 158 kMemoryObjectIndex,
159 kMemoryBufferIndex, 159 kMemoryBufferIndex,
160 kGlobalsBufferIndex, 160 kGlobalsBufferIndex,
161 kDebugInfoIndex, 161 kDebugInfoIndex,
162 kInstanceWrapperIndex,
163 kDirectlyCalledInstancesIndex, 162 kDirectlyCalledInstancesIndex,
164 kFieldCount 163 kFieldCount
165 }; 164 };
166 165
167 DEF_SIZE(JSObject) 166 DEF_SIZE(JSObject)
168 DEF_OFFSET(CompiledModule) 167 DEF_OFFSET(CompiledModule)
169 DEF_OFFSET(MemoryObject) 168 DEF_OFFSET(MemoryObject)
170 DEF_OFFSET(MemoryBuffer) 169 DEF_OFFSET(MemoryBuffer)
171 DEF_OFFSET(GlobalsBuffer) 170 DEF_OFFSET(GlobalsBuffer)
172 DEF_OFFSET(DebugInfo) 171 DEF_OFFSET(DebugInfo)
173 DEF_OFFSET(InstanceWrapper)
174 DEF_OFFSET(DirectlyCalledInstances) 172 DEF_OFFSET(DirectlyCalledInstances)
175 173
176 WasmModuleObject* module_object(); 174 WasmModuleObject* module_object();
177 V8_EXPORT_PRIVATE wasm::WasmModule* module(); 175 V8_EXPORT_PRIVATE wasm::WasmModule* module();
178 176
179 // Get the debug info associated with the given wasm object. 177 // Get the debug info associated with the given wasm object.
180 // If no debug info exists yet, it is created automatically. 178 // If no debug info exists yet, it is created automatically.
181 static Handle<WasmDebugInfo> GetOrCreateDebugInfo(Handle<WasmInstanceObject>); 179 static Handle<WasmDebugInfo> GetOrCreateDebugInfo(Handle<WasmInstanceObject>);
182 180
183 static Handle<WasmInstanceObject> New(Isolate*, Handle<WasmCompiledModule>); 181 static Handle<WasmInstanceObject> New(Isolate*, Handle<WasmCompiledModule>);
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 // for the local scope. Both elements are JSArrays of size 659 // for the local scope. Both elements are JSArrays of size
662 // ScopeIterator::kScopeDetailsSize and layout as described in debug-scopes.h. 660 // ScopeIterator::kScopeDetailsSize and layout as described in debug-scopes.h.
663 // The global scope contains information about globals and the memory. 661 // The global scope contains information about globals and the memory.
664 // The local scope contains information about parameters, locals, and stack 662 // The local scope contains information about parameters, locals, and stack
665 // values. 663 // values.
666 static Handle<JSArray> GetScopeDetails(Handle<WasmDebugInfo>, 664 static Handle<JSArray> GetScopeDetails(Handle<WasmDebugInfo>,
667 Address frame_pointer, 665 Address frame_pointer,
668 int frame_index); 666 int frame_index);
669 }; 667 };
670 668
671 class WasmInstanceWrapper : public FixedArray {
672 public:
673 enum { // --
674 kWrapperInstanceObjectIndex,
675 kNextInstanceWrapperIndex,
676 kPreviousInstanceWrapperIndex,
677 kFieldCount
678 };
679
680 static WasmInstanceWrapper* cast(Object* fixed_array) {
681 SLOW_DCHECK(IsWasmInstanceWrapper(fixed_array));
682 return reinterpret_cast<WasmInstanceWrapper*>(fixed_array);
683 }
684 static bool IsWasmInstanceWrapper(Object* obj);
685 bool has_instance() { return get(kWrapperInstanceObjectIndex)->IsWeakCell(); }
686 Handle<WasmInstanceObject> instance_object() {
687 Object* obj = get(kWrapperInstanceObjectIndex);
688 DCHECK(obj->IsWeakCell());
689 WeakCell* cell = WeakCell::cast(obj);
690 DCHECK(cell->value()->IsJSObject());
691 return handle(WasmInstanceObject::cast(cell->value()));
692 }
693 bool has_next() {
694 return IsWasmInstanceWrapper(get(kNextInstanceWrapperIndex));
695 }
696 bool has_previous() {
697 return IsWasmInstanceWrapper(get(kPreviousInstanceWrapperIndex));
698 }
699 void set_next_wrapper(Object* obj) {
700 DCHECK(IsWasmInstanceWrapper(obj));
701 set(kNextInstanceWrapperIndex, obj);
702 }
703 void set_previous_wrapper(Object* obj) {
704 DCHECK(IsWasmInstanceWrapper(obj));
705 set(kPreviousInstanceWrapperIndex, obj);
706 }
707 Handle<WasmInstanceWrapper> next_wrapper() {
708 Object* obj = get(kNextInstanceWrapperIndex);
709 DCHECK(IsWasmInstanceWrapper(obj));
710 return handle(WasmInstanceWrapper::cast(obj));
711 }
712 Handle<WasmInstanceWrapper> previous_wrapper() {
713 Object* obj = get(kPreviousInstanceWrapperIndex);
714 DCHECK(IsWasmInstanceWrapper(obj));
715 return handle(WasmInstanceWrapper::cast(obj));
716 }
717 void reset_next_wrapper() { set_undefined(kNextInstanceWrapperIndex); }
718 void reset_previous_wrapper() {
719 set_undefined(kPreviousInstanceWrapperIndex);
720 }
721 void reset() {
722 for (int kID = 0; kID < kFieldCount; kID++) set_undefined(kID);
723 }
724
725 static Handle<WasmInstanceWrapper> New(Isolate* isolate,
726 Handle<WasmInstanceObject> instance);
727 };
728
729 // TODO(titzer): these should be moved to wasm-objects-inl.h 669 // TODO(titzer): these should be moved to wasm-objects-inl.h
730 CAST_ACCESSOR(WasmInstanceObject) 670 CAST_ACCESSOR(WasmInstanceObject)
731 CAST_ACCESSOR(WasmMemoryObject) 671 CAST_ACCESSOR(WasmMemoryObject)
732 CAST_ACCESSOR(WasmModuleObject) 672 CAST_ACCESSOR(WasmModuleObject)
733 CAST_ACCESSOR(WasmTableObject) 673 CAST_ACCESSOR(WasmTableObject)
734 674
735 // WasmModuleObject 675 // WasmModuleObject
736 ACCESSORS(WasmModuleObject, compiled_module, WasmCompiledModule, 676 ACCESSORS(WasmModuleObject, compiled_module, WasmCompiledModule,
737 kCompiledModuleOffset) 677 kCompiledModuleOffset)
738 678
739 // WasmTableObject 679 // WasmTableObject
740 ACCESSORS(WasmTableObject, functions, FixedArray, kFunctionsOffset) 680 ACCESSORS(WasmTableObject, functions, FixedArray, kFunctionsOffset)
741 SMI_ACCESSORS(WasmTableObject, maximum_length, kMaximumLengthOffset) 681 SMI_ACCESSORS(WasmTableObject, maximum_length, kMaximumLengthOffset)
742 ACCESSORS(WasmTableObject, dispatch_tables, FixedArray, kDispatchTablesOffset) 682 ACCESSORS(WasmTableObject, dispatch_tables, FixedArray, kDispatchTablesOffset)
743 683
744 // WasmMemoryObject 684 // WasmMemoryObject
745 ACCESSORS(WasmMemoryObject, array_buffer, JSArrayBuffer, kArrayBufferOffset) 685 ACCESSORS(WasmMemoryObject, array_buffer, JSArrayBuffer, kArrayBufferOffset)
746 SMI_ACCESSORS(WasmMemoryObject, maximum_pages, kMaximumPagesOffset) 686 SMI_ACCESSORS(WasmMemoryObject, maximum_pages, kMaximumPagesOffset)
747 ACCESSORS(WasmMemoryObject, instances_link, WasmInstanceWrapper, 687 ACCESSORS(WasmMemoryObject, instances, WeakFixedArray, kInstancesOffset)
748 kInstancesLinkOffset)
749 688
750 // WasmInstanceObject 689 // WasmInstanceObject
751 ACCESSORS(WasmInstanceObject, compiled_module, WasmCompiledModule, 690 ACCESSORS(WasmInstanceObject, compiled_module, WasmCompiledModule,
752 kCompiledModuleOffset) 691 kCompiledModuleOffset)
753 ACCESSORS(WasmInstanceObject, memory_object, WasmMemoryObject, 692 ACCESSORS(WasmInstanceObject, memory_object, WasmMemoryObject,
754 kMemoryObjectOffset) 693 kMemoryObjectOffset)
755 ACCESSORS(WasmInstanceObject, memory_buffer, JSArrayBuffer, kMemoryBufferOffset) 694 ACCESSORS(WasmInstanceObject, memory_buffer, JSArrayBuffer, kMemoryBufferOffset)
756 ACCESSORS(WasmInstanceObject, globals_buffer, JSArrayBuffer, 695 ACCESSORS(WasmInstanceObject, globals_buffer, JSArrayBuffer,
757 kGlobalsBufferOffset) 696 kGlobalsBufferOffset)
758 ACCESSORS(WasmInstanceObject, debug_info, WasmDebugInfo, kDebugInfoOffset) 697 ACCESSORS(WasmInstanceObject, debug_info, WasmDebugInfo, kDebugInfoOffset)
759 ACCESSORS(WasmInstanceObject, instance_wrapper, WasmInstanceWrapper,
760 kInstanceWrapperOffset)
761 ACCESSORS(WasmInstanceObject, directly_called_instances, FixedArray, 698 ACCESSORS(WasmInstanceObject, directly_called_instances, FixedArray,
762 kDirectlyCalledInstancesOffset) 699 kDirectlyCalledInstancesOffset)
763 700
764 // WasmExportedFunction 701 // WasmExportedFunction
765 ACCESSORS(WasmExportedFunction, instance, WasmInstanceObject, kInstanceOffset) 702 ACCESSORS(WasmExportedFunction, instance, WasmInstanceObject, kInstanceOffset)
766 SMI_ACCESSORS(WasmExportedFunction, function_index, kFunctionIndexOffset) 703 SMI_ACCESSORS(WasmExportedFunction, function_index, kFunctionIndexOffset)
767 704
768 // WasmSharedModuleData 705 // WasmSharedModuleData
769 ACCESSORS(WasmSharedModuleData, module_bytes, SeqOneByteString, 706 ACCESSORS(WasmSharedModuleData, module_bytes, SeqOneByteString,
770 kModuleBytesOffset) 707 kModuleBytesOffset)
771 ACCESSORS(WasmSharedModuleData, script, Script, kScriptOffset) 708 ACCESSORS(WasmSharedModuleData, script, Script, kScriptOffset)
772 ACCESSORS(WasmSharedModuleData, asm_js_offset_table, ByteArray, 709 ACCESSORS(WasmSharedModuleData, asm_js_offset_table, ByteArray,
773 kAsmJsOffsetTableOffset) 710 kAsmJsOffsetTableOffset)
774 ACCESSORS(WasmSharedModuleData, breakpoint_infos, FixedArray, 711 ACCESSORS(WasmSharedModuleData, breakpoint_infos, FixedArray,
775 kBreakPointInfosOffset) 712 kBreakPointInfosOffset)
776 713
777 #define OPTIONAL_ACCESSOR(holder, name, offset) \ 714 #define OPTIONAL_ACCESSOR(holder, name, offset) \
778 bool holder::has_##name() { \ 715 bool holder::has_##name() { \
779 return !READ_FIELD(this, offset)->IsUndefined(GetIsolate()); \ 716 return !READ_FIELD(this, offset)->IsUndefined(GetIsolate()); \
780 } 717 }
781 718
782 OPTIONAL_ACCESSOR(WasmInstanceObject, debug_info, kDebugInfoOffset) 719 OPTIONAL_ACCESSOR(WasmInstanceObject, debug_info, kDebugInfoOffset)
783 OPTIONAL_ACCESSOR(WasmInstanceObject, memory_buffer, kMemoryBufferOffset) 720 OPTIONAL_ACCESSOR(WasmInstanceObject, memory_buffer, kMemoryBufferOffset)
784 OPTIONAL_ACCESSOR(WasmInstanceObject, memory_object, kMemoryObjectOffset) 721 OPTIONAL_ACCESSOR(WasmInstanceObject, memory_object, kMemoryObjectOffset)
785 OPTIONAL_ACCESSOR(WasmInstanceObject, instance_wrapper, kInstanceWrapperOffset)
786 722
787 OPTIONAL_ACCESSOR(WasmMemoryObject, instances_link, kInstancesLinkOffset) 723 OPTIONAL_ACCESSOR(WasmMemoryObject, instances, kInstancesOffset)
788 724
789 OPTIONAL_ACCESSOR(WasmSharedModuleData, breakpoint_infos, 725 OPTIONAL_ACCESSOR(WasmSharedModuleData, breakpoint_infos,
790 kBreakPointInfosOffset) 726 kBreakPointInfosOffset)
791 OPTIONAL_ACCESSOR(WasmSharedModuleData, asm_js_offset_table, 727 OPTIONAL_ACCESSOR(WasmSharedModuleData, asm_js_offset_table,
792 kAsmJsOffsetTableOffset) 728 kAsmJsOffsetTableOffset)
793 OPTIONAL_ACCESSOR(WasmSharedModuleData, lazy_compilation_orchestrator, 729 OPTIONAL_ACCESSOR(WasmSharedModuleData, lazy_compilation_orchestrator,
794 kLazyCompilationOrchestratorOffset) 730 kLazyCompilationOrchestratorOffset)
795 731
796 ACCESSORS(WasmDebugInfo, locals_names, FixedArray, kLocalsNamesOffset) 732 ACCESSORS(WasmDebugInfo, locals_names, FixedArray, kLocalsNamesOffset)
797 733
798 OPTIONAL_ACCESSOR(WasmDebugInfo, locals_names, kLocalsNamesOffset) 734 OPTIONAL_ACCESSOR(WasmDebugInfo, locals_names, kLocalsNamesOffset)
799 735
800 inline void WasmMemoryObject::ResetInstancesLink(Isolate* isolate) {
801 // This has to be a raw access to bypass typechecking.
802 WRITE_FIELD(this, kInstancesLinkOffset, isolate->heap()->undefined_value());
803 }
804
805 #undef DECL_OOL_QUERY 736 #undef DECL_OOL_QUERY
806 #undef DECL_OOL_CAST 737 #undef DECL_OOL_CAST
807 #undef DECL_GETTER 738 #undef DECL_GETTER
808 #undef DECL_OPTIONAL_ACCESSORS 739 #undef DECL_OPTIONAL_ACCESSORS
809 #undef DECL_OPTIONAL_GETTER 740 #undef DECL_OPTIONAL_GETTER
810 741
811 #include "src/objects/object-macros-undef.h" 742 #include "src/objects/object-macros-undef.h"
812 743
813 } // namespace internal 744 } // namespace internal
814 } // namespace v8 745 } // namespace v8
815 746
816 #endif // V8_WASM_OBJECTS_H_ 747 #endif // V8_WASM_OBJECTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698