v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
mark-compact-inl.h
Go to the documentation of this file.
1// Copyright 2012 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_HEAP_MARK_COMPACT_INL_H_
6#define V8_HEAP_MARK_COMPACT_INL_H_
7
9// Include the non-inl header before the rest of the headers.
10
11#include "src/common/globals.h"
17#include "src/heap/marking.h"
21#include "src/roots/roots.h"
22
23namespace v8 {
24namespace internal {
25
33
41
42// static
43template <typename THeapObjectSlot>
45 THeapObjectSlot slot,
46 Tagged<HeapObject> target) {
47 MemoryChunk* source_page = MemoryChunk::FromHeapObject(object);
48 if (!source_page->ShouldSkipEvacuationSlotRecording()) {
49 RecordSlot(source_page, slot, target);
50 }
51}
52
53// static
54template <typename THeapObjectSlot>
56 THeapObjectSlot slot,
57 Tagged<HeapObject> target) {
58 MemoryChunk* target_chunk = MemoryChunk::FromHeapObject(target);
59 if (target_chunk->IsEvacuationCandidate()) {
60 MutablePageMetadata* source_page =
61 MutablePageMetadata::cast(source_chunk->Metadata());
62 if (target_chunk->IsFlagSet(MemoryChunk::IS_EXECUTABLE)) {
63 // TODO(377724745): currently needed because flags are untrusted.
64 SBXCHECK(!InsideSandbox(target_chunk->address()));
66 source_page, source_chunk->Offset(slot.address()));
67 } else if (source_chunk->IsFlagSet(MemoryChunk::IS_TRUSTED) &&
68 target_chunk->IsFlagSet(MemoryChunk::IS_TRUSTED)) {
69 // TODO(377724745): currently needed because flags are untrusted.
70 SBXCHECK(!InsideSandbox(target_chunk->address()));
72 source_page, source_chunk->Offset(slot.address()));
73 } else if (V8_LIKELY(!target_chunk->InWritableSharedSpace()) ||
74 source_page->heap()->isolate()->is_shared_space_isolate()) {
75 DCHECK_EQ(source_page->heap(), target_chunk->GetHeap());
77 source_page, source_chunk->Offset(slot.address()));
78 } else {
79 // DCHECK here that we only don't record in case of local->shared
80 // references in a client GC.
81 DCHECK(!source_page->heap()->isolate()->is_shared_space_isolate());
82 DCHECK(target_chunk->GetHeap()->isolate()->is_shared_space_isolate());
83 DCHECK(target_chunk->InWritableSharedSpace());
84 }
85 }
86}
87
89 local_weak_objects()->transition_arrays_local.Push(array);
90}
91
92void RootMarkingVisitor::VisitRootPointer(Root root, const char* description,
95 MarkObjectByPointer(root, p);
96}
97
98void RootMarkingVisitor::VisitRootPointers(Root root, const char* description,
101 for (FullObjectSlot p = start; p < end; ++p) {
102 MarkObjectByPointer(root, p);
103 }
104}
105
107 Tagged<Object> object = *p;
108#ifdef V8_ENABLE_DIRECT_HANDLE
109 if (object.ptr() == kTaggedNullAddress) return;
110#endif
111 if (!IsHeapObject(object)) return;
112 Tagged<HeapObject> heap_object = Cast<HeapObject>(object);
113 const auto target_worklist =
115 if (!target_worklist) {
116 return;
117 }
118 collector_->MarkRootObject(root, heap_object, target_worklist.value());
119}
120
121} // namespace internal
122} // namespace v8
123
124#endif // V8_HEAP_MARK_COMPACT_INL_H_
#define SBXCHECK(condition)
Definition check.h:61
Tagged< Object > Relaxed_Load() const
Definition slots-inl.h:82
V8_EXPORT_PRIVATE bool Contains(Tagged< HeapObject > value) const
Definition heap.cc:4341
Isolate * isolate() const
Definition heap-inl.h:61
bool is_shared_space_isolate() const
Definition isolate.h:2292
static constexpr bool IsPacked(Address)
Definition objects.h:846
V8_INLINE void MarkObject(Tagged< HeapObject > host, Tagged< HeapObject > obj, MarkingHelper::WorklistTarget target_worklist)
V8_INLINE void AddTransitionArray(Tagged< TransitionArray > array)
V8_INLINE void MarkRootObject(Root root, Tagged< HeapObject > obj, MarkingHelper::WorklistTarget target_worklist)
std::unique_ptr< MarkingWorklists::Local > local_marking_worklists_
WeakObjects::Local * local_weak_objects()
static V8_INLINE void RecordSlot(Tagged< HeapObject > object, THeapObjectSlot slot, Tagged< HeapObject > target)
V8_INLINE bool InWritableSharedSpace() const
bool IsEvacuationCandidate() const
V8_INLINE Heap * GetHeap()
V8_INLINE bool IsFlagSet(Flag flag) const
V8_INLINE Address address() const
V8_INLINE MemoryChunkMetadata * Metadata()
size_t Offset(Address addr) const
bool ShouldSkipEvacuationSlotRecording() const
static V8_INLINE MemoryChunk * FromHeapObject(Tagged< HeapObject > object)
static MutablePageMetadata * cast(MemoryChunkMetadata *metadata)
static V8_EXPORT_PRIVATE bool Contains(Address address)
static void Insert(MutablePageMetadata *page, size_t slot_offset)
MarkCompactCollector *const collector_
V8_INLINE void MarkObjectByPointer(Root root, FullObjectSlot p)
V8_INLINE void VisitRootPointers(Root root, const char *description, FullObjectSlot start, FullObjectSlot end) final
V8_INLINE void VisitRootPointer(Root root, const char *description, FullObjectSlot p) final
V8_INLINE constexpr StorageType ptr() const
int start
int end
constexpr Address kTaggedNullAddress
Definition handles.h:53
V8_INLINE constexpr bool IsHeapObject(TaggedImpl< kRefType, StorageType > obj)
Definition objects.h:669
V8_INLINE bool InsideSandbox(uintptr_t address)
Definition sandbox.h:334
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
static V8_INLINE bool TryMarkAndPush(Heap *heap, MarkingWorklists::Local *marking_worklist, MarkingState *marking_state, WorklistTarget target_worklis, Tagged< HeapObject > object)
static V8_INLINE std::optional< WorklistTarget > ShouldMarkObject(Heap *heap, Tagged< HeapObject > object)
#define V8_LIKELY(condition)
Definition v8config.h:661