5 #ifndef V8_OBJECTS_MAYBE_OBJECT_INL_H_ 6 #define V8_OBJECTS_MAYBE_OBJECT_INL_H_ 8 #include "src/objects/maybe-object.h" 10 #include "src/objects-inl.h" 11 #include "src/objects/slots-inl.h" 16 bool MaybeObject::ToSmi(Smi* value) {
17 if (HAS_SMI_TAG(ptr_)) {
18 *value = Smi::cast(ObjectPtr(ptr_));
24 Smi MaybeObject::ToSmi()
const {
25 DCHECK(HAS_SMI_TAG(ptr_));
26 return Smi::cast(ObjectPtr(ptr_));
29 bool MaybeObject::IsStrongOrWeak()
const {
30 if (IsSmi() || IsCleared()) {
36 bool MaybeObject::GetHeapObject(HeapObject** result)
const {
37 if (IsSmi() || IsCleared()) {
40 *result = GetHeapObject();
44 bool MaybeObject::GetHeapObject(HeapObject** result,
45 HeapObjectReferenceType* reference_type)
const {
46 if (IsSmi() || IsCleared()) {
49 *reference_type = HasWeakHeapObjectTag(ptr_)
50 ? HeapObjectReferenceType::WEAK
51 : HeapObjectReferenceType::STRONG;
52 *result = GetHeapObject();
56 bool MaybeObject::IsStrong()
const {
57 return !HasWeakHeapObjectTag(ptr_) && !IsSmi();
60 bool MaybeObject::GetHeapObjectIfStrong(HeapObject** result)
const {
61 if (!HasWeakHeapObjectTag(ptr_) && !IsSmi()) {
62 *result =
reinterpret_cast<HeapObject*
>(ptr_);
68 HeapObject* MaybeObject::GetHeapObjectAssumeStrong()
const {
70 return reinterpret_cast<HeapObject*
>(ptr_);
73 bool MaybeObject::IsWeak()
const {
74 return HasWeakHeapObjectTag(ptr_) && !IsCleared();
77 bool MaybeObject::IsWeakOrCleared()
const {
return HasWeakHeapObjectTag(ptr_); }
79 bool MaybeObject::GetHeapObjectIfWeak(HeapObject** result)
const {
81 *result = GetHeapObject();
87 HeapObject* MaybeObject::GetHeapObjectAssumeWeak()
const {
89 return GetHeapObject();
92 HeapObject* MaybeObject::GetHeapObject()
const {
95 return reinterpret_cast<HeapObject*
>(ptr_ & ~kWeakHeapObjectMask);
98 Object* MaybeObject::GetHeapObjectOrSmi()
const {
100 return reinterpret_cast<Object*
>(ptr_);
102 return GetHeapObject();
105 bool MaybeObject::IsObject()
const {
return IsSmi() || IsStrong(); }
107 MaybeObject MaybeObject::MakeWeak(MaybeObject
object) {
108 DCHECK(
object.IsStrongOrWeak());
109 return MaybeObject(
object.ptr_ | kWeakHeapObjectMask);
113 HeapObjectReference HeapObjectReference::ClearedValue(Isolate* isolate) {
115 Address raw_value = kClearedWeakHeapObjectLower32;
116 #ifdef V8_COMPRESS_POINTERS 119 Address isolate_root = isolate->isolate_root();
120 raw_value |= isolate_root;
121 DCHECK_EQ(raw_value & (~static_cast<Address>(kClearedWeakHeapObjectLower32)),
125 DCHECK_EQ(kClearedWeakHeapObjectLower32, static_cast<uint32_t>(raw_value));
126 return HeapObjectReference(raw_value);
129 void HeapObjectReference::Update(HeapObjectSlot slot, HeapObject* value) {
130 Address old_value = (*slot).ptr();
131 DCHECK(!HAS_SMI_TAG(old_value));
132 Address new_value = value->ptr();
133 DCHECK(Internals::HasHeapObjectTag(new_value));
136 bool weak_before = HasWeakHeapObjectTag(old_value);
140 HeapObjectReference(new_value | (old_value & kWeakHeapObjectMask)));
143 bool weak_after = HasWeakHeapObjectTag((*slot).ptr());
144 DCHECK_EQ(weak_before, weak_after);
151 #endif // V8_OBJECTS_MAYBE_OBJECT_INL_H_