v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
tagged-impl-inl.h
Go to the documentation of this file.
1// Copyright 2019 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_TAGGED_IMPL_INL_H_
6#define V8_OBJECTS_TAGGED_IMPL_INL_H_
7
9// Include the non-inl header before the rest of the headers.
10
11#ifdef V8_COMPRESS_POINTERS
13#endif
17#include "src/objects/smi.h"
18#include "src/roots/roots-inl.h"
19
20namespace v8 {
21namespace internal {
22
23template <HeapObjectReferenceType kRefType, typename StorageType>
25 if (HAS_SMI_TAG(ptr_)) {
26 *value = ToSmi();
27 return true;
28 }
29 return false;
30}
31
32template <HeapObjectReferenceType kRefType, typename StorageType>
35 if constexpr (kIsFull) {
36 return Tagged<Smi>(ptr_);
37 }
38 // Implementation for compressed pointers.
40 static_cast<Tagged_t>(ptr_)));
41}
42
43//
44// TaggedImpl::GetHeapObject(Tagged<HeapObject>* result) implementation.
45//
46
47template <HeapObjectReferenceType kRefType, typename StorageType>
50 CHECK(kIsFull);
51 if (!IsStrongOrWeak()) return false;
52 *result = GetHeapObject();
53 return true;
54}
55
56template <HeapObjectReferenceType kRefType, typename StorageType>
58 Isolate* isolate, Tagged<HeapObject>* result) const {
59 if (kIsFull) return GetHeapObject(result);
60 // Implementation for compressed pointers.
61 if (!IsStrongOrWeak()) return false;
62 *result = GetHeapObject(isolate);
63 return true;
64}
65
66//
67// TaggedImpl::GetHeapObject(Tagged<HeapObject>* result,
68// HeapObjectReferenceType* reference_type)
69// implementation.
70//
71
72template <HeapObjectReferenceType kRefType, typename StorageType>
74 Tagged<HeapObject>* result, HeapObjectReferenceType* reference_type) const {
75 CHECK(kIsFull);
76 if (!IsStrongOrWeak()) return false;
77 *reference_type = IsWeakOrCleared() ? HeapObjectReferenceType::WEAK
78 : HeapObjectReferenceType::STRONG;
79 *result = GetHeapObject();
80 return true;
81}
82
83template <HeapObjectReferenceType kRefType, typename StorageType>
86 HeapObjectReferenceType* reference_type) const {
87 if (kIsFull) return GetHeapObject(result, reference_type);
88 // Implementation for compressed pointers.
89 if (!IsStrongOrWeak()) return false;
90 *reference_type = IsWeakOrCleared() ? HeapObjectReferenceType::WEAK
91 : HeapObjectReferenceType::STRONG;
92 *result = GetHeapObject(isolate);
93 return true;
94}
95
96//
97// TaggedImpl::GetHeapObjectIfStrong(Tagged<HeapObject>* result) implementation.
98//
99
100template <HeapObjectReferenceType kRefType, typename StorageType>
102 Tagged<HeapObject>* result) const {
103 CHECK(kIsFull);
104 if (IsStrong()) {
106 return true;
107 }
108 return false;
109}
110
111template <HeapObjectReferenceType kRefType, typename StorageType>
113 Isolate* isolate, Tagged<HeapObject>* result) const {
114 if (kIsFull) return GetHeapObjectIfStrong(result);
115 // Implementation for compressed pointers.
116 if (IsStrong()) {
119 isolate, static_cast<Tagged_t>(ptr_))));
120 return true;
121 }
122 return false;
124
125//
126// TaggedImpl::GetHeapObjectAssumeStrong() implementation.
127//
128
129template <HeapObjectReferenceType kRefType, typename StorageType>
136
137template <HeapObjectReferenceType kRefType, typename StorageType>
139 Isolate* isolate) const {
140 if (kIsFull) return GetHeapObjectAssumeStrong();
141 // Implementation for compressed pointers.
142 DCHECK(IsStrong());
143 return Cast<HeapObject>(
145 isolate, static_cast<Tagged_t>(ptr_))));
146}
147
148//
149// TaggedImpl::GetHeapObjectIfWeak(Tagged<HeapObject>* result) implementation
150//
151
152template <HeapObjectReferenceType kRefType, typename StorageType>
154 Tagged<HeapObject>* result) const {
155 CHECK(kIsFull);
156 if (kCanBeWeak) {
157 if (IsWeak()) {
158 *result = GetHeapObject();
159 return true;
160 }
161 return false;
162 } else {
164 return false;
165 }
166}
167
168template <HeapObjectReferenceType kRefType, typename StorageType>
170 Isolate* isolate, Tagged<HeapObject>* result) const {
171 if (kIsFull) return GetHeapObjectIfWeak(result);
172 // Implementation for compressed pointers.
173 if (kCanBeWeak) {
174 if (IsWeak()) {
175 *result = GetHeapObject(isolate);
176 return true;
177 }
178 return false;
179 } else {
181 return false;
182 }
183}
186// TaggedImpl::GetHeapObjectAssumeWeak() implementation.
187//
188
189template <HeapObjectReferenceType kRefType, typename StorageType>
191 const {
192 CHECK(kIsFull);
193 DCHECK(IsWeak());
194 return GetHeapObject();
197template <HeapObjectReferenceType kRefType, typename StorageType>
199 Isolate* isolate) const {
200 if (kIsFull) return GetHeapObjectAssumeWeak();
201 // Implementation for compressed pointers.
203 return GetHeapObject(isolate);
204}
205
207// TaggedImpl::GetHeapObject() implementation.
208//
210template <HeapObjectReferenceType kRefType, typename StorageType>
212 CHECK(kIsFull);
213 DCHECK(!IsSmi());
214 if (kCanBeWeak) {
215 DCHECK(!IsCleared());
217 } else {
220 }
223template <HeapObjectReferenceType kRefType, typename StorageType>
225 Isolate* isolate) const {
226 if (kIsFull) return GetHeapObject();
227 // Implementation for compressed pointers.
228 DCHECK(!IsSmi());
229 if (kCanBeWeak) {
230 DCHECK(!IsCleared());
231 return Cast<HeapObject>(
233 isolate, static_cast<Tagged_t>(ptr_) & ~kWeakHeapObjectMask)));
234 } else {
236 return Cast<HeapObject>(
238 isolate, static_cast<Tagged_t>(ptr_))));
239 }
240}
241
242//
243// TaggedImpl::GetHeapObjectOrSmi() implementation.
244//
245
246template <HeapObjectReferenceType kRefType, typename StorageType>
248 CHECK(kIsFull);
249 if (IsSmi()) {
250 return Tagged<Object>(ptr_);
251 }
252 return GetHeapObject();
253}
254
255template <HeapObjectReferenceType kRefType, typename StorageType>
257 Isolate* isolate) const {
258 if constexpr (kIsFull) return GetHeapObjectOrSmi();
259 // Implementation for compressed pointers.
260 if (IsSmi()) return ToSmi();
261 return GetHeapObject(isolate);
262}
263
264} // namespace internal
265} // namespace v8
266
267#endif // V8_OBJECTS_TAGGED_IMPL_INL_H_
bool GetHeapObjectIfStrong(Tagged< HeapObject > *result) const
Tagged< HeapObject > GetHeapObjectAssumeStrong() const
bool GetHeapObjectIfWeak(Tagged< HeapObject > *result) const
Tagged< Smi > ToSmi() const
Tagged< HeapObject > GetHeapObject() const
Tagged< Object > GetHeapObjectOrSmi() const
Tagged< HeapObject > GetHeapObjectAssumeWeak() const
static V8_INLINE Address DecompressTaggedSigned(Tagged_t raw_value)
static V8_INLINE Address DecompressTagged(TOnHeapAddress on_heap_addr, Tagged_t raw_value)
Node ** ptr_
#define HAS_SMI_TAG(value)
Definition globals.h:1771
#define HAS_WEAK_HEAP_OBJECT_TAG(value)
Definition globals.h:1778
ZoneVector< RpoNumber > & result
const Address kWeakHeapObjectMask
Definition globals.h:967
V8_INLINE constexpr bool IsWeak(TaggedImpl< HeapObjectReferenceType::WEAK, StorageType > obj)
Definition objects.h:673
V8_INLINE constexpr bool IsSmi(TaggedImpl< kRefType, StorageType > obj)
Definition objects.h:665
Address Tagged_t
Definition globals.h:547
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
#define CHECK(condition)
Definition logging.h:124
#define DCHECK(condition)
Definition logging.h:482
#define V8_ASSUME
Definition v8config.h:533