5 #ifndef V8_WASM_WASM_OBJECTS_INL_H_ 6 #define V8_WASM_WASM_OBJECTS_INL_H_ 8 #include "src/wasm/wasm-objects.h" 10 #include "src/contexts-inl.h" 11 #include "src/heap/heap-inl.h" 12 #include "src/objects/js-array-buffer-inl.h" 13 #include "src/objects/managed.h" 14 #include "src/v8memory.h" 15 #include "src/wasm/wasm-code-manager.h" 16 #include "src/wasm/wasm-module.h" 19 #include "src/objects/object-macros.h" 24 CAST_ACCESSOR(WasmDebugInfo)
25 CAST_ACCESSOR(WasmExceptionObject)
26 CAST_ACCESSOR(WasmExportedFunctionData)
27 CAST_ACCESSOR(WasmGlobalObject)
28 CAST_ACCESSOR(WasmInstanceObject)
29 CAST_ACCESSOR(WasmMemoryObject)
30 CAST_ACCESSOR(WasmModuleObject)
31 CAST_ACCESSOR(WasmTableObject)
32 CAST_ACCESSOR(AsmWasmData)
34 #define OPTIONAL_ACCESSORS(holder, name, type, offset) \ 35 bool holder::has_##name() { \ 36 return !READ_FIELD(this, offset)->IsUndefined(); \ 38 ACCESSORS(holder, name, type, offset) 41 #define OPTIONAL_ACCESSORS2(holder, name, type, offset) \ 42 bool holder::has_##name() { \ 43 return !READ_FIELD(this, offset)->IsUndefined(); \ 45 ACCESSORS2(holder, name, type, offset) 47 #define READ_PRIMITIVE_FIELD(p, type, offset) \ 48 (*reinterpret_cast<type const*>(FIELD_ADDR(p, offset))) 50 #define WRITE_PRIMITIVE_FIELD(p, type, offset, value) \ 51 (*reinterpret_cast<type*>(FIELD_ADDR(p, offset)) = value) 53 #define PRIMITIVE_ACCESSORS(holder, name, type, offset) \ 54 type holder::name() const { \ 55 return READ_PRIMITIVE_FIELD(this, type, offset); \ 57 void holder::set_##name(type value) { \ 58 WRITE_PRIMITIVE_FIELD(this, type, offset, value); \ 62 ACCESSORS(WasmModuleObject, managed_native_module, Managed<wasm::NativeModule>,
64 ACCESSORS2(WasmModuleObject, export_wrappers, FixedArray, kExportWrappersOffset)
65 ACCESSORS(WasmModuleObject, script, Script, kScriptOffset)
66 ACCESSORS(WasmModuleObject, weak_instance_list, WeakArrayList,
67 kWeakInstanceListOffset)
68 OPTIONAL_ACCESSORS2(WasmModuleObject, asm_js_offset_table, ByteArray,
69 kAsmJsOffsetTableOffset)
70 OPTIONAL_ACCESSORS2(WasmModuleObject, breakpoint_infos, FixedArray,
71 kBreakPointInfosOffset)
72 wasm::NativeModule* WasmModuleObject::native_module()
const {
73 return managed_native_module()->raw();
75 const wasm::WasmModule* WasmModuleObject::module()
const {
77 return native_module()->module();
79 void WasmModuleObject::reset_breakpoint_infos() {
80 WRITE_FIELD(
this, kBreakPointInfosOffset,
81 GetReadOnlyRoots().undefined_value());
83 bool WasmModuleObject::is_asm_js() {
84 bool asm_js = module()->origin == wasm::kAsmJsOrigin;
85 DCHECK_EQ(asm_js, script()->IsUserJavaScript());
86 DCHECK_EQ(asm_js, has_asm_js_offset_table());
91 ACCESSORS2(WasmTableObject, functions, FixedArray, kFunctionsOffset)
92 ACCESSORS(WasmTableObject, maximum_length, Object, kMaximumLengthOffset)
93 ACCESSORS2(WasmTableObject, dispatch_tables, FixedArray, kDispatchTablesOffset)
96 ACCESSORS(WasmMemoryObject, array_buffer, JSArrayBuffer, kArrayBufferOffset)
97 SMI_ACCESSORS(WasmMemoryObject, maximum_pages, kMaximumPagesOffset)
98 OPTIONAL_ACCESSORS(WasmMemoryObject, instances, WeakArrayList, kInstancesOffset)
101 ACCESSORS(WasmGlobalObject, array_buffer, JSArrayBuffer, kArrayBufferOffset)
102 SMI_ACCESSORS(WasmGlobalObject, offset, kOffsetOffset)
103 SMI_ACCESSORS(WasmGlobalObject, flags, kFlagsOffset)
104 BIT_FIELD_ACCESSORS(WasmGlobalObject, flags, type, WasmGlobalObject::TypeBits)
105 BIT_FIELD_ACCESSORS(WasmGlobalObject, flags, is_mutable,
106 WasmGlobalObject::IsMutableBit)
108 int WasmGlobalObject::type_size()
const {
109 return wasm::ValueTypes::ElementSizeInBytes(type());
112 Address WasmGlobalObject::address()
const {
113 DCHECK_LE(offset() + type_size(), array_buffer()->byte_length());
114 return Address(array_buffer()->backing_store()) + offset();
117 int32_t WasmGlobalObject::GetI32() {
118 return ReadLittleEndianValue<int32_t>(address());
121 int64_t WasmGlobalObject::GetI64() {
122 return ReadLittleEndianValue<int64_t>(address());
125 float WasmGlobalObject::GetF32() {
126 return ReadLittleEndianValue<float>(address());
129 double WasmGlobalObject::GetF64() {
130 return ReadLittleEndianValue<double>(address());
133 void WasmGlobalObject::SetI32(int32_t value) {
134 WriteLittleEndianValue<int32_t>(address(), value);
137 void WasmGlobalObject::SetI64(
int64_t value) {
138 WriteLittleEndianValue<int64_t>(address(), value);
141 void WasmGlobalObject::SetF32(
float value) {
142 WriteLittleEndianValue<float>(address(), value);
145 void WasmGlobalObject::SetF64(
double value) {
146 WriteLittleEndianValue<double>(address(), value);
150 PRIMITIVE_ACCESSORS(WasmInstanceObject, memory_start, byte*, kMemoryStartOffset)
151 PRIMITIVE_ACCESSORS(WasmInstanceObject, memory_size,
size_t, kMemorySizeOffset)
152 PRIMITIVE_ACCESSORS(WasmInstanceObject, memory_mask,
size_t, kMemoryMaskOffset)
153 PRIMITIVE_ACCESSORS(WasmInstanceObject, isolate_root, Address,
155 PRIMITIVE_ACCESSORS(WasmInstanceObject, stack_limit_address, Address,
156 kStackLimitAddressOffset)
157 PRIMITIVE_ACCESSORS(WasmInstanceObject, real_stack_limit_address, Address,
158 kRealStackLimitAddressOffset)
159 PRIMITIVE_ACCESSORS(WasmInstanceObject, imported_function_targets, Address*,
160 kImportedFunctionTargetsOffset)
161 PRIMITIVE_ACCESSORS(WasmInstanceObject, globals_start, byte*,
163 PRIMITIVE_ACCESSORS(WasmInstanceObject, imported_mutable_globals, Address*,
164 kImportedMutableGlobalsOffset)
165 PRIMITIVE_ACCESSORS(WasmInstanceObject, indirect_function_table_size,
uint32_t,
166 kIndirectFunctionTableSizeOffset)
167 PRIMITIVE_ACCESSORS(WasmInstanceObject, indirect_function_table_sig_ids,
168 uint32_t*, kIndirectFunctionTableSigIdsOffset)
169 PRIMITIVE_ACCESSORS(WasmInstanceObject, indirect_function_table_targets,
170 Address*, kIndirectFunctionTableTargetsOffset)
171 PRIMITIVE_ACCESSORS(WasmInstanceObject, jump_table_start, Address,
172 kJumpTableStartOffset)
174 ACCESSORS(WasmInstanceObject, module_object, WasmModuleObject,
176 ACCESSORS(WasmInstanceObject, exports_object, JSObject, kExportsObjectOffset)
177 ACCESSORS2(WasmInstanceObject, native_context, Context, kNativeContextOffset)
178 OPTIONAL_ACCESSORS(WasmInstanceObject, memory_object, WasmMemoryObject,
180 OPTIONAL_ACCESSORS(WasmInstanceObject, globals_buffer, JSArrayBuffer,
181 kGlobalsBufferOffset)
182 OPTIONAL_ACCESSORS2(WasmInstanceObject, imported_mutable_globals_buffers,
183 FixedArray, kImportedMutableGlobalsBuffersOffset)
184 OPTIONAL_ACCESSORS(WasmInstanceObject, debug_info, WasmDebugInfo,
186 OPTIONAL_ACCESSORS(WasmInstanceObject, table_object, WasmTableObject,
188 ACCESSORS2(WasmInstanceObject, imported_function_refs, FixedArray,
189 kImportedFunctionRefsOffset)
190 OPTIONAL_ACCESSORS2(WasmInstanceObject, indirect_function_table_refs,
191 FixedArray, kIndirectFunctionTableRefsOffset)
192 OPTIONAL_ACCESSORS(WasmInstanceObject, managed_native_allocations, Foreign,
193 kManagedNativeAllocationsOffset)
194 OPTIONAL_ACCESSORS2(WasmInstanceObject, exceptions_table, FixedArray,
195 kExceptionsTableOffset)
196 ACCESSORS(WasmInstanceObject, undefined_value, Oddball, kUndefinedValueOffset)
197 ACCESSORS(WasmInstanceObject, null_value, Oddball, kNullValueOffset)
198 ACCESSORS2(WasmInstanceObject, centry_stub, Code, kCEntryStubOffset)
200 inline bool WasmInstanceObject::has_indirect_function_table() {
201 return indirect_function_table_sig_ids() !=
nullptr;
204 IndirectFunctionTableEntry::IndirectFunctionTableEntry(
205 Handle<WasmInstanceObject> instance,
int index)
206 : instance_(instance), index_(index) {
208 DCHECK_LT(index, instance->indirect_function_table_size());
211 ImportedFunctionEntry::ImportedFunctionEntry(
212 Handle<WasmInstanceObject> instance,
int index)
213 : instance_(instance), index_(index) {
215 DCHECK_LT(index, instance->module()->num_imported_functions);
219 ACCESSORS2(WasmExceptionObject, serialized_signature, PodArray<wasm::ValueType>,
220 kSerializedSignatureOffset)
221 ACCESSORS(WasmExceptionObject, exception_tag, HeapObject, kExceptionTagOffset)
224 ACCESSORS2(WasmExportedFunctionData, wrapper_code, Code, kWrapperCodeOffset)
225 ACCESSORS(WasmExportedFunctionData, instance, WasmInstanceObject,
227 SMI_ACCESSORS(WasmExportedFunctionData, jump_table_offset,
228 kJumpTableOffsetOffset)
229 SMI_ACCESSORS(WasmExportedFunctionData, function_index, kFunctionIndexOffset)
232 ACCESSORS(WasmDebugInfo, wasm_instance, WasmInstanceObject, kInstanceOffset)
233 ACCESSORS(WasmDebugInfo, interpreter_handle, Object, kInterpreterHandleOffset)
234 ACCESSORS2(WasmDebugInfo, interpreted_functions, FixedArray,
235 kInterpretedFunctionsOffset)
236 OPTIONAL_ACCESSORS2(WasmDebugInfo, locals_names, FixedArray, kLocalsNamesOffset)
237 OPTIONAL_ACCESSORS2(WasmDebugInfo, c_wasm_entries, FixedArray,
239 OPTIONAL_ACCESSORS(WasmDebugInfo, c_wasm_entry_map, Managed<wasm::SignatureMap>,
240 kCWasmEntryMapOffset)
242 #undef OPTIONAL_ACCESSORS 243 #undef READ_PRIMITIVE_FIELD 244 #undef WRITE_PRIMITIVE_FIELD 245 #undef PRIMITIVE_ACCESSORS 247 uint32_t WasmTableObject::current_length() {
return functions()->length(); }
249 bool WasmMemoryObject::has_maximum_pages() {
return maximum_pages() >= 0; }
252 ACCESSORS(AsmWasmData, managed_native_module, Managed<wasm::NativeModule>,
253 kManagedNativeModuleOffset)
254 ACCESSORS2(AsmWasmData, export_wrappers, FixedArray, kExportWrappersOffset)
255 ACCESSORS2(AsmWasmData, asm_js_offset_table, ByteArray, kAsmJsOffsetTableOffset)
256 ACCESSORS(AsmWasmData, uses_bitset, HeapNumber, kUsesBitsetOffset)
258 #include "src/objects/object-macros-undef.h" 263 #endif // V8_WASM_WASM_OBJECTS_INL_H_