LCOV - code coverage report
Current view: top level - src/objects - embedder-data-slot-inl.h (source / functions) Hit Total Coverage
Test: app.info Lines: 21 21 100.0 %
Date: 2019-01-20 Functions: 0 0 -

          Line data    Source code
       1             : // Copyright 2018 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_OBJECTS_EMBEDDER_DATA_SLOT_INL_H_
       6             : #define V8_OBJECTS_EMBEDDER_DATA_SLOT_INL_H_
       7             : 
       8             : #include "src/heap/heap-write-barrier-inl.h"
       9             : #include "src/objects/embedder-data-array.h"
      10             : #include "src/objects/embedder-data-slot.h"
      11             : #include "src/objects/js-objects.h"
      12             : 
      13             : // Has to be the last include (doesn't have include guards):
      14             : #include "src/objects/object-macros.h"
      15             : 
      16             : namespace v8 {
      17             : namespace internal {
      18             : 
      19             : EmbedderDataSlot::EmbedderDataSlot(EmbedderDataArray array, int entry_index)
      20      110329 :     : SlotBase(FIELD_ADDR(array,
      21      110329 :                           EmbedderDataArray::OffsetOfElementAt(entry_index))) {}
      22             : 
      23             : EmbedderDataSlot::EmbedderDataSlot(JSObject object, int embedder_field_index)
      24      952642 :     : SlotBase(FIELD_ADDR(
      25      952647 :           object, object->GetEmbedderFieldOffset(embedder_field_index))) {}
      26             : 
      27             : Object EmbedderDataSlot::load_tagged() const {
      28      950964 :   return ObjectSlot(address() + kTaggedPayloadOffset).Relaxed_Load();
      29             : }
      30             : 
      31             : void EmbedderDataSlot::store_smi(Smi value) {
      32             :   ObjectSlot(address() + kTaggedPayloadOffset).Relaxed_Store(value);
      33             : #ifdef V8_COMPRESS_POINTERS
      34             :   ObjectSlot(address() + kRawPayloadOffset).Relaxed_Store(Smi::kZero);
      35             : #endif
      36             : }
      37             : 
      38             : // static
      39             : void EmbedderDataSlot::store_tagged(EmbedderDataArray array, int entry_index,
      40             :                                     Object value) {
      41          60 :   int slot_offset = EmbedderDataArray::OffsetOfElementAt(entry_index);
      42          60 :   ObjectSlot(FIELD_ADDR(array, slot_offset + kTaggedPayloadOffset))
      43          60 :       .Relaxed_Store(value);
      44          60 :   WRITE_BARRIER(array, slot_offset, value);
      45             : #ifdef V8_COMPRESS_POINTERS
      46             :   ObjectSlot(FIELD_ADDR(array, slot_offset + kRawPayloadOffset))
      47             :       .Relaxed_Store(Smi::kZero);
      48             : #endif
      49             : }
      50             : 
      51             : // static
      52             : void EmbedderDataSlot::store_tagged(JSObject object, int embedder_field_index,
      53             :                                     Object value) {
      54      915210 :   int slot_offset = object->GetEmbedderFieldOffset(embedder_field_index);
      55      915215 :   ObjectSlot(FIELD_ADDR(object, slot_offset + kTaggedPayloadOffset))
      56      915214 :       .Relaxed_Store(value);
      57      915214 :   WRITE_BARRIER(object, slot_offset, value);
      58             : #ifdef V8_COMPRESS_POINTERS
      59             :   ObjectSlot(FIELD_ADDR(object, slot_offset + kRawPayloadOffset))
      60             :       .Relaxed_Store(Smi::kZero);
      61             : #endif
      62             : }
      63             : 
      64             : bool EmbedderDataSlot::ToAlignedPointer(void** out_pointer) const {
      65             :   Object tagged_value =
      66         209 :       ObjectSlot(address() + kTaggedPayloadOffset).Relaxed_Load();
      67         418 :   if (!tagged_value->IsSmi()) return false;
      68             : #ifdef V8_COMPRESS_POINTERS
      69             :   STATIC_ASSERT(kSmiShiftSize == 0);
      70             :   STATIC_ASSERT(SmiValuesAre31Bits());
      71             :   Address value_lo = static_cast<uint32_t>(tagged_value->ptr());
      72             :   STATIC_ASSERT(kTaggedSize == kSystemPointerSize);
      73             :   Address value_hi =
      74             :       FullObjectSlot(address() + kRawPayloadOffset).Relaxed_Load()->ptr();
      75             :   Address value = value_lo | (value_hi << 32);
      76             :   *out_pointer = reinterpret_cast<void*>(value);
      77             : #else
      78         194 :   *out_pointer = reinterpret_cast<void*>(tagged_value->ptr());
      79             : #endif
      80             :   return true;
      81             : }
      82             : 
      83             : bool EmbedderDataSlot::store_aligned_pointer(void* ptr) {
      84      111773 :   Address value = reinterpret_cast<Address>(ptr);
      85      111773 :   if (!HAS_SMI_TAG(value)) return false;
      86             : #ifdef V8_COMPRESS_POINTERS
      87             :   STATIC_ASSERT(kSmiShiftSize == 0);
      88             :   STATIC_ASSERT(SmiValuesAre31Bits());
      89             :   // Sign-extend lower 32-bits in order to form a proper Smi value.
      90             :   STATIC_ASSERT(kTaggedSize == kSystemPointerSize);
      91             :   Address lo = static_cast<intptr_t>(static_cast<int32_t>(value));
      92             :   ObjectSlot(address() + kTaggedPayloadOffset).Relaxed_Store(Smi(lo));
      93             :   Address hi = value >> 32;
      94             :   ObjectSlot(address() + kRawPayloadOffset).Relaxed_Store(Object(hi));
      95             : #else
      96      111773 :   ObjectSlot(address() + kTaggedPayloadOffset).Relaxed_Store(Smi(value));
      97             : #endif
      98             :   return true;
      99             : }
     100             : 
     101             : EmbedderDataSlot::RawData EmbedderDataSlot::load_raw(
     102             :     const DisallowHeapAllocation& no_gc) const {
     103             :   STATIC_ASSERT(kTaggedSize == kSystemPointerSize);
     104             :   return RawData{
     105         360 :       ObjectSlot(address() + kTaggedPayloadOffset).Relaxed_Load()->ptr(),
     106             : #ifdef V8_COMPRESS_POINTERS
     107             :       FullObjectSlot(address() + kRawPayloadOffset).Relaxed_Load()->ptr()
     108             : #endif
     109             :   };
     110             : }
     111             : 
     112             : void EmbedderDataSlot::store_raw(const EmbedderDataSlot::RawData& data,
     113             :                                  const DisallowHeapAllocation& no_gc) {
     114             :   ObjectSlot(address() + kTaggedPayloadOffset)
     115          30 :       .Relaxed_Store(Object(data.data_[0]));
     116             : #ifdef V8_COMPRESS_POINTERS
     117             :   ObjectSlot(address() + kRawPayloadOffset)
     118             :       .Relaxed_Store(Object(data.data_[1]));
     119             : #endif
     120             : }
     121             : 
     122             : }  // namespace internal
     123             : }  // namespace v8
     124             : 
     125             : #include "src/objects/object-macros-undef.h"
     126             : 
     127             : #endif  // V8_OBJECTS_EMBEDDER_DATA_SLOT_INL_H_

Generated by: LCOV version 1.10