v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
minor-mark-sweep-inl.h
Go to the documentation of this file.
1// Copyright 2023 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_MINOR_MARK_SWEEP_INL_H_
6#define V8_HEAP_MINOR_MARK_SWEEP_INL_H_
7
9// Include the non-inl header before the rest of the headers.
10
11#include <atomic>
12#include <optional>
13
15#include "src/common/globals.h"
20#include "src/objects/map.h"
21#include "src/objects/string.h"
23
24namespace v8 {
25namespace internal {
26
28 Root root, const char* description, FullObjectSlot p) {
29 VisitPointersImpl(root, p, p + 1);
30}
31
37
38template <typename TSlot>
60
61template <typename Visitor>
63 Visitor* visitor, std::optional<size_t>& index) {
65 std::memory_order_relaxed) == 0) {
66 return false;
67 }
68 while (true) {
69 if (index && (index < remembered_sets_marking_items_.size())) {
70 auto& work_item = remembered_sets_marking_items_[*index];
71 if (work_item.TryAcquire()) {
73 1, std::memory_order_relaxed);
74 work_item.Process(visitor);
75 (*index)++;
76 return true;
77 }
78 }
80 if (!index) return false;
81 }
82}
83
84template <typename Visitor>
86 Visitor* visitor) {
88 MarkUntypedPointers(visitor);
89 } else {
90 MarkTypedPointers(visitor);
91 }
92}
93
94template <typename Visitor>
96 MarkUntypedPointers(Visitor* visitor) {
98 "MarkingItem::MarkUntypedPointers");
99 auto callback = [this, visitor](MaybeObjectSlot slot) {
100 return CheckAndMarkObject(visitor, slot);
101 };
102 if (slot_set_) {
103 const auto slot_count =
104 RememberedSet<OLD_TO_NEW>::template Iterate<AccessMode::NON_ATOMIC>(
106 if (slot_count == 0) {
107 SlotSet::Delete(slot_set_);
108 slot_set_ = nullptr;
109 }
110 }
111 if (background_slot_set_) {
112 const auto slot_count =
114 AccessMode::NON_ATOMIC>(background_slot_set_, chunk_, callback,
116 if (slot_count == 0) {
117 SlotSet::Delete(background_slot_set_);
118 background_slot_set_ = nullptr;
119 }
120 }
121}
122
123template <typename Visitor>
125 MarkTypedPointers(Visitor* visitor) {
127 "MarkingItem::MarkTypedPointers");
128 DCHECK_NULL(background_slot_set_);
129 DCHECK_NOT_NULL(typed_slot_set_);
130 const auto slot_count = RememberedSet<OLD_TO_NEW>::IterateTyped(
131 typed_slot_set_,
132 [this, visitor](SlotType slot_type, Address slot_address) {
134 heap(), slot_type, slot_address);
135 FullMaybeObjectSlot slot(&object);
136 return CheckAndMarkObject(visitor, slot);
137 });
138 if (slot_count == 0) {
139 delete typed_slot_set_;
140 typed_slot_set_ = nullptr;
141 }
142}
143
144template <typename Visitor, typename TSlot>
145V8_INLINE SlotCallbackResult
147 Visitor* visitor, TSlot slot) {
148 static_assert(
149 std::is_same<TSlot, FullMaybeObjectSlot>::value ||
150 std::is_same<TSlot, MaybeObjectSlot>::value,
151 "Only FullMaybeObjectSlot and MaybeObjectSlot are expected here");
152 return visitor->VisitObjectViaSlotInRememberedSet(slot) ? KEEP_SLOT
153 : REMOVE_SLOT;
154}
155
156} // namespace internal
157} // namespace v8
158
159#endif // V8_HEAP_MINOR_MARK_SWEEP_INL_H_
static void Delete(BasicSlotSet *slot_set)
std::optional< size_t > GetNext()
static int IterateTyped(MutablePageMetadata *chunk, Callback callback)
static Tagged< HeapObject > GetTargetObject(Heap *heap, SlotType slot_type, Address addr)
V8_INLINE SlotCallbackResult CheckAndMarkObject(Visitor *visitor, TSlot slot)
bool ProcessNextItem(Visitor *visitor, std::optional< size_t > &index)
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
YoungGenerationMainMarkingVisitor *const main_marking_visitor_
void VisitPointersImpl(Root root, TSlot start, TSlot end)
int start
int end
TNode< Object > callback
MutablePageMetadata * chunk_
#define DCHECK_NULL(val)
Definition logging.h:491
#define DCHECK_NOT_NULL(val)
Definition logging.h:492
#define TRACE_EVENT0(category_group, name)
#define TRACE_DISABLED_BY_DEFAULT(name)
#define V8_INLINE
Definition v8config.h:500