v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
heap-write-barrier.h
Go to the documentation of this file.
1// Copyright 2018 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_HEAP_WRITE_BARRIER_H_
6#define V8_HEAP_HEAP_WRITE_BARRIER_H_
7
8// Clients of this interface shouldn't depend on lots of heap internals.
9// Do not include anything from src/heap here!
10
11#include "include/v8-internal.h"
12#include "src/common/globals.h"
14
15namespace v8::internal {
16
17class ArrayBufferExtension;
18class InstructionStream;
19class DescriptorArray;
20class EphemeronHashTable;
21class FixedArray;
22class Heap;
23class JSArrayBuffer;
24class Map;
25class MarkCompactCollector;
26class MarkingBarrier;
27class RelocInfo;
28
29// Write barrier interface. It's preferred to use the macros defined in
30// `object-macros.h`.
31//
32// Refer to the `ForFoo()` versions which will dispatch to all relevant barriers
33// instead of emiting marking, compaction, generational, and shared barriers
34// separately.
36 public:
37 // Trampolines for generated code. Have to take raw addresses.
38 static void EphemeronKeyWriteBarrierFromCode(Address raw_object,
39 Address key_slot_address,
40 Isolate* isolate);
41 static int MarkingFromCode(Address raw_host, Address raw_slot);
42 static int IndirectPointerMarkingFromCode(Address raw_host, Address raw_slot,
43 Address raw_tag);
44 static int SharedMarkingFromCode(Address raw_host, Address raw_slot);
45 static int SharedFromCode(Address raw_host, Address raw_slot);
46
47 static inline WriteBarrierMode GetWriteBarrierModeForObject(
48 Tagged<HeapObject> object, const DisallowGarbageCollection& promise);
49
50 template <typename T>
51 static inline void ForValue(Tagged<HeapObject> host, MaybeObjectSlot slot,
52 Tagged<T> value, WriteBarrierMode mode);
53 template <typename T>
54 static inline void ForValue(HeapObjectLayout* host, TaggedMemberBase* slot,
55 Tagged<T> value, WriteBarrierMode mode);
56 static inline void ForEphemeronHashTable(Tagged<EphemeronHashTable> host,
57 ObjectSlot slot,
58 Tagged<Object> value,
59 WriteBarrierMode mode);
60 static inline void ForRelocInfo(Tagged<InstructionStream> host,
61 RelocInfo* rinfo, Tagged<HeapObject> value,
63 static inline void ForDescriptorArray(Tagged<DescriptorArray>,
64 int number_of_own_descriptors);
65 static inline void ForArrayBufferExtension(Tagged<JSArrayBuffer> host,
67 static inline void ForExternalPointer(
70 static inline void ForIndirectPointer(
73 static inline void ForProtectedPointer(
77 static inline void ForCppHeapPointer(Tagged<JSObject> host,
78 CppHeapPointerSlot slot, void* value);
79 static inline void ForJSDispatchHandle(
82 // Executes generational and/or marking write barrier for a [start, end) range
83 // of non-weak slots inside |object|.
84 template <typename TSlot>
85 static void ForRange(Heap* heap, Tagged<HeapObject> object, TSlot start,
86 TSlot end);
87
88 static MarkingBarrier* SetForThread(MarkingBarrier* marking_barrier);
89 static MarkingBarrier* CurrentMarkingBarrier(
90 Tagged<HeapObject> verification_candidate);
91
92 // Invoked from traced handles where no host object is available.
93 static inline void MarkingFromTracedHandle(Tagged<Object> value);
94
95 static inline void GenerationalForRelocInfo(Tagged<InstructionStream> host,
96 RelocInfo* rinfo,
97 Tagged<HeapObject> object);
98 static inline void SharedForRelocInfo(Tagged<InstructionStream> host,
100
101 static inline void MarkingForTesting(Tagged<HeapObject> host, ObjectSlot,
102 Tagged<Object> value);
103
104#if defined(ENABLE_SLOW_DCHECKS) || defined(V8_ENABLE_DEBUG_CODE)
105 template <typename T>
106 static inline bool IsRequired(Tagged<HeapObject> host, T value);
107#endif
108
109#ifdef ENABLE_SLOW_DCHECKS
110 template <typename T>
111 static inline bool IsRequired(const HeapObjectLayout* host, T value);
112 static bool VerifyDispatchHandleMarkingState(Tagged<HeapObject> host,
113 JSDispatchHandle value,
114 WriteBarrierMode mode);
115#endif
116
117 // In native code we skip any further write barrier processing if the hosts
118 // page does not have the kPointersFromHereAreInterestingMask. Users of this
119 // variable rely on that fact.
120 static constexpr bool kUninterestingPagesCanBeSkipped = true;
121
122 private:
123 static bool PageFlagsAreConsistent(Tagged<HeapObject> object);
124
125 static inline bool IsImmortalImmovableHeapObject(Tagged<HeapObject> object);
126
127 static inline bool IsMarking(Tagged<HeapObject> object);
128
129 static inline void Marking(Tagged<HeapObject> host, HeapObjectSlot,
130 Tagged<HeapObject> value);
131 static inline void Marking(Tagged<HeapObject> host, MaybeObjectSlot,
132 Tagged<MaybeObject> value);
133 static inline void MarkingForRelocInfo(Tagged<InstructionStream> host,
135 static inline void Marking(Tagged<HeapObject> host, ExternalPointerSlot slot);
136 static inline void Marking(Tagged<HeapObject> host, IndirectPointerSlot slot);
137 static inline void Marking(Tagged<TrustedObject> host,
140 static inline void Marking(Tagged<HeapObject> host, JSDispatchHandle handle);
141
142 static void MarkingSlow(Tagged<HeapObject> host, HeapObjectSlot,
143 Tagged<HeapObject> value);
144 static void MarkingSlow(Tagged<InstructionStream> host, RelocInfo*,
145 Tagged<HeapObject> value);
146 static void MarkingSlow(Tagged<JSArrayBuffer> host, ArrayBufferExtension*);
147 static void MarkingSlow(Tagged<DescriptorArray>,
148 int number_of_own_descriptors);
149 static void MarkingSlow(Tagged<HeapObject> host, ExternalPointerSlot slot);
150 static void MarkingSlow(Tagged<HeapObject> host, IndirectPointerSlot slot);
151 static void MarkingSlow(Tagged<TrustedObject> host, ProtectedPointerSlot slot,
153 static void MarkingSlow(Tagged<HeapObject> host, JSDispatchHandle handle);
154 static void MarkingSlowFromTracedHandle(Tagged<HeapObject> value);
155 static void MarkingSlowFromCppHeapWrappable(Heap* heap, Tagged<JSObject> host,
157 void* object);
158
159 static void GenerationalBarrierSlow(Tagged<HeapObject> object, Address slot,
160 Tagged<HeapObject> value);
161 static inline void GenerationalBarrierForCppHeapPointer(Tagged<JSObject> host,
162 void* value);
163
164 static void SharedSlow(Tagged<TrustedObject> host, ProtectedPointerSlot slot,
166 static void SharedSlow(Tagged<InstructionStream> host, RelocInfo*,
167 Tagged<HeapObject> value);
168 static void SharedHeapBarrierSlow(Tagged<HeapObject> object, Address slot);
169
170 static inline void CombinedWriteBarrierInternal(Tagged<HeapObject> host,
171 HeapObjectSlot slot,
172 Tagged<HeapObject> value,
173 WriteBarrierMode mode);
174
175 static void CombinedGenerationalAndSharedBarrierSlow(
176 Tagged<HeapObject> object, Address slot, Tagged<HeapObject> value);
177 static void CombinedGenerationalAndSharedEphemeronBarrierSlow(
178 Tagged<EphemeronHashTable> table, Address slot, Tagged<HeapObject> value);
179 static void GenerationalBarrierForCodeSlow(Tagged<InstructionStream> host,
180 RelocInfo* rinfo,
181 Tagged<HeapObject> value);
182};
183
184} // namespace v8::internal
185
186#endif // V8_HEAP_HEAP_WRITE_BARRIER_H_
int start
int end
std::string extension
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
Definition handles-inl.h:72
@ UPDATE_WRITE_BARRIER
Definition objects.h:55
#define V8_EXPORT_PRIVATE
Definition macros.h:460