LCOV - code coverage report
Current view: top level - src/wasm - wasm-objects-inl.h (source / functions) Hit Total Coverage
Test: app.info Lines: 127 127 100.0 %
Date: 2019-02-19 Functions: 105 105 100.0 %

          Line data    Source code
       1             : // Copyright 2017 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #ifndef V8_WASM_WASM_OBJECTS_INL_H_
       6             : #define V8_WASM_WASM_OBJECTS_INL_H_
       7             : 
       8             : #include "src/wasm/wasm-objects.h"
       9             : 
      10             : #include "src/contexts-inl.h"
      11             : #include "src/heap/heap-write-barrier-inl.h"
      12             : #include "src/objects/foreign-inl.h"
      13             : #include "src/objects/heap-number-inl.h"
      14             : #include "src/objects/js-array-buffer-inl.h"
      15             : #include "src/objects/js-objects-inl.h"
      16             : #include "src/objects/managed.h"
      17             : #include "src/objects/oddball-inl.h"
      18             : #include "src/objects/script-inl.h"
      19             : #include "src/roots.h"
      20             : #include "src/v8memory.h"
      21             : #include "src/wasm/wasm-code-manager.h"
      22             : #include "src/wasm/wasm-module.h"
      23             : 
      24             : // Has to be the last include (doesn't have include guards)
      25             : #include "src/objects/object-macros.h"
      26             : 
      27             : namespace v8 {
      28             : namespace internal {
      29             : 
      30         304 : OBJECT_CONSTRUCTORS_IMPL(WasmExceptionObject, JSObject)
      31        2208 : OBJECT_CONSTRUCTORS_IMPL(WasmExceptionTag, Struct)
      32     2054646 : OBJECT_CONSTRUCTORS_IMPL(WasmExportedFunctionData, Struct)
      33      823004 : OBJECT_CONSTRUCTORS_IMPL(WasmDebugInfo, Struct)
      34       39104 : OBJECT_CONSTRUCTORS_IMPL(WasmGlobalObject, JSObject)
      35    49045420 : OBJECT_CONSTRUCTORS_IMPL(WasmInstanceObject, JSObject)
      36      204354 : OBJECT_CONSTRUCTORS_IMPL(WasmMemoryObject, JSObject)
      37    10088678 : OBJECT_CONSTRUCTORS_IMPL(WasmModuleObject, JSObject)
      38       62356 : OBJECT_CONSTRUCTORS_IMPL(WasmTableObject, JSObject)
      39       14802 : OBJECT_CONSTRUCTORS_IMPL(AsmWasmData, Struct)
      40             : 
      41             : NEVER_READ_ONLY_SPACE_IMPL(WasmDebugInfo)
      42             : 
      43      411502 : CAST_ACCESSOR(WasmDebugInfo)
      44         152 : CAST_ACCESSOR(WasmExceptionObject)
      45        1104 : CAST_ACCESSOR(WasmExceptionTag)
      46     1027325 : CAST_ACCESSOR(WasmExportedFunctionData)
      47       19552 : CAST_ACCESSOR(WasmGlobalObject)
      48    24522710 : CAST_ACCESSOR(WasmInstanceObject)
      49      102175 : CAST_ACCESSOR(WasmMemoryObject)
      50     5044339 : CAST_ACCESSOR(WasmModuleObject)
      51       31178 : CAST_ACCESSOR(WasmTableObject)
      52        7401 : CAST_ACCESSOR(AsmWasmData)
      53             : 
      54             : #define OPTIONAL_ACCESSORS(holder, name, type, offset) \
      55             :   bool holder::has_##name() {                          \
      56             :     return !READ_FIELD(*this, offset)->IsUndefined();  \
      57             :   }                                                    \
      58             :   ACCESSORS(holder, name, type, offset)
      59             : 
      60             : #define READ_PRIMITIVE_FIELD(p, type, offset) \
      61             :   (*reinterpret_cast<type const*>(FIELD_ADDR(p, offset)))
      62             : 
      63             : #define WRITE_PRIMITIVE_FIELD(p, type, offset, value) \
      64             :   (*reinterpret_cast<type*>(FIELD_ADDR(p, offset)) = value)
      65             : 
      66             : #define PRIMITIVE_ACCESSORS(holder, name, type, offset) \
      67             :   type holder::name() const {                           \
      68             :     return READ_PRIMITIVE_FIELD(*this, type, offset);   \
      69             :   }                                                     \
      70             :   void holder::set_##name(type value) {                 \
      71             :     WRITE_PRIMITIVE_FIELD(*this, type, offset, value);  \
      72             :   }
      73             : 
      74             : // WasmModuleObject
      75    18015492 : ACCESSORS(WasmModuleObject, managed_native_module, Managed<wasm::NativeModule>,
      76             :           kNativeModuleOffset)
      77     6616655 : ACCESSORS(WasmModuleObject, export_wrappers, FixedArray, kExportWrappersOffset)
      78     6646572 : ACCESSORS(WasmModuleObject, script, Script, kScriptOffset)
      79    16008783 : ACCESSORS(WasmModuleObject, weak_instance_list, WeakArrayList,
      80             :           kWeakInstanceListOffset)
      81       27862 : OPTIONAL_ACCESSORS(WasmModuleObject, asm_js_offset_table, ByteArray,
      82             :                    kAsmJsOffsetTableOffset)
      83      269906 : OPTIONAL_ACCESSORS(WasmModuleObject, breakpoint_infos, FixedArray,
      84             :                    kBreakPointInfosOffset)
      85    11839399 : wasm::NativeModule* WasmModuleObject::native_module() const {
      86    23678803 :   return managed_native_module()->raw();
      87             : }
      88         238 : std::shared_ptr<wasm::NativeModule> WasmModuleObject::shared_native_module()
      89             :     const {
      90         476 :   return managed_native_module()->get();
      91             : }
      92             : const wasm::WasmModule* WasmModuleObject::module() const {
      93             :   // TODO(clemensh): Remove this helper (inline in callers).
      94     5160792 :   return native_module()->module();
      95             : }
      96             : void WasmModuleObject::reset_breakpoint_infos() {
      97             :   WRITE_FIELD(*this, kBreakPointInfosOffset,
      98             :               GetReadOnlyRoots().undefined_value());
      99             : }
     100             : bool WasmModuleObject::is_asm_js() {
     101      154931 :   bool asm_js = module()->origin == wasm::kAsmJsOrigin;
     102             :   DCHECK_EQ(asm_js, script()->IsUserJavaScript());
     103             :   DCHECK_EQ(asm_js, has_asm_js_offset_table());
     104             :   return asm_js;
     105             : }
     106             : 
     107             : // WasmTableObject
     108      100677 : ACCESSORS(WasmTableObject, elements, FixedArray, kElementsOffset)
     109       17709 : ACCESSORS(WasmTableObject, maximum_length, Object, kMaximumLengthOffset)
     110       43525 : ACCESSORS(WasmTableObject, dispatch_tables, FixedArray, kDispatchTablesOffset)
     111             : 
     112             : // WasmMemoryObject
     113      546922 : ACCESSORS(WasmMemoryObject, array_buffer, JSArrayBuffer, kArrayBufferOffset)
     114       73545 : SMI_ACCESSORS(WasmMemoryObject, maximum_pages, kMaximumPagesOffset)
     115      399765 : OPTIONAL_ACCESSORS(WasmMemoryObject, instances, WeakArrayList, kInstancesOffset)
     116             : 
     117             : // WasmGlobalObject
     118       91624 : ACCESSORS(WasmGlobalObject, untagged_buffer, JSArrayBuffer,
     119             :           kUntaggedBufferOffset)
     120        2368 : ACCESSORS(WasmGlobalObject, tagged_buffer, FixedArray, kTaggedBufferOffset)
     121       44872 : SMI_ACCESSORS(WasmGlobalObject, offset, kOffsetOffset)
     122       82792 : SMI_ACCESSORS(WasmGlobalObject, flags, kFlagsOffset)
     123       30496 : BIT_FIELD_ACCESSORS(WasmGlobalObject, flags, type, WasmGlobalObject::TypeBits)
     124       39544 : BIT_FIELD_ACCESSORS(WasmGlobalObject, flags, is_mutable,
     125             :                     WasmGlobalObject::IsMutableBit)
     126             : 
     127             : int WasmGlobalObject::type_size() const {
     128             :   return wasm::ValueTypes::ElementSizeInBytes(type());
     129             : }
     130             : 
     131       17992 : Address WasmGlobalObject::address() const {
     132             :   DCHECK_NE(type(), wasm::kWasmAnyRef);
     133             :   DCHECK_LE(offset() + type_size(), untagged_buffer()->byte_length());
     134       53976 :   return Address(untagged_buffer()->backing_store()) + offset();
     135             : }
     136             : 
     137             : int32_t WasmGlobalObject::GetI32() {
     138        3528 :   return ReadLittleEndianValue<int32_t>(address());
     139             : }
     140             : 
     141             : int64_t WasmGlobalObject::GetI64() {
     142          80 :   return ReadLittleEndianValue<int64_t>(address());
     143             : }
     144             : 
     145             : float WasmGlobalObject::GetF32() {
     146        3296 :   return ReadLittleEndianValue<float>(address());
     147             : }
     148             : 
     149             : double WasmGlobalObject::GetF64() {
     150        1752 :   return ReadLittleEndianValue<double>(address());
     151             : }
     152             : 
     153         256 : Handle<Object> WasmGlobalObject::GetAnyRef() {
     154             :   DCHECK_EQ(type(), wasm::kWasmAnyRef);
     155         512 :   return handle(tagged_buffer()->get(offset()), GetIsolate());
     156             : }
     157             : 
     158        3568 : void WasmGlobalObject::SetI32(int32_t value) {
     159        3568 :   WriteLittleEndianValue<int32_t>(address(), value);
     160        3568 : }
     161             : 
     162          80 : void WasmGlobalObject::SetI64(int64_t value) {
     163          80 :   WriteLittleEndianValue<int64_t>(address(), value);
     164          80 : }
     165             : 
     166        3896 : void WasmGlobalObject::SetF32(float value) {
     167        3896 :   WriteLittleEndianValue<float>(address(), value);
     168        3896 : }
     169             : 
     170        1792 : void WasmGlobalObject::SetF64(double value) {
     171        1792 :   WriteLittleEndianValue<double>(address(), value);
     172        1792 : }
     173             : 
     174         168 : void WasmGlobalObject::SetAnyRef(Handle<Object> value) {
     175             :   DCHECK_EQ(type(), wasm::kWasmAnyRef);
     176         168 :   tagged_buffer()->set(offset(), *value);
     177         168 : }
     178             : 
     179             : // WasmInstanceObject
     180     7470653 : PRIMITIVE_ACCESSORS(WasmInstanceObject, memory_start, byte*, kMemoryStartOffset)
     181     7475581 : PRIMITIVE_ACCESSORS(WasmInstanceObject, memory_size, size_t, kMemorySizeOffset)
     182     7456640 : PRIMITIVE_ACCESSORS(WasmInstanceObject, memory_mask, size_t, kMemoryMaskOffset)
     183     1229053 : PRIMITIVE_ACCESSORS(WasmInstanceObject, isolate_root, Address,
     184             :                     kIsolateRootOffset)
     185     1229053 : PRIMITIVE_ACCESSORS(WasmInstanceObject, stack_limit_address, Address,
     186             :                     kStackLimitAddressOffset)
     187     1229053 : PRIMITIVE_ACCESSORS(WasmInstanceObject, real_stack_limit_address, Address,
     188             :                     kRealStackLimitAddressOffset)
     189     1356126 : PRIMITIVE_ACCESSORS(WasmInstanceObject, imported_function_targets, Address*,
     190             :                     kImportedFunctionTargetsOffset)
     191     2345092 : PRIMITIVE_ACCESSORS(WasmInstanceObject, globals_start, byte*,
     192             :                     kGlobalsStartOffset)
     193     1229317 : PRIMITIVE_ACCESSORS(WasmInstanceObject, imported_mutable_globals, Address*,
     194             :                     kImportedMutableGlobalsOffset)
     195     1241660 : PRIMITIVE_ACCESSORS(WasmInstanceObject, indirect_function_table_size, uint32_t,
     196             :                     kIndirectFunctionTableSizeOffset)
     197    21474497 : PRIMITIVE_ACCESSORS(WasmInstanceObject, indirect_function_table_sig_ids,
     198             :                     uint32_t*, kIndirectFunctionTableSigIdsOffset)
     199    21471160 : PRIMITIVE_ACCESSORS(WasmInstanceObject, indirect_function_table_targets,
     200             :                     Address*, kIndirectFunctionTableTargetsOffset)
     201     1229053 : PRIMITIVE_ACCESSORS(WasmInstanceObject, jump_table_start, Address,
     202             :                     kJumpTableStartOffset)
     203     1229125 : PRIMITIVE_ACCESSORS(WasmInstanceObject, data_segment_starts, Address*,
     204             :                     kDataSegmentStartsOffset)
     205     1229125 : PRIMITIVE_ACCESSORS(WasmInstanceObject, data_segment_sizes, uint32_t*,
     206             :                     kDataSegmentSizesOffset)
     207     1229125 : PRIMITIVE_ACCESSORS(WasmInstanceObject, dropped_data_segments, byte*,
     208             :                     kDroppedDataSegmentsOffset)
     209     1231054 : PRIMITIVE_ACCESSORS(WasmInstanceObject, dropped_elem_segments, byte*,
     210             :                     kDroppedElemSegmentsOffset)
     211             : 
     212    16780919 : ACCESSORS(WasmInstanceObject, module_object, WasmModuleObject,
     213             :           kModuleObjectOffset)
     214    63820269 : ACCESSORS(WasmInstanceObject, exports_object, JSObject, kExportsObjectOffset)
     215     6262037 : ACCESSORS(WasmInstanceObject, native_context, Context, kNativeContextOffset)
     216      353625 : OPTIONAL_ACCESSORS(WasmInstanceObject, memory_object, WasmMemoryObject,
     217             :                    kMemoryObjectOffset)
     218       21539 : OPTIONAL_ACCESSORS(WasmInstanceObject, untagged_globals_buffer, JSArrayBuffer,
     219             :                    kUntaggedGlobalsBufferOffset)
     220         640 : OPTIONAL_ACCESSORS(WasmInstanceObject, tagged_globals_buffer, FixedArray,
     221             :                    kTaggedGlobalsBufferOffset)
     222        1712 : OPTIONAL_ACCESSORS(WasmInstanceObject, imported_mutable_globals_buffers,
     223             :                    FixedArray, kImportedMutableGlobalsBuffersOffset)
     224     2035686 : OPTIONAL_ACCESSORS(WasmInstanceObject, debug_info, WasmDebugInfo,
     225             :                    kDebugInfoOffset)
     226        9416 : OPTIONAL_ACCESSORS(WasmInstanceObject, table_object, WasmTableObject,
     227             :                    kTableObjectOffset)
     228      677201 : OPTIONAL_ACCESSORS(WasmInstanceObject, tables, FixedArray, kTablesOffset)
     229     6526388 : ACCESSORS(WasmInstanceObject, imported_function_refs, FixedArray,
     230             :           kImportedFunctionRefsOffset)
     231    60735083 : OPTIONAL_ACCESSORS(WasmInstanceObject, indirect_function_table_refs, FixedArray,
     232             :                    kIndirectFunctionTableRefsOffset)
     233     6154412 : OPTIONAL_ACCESSORS(WasmInstanceObject, managed_native_allocations, Foreign,
     234             :                    kManagedNativeAllocationsOffset)
     235     5472304 : OPTIONAL_ACCESSORS(WasmInstanceObject, exceptions_table, FixedArray,
     236             :                    kExceptionsTableOffset)
     237     6145265 : ACCESSORS(WasmInstanceObject, undefined_value, Oddball, kUndefinedValueOffset)
     238     6145265 : ACCESSORS(WasmInstanceObject, null_value, Oddball, kNullValueOffset)
     239     6145265 : ACCESSORS(WasmInstanceObject, centry_stub, Code, kCEntryStubOffset)
     240     2996293 : OPTIONAL_ACCESSORS(WasmInstanceObject, wasm_exported_functions, FixedArray,
     241             :                    kWasmExportedFunctionsOffset)
     242             : 
     243             : inline bool WasmInstanceObject::has_indirect_function_table() {
     244             :   return indirect_function_table_sig_ids() != nullptr;
     245             : }
     246             : 
     247             : void WasmInstanceObject::clear_padding() {
     248             :   if (FIELD_SIZE(kOptionalPaddingOffset) != 0) {
     249             :     DCHECK_EQ(4, FIELD_SIZE(kOptionalPaddingOffset));
     250     1229053 :     memset(reinterpret_cast<void*>(address() + kOptionalPaddingOffset), 0,
     251     1229053 :            FIELD_SIZE(kOptionalPaddingOffset));
     252             :   }
     253             : }
     254             : 
     255             : IndirectFunctionTableEntry::IndirectFunctionTableEntry(
     256             :     Handle<WasmInstanceObject> instance, int index)
     257    20239082 :     : instance_(instance), index_(index) {
     258             :   DCHECK_GE(index, 0);
     259             :   DCHECK_LT(index, instance->indirect_function_table_size());
     260             : }
     261             : 
     262             : ImportedFunctionEntry::ImportedFunctionEntry(
     263             :     Handle<WasmInstanceObject> instance, int index)
     264      127041 :     : instance_(instance), index_(index) {
     265             :   DCHECK_GE(index, 0);
     266             :   DCHECK_LT(index, instance->module()->num_imported_functions);
     267             : }
     268             : 
     269             : // WasmExceptionObject
     270         648 : ACCESSORS(WasmExceptionObject, serialized_signature, PodArray<wasm::ValueType>,
     271             :           kSerializedSignatureOffset)
     272         624 : ACCESSORS(WasmExceptionObject, exception_tag, HeapObject, kExceptionTagOffset)
     273             : 
     274             : // WasmExportedFunction
     275      565032 : WasmExportedFunction::WasmExportedFunction(Address ptr) : JSFunction(ptr) {
     276             :   SLOW_DCHECK(IsWasmExportedFunction(*this));
     277      565032 : }
     278      565032 : CAST_ACCESSOR(WasmExportedFunction)
     279             : 
     280             : // WasmExportedFunctionData
     281     1897106 : ACCESSORS(WasmExportedFunctionData, wrapper_code, Code, kWrapperCodeOffset)
     282     2178791 : ACCESSORS(WasmExportedFunctionData, instance, WasmInstanceObject,
     283             :           kInstanceOffset)
     284      237139 : SMI_ACCESSORS(WasmExportedFunctionData, jump_table_offset,
     285             :               kJumpTableOffsetOffset)
     286      681173 : SMI_ACCESSORS(WasmExportedFunctionData, function_index, kFunctionIndexOffset)
     287             : 
     288             : // WasmDebugInfo
     289     5234432 : ACCESSORS(WasmDebugInfo, wasm_instance, WasmInstanceObject, kInstanceOffset)
     290     1919546 : ACCESSORS(WasmDebugInfo, interpreter_handle, Object, kInterpreterHandleOffset)
     291     1835730 : ACCESSORS(WasmDebugInfo, interpreted_functions, FixedArray,
     292             :           kInterpretedFunctionsOffset)
     293        3060 : OPTIONAL_ACCESSORS(WasmDebugInfo, locals_names, FixedArray, kLocalsNamesOffset)
     294       40080 : OPTIONAL_ACCESSORS(WasmDebugInfo, c_wasm_entries, FixedArray,
     295             :                    kCWasmEntriesOffset)
     296       13376 : OPTIONAL_ACCESSORS(WasmDebugInfo, c_wasm_entry_map, Managed<wasm::SignatureMap>,
     297             :                    kCWasmEntryMapOffset)
     298             : 
     299             : #undef OPTIONAL_ACCESSORS
     300             : #undef READ_PRIMITIVE_FIELD
     301             : #undef WRITE_PRIMITIVE_FIELD
     302             : #undef PRIMITIVE_ACCESSORS
     303             : 
     304       15792 : uint32_t WasmTableObject::current_length() { return elements()->length(); }
     305             : 
     306             : bool WasmMemoryObject::has_maximum_pages() { return maximum_pages() >= 0; }
     307             : 
     308             : // WasmExceptionTag
     309         412 : SMI_ACCESSORS(WasmExceptionTag, index, kIndexOffset)
     310             : 
     311             : // AsmWasmData
     312       17157 : ACCESSORS(AsmWasmData, managed_native_module, Managed<wasm::NativeModule>,
     313             :           kManagedNativeModuleOffset)
     314       27081 : ACCESSORS(AsmWasmData, export_wrappers, FixedArray, kExportWrappersOffset)
     315       27081 : ACCESSORS(AsmWasmData, asm_js_offset_table, ByteArray, kAsmJsOffsetTableOffset)
     316       27081 : ACCESSORS(AsmWasmData, uses_bitset, HeapNumber, kUsesBitsetOffset)
     317             : 
     318             : #include "src/objects/object-macros-undef.h"
     319             : 
     320             : }  // namespace internal
     321             : }  // namespace v8
     322             : 
     323             : #endif  // V8_WASM_WASM_OBJECTS_INL_H_

Generated by: LCOV version 1.10