• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 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_COMPRESSED_SLOTS_H_
6 #define V8_OBJECTS_COMPRESSED_SLOTS_H_
7 
8 #include "include/v8config.h"
9 #include "src/objects/slots.h"
10 
11 namespace v8 {
12 namespace internal {
13 
14 #ifdef V8_COMPRESS_POINTERS
15 // A CompressedObjectSlot instance describes a kTaggedSize-sized field ("slot")
16 // holding a compressed tagged pointer (smi or heap object).
17 // Its address() is the address of the slot.
18 // The slot's contents can be read and written using operator* and store().
19 class CompressedObjectSlot : public SlotBase<CompressedObjectSlot, Tagged_t> {
20  public:
21   using TObject = Object;
22   using THeapObjectSlot = CompressedHeapObjectSlot;
23 
24   static constexpr bool kCanBeWeak = false;
25 
CompressedObjectSlot()26   CompressedObjectSlot() : SlotBase(kNullAddress) {}
CompressedObjectSlot(Address ptr)27   explicit CompressedObjectSlot(Address ptr) : SlotBase(ptr) {}
CompressedObjectSlot(Address * ptr)28   explicit CompressedObjectSlot(Address* ptr)
29       : SlotBase(reinterpret_cast<Address>(ptr)) {}
30   inline explicit CompressedObjectSlot(Object* object);
CompressedObjectSlot(Object const * const * ptr)31   explicit CompressedObjectSlot(Object const* const* ptr)
32       : SlotBase(reinterpret_cast<Address>(ptr)) {}
33   template <typename T>
CompressedObjectSlot(SlotBase<T,TData,kSlotDataAlignment> slot)34   explicit CompressedObjectSlot(SlotBase<T, TData, kSlotDataAlignment> slot)
35       : SlotBase(slot.address()) {}
36 
37   // Compares memory representation of a value stored in the slot with given
38   // raw value without decompression.
39   inline bool contains_value(Address raw_value) const;
40   inline bool contains_map_value(Address raw_value) const;
41 
42   // TODO(leszeks): Consider deprecating the operator* load, and always pass the
43   // Isolate.
44   inline Object operator*() const;
45   inline Object load(PtrComprCageBase cage_base) const;
46   inline void store(Object value) const;
47   inline void store_map(Map map) const;
48 
49   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   inline void Relaxed_Store(Object value) const;
55   inline void Release_Store(Object value) const;
56   inline Object Release_CompareAndSwap(Object old, Object target) const;
57 };
58 
59 // A CompressedMaybeObjectSlot instance describes a kTaggedSize-sized field
60 // ("slot") holding a possibly-weak compressed tagged pointer
61 // (think: MaybeObject).
62 // Its address() is the address of the slot.
63 // The slot's contents can be read and written using operator* and store().
64 class CompressedMaybeObjectSlot
65     : public SlotBase<CompressedMaybeObjectSlot, Tagged_t> {
66  public:
67   using TObject = MaybeObject;
68   using THeapObjectSlot = CompressedHeapObjectSlot;
69 
70   static constexpr bool kCanBeWeak = true;
71 
CompressedMaybeObjectSlot()72   CompressedMaybeObjectSlot() : SlotBase(kNullAddress) {}
CompressedMaybeObjectSlot(Address ptr)73   explicit CompressedMaybeObjectSlot(Address ptr) : SlotBase(ptr) {}
CompressedMaybeObjectSlot(Object * ptr)74   explicit CompressedMaybeObjectSlot(Object* ptr)
75       : SlotBase(reinterpret_cast<Address>(ptr)) {}
CompressedMaybeObjectSlot(MaybeObject * ptr)76   explicit CompressedMaybeObjectSlot(MaybeObject* ptr)
77       : SlotBase(reinterpret_cast<Address>(ptr)) {}
78   template <typename T>
CompressedMaybeObjectSlot(SlotBase<T,TData,kSlotDataAlignment> slot)79   explicit CompressedMaybeObjectSlot(
80       SlotBase<T, TData, kSlotDataAlignment> slot)
81       : SlotBase(slot.address()) {}
82 
83   inline MaybeObject operator*() const;
84   inline MaybeObject load(PtrComprCageBase cage_base) const;
85   inline void store(MaybeObject value) const;
86 
87   inline MaybeObject Relaxed_Load() const;
88   inline MaybeObject Relaxed_Load(PtrComprCageBase cage_base) const;
89   inline void Relaxed_Store(MaybeObject value) const;
90   inline void Release_CompareAndSwap(MaybeObject old, MaybeObject target) const;
91 };
92 
93 // A CompressedHeapObjectSlot instance describes a kTaggedSize-sized field
94 // ("slot") holding a weak or strong compressed pointer to a heap object (think:
95 // HeapObjectReference).
96 // Its address() is the address of the slot.
97 // The slot's contents can be read and written using operator* and store().
98 // In case it is known that that slot contains a strong heap object pointer,
99 // ToHeapObject() can be used to retrieve that heap object.
100 class CompressedHeapObjectSlot
101     : public SlotBase<CompressedHeapObjectSlot, Tagged_t> {
102  public:
CompressedHeapObjectSlot()103   CompressedHeapObjectSlot() : SlotBase(kNullAddress) {}
CompressedHeapObjectSlot(Address ptr)104   explicit CompressedHeapObjectSlot(Address ptr) : SlotBase(ptr) {}
CompressedHeapObjectSlot(Object * ptr)105   explicit CompressedHeapObjectSlot(Object* ptr)
106       : SlotBase(reinterpret_cast<Address>(ptr)) {}
107   template <typename T>
CompressedHeapObjectSlot(SlotBase<T,TData,kSlotDataAlignment> slot)108   explicit CompressedHeapObjectSlot(SlotBase<T, TData, kSlotDataAlignment> slot)
109       : SlotBase(slot.address()) {}
110 
111   inline HeapObjectReference operator*() const;
112   inline HeapObjectReference load(PtrComprCageBase cage_base) const;
113   inline void store(HeapObjectReference value) const;
114 
115   inline HeapObject ToHeapObject() const;
116 
117   inline void StoreHeapObject(HeapObject value) const;
118 };
119 
120 // An OffHeapCompressedObjectSlot instance describes a kTaggedSize-sized field
121 // ("slot") holding a compressed tagged pointer (smi or heap object).
122 // Unlike CompressedObjectSlot, it does not assume that the slot is on the heap,
123 // and so does not provide an operator* with implicit Isolate* calculation.
124 // Its address() is the address of the slot.
125 // The slot's contents can be read and written using load() and store().
126 class OffHeapCompressedObjectSlot
127     : public SlotBase<OffHeapCompressedObjectSlot, Tagged_t> {
128  public:
129   using TObject = Object;
130   using THeapObjectSlot = OffHeapCompressedObjectSlot;
131 
132   static constexpr bool kCanBeWeak = false;
133 
OffHeapCompressedObjectSlot()134   OffHeapCompressedObjectSlot() : SlotBase(kNullAddress) {}
OffHeapCompressedObjectSlot(Address ptr)135   explicit OffHeapCompressedObjectSlot(Address ptr) : SlotBase(ptr) {}
OffHeapCompressedObjectSlot(const uint32_t * ptr)136   explicit OffHeapCompressedObjectSlot(const uint32_t* ptr)
137       : SlotBase(reinterpret_cast<Address>(ptr)) {}
138 
139   inline Object load(PtrComprCageBase cage_base) const;
140   inline void store(Object value) const;
141 
142   inline Object Relaxed_Load(PtrComprCageBase cage_base) const;
143   inline Object Acquire_Load(PtrComprCageBase cage_base) const;
144   inline void Relaxed_Store(Object value) const;
145   inline void Release_Store(Object value) const;
146   inline void Release_CompareAndSwap(Object old, Object target) const;
147 };
148 
149 #endif  // V8_COMPRESS_POINTERS
150 
151 }  // namespace internal
152 }  // namespace v8
153 
154 #endif  // V8_OBJECTS_COMPRESSED_SLOTS_H_
155