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_INL_H_ |
6 | #define V8_OBJECTS_COMPRESSED_SLOTS_INL_H_ |
7 | |
8 | #ifdef V8_COMPRESS_POINTERS |
9 | |
10 | #include "src/objects/compressed-slots.h" |
11 | #include "src/objects/heap-object-inl.h" |
12 | #include "src/objects/maybe-object-inl.h" |
13 | #include "src/ptr-compr-inl.h" |
14 | |
15 | namespace v8 { |
16 | namespace internal { |
17 | |
18 | // |
19 | // CompressedObjectSlot implementation. |
20 | // |
21 | |
22 | CompressedObjectSlot::CompressedObjectSlot(Object* object) |
23 | : SlotBase(reinterpret_cast<Address>(&object->ptr_)) {} |
24 | |
25 | Object CompressedObjectSlot::operator*() const { |
26 | Tagged_t value = *location(); |
27 | return Object(DecompressTaggedAny(address(), value)); |
28 | } |
29 | |
30 | void CompressedObjectSlot::store(Object value) const { |
31 | *location() = CompressTagged(value->ptr()); |
32 | } |
33 | |
34 | Object CompressedObjectSlot::Acquire_Load() const { |
35 | AtomicTagged_t value = AsAtomicTagged::Acquire_Load(location()); |
36 | return Object(DecompressTaggedAny(address(), value)); |
37 | } |
38 | |
39 | Object CompressedObjectSlot::Relaxed_Load() const { |
40 | AtomicTagged_t value = AsAtomicTagged::Relaxed_Load(location()); |
41 | return Object(DecompressTaggedAny(address(), value)); |
42 | } |
43 | |
44 | void CompressedObjectSlot::Relaxed_Store(Object value) const { |
45 | Tagged_t ptr = CompressTagged(value->ptr()); |
46 | AsAtomicTagged::Relaxed_Store(location(), ptr); |
47 | } |
48 | |
49 | void CompressedObjectSlot::Release_Store(Object value) const { |
50 | Tagged_t ptr = CompressTagged(value->ptr()); |
51 | AsAtomicTagged::Release_Store(location(), ptr); |
52 | } |
53 | |
54 | Object CompressedObjectSlot::Release_CompareAndSwap(Object old, |
55 | Object target) const { |
56 | Tagged_t old_ptr = CompressTagged(old->ptr()); |
57 | Tagged_t target_ptr = CompressTagged(target->ptr()); |
58 | Tagged_t result = |
59 | AsAtomicTagged::Release_CompareAndSwap(location(), old_ptr, target_ptr); |
60 | return Object(DecompressTaggedAny(address(), result)); |
61 | } |
62 | |
63 | // |
64 | // CompressedMapWordSlot implementation. |
65 | // |
66 | |
67 | bool CompressedMapWordSlot::contains_value(Address raw_value) const { |
68 | AtomicTagged_t value = AsAtomicTagged::Relaxed_Load(location()); |
69 | return static_cast<uint32_t>(value) == |
70 | static_cast<uint32_t>(static_cast<Tagged_t>(raw_value)); |
71 | } |
72 | |
73 | Object CompressedMapWordSlot::operator*() const { |
74 | Tagged_t value = *location(); |
75 | return Object(DecompressTaggedPointer(address(), value)); |
76 | } |
77 | |
78 | void CompressedMapWordSlot::store(Object value) const { |
79 | *location() = CompressTagged(value.ptr()); |
80 | } |
81 | |
82 | Object CompressedMapWordSlot::Relaxed_Load() const { |
83 | AtomicTagged_t value = AsAtomicTagged::Relaxed_Load(location()); |
84 | return Object(DecompressTaggedPointer(address(), value)); |
85 | } |
86 | |
87 | void CompressedMapWordSlot::Relaxed_Store(Object value) const { |
88 | Tagged_t ptr = CompressTagged(value.ptr()); |
89 | AsAtomicTagged::Relaxed_Store(location(), ptr); |
90 | } |
91 | |
92 | Object CompressedMapWordSlot::Acquire_Load() const { |
93 | AtomicTagged_t value = AsAtomicTagged::Acquire_Load(location()); |
94 | return Object(DecompressTaggedPointer(address(), value)); |
95 | } |
96 | |
97 | void CompressedMapWordSlot::Release_Store(Object value) const { |
98 | Tagged_t ptr = CompressTagged(value->ptr()); |
99 | AsAtomicTagged::Release_Store(location(), ptr); |
100 | } |
101 | |
102 | Object CompressedMapWordSlot::Release_CompareAndSwap(Object old, |
103 | Object target) const { |
104 | Tagged_t old_ptr = CompressTagged(old->ptr()); |
105 | Tagged_t target_ptr = CompressTagged(target->ptr()); |
106 | Tagged_t result = |
107 | AsAtomicTagged::Release_CompareAndSwap(location(), old_ptr, target_ptr); |
108 | return Object(DecompressTaggedPointer(address(), result)); |
109 | } |
110 | |
111 | // |
112 | // CompressedMaybeObjectSlot implementation. |
113 | // |
114 | |
115 | MaybeObject CompressedMaybeObjectSlot::operator*() const { |
116 | Tagged_t value = *location(); |
117 | return MaybeObject(DecompressTaggedAny(address(), value)); |
118 | } |
119 | |
120 | void CompressedMaybeObjectSlot::store(MaybeObject value) const { |
121 | *location() = CompressTagged(value->ptr()); |
122 | } |
123 | |
124 | MaybeObject CompressedMaybeObjectSlot::Relaxed_Load() const { |
125 | AtomicTagged_t value = AsAtomicTagged::Relaxed_Load(location()); |
126 | return MaybeObject(DecompressTaggedAny(address(), value)); |
127 | } |
128 | |
129 | void CompressedMaybeObjectSlot::Relaxed_Store(MaybeObject value) const { |
130 | Tagged_t ptr = CompressTagged(value->ptr()); |
131 | AsAtomicTagged::Relaxed_Store(location(), ptr); |
132 | } |
133 | |
134 | void CompressedMaybeObjectSlot::Release_CompareAndSwap( |
135 | MaybeObject old, MaybeObject target) const { |
136 | Tagged_t old_ptr = CompressTagged(old->ptr()); |
137 | Tagged_t target_ptr = CompressTagged(target->ptr()); |
138 | AsAtomicTagged::Release_CompareAndSwap(location(), old_ptr, target_ptr); |
139 | } |
140 | |
141 | // |
142 | // CompressedHeapObjectSlot implementation. |
143 | // |
144 | |
145 | HeapObjectReference CompressedHeapObjectSlot::operator*() const { |
146 | Tagged_t value = *location(); |
147 | return HeapObjectReference(DecompressTaggedPointer(address(), value)); |
148 | } |
149 | |
150 | void CompressedHeapObjectSlot::store(HeapObjectReference value) const { |
151 | *location() = CompressTagged(value.ptr()); |
152 | } |
153 | |
154 | HeapObject CompressedHeapObjectSlot::ToHeapObject() const { |
155 | Tagged_t value = *location(); |
156 | DCHECK_EQ(value & kHeapObjectTagMask, kHeapObjectTag); |
157 | return HeapObject::cast(Object(DecompressTaggedPointer(address(), value))); |
158 | } |
159 | |
160 | void CompressedHeapObjectSlot::StoreHeapObject(HeapObject value) const { |
161 | *location() = CompressTagged(value->ptr()); |
162 | } |
163 | |
164 | } // namespace internal |
165 | } // namespace v8 |
166 | |
167 | #endif // V8_COMPRESS_POINTERS |
168 | |
169 | #endif // V8_OBJECTS_COMPRESSED_SLOTS_INL_H_ |
170 | |