• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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_SLOTS_INL_H_
6 #define V8_OBJECTS_SLOTS_INL_H_
7 
8 #include "src/base/atomic-utils.h"
9 #include "src/common/globals.h"
10 #include "src/common/ptr-compr-inl.h"
11 #include "src/objects/compressed-slots.h"
12 #include "src/objects/heap-object.h"
13 #include "src/objects/map.h"
14 #include "src/objects/maybe-object.h"
15 #include "src/objects/objects.h"
16 #include "src/objects/slots.h"
17 #include "src/utils/memcopy.h"
18 
19 namespace v8 {
20 namespace internal {
21 
22 //
23 // FullObjectSlot implementation.
24 //
25 
FullObjectSlot(Object * object)26 FullObjectSlot::FullObjectSlot(Object* object)
27     : SlotBase(reinterpret_cast<Address>(&object->ptr_)) {}
28 
contains_value(Address raw_value)29 bool FullObjectSlot::contains_value(Address raw_value) const {
30   return base::AsAtomicPointer::Relaxed_Load(location()) == raw_value;
31 }
32 
contains_map_value(Address raw_value)33 bool FullObjectSlot::contains_map_value(Address raw_value) const {
34   return load_map().ptr() == raw_value;
35 }
36 
37 Object FullObjectSlot::operator*() const { return Object(*location()); }
38 
load(PtrComprCageBase cage_base)39 Object FullObjectSlot::load(PtrComprCageBase cage_base) const { return **this; }
40 
store(Object value)41 void FullObjectSlot::store(Object value) const { *location() = value.ptr(); }
42 
store_map(Map map)43 void FullObjectSlot::store_map(Map map) const {
44 #ifdef V8_MAP_PACKING
45   *location() = MapWord::Pack(map.ptr());
46 #else
47   store(map);
48 #endif
49 }
50 
load_map()51 Map FullObjectSlot::load_map() const {
52 #ifdef V8_MAP_PACKING
53   return Map::unchecked_cast(Object(MapWord::Unpack(*location())));
54 #else
55   return Map::unchecked_cast(Object(*location()));
56 #endif
57 }
58 
Acquire_Load()59 Object FullObjectSlot::Acquire_Load() const {
60   return Object(base::AsAtomicPointer::Acquire_Load(location()));
61 }
62 
Acquire_Load(PtrComprCageBase cage_base)63 Object FullObjectSlot::Acquire_Load(PtrComprCageBase cage_base) const {
64   return Acquire_Load();
65 }
66 
Relaxed_Load()67 Object FullObjectSlot::Relaxed_Load() const {
68   return Object(base::AsAtomicPointer::Relaxed_Load(location()));
69 }
70 
Relaxed_Load(PtrComprCageBase cage_base)71 Object FullObjectSlot::Relaxed_Load(PtrComprCageBase cage_base) const {
72   return Relaxed_Load();
73 }
74 
Relaxed_Store(Object value)75 void FullObjectSlot::Relaxed_Store(Object value) const {
76   base::AsAtomicPointer::Relaxed_Store(location(), value.ptr());
77 }
78 
Release_Store(Object value)79 void FullObjectSlot::Release_Store(Object value) const {
80   base::AsAtomicPointer::Release_Store(location(), value.ptr());
81 }
82 
Relaxed_CompareAndSwap(Object old,Object target)83 Object FullObjectSlot::Relaxed_CompareAndSwap(Object old, Object target) const {
84   Address result = base::AsAtomicPointer::Relaxed_CompareAndSwap(
85       location(), old.ptr(), target.ptr());
86   return Object(result);
87 }
88 
Release_CompareAndSwap(Object old,Object target)89 Object FullObjectSlot::Release_CompareAndSwap(Object old, Object target) const {
90   Address result = base::AsAtomicPointer::Release_CompareAndSwap(
91       location(), old.ptr(), target.ptr());
92   return Object(result);
93 }
94 
95 //
96 // FullMaybeObjectSlot implementation.
97 //
98 
99 MaybeObject FullMaybeObjectSlot::operator*() const {
100   return MaybeObject(*location());
101 }
102 
load(PtrComprCageBase cage_base)103 MaybeObject FullMaybeObjectSlot::load(PtrComprCageBase cage_base) const {
104   return **this;
105 }
106 
store(MaybeObject value)107 void FullMaybeObjectSlot::store(MaybeObject value) const {
108   *location() = value.ptr();
109 }
110 
Relaxed_Load()111 MaybeObject FullMaybeObjectSlot::Relaxed_Load() const {
112   return MaybeObject(base::AsAtomicPointer::Relaxed_Load(location()));
113 }
114 
Relaxed_Load(PtrComprCageBase cage_base)115 MaybeObject FullMaybeObjectSlot::Relaxed_Load(
116     PtrComprCageBase cage_base) const {
117   return Relaxed_Load();
118 }
119 
Relaxed_Store(MaybeObject value)120 void FullMaybeObjectSlot::Relaxed_Store(MaybeObject value) const {
121   base::AsAtomicPointer::Relaxed_Store(location(), value->ptr());
122 }
123 
Release_CompareAndSwap(MaybeObject old,MaybeObject target)124 void FullMaybeObjectSlot::Release_CompareAndSwap(MaybeObject old,
125                                                  MaybeObject target) const {
126   base::AsAtomicPointer::Release_CompareAndSwap(location(), old.ptr(),
127                                                 target.ptr());
128 }
129 
130 //
131 // FullHeapObjectSlot implementation.
132 //
133 
134 HeapObjectReference FullHeapObjectSlot::operator*() const {
135   return HeapObjectReference(*location());
136 }
137 
load(PtrComprCageBase cage_base)138 HeapObjectReference FullHeapObjectSlot::load(PtrComprCageBase cage_base) const {
139   return **this;
140 }
141 
store(HeapObjectReference value)142 void FullHeapObjectSlot::store(HeapObjectReference value) const {
143   *location() = value.ptr();
144 }
145 
ToHeapObject()146 HeapObject FullHeapObjectSlot::ToHeapObject() const {
147   TData value = *location();
148   DCHECK(HAS_STRONG_HEAP_OBJECT_TAG(value));
149   return HeapObject::cast(Object(value));
150 }
151 
StoreHeapObject(HeapObject value)152 void FullHeapObjectSlot::StoreHeapObject(HeapObject value) const {
153   *location() = value.ptr();
154 }
155 
156 //
157 // Utils.
158 //
159 
160 // Copies tagged words from |src| to |dst|. The data spans must not overlap.
161 // |src| and |dst| must be kTaggedSize-aligned.
CopyTagged(Address dst,const Address src,size_t num_tagged)162 inline void CopyTagged(Address dst, const Address src, size_t num_tagged) {
163   static const size_t kBlockCopyLimit = 16;
164   CopyImpl<kBlockCopyLimit>(reinterpret_cast<Tagged_t*>(dst),
165                             reinterpret_cast<const Tagged_t*>(src), num_tagged);
166 }
167 
168 // Sets |counter| number of kTaggedSize-sized values starting at |start| slot.
MemsetTagged(Tagged_t * start,Object value,size_t counter)169 inline void MemsetTagged(Tagged_t* start, Object value, size_t counter) {
170 #ifdef V8_COMPRESS_POINTERS
171   Tagged_t raw_value = CompressTagged(value.ptr());
172   MemsetUint32(start, raw_value, counter);
173 #else
174   Address raw_value = value.ptr();
175   MemsetPointer(start, raw_value, counter);
176 #endif
177 }
178 
179 // Sets |counter| number of kTaggedSize-sized values starting at |start| slot.
180 template <typename T>
MemsetTagged(SlotBase<T,Tagged_t> start,Object value,size_t counter)181 inline void MemsetTagged(SlotBase<T, Tagged_t> start, Object value,
182                          size_t counter) {
183   MemsetTagged(start.location(), value, counter);
184 }
185 
186 // Sets |counter| number of kSystemPointerSize-sized values starting at |start|
187 // slot.
MemsetPointer(FullObjectSlot start,Object value,size_t counter)188 inline void MemsetPointer(FullObjectSlot start, Object value, size_t counter) {
189   MemsetPointer(start.location(), value.ptr(), counter);
190 }
191 
192 }  // namespace internal
193 }  // namespace v8
194 
195 #endif  // V8_OBJECTS_SLOTS_INL_H_
196