Line data Source code
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/objects/slots.h"
9 :
10 : #include "src/base/atomic-utils.h"
11 : #include "src/memcopy.h"
12 : #include "src/objects.h"
13 : #include "src/objects/heap-object-inl.h"
14 : #include "src/objects/maybe-object.h"
15 :
16 : #ifdef V8_COMPRESS_POINTERS
17 : #include "src/ptr-compr-inl.h"
18 : #endif
19 :
20 : namespace v8 {
21 : namespace internal {
22 :
23 : //
24 : // FullObjectSlot implementation.
25 : //
26 :
27 0 : FullObjectSlot::FullObjectSlot(Object* object)
28 480824708 : : SlotBase(reinterpret_cast<Address>(&object->ptr_)) {}
29 :
30 : bool FullObjectSlot::contains_value(Address raw_value) const {
31 : return base::AsAtomicPointer::Relaxed_Load(location()) == raw_value;
32 : }
33 :
34 16623883273 : Object FullObjectSlot::operator*() const { return Object(*location()); }
35 :
36 62731135 : void FullObjectSlot::store(Object value) const { *location() = value->ptr(); }
37 :
38 : Object FullObjectSlot::Acquire_Load() const {
39 : return Object(base::AsAtomicPointer::Acquire_Load(location()));
40 : }
41 :
42 3296484501 : Object FullObjectSlot::Relaxed_Load() const {
43 3296484501 : return Object(base::AsAtomicPointer::Relaxed_Load(location()));
44 : }
45 :
46 14147789 : void FullObjectSlot::Relaxed_Store(Object value) const {
47 : base::AsAtomicPointer::Relaxed_Store(location(), value->ptr());
48 14147789 : }
49 :
50 521765 : void FullObjectSlot::Release_Store(Object value) const {
51 : base::AsAtomicPointer::Release_Store(location(), value->ptr());
52 521765 : }
53 :
54 116221115 : Object FullObjectSlot::Release_CompareAndSwap(Object old, Object target) const {
55 : Address result = base::AsAtomicPointer::Release_CompareAndSwap(
56 : location(), old->ptr(), target->ptr());
57 116221115 : return Object(result);
58 : }
59 :
60 : //
61 : // FullMaybeObjectSlot implementation.
62 : //
63 :
64 599353388 : MaybeObject FullMaybeObjectSlot::operator*() const {
65 945200347 : return MaybeObject(*location());
66 : }
67 :
68 : void FullMaybeObjectSlot::store(MaybeObject value) const {
69 48546605 : *location() = value.ptr();
70 : }
71 :
72 428216491 : MaybeObject FullMaybeObjectSlot::Relaxed_Load() const {
73 428216491 : return MaybeObject(AsAtomicTagged::Relaxed_Load(location()));
74 : }
75 :
76 : void FullMaybeObjectSlot::Relaxed_Store(MaybeObject value) const {
77 : AsAtomicTagged::Relaxed_Store(location(), value->ptr());
78 : }
79 :
80 : void FullMaybeObjectSlot::Release_CompareAndSwap(MaybeObject old,
81 : MaybeObject target) const {
82 : AsAtomicTagged::Release_CompareAndSwap(location(), old.ptr(), target.ptr());
83 : }
84 :
85 : //
86 : // FullHeapObjectSlot implementation.
87 : //
88 :
89 195019748 : HeapObjectReference FullHeapObjectSlot::operator*() const {
90 232475567 : return HeapObjectReference(*location());
91 : }
92 :
93 147724235 : void FullHeapObjectSlot::store(HeapObjectReference value) const {
94 147898871 : *location() = value.ptr();
95 147724235 : }
96 :
97 514160 : HeapObject FullHeapObjectSlot::ToHeapObject() const {
98 : DCHECK((*location() & kHeapObjectTagMask) == kHeapObjectTag);
99 1028274 : return HeapObject::cast(Object(*location()));
100 : }
101 :
102 : void FullHeapObjectSlot::StoreHeapObject(HeapObject value) const {
103 1133354 : *location() = value->ptr();
104 : }
105 :
106 : //
107 : // Utils.
108 : //
109 :
110 : // Sets |counter| number of kTaggedSize-sized values starting at |start| slot.
111 0 : inline void MemsetTagged(ObjectSlot start, Object value, size_t counter) {
112 : // TODO(ishell): revisit this implementation, maybe use "rep stosl"
113 : STATIC_ASSERT(kTaggedSize == kSystemPointerSize);
114 : MemsetPointer(start.location(), value.ptr(), counter);
115 0 : }
116 :
117 : // Sets |counter| number of kSystemPointerSize-sized values starting at |start|
118 : // slot.
119 : inline void MemsetPointer(FullObjectSlot start, Object value, size_t counter) {
120 : MemsetPointer(start.location(), value.ptr(), counter);
121 : }
122 :
123 : } // namespace internal
124 : } // namespace v8
125 :
126 : #endif // V8_OBJECTS_SLOTS_INL_H_
|