blob: df34bbddfe9306eb7dedec96e7968647665566d0 [file] [log] [blame]
Kaido Kertf309f9a2021-04-30 12:09:15 -07001// 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_H_
6#define V8_HEAP_MARKING_BARRIER_H_
7
8#include "include/v8-internal.h"
9#include "src/common/globals.h"
10#include "src/heap/mark-compact.h"
11
12namespace v8 {
13namespace internal {
14
15class Heap;
16class IncrementalMarking;
17class LocalHeap;
18class PagedSpace;
19class NewSpace;
20
21class MarkingBarrier {
22 public:
23 explicit MarkingBarrier(Heap*);
24 explicit MarkingBarrier(LocalHeap*);
25 ~MarkingBarrier();
26
27 void Activate(bool is_compacting);
28 void Deactivate();
29 void Publish();
30
31 static void ActivateAll(Heap* heap, bool is_compacting);
32 static void DeactivateAll(Heap* heap);
33 static void PublishAll(Heap* heap);
34
35 void Write(HeapObject host, HeapObjectSlot, HeapObject value);
36 void Write(Code host, RelocInfo*, HeapObject value);
37 void Write(JSArrayBuffer host, ArrayBufferExtension*);
38 void Write(DescriptorArray, int number_of_own_descriptors);
39
40 // Returns true if the slot needs to be recorded.
41 inline bool MarkValue(HeapObject host, HeapObject value);
42
43 private:
44 using MarkingState = MarkCompactCollector::MarkingState;
45
46 inline bool WhiteToGreyAndPush(HeapObject value);
47
48 void RecordRelocSlot(Code host, RelocInfo* rinfo, HeapObject target);
49
50 void ActivateSpace(PagedSpace*);
51 void ActivateSpace(NewSpace*);
52
53 void DeactivateSpace(PagedSpace*);
54 void DeactivateSpace(NewSpace*);
55
56 Heap* heap_;
57 MarkCompactCollector* collector_;
58 IncrementalMarking* incremental_marking_;
59 MarkingWorklist::Local worklist_;
60 MarkingState marking_state_;
61 std::unordered_map<MemoryChunk*, std::unique_ptr<TypedSlots>,
62 MemoryChunk::Hasher>
63 typed_slots_map_;
64 bool is_compacting_ = false;
65 bool is_activated_ = false;
66 bool is_main_thread_barrier_;
67};
68
69} // namespace internal
70} // namespace v8
71
72#endif // V8_HEAP_MARKING_BARRIER_H_