v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
marking-barrier-inl.h
Go to the documentation of this file.
1// Copyright 2020 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_MARKING_BARRIER_INL_H_
6#define V8_HEAP_MARKING_BARRIER_INL_H_
7
9// Include the non-inl header before the rest of the headers.
10
11#include "src/base/logging.h"
15#include "src/heap/marking.h"
16
17namespace v8 {
18namespace internal {
19
20template <typename TSlot>
22 Tagged<HeapObject> value) {
25 DCHECK(MemoryChunk::FromHeapObject(host)->IsMarking());
26
27 MarkValue(host, value);
28
29 if (slot.address() && IsCompacting(host)) {
30 MarkCompactCollector::RecordSlot(host, slot, value);
31 }
32}
33
35 Tagged<HeapObject> value) {
36 if (HeapLayout::InReadOnlySpace(value)) return;
37
40
41 // When shared heap isn't enabled all objects are local, we can just run the
42 // local marking barrier. Also from the point-of-view of the shared space
43 // isolate (= main isolate) also shared objects are considered local.
45 // Check whether incremental marking is enabled for that object's space.
46 if (!MemoryChunk::FromHeapObject(host)->IsMarking()) {
47 return;
48 }
49
50 if (v8_flags.black_allocated_pages &&
52 return;
53 }
54
56 // Invoking shared marking barrier when storing into shared objects.
57 MarkValueShared(value);
58 return;
59 } else if (HeapLayout::InWritableSharedSpace(value)) {
60 // No marking needed when storing shared objects in local objects.
61 return;
62 }
63 }
64
69
71 MarkValueLocal(value);
72}
73
75 // Value is either in read-only space or shared heap.
77
78 // We should only reach this on client isolates (= worker isolates).
80 DCHECK(shared_heap_worklists_.has_value());
81
82 // Mark shared object and push it onto shared heap worklist.
83 if (marking_state_.TryMark(value)) {
84 shared_heap_worklists_->Push(value);
85 }
86}
87
90 if (is_minor()) {
91 // We do not need to insert into RememberedSet<OLD_TO_NEW> here because the
92 // C++ marking barrier already does this for us.
93 // TODO(v8:13012): Consider updating C++ barriers to respect
94 // POINTERS_TO_HERE_ARE_INTERESTING and POINTERS_FROM_HERE_ARE_INTERESTING
95 // page flags and make the following branch a DCHECK.
100 }
101 } else {
102 // At this point `ShouldMarkObject()` should always succeed here because
103 // value has gone through all the necessary filters. However, we do want to
104 // push to the right target worklist immediately.
105 const auto target_worklist = MarkingHelper::ShouldMarkObject(heap_, value);
106 if (!target_worklist) return;
108 &marking_state_, target_worklist.value(),
109 value);
110 }
111}
112
113template <typename TSlot>
115 TSlot end) {
116 auto* isolate = heap_->isolate();
117 const bool record_slots =
118 IsCompacting(host) &&
120 for (TSlot slot = start; slot < end; ++slot) {
121 typename TSlot::TObject object = slot.Relaxed_Load();
122 Tagged<HeapObject> heap_object;
123 // Mark both, weak and strong edges.
124 if (object.GetHeapObject(isolate, &heap_object)) {
125 MarkValue(host, heap_object);
126 if (record_slots) {
127 major_collector_->RecordSlot(host, HeapObjectSlot(slot), heap_object);
128 }
129 }
130 }
131}
132
134 if (is_compacting_) {
135 DCHECK(is_major());
136 return true;
137 }
138
139 return shared_heap_worklists_.has_value() &&
141}
142
143} // namespace internal
144} // namespace v8
145
146#endif // V8_HEAP_MARKING_BARRIER_INL_H_
static V8_INLINE bool InYoungGeneration(Tagged< Object > object)
static V8_INLINE bool InWritableSharedSpace(Tagged< HeapObject > object)
static V8_INLINE bool InReadOnlySpace(Tagged< HeapObject > object)
static V8_INLINE bool InBlackAllocatedPage(Tagged< HeapObject > object)
static V8_INLINE bool InAnySharedSpace(Tagged< HeapObject > object)
Isolate * isolate() const
Definition heap-inl.h:61
static V8_INLINE void RecordSlot(Tagged< HeapObject > object, THeapObjectSlot slot, Tagged< HeapObject > target)
void MarkValue(Tagged< HeapObject > host, Tagged< HeapObject > value)
std::optional< MarkingWorklists::Local > shared_heap_worklists_
void MarkValueLocal(Tagged< HeapObject > value)
void Write(Tagged< HeapObject > host, TSlot slot, Tagged< HeapObject > value)
std::unique_ptr< MarkingWorklists::Local > current_worklists_
bool IsCurrentMarkingBarrier(Tagged< HeapObject > verification_candidate)
void MarkRange(Tagged< HeapObject > value, TSlot start, TSlot end)
MarkCompactCollector * major_collector_
void MarkValueShared(Tagged< HeapObject > value)
bool IsCompacting(Tagged< HeapObject > object) const
V8_INLINE bool TryMark(Tagged< HeapObject > obj)
bool ShouldSkipEvacuationSlotRecording() const
static V8_INLINE MemoryChunk * FromHeapObject(Tagged< HeapObject > object)
int start
int end
V8_EXPORT_PRIVATE FlagValues v8_flags
SlotTraits::THeapObjectSlot HeapObjectSlot
Definition globals.h:1253
#define DCHECK_IMPLIES(v1, v2)
Definition logging.h:493
#define DCHECK(condition)
Definition logging.h:482
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_UNLIKELY(condition)
Definition v8config.h:660