compressed-slots.h 6 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_OBJECTS_COMPRESSED_SLOTS_H_
#define V8_OBJECTS_COMPRESSED_SLOTS_H_

8
#include "include/v8config.h"
9 10 11 12 13
#include "src/objects/slots.h"

namespace v8 {
namespace internal {

14
#ifdef V8_COMPRESS_POINTERS
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
// A CompressedObjectSlot instance describes a kTaggedSize-sized field ("slot")
// holding a compressed tagged pointer (smi or heap object).
// Its address() is the address of the slot.
// The slot's contents can be read and written using operator* and store().
class CompressedObjectSlot : public SlotBase<CompressedObjectSlot, Tagged_t> {
 public:
  using TObject = Object;
  using THeapObjectSlot = CompressedHeapObjectSlot;

  static constexpr bool kCanBeWeak = false;

  CompressedObjectSlot() : SlotBase(kNullAddress) {}
  explicit CompressedObjectSlot(Address ptr) : SlotBase(ptr) {}
  explicit CompressedObjectSlot(Address* ptr)
      : SlotBase(reinterpret_cast<Address>(ptr)) {}
  inline explicit CompressedObjectSlot(Object* object);
  explicit CompressedObjectSlot(Object const* const* ptr)
      : SlotBase(reinterpret_cast<Address>(ptr)) {}
  template <typename T>
  explicit CompressedObjectSlot(SlotBase<T, TData, kSlotDataAlignment> slot)
      : SlotBase(slot.address()) {}

  // Compares memory representation of a value stored in the slot with given
  // raw value without decompression.
  inline bool contains_value(Address raw_value) const;
40
  inline bool contains_map_value(Address raw_value) const;
41

42 43
  // TODO(leszeks): Consider deprecating the operator* load, and always pass the
  // Isolate.
44
  inline Object operator*() const;
45
  inline Object load(PtrComprCageBase cage_base) const;
46
  inline void store(Object value) const;
47 48 49
  inline void store_map(Map map) const;

  inline Map load_map() const;
50

51
  inline Object Acquire_Load() const;
52
  inline Object Relaxed_Load() const;
53
  inline Object Relaxed_Load(PtrComprCageBase cage_base) const;
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
  inline void Relaxed_Store(Object value) const;
  inline void Release_Store(Object value) const;
  inline Object Release_CompareAndSwap(Object old, Object target) const;
};

// A CompressedMaybeObjectSlot instance describes a kTaggedSize-sized field
// ("slot") holding a possibly-weak compressed tagged pointer
// (think: MaybeObject).
// Its address() is the address of the slot.
// The slot's contents can be read and written using operator* and store().
class CompressedMaybeObjectSlot
    : public SlotBase<CompressedMaybeObjectSlot, Tagged_t> {
 public:
  using TObject = MaybeObject;
  using THeapObjectSlot = CompressedHeapObjectSlot;

  static constexpr bool kCanBeWeak = true;

  CompressedMaybeObjectSlot() : SlotBase(kNullAddress) {}
  explicit CompressedMaybeObjectSlot(Address ptr) : SlotBase(ptr) {}
  explicit CompressedMaybeObjectSlot(Object* ptr)
      : SlotBase(reinterpret_cast<Address>(ptr)) {}
  explicit CompressedMaybeObjectSlot(MaybeObject* ptr)
      : SlotBase(reinterpret_cast<Address>(ptr)) {}
  template <typename T>
  explicit CompressedMaybeObjectSlot(
      SlotBase<T, TData, kSlotDataAlignment> slot)
      : SlotBase(slot.address()) {}

  inline MaybeObject operator*() const;
84
  inline MaybeObject load(PtrComprCageBase cage_base) const;
85 86 87
  inline void store(MaybeObject value) const;

  inline MaybeObject Relaxed_Load() const;
88
  inline MaybeObject Relaxed_Load(PtrComprCageBase cage_base) const;
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
  inline void Relaxed_Store(MaybeObject value) const;
  inline void Release_CompareAndSwap(MaybeObject old, MaybeObject target) const;
};

// A CompressedHeapObjectSlot instance describes a kTaggedSize-sized field
// ("slot") holding a weak or strong compressed pointer to a heap object (think:
// HeapObjectReference).
// Its address() is the address of the slot.
// The slot's contents can be read and written using operator* and store().
// In case it is known that that slot contains a strong heap object pointer,
// ToHeapObject() can be used to retrieve that heap object.
class CompressedHeapObjectSlot
    : public SlotBase<CompressedHeapObjectSlot, Tagged_t> {
 public:
  CompressedHeapObjectSlot() : SlotBase(kNullAddress) {}
  explicit CompressedHeapObjectSlot(Address ptr) : SlotBase(ptr) {}
  explicit CompressedHeapObjectSlot(Object* ptr)
      : SlotBase(reinterpret_cast<Address>(ptr)) {}
  template <typename T>
  explicit CompressedHeapObjectSlot(SlotBase<T, TData, kSlotDataAlignment> slot)
      : SlotBase(slot.address()) {}

  inline HeapObjectReference operator*() const;
112
  inline HeapObjectReference load(PtrComprCageBase cage_base) const;
113 114 115 116 117 118 119
  inline void store(HeapObjectReference value) const;

  inline HeapObject ToHeapObject() const;

  inline void StoreHeapObject(HeapObject value) const;
};

120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
// An OffHeapCompressedObjectSlot instance describes a kTaggedSize-sized field
// ("slot") holding a compressed tagged pointer (smi or heap object).
// Unlike CompressedObjectSlot, it does not assume that the slot is on the heap,
// and so does not provide an operator* with implicit Isolate* calculation.
// Its address() is the address of the slot.
// The slot's contents can be read and written using load() and store().
class OffHeapCompressedObjectSlot
    : public SlotBase<OffHeapCompressedObjectSlot, Tagged_t> {
 public:
  using TObject = Object;
  using THeapObjectSlot = OffHeapCompressedObjectSlot;

  static constexpr bool kCanBeWeak = false;

  OffHeapCompressedObjectSlot() : SlotBase(kNullAddress) {}
  explicit OffHeapCompressedObjectSlot(const uint32_t* ptr)
      : SlotBase(reinterpret_cast<Address>(ptr)) {}

138
  inline Object load(PtrComprCageBase cage_base) const;
139 140
  inline void store(Object value) const;

141 142
  inline Object Relaxed_Load(PtrComprCageBase cage_base) const;
  inline Object Acquire_Load(PtrComprCageBase cage_base) const;
143
  inline void Relaxed_Store(Object value) const;
144
  inline void Release_Store(Object value) const;
145 146 147
  inline void Release_CompareAndSwap(Object old, Object target) const;
};

148 149
#endif  // V8_COMPRESS_POINTERS

150 151 152 153
}  // namespace internal
}  // namespace v8

#endif  // V8_OBJECTS_COMPRESSED_SLOTS_H_