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

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

Issue 2972803002: [wasm] Use WeakFixedArray for list of instances sharing a WasmMemoryObject. (Closed)
Patch Set: [wasm] Use WeakFixedArray for list of instances sharing a WasmMemoryObject. 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
« no previous file with comments | « src/wasm/wasm-module.cc ('k') | src/wasm/wasm-objects.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Add an instance to the internal (weak) list. amortized O(n).
131 inline void ResetInstancesLink(Isolate* isolate); 130 static void AddInstance(Isolate* isolate, Handle<WasmMemoryObject> memory,
131 Handle<WasmInstanceObject> object);
132 // Remove an instance from the internal (weak) list. O(n).
133 static void RemoveInstance(Isolate* isolate, Handle<WasmMemoryObject> memory,
134 Handle<WasmInstanceObject> object);
132 uint32_t current_pages(); 135 uint32_t current_pages();
133 inline bool has_maximum_pages() { return maximum_pages() >= 0; } 136 inline bool has_maximum_pages() { return maximum_pages() >= 0; }
134 137
135 static Handle<WasmMemoryObject> New(Isolate* isolate, 138 static Handle<WasmMemoryObject> New(Isolate* isolate,
136 Handle<JSArrayBuffer> buffer, 139 Handle<JSArrayBuffer> buffer,
137 int32_t maximum); 140 int32_t maximum);
138 141
139 static int32_t Grow(Isolate*, Handle<WasmMemoryObject>, uint32_t pages); 142 static int32_t Grow(Isolate*, Handle<WasmMemoryObject>, uint32_t pages);
140 }; 143 };
141 144
142 // A WebAssembly.Instance JavaScript-level object. 145 // A WebAssembly.Instance JavaScript-level object.
143 class WasmInstanceObject : public JSObject { 146 class WasmInstanceObject : public JSObject {
144 public: 147 public:
145 DECL_CAST(WasmInstanceObject) 148 DECL_CAST(WasmInstanceObject)
146 149
147 DECL_ACCESSORS(compiled_module, WasmCompiledModule) 150 DECL_ACCESSORS(compiled_module, WasmCompiledModule)
148 DECL_OPTIONAL_ACCESSORS(memory_object, WasmMemoryObject) 151 DECL_OPTIONAL_ACCESSORS(memory_object, WasmMemoryObject)
149 DECL_OPTIONAL_ACCESSORS(memory_buffer, JSArrayBuffer) 152 DECL_OPTIONAL_ACCESSORS(memory_buffer, JSArrayBuffer)
150 DECL_OPTIONAL_ACCESSORS(globals_buffer, JSArrayBuffer) 153 DECL_OPTIONAL_ACCESSORS(globals_buffer, JSArrayBuffer)
151 DECL_OPTIONAL_ACCESSORS(debug_info, WasmDebugInfo) 154 DECL_OPTIONAL_ACCESSORS(debug_info, WasmDebugInfo)
152 DECL_OPTIONAL_ACCESSORS(instance_wrapper, WasmInstanceWrapper)
153 // FixedArray of all instances whose code was imported 155 // FixedArray of all instances whose code was imported
154 DECL_OPTIONAL_ACCESSORS(directly_called_instances, FixedArray) 156 DECL_OPTIONAL_ACCESSORS(directly_called_instances, FixedArray)
155 157
156 enum { // -- 158 enum { // --
157 kCompiledModuleIndex, 159 kCompiledModuleIndex,
158 kMemoryObjectIndex, 160 kMemoryObjectIndex,
159 kMemoryBufferIndex, 161 kMemoryBufferIndex,
160 kGlobalsBufferIndex, 162 kGlobalsBufferIndex,
161 kDebugInfoIndex, 163 kDebugInfoIndex,
162 kInstanceWrapperIndex,
163 kDirectlyCalledInstancesIndex, 164 kDirectlyCalledInstancesIndex,
164 kFieldCount 165 kFieldCount
165 }; 166 };
166 167
167 DEF_SIZE(JSObject) 168 DEF_SIZE(JSObject)
168 DEF_OFFSET(CompiledModule) 169 DEF_OFFSET(CompiledModule)
169 DEF_OFFSET(MemoryObject) 170 DEF_OFFSET(MemoryObject)
170 DEF_OFFSET(MemoryBuffer) 171 DEF_OFFSET(MemoryBuffer)
171 DEF_OFFSET(GlobalsBuffer) 172 DEF_OFFSET(GlobalsBuffer)
172 DEF_OFFSET(DebugInfo) 173 DEF_OFFSET(DebugInfo)
173 DEF_OFFSET(InstanceWrapper)
174 DEF_OFFSET(DirectlyCalledInstances) 174 DEF_OFFSET(DirectlyCalledInstances)
175 175
176 WasmModuleObject* module_object(); 176 WasmModuleObject* module_object();
177 V8_EXPORT_PRIVATE wasm::WasmModule* module(); 177 V8_EXPORT_PRIVATE wasm::WasmModule* module();
178 178
179 // Get the debug info associated with the given wasm object. 179 // Get the debug info associated with the given wasm object.
180 // If no debug info exists yet, it is created automatically. 180 // If no debug info exists yet, it is created automatically.
181 static Handle<WasmDebugInfo> GetOrCreateDebugInfo(Handle<WasmInstanceObject>); 181 static Handle<WasmDebugInfo> GetOrCreateDebugInfo(Handle<WasmInstanceObject>);
182 182
183 static Handle<WasmInstanceObject> New(Isolate*, Handle<WasmCompiledModule>); 183 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 661 // for the local scope. Both elements are JSArrays of size
662 // ScopeIterator::kScopeDetailsSize and layout as described in debug-scopes.h. 662 // ScopeIterator::kScopeDetailsSize and layout as described in debug-scopes.h.
663 // The global scope contains information about globals and the memory. 663 // The global scope contains information about globals and the memory.
664 // The local scope contains information about parameters, locals, and stack 664 // The local scope contains information about parameters, locals, and stack
665 // values. 665 // values.
666 static Handle<JSArray> GetScopeDetails(Handle<WasmDebugInfo>, 666 static Handle<JSArray> GetScopeDetails(Handle<WasmDebugInfo>,
667 Address frame_pointer, 667 Address frame_pointer,
668 int frame_index); 668 int frame_index);
669 }; 669 };
670 670
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 671 // TODO(titzer): these should be moved to wasm-objects-inl.h
730 CAST_ACCESSOR(WasmInstanceObject) 672 CAST_ACCESSOR(WasmInstanceObject)
731 CAST_ACCESSOR(WasmMemoryObject) 673 CAST_ACCESSOR(WasmMemoryObject)
732 CAST_ACCESSOR(WasmModuleObject) 674 CAST_ACCESSOR(WasmModuleObject)
733 CAST_ACCESSOR(WasmTableObject) 675 CAST_ACCESSOR(WasmTableObject)
734 676
735 // WasmModuleObject 677 // WasmModuleObject
736 ACCESSORS(WasmModuleObject, compiled_module, WasmCompiledModule, 678 ACCESSORS(WasmModuleObject, compiled_module, WasmCompiledModule,
737 kCompiledModuleOffset) 679 kCompiledModuleOffset)
738 680
739 // WasmTableObject 681 // WasmTableObject
740 ACCESSORS(WasmTableObject, functions, FixedArray, kFunctionsOffset) 682 ACCESSORS(WasmTableObject, functions, FixedArray, kFunctionsOffset)
741 SMI_ACCESSORS(WasmTableObject, maximum_length, kMaximumLengthOffset) 683 SMI_ACCESSORS(WasmTableObject, maximum_length, kMaximumLengthOffset)
742 ACCESSORS(WasmTableObject, dispatch_tables, FixedArray, kDispatchTablesOffset) 684 ACCESSORS(WasmTableObject, dispatch_tables, FixedArray, kDispatchTablesOffset)
743 685
744 // WasmMemoryObject 686 // WasmMemoryObject
745 ACCESSORS(WasmMemoryObject, array_buffer, JSArrayBuffer, kArrayBufferOffset) 687 ACCESSORS(WasmMemoryObject, array_buffer, JSArrayBuffer, kArrayBufferOffset)
746 SMI_ACCESSORS(WasmMemoryObject, maximum_pages, kMaximumPagesOffset) 688 SMI_ACCESSORS(WasmMemoryObject, maximum_pages, kMaximumPagesOffset)
747 ACCESSORS(WasmMemoryObject, instances_link, WasmInstanceWrapper, 689 ACCESSORS(WasmMemoryObject, instances, WeakFixedArray, kInstancesOffset)
748 kInstancesLinkOffset)
749 690
750 // WasmInstanceObject 691 // WasmInstanceObject
751 ACCESSORS(WasmInstanceObject, compiled_module, WasmCompiledModule, 692 ACCESSORS(WasmInstanceObject, compiled_module, WasmCompiledModule,
752 kCompiledModuleOffset) 693 kCompiledModuleOffset)
753 ACCESSORS(WasmInstanceObject, memory_object, WasmMemoryObject, 694 ACCESSORS(WasmInstanceObject, memory_object, WasmMemoryObject,
754 kMemoryObjectOffset) 695 kMemoryObjectOffset)
755 ACCESSORS(WasmInstanceObject, memory_buffer, JSArrayBuffer, kMemoryBufferOffset) 696 ACCESSORS(WasmInstanceObject, memory_buffer, JSArrayBuffer, kMemoryBufferOffset)
756 ACCESSORS(WasmInstanceObject, globals_buffer, JSArrayBuffer, 697 ACCESSORS(WasmInstanceObject, globals_buffer, JSArrayBuffer,
757 kGlobalsBufferOffset) 698 kGlobalsBufferOffset)
758 ACCESSORS(WasmInstanceObject, debug_info, WasmDebugInfo, kDebugInfoOffset) 699 ACCESSORS(WasmInstanceObject, debug_info, WasmDebugInfo, kDebugInfoOffset)
759 ACCESSORS(WasmInstanceObject, instance_wrapper, WasmInstanceWrapper,
760 kInstanceWrapperOffset)
761 ACCESSORS(WasmInstanceObject, directly_called_instances, FixedArray, 700 ACCESSORS(WasmInstanceObject, directly_called_instances, FixedArray,
762 kDirectlyCalledInstancesOffset) 701 kDirectlyCalledInstancesOffset)
763 702
764 // WasmExportedFunction 703 // WasmExportedFunction
765 ACCESSORS(WasmExportedFunction, instance, WasmInstanceObject, kInstanceOffset) 704 ACCESSORS(WasmExportedFunction, instance, WasmInstanceObject, kInstanceOffset)
766 SMI_ACCESSORS(WasmExportedFunction, function_index, kFunctionIndexOffset) 705 SMI_ACCESSORS(WasmExportedFunction, function_index, kFunctionIndexOffset)
767 706
768 // WasmSharedModuleData 707 // WasmSharedModuleData
769 ACCESSORS(WasmSharedModuleData, module_bytes, SeqOneByteString, 708 ACCESSORS(WasmSharedModuleData, module_bytes, SeqOneByteString,
770 kModuleBytesOffset) 709 kModuleBytesOffset)
771 ACCESSORS(WasmSharedModuleData, script, Script, kScriptOffset) 710 ACCESSORS(WasmSharedModuleData, script, Script, kScriptOffset)
772 ACCESSORS(WasmSharedModuleData, asm_js_offset_table, ByteArray, 711 ACCESSORS(WasmSharedModuleData, asm_js_offset_table, ByteArray,
773 kAsmJsOffsetTableOffset) 712 kAsmJsOffsetTableOffset)
774 ACCESSORS(WasmSharedModuleData, breakpoint_infos, FixedArray, 713 ACCESSORS(WasmSharedModuleData, breakpoint_infos, FixedArray,
775 kBreakPointInfosOffset) 714 kBreakPointInfosOffset)
776 715
777 #define OPTIONAL_ACCESSOR(holder, name, offset) \ 716 #define OPTIONAL_ACCESSOR(holder, name, offset) \
778 bool holder::has_##name() { \ 717 bool holder::has_##name() { \
779 return !READ_FIELD(this, offset)->IsUndefined(GetIsolate()); \ 718 return !READ_FIELD(this, offset)->IsUndefined(GetIsolate()); \
780 } 719 }
781 720
782 OPTIONAL_ACCESSOR(WasmInstanceObject, debug_info, kDebugInfoOffset) 721 OPTIONAL_ACCESSOR(WasmInstanceObject, debug_info, kDebugInfoOffset)
783 OPTIONAL_ACCESSOR(WasmInstanceObject, memory_buffer, kMemoryBufferOffset) 722 OPTIONAL_ACCESSOR(WasmInstanceObject, memory_buffer, kMemoryBufferOffset)
784 OPTIONAL_ACCESSOR(WasmInstanceObject, memory_object, kMemoryObjectOffset) 723 OPTIONAL_ACCESSOR(WasmInstanceObject, memory_object, kMemoryObjectOffset)
785 OPTIONAL_ACCESSOR(WasmInstanceObject, instance_wrapper, kInstanceWrapperOffset)
786 724
787 OPTIONAL_ACCESSOR(WasmMemoryObject, instances_link, kInstancesLinkOffset) 725 OPTIONAL_ACCESSOR(WasmMemoryObject, instances, kInstancesOffset)
788 726
789 OPTIONAL_ACCESSOR(WasmSharedModuleData, breakpoint_infos, 727 OPTIONAL_ACCESSOR(WasmSharedModuleData, breakpoint_infos,
790 kBreakPointInfosOffset) 728 kBreakPointInfosOffset)
791 OPTIONAL_ACCESSOR(WasmSharedModuleData, asm_js_offset_table, 729 OPTIONAL_ACCESSOR(WasmSharedModuleData, asm_js_offset_table,
792 kAsmJsOffsetTableOffset) 730 kAsmJsOffsetTableOffset)
793 OPTIONAL_ACCESSOR(WasmSharedModuleData, lazy_compilation_orchestrator, 731 OPTIONAL_ACCESSOR(WasmSharedModuleData, lazy_compilation_orchestrator,
794 kLazyCompilationOrchestratorOffset) 732 kLazyCompilationOrchestratorOffset)
795 733
796 ACCESSORS(WasmDebugInfo, locals_names, FixedArray, kLocalsNamesOffset) 734 ACCESSORS(WasmDebugInfo, locals_names, FixedArray, kLocalsNamesOffset)
797 735
798 OPTIONAL_ACCESSOR(WasmDebugInfo, locals_names, kLocalsNamesOffset) 736 OPTIONAL_ACCESSOR(WasmDebugInfo, locals_names, kLocalsNamesOffset)
799 737
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 738 #undef DECL_OOL_QUERY
806 #undef DECL_OOL_CAST 739 #undef DECL_OOL_CAST
807 #undef DECL_GETTER 740 #undef DECL_GETTER
808 #undef DECL_OPTIONAL_ACCESSORS 741 #undef DECL_OPTIONAL_ACCESSORS
809 #undef DECL_OPTIONAL_GETTER 742 #undef DECL_OPTIONAL_GETTER
810 743
811 #include "src/objects/object-macros-undef.h" 744 #include "src/objects/object-macros-undef.h"
812 745
813 } // namespace internal 746 } // namespace internal
814 } // namespace v8 747 } // namespace v8
815 748
816 #endif // V8_WASM_OBJECTS_H_ 749 #endif // V8_WASM_OBJECTS_H_
OLDNEW
« no previous file with comments | « src/wasm/wasm-module.cc ('k') | src/wasm/wasm-objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698