chromium/v8/src/heap/heap-write-barrier-inl.h

// 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.

#ifndef V8_HEAP_HEAP_WRITE_BARRIER_INL_H_
#define V8_HEAP_HEAP_WRITE_BARRIER_INL_H_

// Clients of this interface shouldn't depend on lots of heap internals.
// Do not include anything from src/heap here!

#include "src/heap/heap-write-barrier.h"
#include "src/heap/marking-barrier.h"
#include "src/heap/memory-chunk.h"
#include "src/objects/compressed-slots-inl.h"
#include "src/objects/maybe-object-inl.h"

namespace v8 {
namespace internal {

// Defined in heap.cc.
V8_EXPORT_PRIVATE bool Heap_PageFlagsAreConsistent(Tagged<HeapObject> object);
V8_EXPORT_PRIVATE void Heap_CombinedGenerationalAndSharedBarrierSlow(
    Tagged<HeapObject> object, Address slot, Tagged<HeapObject> value);
V8_EXPORT_PRIVATE void Heap_CombinedGenerationalAndSharedEphemeronBarrierSlow(
    Tagged<EphemeronHashTable> table, Address slot, Tagged<HeapObject> value);

V8_EXPORT_PRIVATE void Heap_GenerationalBarrierForCodeSlow(
    Tagged<InstructionStream> host, RelocInfo* rinfo,
    Tagged<HeapObject> object);

V8_EXPORT_PRIVATE void Heap_GenerationalEphemeronKeyBarrierSlow(
    Heap* heap, Tagged<HeapObject> table, Address slot);

inline bool IsCodeSpaceObject(Tagged<HeapObject> object);
inline bool IsTrustedSpaceObject(Tagged<HeapObject> object);

// TODO(333906585): Due to cyclic dependency, we cannot pull in marking-inl.h
// here. Fix it and make the call inlined.
V8_EXPORT_PRIVATE bool HeapObjectInYoungGenerationSticky(
    MemoryChunk* chunk, Tagged<HeapObject> object);

inline bool HeapObjectInYoungGeneration(MemoryChunk* chunk,
                                        Tagged<HeapObject> object) {}

inline bool HeapObjectInYoungGeneration(Tagged<HeapObject> object) {}

// Do not use these internal details anywhere outside of this file. These
// internals are only intended to shortcut write barrier checks.
namespace heap_internals {

inline void CombinedWriteBarrierInternal(Tagged<HeapObject> host,
                                         HeapObjectSlot slot,
                                         Tagged<HeapObject> value,
                                         WriteBarrierMode mode) {}

}  // namespace heap_internals

inline void WriteBarrierForCode(Tagged<InstructionStream> host,
                                RelocInfo* rinfo, Tagged<Object> value,
                                WriteBarrierMode mode) {}

inline void WriteBarrierForCode(Tagged<InstructionStream> host,
                                RelocInfo* rinfo, Tagged<HeapObject> value,
                                WriteBarrierMode mode) {}

inline void CombinedWriteBarrier(Tagged<HeapObject> host, ObjectSlot slot,
                                 Tagged<Object> value, WriteBarrierMode mode) {}

inline void CombinedWriteBarrier(Tagged<HeapObject> host, MaybeObjectSlot slot,
                                 Tagged<MaybeObject> value,
                                 WriteBarrierMode mode) {}

inline void CombinedWriteBarrier(HeapObjectLayout* host,
                                 TaggedMemberBase* member, Tagged<Object> value,
                                 WriteBarrierMode mode) {}

inline void CombinedEphemeronWriteBarrier(Tagged<EphemeronHashTable> host,
                                          ObjectSlot slot, Tagged<Object> value,
                                          WriteBarrierMode mode) {}

inline void IndirectPointerWriteBarrier(Tagged<HeapObject> host,
                                        IndirectPointerSlot slot,
                                        Tagged<HeapObject> value,
                                        WriteBarrierMode mode) {}

inline void JSDispatchHandleWriteBarrier(Tagged<HeapObject> host,
                                         JSDispatchHandle handle,
                                         WriteBarrierMode mode) {}

inline void ProtectedPointerWriteBarrier(Tagged<TrustedObject> host,
                                         ProtectedPointerSlot slot,
                                         Tagged<TrustedObject> value,
                                         WriteBarrierMode mode) {}

inline void GenerationalBarrierForCode(Tagged<InstructionStream> host,
                                       RelocInfo* rinfo,
                                       Tagged<HeapObject> object) {}

inline WriteBarrierMode GetWriteBarrierModeForObject(
    Tagged<HeapObject> object, const DisallowGarbageCollection* promise) {}

inline bool ObjectInYoungGeneration(Tagged<Object> object) {}

inline bool IsReadOnlyHeapObject(Tagged<HeapObject> object) {}

inline bool IsCodeSpaceObject(Tagged<HeapObject> object) {}

inline bool IsTrustedSpaceObject(Tagged<HeapObject> object) {}

bool WriteBarrier::IsMarking(Tagged<HeapObject> object) {}

void WriteBarrier::Marking(Tagged<HeapObject> host, ObjectSlot slot,
                           Tagged<Object> value) {}

void WriteBarrier::Marking(Tagged<HeapObject> host, MaybeObjectSlot slot,
                           Tagged<MaybeObject> value) {}

void WriteBarrier::Marking(Tagged<HeapObject> host, HeapObjectSlot slot,
                           Tagged<HeapObject> value) {}

void WriteBarrier::Marking(Tagged<InstructionStream> host,
                           RelocInfo* reloc_info, Tagged<HeapObject> value) {}

void WriteBarrier::Shared(Tagged<InstructionStream> host, RelocInfo* reloc_info,
                          Tagged<HeapObject> value) {}

void WriteBarrier::Marking(Tagged<JSArrayBuffer> host,
                           ArrayBufferExtension* extension) {}

void WriteBarrier::Marking(Tagged<DescriptorArray> descriptor_array,
                           int number_of_own_descriptors) {}

void WriteBarrier::Marking(Tagged<HeapObject> host, IndirectPointerSlot slot) {}

void WriteBarrier::Marking(Tagged<TrustedObject> host,
                           ProtectedPointerSlot slot,
                           Tagged<TrustedObject> value) {}

void WriteBarrier::Marking(Tagged<HeapObject> host, JSDispatchHandle handle) {}

// static
void WriteBarrier::MarkingFromGlobalHandle(Tagged<Object> value) {}

// static
void WriteBarrier::CombinedBarrierForCppHeapPointer(Tagged<JSObject> host,
                                                    void* value) {}

// static
void WriteBarrier::GenerationalBarrierForCppHeapPointer(Tagged<JSObject> host,
                                                        void* value) {}

#ifdef ENABLE_SLOW_DCHECKS
// static
template <typename T>
bool WriteBarrier::IsRequired(Tagged<HeapObject> host, T value) {
  if (HeapObjectInYoungGeneration(host)) return false;
  if (IsSmi(value)) return false;
  if (value.IsCleared()) return false;
  Tagged<HeapObject> target = value.GetHeapObject();
  if (ReadOnlyHeap::Contains(target)) return false;
  return !IsImmortalImmovableHeapObject(target);
}
// static
template <typename T>
bool WriteBarrier::IsRequired(const HeapObjectLayout* host, T value) {
  if (HeapObjectInYoungGeneration(host)) return false;
  if (IsSmi(value)) return false;
  if (value.IsCleared()) return false;
  Tagged<HeapObject> target = value.GetHeapObject();
  if (ReadOnlyHeap::Contains(target)) return false;
  return !IsImmortalImmovableHeapObject(target);
}
#endif

}  // namespace internal
}  // namespace v8

#endif  // V8_HEAP_HEAP_WRITE_BARRIER_INL_H_