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