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#ifdef V8_COMPRESS_POINTERS
9
10#include "src/objects/slots.h"
11
12namespace v8 {
13namespace internal {
14
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().
19class CompressedObjectSlot : public SlotBase<CompressedObjectSlot, Tagged_t> {
20 public:
21 using TObject = Object;
22 using THeapObjectSlot = CompressedHeapObjectSlot;
23
24 static constexpr bool kCanBeWeak = false;
25
26 CompressedObjectSlot() : SlotBase(kNullAddress) {}
27 explicit CompressedObjectSlot(Address ptr) : SlotBase(ptr) {}
28 explicit CompressedObjectSlot(Address* ptr)
29 : SlotBase(reinterpret_cast<Address>(ptr)) {}
30 inline explicit CompressedObjectSlot(Object* object);
31 explicit CompressedObjectSlot(Object const* const* ptr)
32 : SlotBase(reinterpret_cast<Address>(ptr)) {}
33 template <typename T>
34 explicit CompressedObjectSlot(SlotBase<T, TData, kSlotDataAlignment> slot)
35 : SlotBase(slot.address()) {}
36
37 inline Object operator*() const;
38 inline void store(Object value) const;
39
40 inline Object Acquire_Load() const;
41 inline Object Relaxed_Load() const;
42 inline void Relaxed_Store(Object value) const;
43 inline void Release_Store(Object value) const;
44 inline Object Release_CompareAndSwap(Object old, Object target) const;
45};
46
47// A CompressedMapWordSlot instance describes a kTaggedSize-sized map-word field
48// ("slot") of heap objects holding a compressed tagged pointer or a Smi
49// representing forwaring pointer value.
50// This slot kind is similar to CompressedObjectSlot but decompression of
51// forwarding pointer is different.
52// Its address() is the address of the slot.
53// The slot's contents can be read and written using operator* and store().
54class CompressedMapWordSlot : public SlotBase<CompressedMapWordSlot, Tagged_t> {
55 public:
56 using TObject = Object;
57
58 static constexpr bool kCanBeWeak = false;
59
60 CompressedMapWordSlot() : SlotBase(kNullAddress) {}
61 explicit CompressedMapWordSlot(Address ptr) : SlotBase(ptr) {}
62
63 // Compares memory representation of a value stored in the slot with given
64 // raw value without decompression.
65 inline bool contains_value(Address raw_value) const;
66
67 inline Object operator*() const;
68 inline void store(Object value) const;
69
70 inline Object Relaxed_Load() const;
71 inline void Relaxed_Store(Object value) const;
72
73 inline Object Acquire_Load() const;
74 inline void Release_Store(Object value) const;
75 inline Object Release_CompareAndSwap(Object old, Object target) const;
76};
77
78// A CompressedMaybeObjectSlot instance describes a kTaggedSize-sized field
79// ("slot") holding a possibly-weak compressed tagged pointer
80// (think: MaybeObject).
81// Its address() is the address of the slot.
82// The slot's contents can be read and written using operator* and store().
83class CompressedMaybeObjectSlot
84 : public SlotBase<CompressedMaybeObjectSlot, Tagged_t> {
85 public:
86 using TObject = MaybeObject;
87 using THeapObjectSlot = CompressedHeapObjectSlot;
88
89 static constexpr bool kCanBeWeak = true;
90
91 CompressedMaybeObjectSlot() : SlotBase(kNullAddress) {}
92 explicit CompressedMaybeObjectSlot(Address ptr) : SlotBase(ptr) {}
93 explicit CompressedMaybeObjectSlot(Object* ptr)
94 : SlotBase(reinterpret_cast<Address>(ptr)) {}
95 explicit CompressedMaybeObjectSlot(MaybeObject* ptr)
96 : SlotBase(reinterpret_cast<Address>(ptr)) {}
97 template <typename T>
98 explicit CompressedMaybeObjectSlot(
99 SlotBase<T, TData, kSlotDataAlignment> slot)
100 : SlotBase(slot.address()) {}
101
102 inline MaybeObject operator*() const;
103 inline void store(MaybeObject value) const;
104
105 inline MaybeObject Relaxed_Load() const;
106 inline void Relaxed_Store(MaybeObject value) const;
107 inline void Release_CompareAndSwap(MaybeObject old, MaybeObject target) const;
108};
109
110// A CompressedHeapObjectSlot instance describes a kTaggedSize-sized field
111// ("slot") holding a weak or strong compressed pointer to a heap object (think:
112// HeapObjectReference).
113// Its address() is the address of the slot.
114// The slot's contents can be read and written using operator* and store().
115// In case it is known that that slot contains a strong heap object pointer,
116// ToHeapObject() can be used to retrieve that heap object.
117class CompressedHeapObjectSlot
118 : public SlotBase<CompressedHeapObjectSlot, Tagged_t> {
119 public:
120 CompressedHeapObjectSlot() : SlotBase(kNullAddress) {}
121 explicit CompressedHeapObjectSlot(Address ptr) : SlotBase(ptr) {}
122 explicit CompressedHeapObjectSlot(Object* ptr)
123 : SlotBase(reinterpret_cast<Address>(ptr)) {}
124 template <typename T>
125 explicit CompressedHeapObjectSlot(SlotBase<T, TData, kSlotDataAlignment> slot)
126 : SlotBase(slot.address()) {}
127
128 inline HeapObjectReference operator*() const;
129 inline void store(HeapObjectReference value) const;
130
131 inline HeapObject ToHeapObject() const;
132
133 inline void StoreHeapObject(HeapObject value) const;
134};
135
136} // namespace internal
137} // namespace v8
138
139#endif // V8_COMPRESS_POINTERS
140
141#endif // V8_OBJECTS_COMPRESSED_SLOTS_H_
142