v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
property-array-inl.h
Go to the documentation of this file.
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_PROPERTY_ARRAY_INL_H_
6#define V8_OBJECTS_PROPERTY_ARRAY_INL_H_
7
9// Include the non-inl header before the rest of the headers.
10
14#include "src/objects/smi-inl.h"
15
16// Has to be the last include (doesn't have include guards):
18
19namespace v8 {
20namespace internal {
21
22#include "torque-generated/src/objects/property-array-tq-inl.inc"
23
24TQ_OBJECT_CONSTRUCTORS_IMPL(PropertyArray)
25
26SMI_ACCESSORS(PropertyArray, length_and_hash, kLengthAndHashOffset)
28 kLengthAndHashOffset)
29
30Tagged<JSAny> PropertyArray::get(int index) const {
31 PtrComprCageBase cage_base = GetPtrComprCageBase(*this);
32 return get(cage_base, index);
33}
34
35Tagged<JSAny> PropertyArray::get(PtrComprCageBase cage_base, int index) const {
36 DCHECK_LT(static_cast<unsigned>(index),
37 static_cast<unsigned>(this->length(kAcquireLoad)));
38 return TaggedField<JSAny>::Relaxed_Load(cage_base, *this,
39 OffsetOfElementAt(index));
40}
41
42Tagged<JSAny> PropertyArray::get(int index, SeqCstAccessTag tag) const {
43 PtrComprCageBase cage_base = GetPtrComprCageBase(*this);
44 return get(cage_base, index, tag);
45}
46
47Tagged<JSAny> PropertyArray::get(PtrComprCageBase cage_base, int index,
48 SeqCstAccessTag tag) const {
49 DCHECK_LT(static_cast<unsigned>(index),
50 static_cast<unsigned>(this->length(kAcquireLoad)));
51 return TaggedField<JSAny>::SeqCst_Load(cage_base, *this,
52 OffsetOfElementAt(index));
53}
54
55void PropertyArray::set(int index, Tagged<Object> value) {
56 DCHECK(IsPropertyArray(*this));
57 DCHECK_LT(static_cast<unsigned>(index),
58 static_cast<unsigned>(this->length(kAcquireLoad)));
59 int offset = OffsetOfElementAt(index);
60 RELAXED_WRITE_FIELD(*this, offset, value);
61 WRITE_BARRIER(*this, offset, value);
62}
63
64void PropertyArray::set(int index, Tagged<Object> value,
65 WriteBarrierMode mode) {
66 DCHECK_LT(static_cast<unsigned>(index),
67 static_cast<unsigned>(this->length(kAcquireLoad)));
68 int offset = OffsetOfElementAt(index);
69 RELAXED_WRITE_FIELD(*this, offset, value);
70 CONDITIONAL_WRITE_BARRIER(*this, offset, value, mode);
71}
72
74 DCHECK(IsPropertyArray(*this));
75 DCHECK_LT(static_cast<unsigned>(index),
76 static_cast<unsigned>(this->length(kAcquireLoad)));
77 DCHECK(IsShared(value));
78 int offset = OffsetOfElementAt(index);
79 SEQ_CST_WRITE_FIELD(*this, offset, value);
81}
82
84 SeqCstAccessTag tag) {
85 PtrComprCageBase cage_base = GetPtrComprCageBase(*this);
86 return Swap(cage_base, index, value, tag);
87}
88
91 DCHECK(IsPropertyArray(*this));
92 DCHECK_LT(static_cast<unsigned>(index),
93 static_cast<unsigned>(this->length(kAcquireLoad)));
94 DCHECK(IsShared(value));
96 cage_base, *this, OffsetOfElementAt(index), value);
99 return result;
100}
101
103 Tagged<Object> value,
104 SeqCstAccessTag tag) {
105 DCHECK(IsPropertyArray(*this));
106 DCHECK_LT(static_cast<unsigned>(index),
107 static_cast<unsigned>(this->length(kAcquireLoad)));
108 DCHECK(IsShared(value));
110 *this, OffsetOfElementAt(index), expected, value);
111 if (result == expected) {
112 CONDITIONAL_WRITE_BARRIER(*this, OffsetOfElementAt(index), value,
114 }
115 return result;
116}
117
119
121 return RawField(OffsetOfElementAt(index));
122}
123
125 return LengthField::decode(length_and_hash());
126}
127
130 set_length_and_hash(len);
131}
132
134 return LengthField::decode(length_and_hash(kAcquireLoad));
135}
136
137int PropertyArray::Hash() const { return HashField::decode(length_and_hash()); }
138
140 int value = length_and_hash();
141 value = HashField::update(value, hash);
142 set_length_and_hash(value, kReleaseStore);
143}
144
145// static
147 int dst_index, Tagged<PropertyArray> src,
148 int src_index, int len,
149 WriteBarrierMode mode) {
150 if (len == 0) return;
152 ObjectSlot dst_slot(dst->data_start() + dst_index);
153 ObjectSlot src_slot(src->data_start() + src_index);
154 isolate->heap()->CopyRange(dst, dst_slot, src_slot, len, mode);
155}
156
157} // namespace internal
158} // namespace v8
159
161
162#endif // V8_OBJECTS_PROPERTY_ARRAY_INL_H_
static constexpr T decode(U value)
Definition bit-field.h:66
static constexpr bool is_valid(T value)
Definition bit-field.h:50
static V8_NODISCARD constexpr U update(U previous, T value)
Definition bit-field.h:61
static void CopyElements(Isolate *isolate, Tagged< PropertyArray > dst, int dst_index, Tagged< PropertyArray > src, int src_index, int len, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
Tagged< Object > Swap(int index, Tagged< Object > value, SeqCstAccessTag tag)
void set(int index, Tagged< Object > value)
Tagged< Object > CompareAndSwap(int index, Tagged< Object > expected, Tagged< Object > value, SeqCstAccessTag tag)
static constexpr int OffsetOfElementAt(int index)
Tagged< JSAny > get(int index) const
ObjectSlot RawFieldOfElementAt(int index)
static PtrType Relaxed_Load(Tagged< HeapObject > host, int offset=0)
static PtrType SeqCst_CompareAndSwap(Tagged< HeapObject > host, int offset, PtrType old, PtrType value)
static PtrType SeqCst_Load(Tagged< HeapObject > host, int offset=0)
static PtrType SeqCst_Swap(Tagged< HeapObject > host, int offset, PtrType value)
int32_t offset
ZoneVector< RpoNumber > & result
@ UPDATE_WRITE_BARRIER
Definition objects.h:55
Tagged(T object) -> Tagged< T >
V8_INLINE PtrComprCageBase GetPtrComprCageBase()
bool IsShared(Tagged< Object > obj)
static constexpr ReleaseStoreTag kReleaseStore
Definition globals.h:2910
static constexpr AcquireLoadTag kAcquireLoad
Definition globals.h:2908
#define TQ_OBJECT_CONSTRUCTORS_IMPL(Type)
#define SMI_ACCESSORS(holder, name, offset)
#define CONDITIONAL_WRITE_BARRIER(object, offset, value, mode)
#define WRITE_BARRIER(object, offset, value)
#define SEQ_CST_WRITE_FIELD(p, offset, value)
#define RELEASE_ACQUIRE_SMI_ACCESSORS(holder, name, offset)
#define RELAXED_WRITE_FIELD(p, offset, value)
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_LT(v1, v2)
Definition logging.h:489