1 | // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
---|---|
2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | // BSD-style license that can be found in the LICENSE file. |
4 | |
5 | #ifndef RUNTIME_VM_HEAP_MARKER_H_ |
6 | #define RUNTIME_VM_HEAP_MARKER_H_ |
7 | |
8 | #include "vm/allocation.h" |
9 | #include "vm/heap/pointer_block.h" |
10 | #include "vm/os_thread.h" // Mutex. |
11 | |
12 | namespace dart { |
13 | |
14 | // Forward declarations. |
15 | class HandleVisitor; |
16 | class Heap; |
17 | class IsolateGroup; |
18 | class ObjectPointerVisitor; |
19 | class PageSpace; |
20 | template <bool sync> |
21 | class MarkingVisitorBase; |
22 | class NewPage; |
23 | class Thread; |
24 | |
25 | // The class GCMarker is used to mark reachable old generation objects as part |
26 | // of the mark-sweep collection. The marking bit used is defined in RawObject. |
27 | // Instances have a lifetime that spans from the beginining of concurrent |
28 | // marking (or stop-the-world marking) until marking is complete. In particular, |
29 | // an instance may be created and destroyed on different threads if the isolate |
30 | // is exited during concurrent marking. |
31 | class GCMarker { |
32 | public: |
33 | GCMarker(IsolateGroup* isolate_group, Heap* heap); |
34 | ~GCMarker(); |
35 | |
36 | // Mark roots synchronously, then spawn tasks to concurrently drain the |
37 | // marking queue. Only called when no marking or sweeping is in progress. |
38 | // Marking must later be finalized by calling MarkObjects. |
39 | void StartConcurrentMark(PageSpace* page_space); |
40 | |
41 | // (Re)mark roots, drain the marking queue and finalize weak references. |
42 | // Does not required StartConcurrentMark to have been previously called. |
43 | void MarkObjects(PageSpace* page_space); |
44 | |
45 | intptr_t marked_words() const { return marked_bytes_ >> kWordSizeLog2; } |
46 | intptr_t MarkedWordsPerMicro() const; |
47 | |
48 | private: |
49 | void Prologue(); |
50 | void Epilogue(); |
51 | void ResetSlices(); |
52 | void IterateRoots(ObjectPointerVisitor* visitor); |
53 | void IterateWeakRoots(Thread* thread); |
54 | void ProcessWeakHandles(Thread* thread); |
55 | void ProcessWeakTables(Thread* thread); |
56 | void ProcessRememberedSet(Thread* thread); |
57 | void ProcessObjectIdTable(Thread* thread); |
58 | |
59 | // Called by anyone: finalize and accumulate stats from 'visitor'. |
60 | template <class MarkingVisitorType> |
61 | void FinalizeResultsFrom(MarkingVisitorType* visitor); |
62 | |
63 | IsolateGroup* const isolate_group_; |
64 | Heap* const heap_; |
65 | MarkingStack marking_stack_; |
66 | MarkingStack deferred_marking_stack_; |
67 | MarkingVisitorBase<true>** visitors_; |
68 | |
69 | NewPage* new_page_; |
70 | Monitor root_slices_monitor_; |
71 | RelaxedAtomic<intptr_t> root_slices_started_; |
72 | intptr_t root_slices_finished_; |
73 | intptr_t root_slices_count_; |
74 | RelaxedAtomic<intptr_t> weak_slices_started_; |
75 | |
76 | Mutex stats_mutex_; |
77 | uintptr_t marked_bytes_; |
78 | int64_t marked_micros_; |
79 | |
80 | friend class ConcurrentMarkTask; |
81 | friend class ParallelMarkTask; |
82 | DISALLOW_IMPLICIT_CONSTRUCTORS(GCMarker); |
83 | }; |
84 | |
85 | } // namespace dart |
86 | |
87 | #endif // RUNTIME_VM_HEAP_MARKER_H_ |
88 |