| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VM_GC_MARKER_H_ | 5 #ifndef VM_GC_MARKER_H_ |
| 6 #define VM_GC_MARKER_H_ | 6 #define VM_GC_MARKER_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| 11 | 11 |
| 12 // Forward declarations. | 12 // Forward declarations. |
| 13 class HandleVisitor; | 13 class HandleVisitor; |
| 14 class Heap; | 14 class Heap; |
| 15 class Isolate; | 15 class Isolate; |
| 16 class MarkingVisitor; | 16 class MarkingVisitor; |
| 17 class ObjectPointerVisitor; | 17 class ObjectPointerVisitor; |
| 18 class PageSpace; | 18 class PageSpace; |
| 19 class RawWeakProperty; | 19 class RawWeakProperty; |
| 20 | 20 |
| 21 // The class GCMarker is used to mark reachable old generation objects as part | 21 // The class GCMarker is used to mark reachable old generation objects as part |
| 22 // of the mark-sweep collection. The marking bit used is defined in RawObject. | 22 // of the mark-sweep collection. The marking bit used is defined in RawObject. |
| 23 class GCMarker : public ValueObject { | 23 class GCMarker : public ValueObject { |
| 24 public: | 24 public: |
| 25 explicit GCMarker(Heap* heap) : heap_(heap), marked_bytes_(0) { } | 25 explicit GCMarker(Heap* heap) |
| 26 : heap_(heap), marked_bytes_(0), done_count_(0) { } |
| 26 ~GCMarker() { } | 27 ~GCMarker() { } |
| 27 | 28 |
| 28 void MarkObjects(Isolate* isolate, | 29 void MarkObjects(Isolate* isolate, |
| 29 PageSpace* page_space, | 30 PageSpace* page_space, |
| 30 bool invoke_api_callbacks, | 31 bool invoke_api_callbacks, |
| 31 bool collect_code); | 32 bool collect_code); |
| 32 | 33 |
| 33 intptr_t marked_words() { return marked_bytes_ >> kWordSizeLog2; } | 34 intptr_t marked_words() { return marked_bytes_ >> kWordSizeLog2; } |
| 34 | 35 |
| 35 private: | 36 private: |
| 36 void Prologue(Isolate* isolate, bool invoke_api_callbacks); | 37 void Prologue(Isolate* isolate, bool invoke_api_callbacks); |
| 37 void Epilogue(Isolate* isolate, bool invoke_api_callbacks); | 38 void Epilogue(Isolate* isolate, bool invoke_api_callbacks); |
| 38 void IterateRoots(Isolate* isolate, | 39 static void IterateRoots(Isolate* isolate, |
| 39 ObjectPointerVisitor* visitor, | 40 ObjectPointerVisitor* visitor, |
| 40 bool visit_prologue_weak_persistent_handles); | 41 bool visit_prologue_weak_persistent_handles); |
| 41 void IterateWeakRoots(Isolate* isolate, | 42 void IterateWeakRoots(Isolate* isolate, |
| 42 HandleVisitor* visitor, | 43 HandleVisitor* visitor, |
| 43 bool visit_prologue_weak_persistent_handles); | 44 bool visit_prologue_weak_persistent_handles); |
| 44 void IterateWeakReferences(Isolate* isolate, MarkingVisitor* visitor); | 45 void IterateWeakReferences(Isolate* isolate, MarkingVisitor* visitor); |
| 45 void ProcessWeakTables(PageSpace* page_space); | 46 void ProcessWeakTables(PageSpace* page_space); |
| 46 void ProcessObjectIdTable(Isolate* isolate); | 47 void ProcessObjectIdTable(Isolate* isolate); |
| 47 | 48 |
| 49 // Synchronization between GCMarker's main thread and its marking tasks. |
| 50 // Called by main thread: wait for 'num_tasks' tasks, then let them resume. |
| 51 void MainSync(intptr_t num_tasks); |
| 52 // Called by tasks: notify main thread; wait until it lets us continue. |
| 53 void TaskSync(); |
| 54 // Called by tasks: notify main thread, but don't wait (used for exiting). |
| 55 void TaskNotifyDone(); |
| 56 // Called by anyone: finalize and accumulate stats from 'visitor'. |
| 57 void FinalizeResultsFrom(MarkingVisitor* visitor); |
| 48 | 58 |
| 59 Monitor monitor_; // Protects marked_bytes_ and done_count_. |
| 49 Heap* heap_; | 60 Heap* heap_; |
| 50 uintptr_t marked_bytes_; | 61 uintptr_t marked_bytes_; |
| 62 intptr_t done_count_; |
| 51 | 63 |
| 64 friend class MarkTask; |
| 52 DISALLOW_IMPLICIT_CONSTRUCTORS(GCMarker); | 65 DISALLOW_IMPLICIT_CONSTRUCTORS(GCMarker); |
| 53 }; | 66 }; |
| 54 | 67 |
| 55 } // namespace dart | 68 } // namespace dart |
| 56 | 69 |
| 57 #endif // VM_GC_MARKER_H_ | 70 #endif // VM_GC_MARKER_H_ |
| OLD | NEW |