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 448886804 : : 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 16963270077 : const Object FullObjectSlot::operator*() const { return Object(*location()); }
35 :
36 63191255 : void FullObjectSlot::store(Object value) const { *location() = value->ptr(); }
37 :
38 1680 : Object FullObjectSlot::Acquire_Load() const {
39 1680 : return Object(base::AsAtomicPointer::Acquire_Load(location()));
40 : }
41 :
42 3149546047 : Object FullObjectSlot::Relaxed_Load() const {
43 3149546047 : return Object(base::AsAtomicPointer::Relaxed_Load(location()));
44 : }
45 :
46 16644063 : void FullObjectSlot::Relaxed_Store(Object value) const {
47 2768356 : base::AsAtomicPointer::Relaxed_Store(location(), value->ptr());
48 16644044 : }
49 :
50 514686 : void FullObjectSlot::Release_Store(Object value) const {
51 5824 : base::AsAtomicPointer::Release_Store(location(), value->ptr());
52 514686 : }
53 :
54 116683633 : Object FullObjectSlot::Release_CompareAndSwap(Object old, Object target) const {
55 : Address result = base::AsAtomicPointer::Release_CompareAndSwap(
56 : location(), old->ptr(), target->ptr());
57 116683633 : return Object(result);
58 : }
59 :
60 : //
61 : // FullMaybeObjectSlot implementation.
62 : //
63 :
64 589915867 : const MaybeObject FullMaybeObjectSlot::operator*() const {
65 924061124 : return MaybeObject(*location());
66 : }
67 :
68 : void FullMaybeObjectSlot::store(MaybeObject value) const {
69 2603123281 : *location() = value.ptr();
70 : }
71 :
72 401960086 : MaybeObject FullMaybeObjectSlot::Relaxed_Load() const {
73 401960086 : return MaybeObject(AsAtomicTagged::Relaxed_Load(location()));
74 : }
75 :
76 2912 : void FullMaybeObjectSlot::Relaxed_Store(MaybeObject value) const {
77 2912 : AsAtomicTagged::Relaxed_Store(location(), value->ptr());
78 2912 : }
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 231650841 : const HeapObjectReference FullHeapObjectSlot::operator*() const {
90 231650841 : return HeapObjectReference(*location());
91 : }
92 :
93 184450519 : void FullHeapObjectSlot::store(HeapObjectReference value) const {
94 184450519 : *location() = value.ptr();
95 184450519 : }
96 :
97 502011 : HeapObject FullHeapObjectSlot::ToHeapObject() const {
98 : DCHECK((*location() & kHeapObjectTagMask) == kHeapObjectTag);
99 1003863 : return HeapObject::cast(Object(*location()));
100 : }
101 :
102 : void FullHeapObjectSlot::StoreHeapObject(HeapObject value) const {
103 : *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 : Address raw_value = value.ptr();
115 : #ifdef V8_COMPRESS_POINTERS
116 : raw_value = CompressTagged(raw_value);
117 : #endif
118 : MemsetPointer(start.location(), raw_value, counter);
119 0 : }
120 :
121 : // Sets |counter| number of kSystemPointerSize-sized values starting at |start|
122 : // slot.
123 : inline void MemsetPointer(FullObjectSlot start, Object value, size_t counter) {
124 : MemsetPointer(start.location(), value.ptr(), counter);
125 : }
126 :
127 : } // namespace internal
128 : } // namespace v8
129 :
130 : #endif // V8_OBJECTS_SLOTS_INL_H_
|