5 #ifndef V8_OBJECTS_SLOTS_H_ 6 #define V8_OBJECTS_SLOTS_H_ 8 #include "src/globals.h" 15 template <
typename Sub
class,
typename Data,
size_t SlotDataSize>
21 static constexpr
size_t kSlotDataSize = SlotDataSize;
23 Subclass& operator++() {
24 ptr_ += kSlotDataSize;
25 return *
static_cast<Subclass*
>(
this);
27 Subclass operator++(
int) {
28 Subclass result = *
static_cast<Subclass*
>(
this);
29 ptr_ += kSlotDataSize;
32 Subclass& operator--() {
33 ptr_ -= kSlotDataSize;
34 return *
static_cast<Subclass*
>(
this);
36 Subclass operator--(
int) {
37 Subclass result = *
static_cast<Subclass*
>(
this);
38 ptr_ -= kSlotDataSize;
42 bool operator<(
const SlotBase& other)
const {
return ptr_ < other.ptr_; }
43 bool operator<=(
const SlotBase& other)
const {
return ptr_ <= other.ptr_; }
44 bool operator>(
const SlotBase& other)
const {
return ptr_ > other.ptr_; }
45 bool operator>=(
const SlotBase& other)
const {
return ptr_ >= other.ptr_; }
46 bool operator==(
const SlotBase& other)
const {
return ptr_ == other.ptr_; }
47 bool operator!=(
const SlotBase& other)
const {
return ptr_ != other.ptr_; }
48 size_t operator-(
const SlotBase& other)
const {
49 DCHECK_GE(ptr_, other.ptr_);
50 return static_cast<size_t>((ptr_ - other.ptr_) / kSlotDataSize);
52 Subclass operator-(
int i)
const {
return Subclass(ptr_ -
i * kSlotDataSize); }
53 Subclass operator+(
int i)
const {
return Subclass(ptr_ +
i * kSlotDataSize); }
54 friend Subclass operator+(
int i,
const Subclass& slot) {
55 return Subclass(slot.ptr_ +
i * kSlotDataSize);
57 Subclass& operator+=(
int i) {
58 ptr_ +=
i * kSlotDataSize;
59 return *
static_cast<Subclass*
>(
this);
61 Subclass operator-(
int i) {
return Subclass(ptr_ -
i * kSlotDataSize); }
62 Subclass& operator-=(
int i) {
63 ptr_ -=
i * kSlotDataSize;
64 return *
static_cast<Subclass*
>(
this);
67 void* ToVoidPtr()
const {
return reinterpret_cast<void*
>(address()); }
69 Address address()
const {
return ptr_; }
71 TData* location()
const {
return reinterpret_cast<TData*
>(ptr_); }
74 STATIC_ASSERT(IsAligned(kSlotDataSize, kTaggedSize));
76 DCHECK(IsAligned(ptr, kTaggedSize));
95 :
SlotBase(reinterpret_cast<Address>(ptr)) {}
98 :
SlotBase(reinterpret_cast<Address>(ptr)) {}
103 Object* operator*()
const {
return *
reinterpret_cast<Object**
>(address()); }
104 inline void store(
Object* value)
const;
108 inline void Relaxed_Store(
ObjectPtr value)
const;
109 inline void Release_Store(
ObjectPtr value)
const;
115 inline Object* Acquire_Load1()
const;
116 inline void Relaxed_Store1(
Object* value)
const;
117 inline void Release_Store1(
Object* value)
const;
125 :
public SlotBase<MaybeObjectSlot, Tagged_t, kTaggedSize> {
129 :
SlotBase(reinterpret_cast<Address>(ptr)) {}
130 template <
typename T>
138 inline void Relaxed_Store(
MaybeObject value)
const;
153 template <
typename T>
161 DCHECK((*location() & kHeapObjectTagMask) == kHeapObjectTag);
162 return reinterpret_cast<HeapObject*
>(*location());
165 void StoreHeapObject(
HeapObject* value)
const {
166 *
reinterpret_cast<HeapObject**
>(address()) = value;
173 #endif // V8_OBJECTS_SLOTS_H_