blob: 3fe69ee5ec7a36a8ffb70beeec5b28827e15ddb6 [file] [log] [blame]
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/objects/tagged-impl.h"
namespace v8 {
namespace internal {
// A MaybeObject is either a SMI, a strong reference to a HeapObject, a weak
// reference to a HeapObject, or a cleared weak reference. It's used for
// implementing in-place weak references (see design doc: )
class MaybeObject : public TaggedImpl<HeapObjectReferenceType::WEAK, Address> {
constexpr MaybeObject() : TaggedImpl(kNullAddress) {}
constexpr explicit MaybeObject(Address ptr) : TaggedImpl(ptr) {}
// These operator->() overloads are required for handlified code.
constexpr const MaybeObject* operator->() const { return this; }
V8_INLINE static MaybeObject FromSmi(Smi smi);
V8_INLINE static MaybeObject FromObject(Object object);
V8_INLINE static MaybeObject MakeWeak(MaybeObject object);
V8_INLINE static MaybeObject Create(MaybeObject o);
V8_INLINE static MaybeObject Create(Object o);
V8_INLINE static MaybeObject Create(Smi smi);
static void VerifyMaybeObjectPointer(Isolate* isolate, MaybeObject p);
template <typename TFieldType, int kFieldOffset>
friend class TaggedField;
// A HeapObjectReference is either a strong reference to a HeapObject, a weak
// reference to a HeapObject, or a cleared weak reference.
class HeapObjectReference : public MaybeObject {
explicit HeapObjectReference(Address address) : MaybeObject(address) {}
V8_INLINE explicit HeapObjectReference(Object object);
V8_INLINE static HeapObjectReference Strong(Object object);
V8_INLINE static HeapObjectReference Weak(Object object);
V8_INLINE static HeapObjectReference From(Object object,
HeapObjectReferenceType type);
V8_INLINE static HeapObjectReference ClearedValue(IsolateRoot isolate);
template <typename THeapObjectSlot>
V8_INLINE static void Update(THeapObjectSlot slot, HeapObject value);
} // namespace internal
} // namespace v8