Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | // Author: cshapiro@google.com (Carl Shapiro) |
| 3 | |
| 4 | #ifndef ART_SRC_MARK_SWEEP_H_ |
| 5 | #define ART_SRC_MARK_SWEEP_H_ |
| 6 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame^] | 7 | #include "macros.h" |
| 8 | #include "mark_stack.h" |
| 9 | #include "object_bitmap.h" |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 10 | |
| 11 | namespace art { |
| 12 | |
| 13 | class Class; |
| 14 | class Object; |
| 15 | |
| 16 | class MarkSweep { |
| 17 | public: |
| 18 | ~MarkSweep(); |
| 19 | |
| 20 | // Marks the root set at the start of a garbage collection. |
| 21 | void MarkRoots(); |
| 22 | |
| 23 | // Remarks the root set after completing the concurrent mark. |
| 24 | void ReMarkRoots(); |
| 25 | |
| 26 | // Sweeps unmarked objects to complete the garbage collection. |
| 27 | void Sweep(); |
| 28 | |
| 29 | private: |
| 30 | // Returns true if the object has its bit set in the mark bitmap. |
| 31 | bool IsMarked(const Object* object) const { |
| 32 | return mark_bitmap_->Test(object); |
| 33 | } |
| 34 | |
| 35 | // Marks an object. |
| 36 | void MarkObject(const Object* obj); |
| 37 | |
| 38 | // Yuck. |
| 39 | void MarkObject0(const Object* obj, bool check_finger); |
| 40 | |
| 41 | // Blackens an object. |
| 42 | void ScanObject(const Object* obj); |
| 43 | |
| 44 | // Grays references in instance fields. |
| 45 | void ScanInstanceFields(const Object* obj); |
| 46 | |
| 47 | // Blackens a class object. |
| 48 | void ScanClass(const Object* obj); |
| 49 | |
| 50 | // Grays references in static fields. |
| 51 | void ScanStaticFields(const Class* klass); |
| 52 | |
| 53 | // Grays interface class objects. |
| 54 | void ScanInterfaces(const Class* klass); |
| 55 | |
| 56 | // Grays references in an array. |
| 57 | void ScanArray(const Object* obj); |
| 58 | |
| 59 | void ScanDataObject(const Object* obj); |
| 60 | |
| 61 | // Blackens objects grayed during a garbage collection. |
| 62 | void ScanDirtyObjects(); |
| 63 | |
| 64 | // Schedules an unmarked object for reference processing. |
| 65 | void DelayReferenceReferent(Object* reference); |
| 66 | |
| 67 | // Recursively blackens objects on the mark stack. |
| 68 | void ProcessMarkStack(); |
| 69 | |
| 70 | // Adds a reference to the tail of a circular queue of references. |
| 71 | static void EnqueuePendingReference(Object* ref, Object** list); |
| 72 | |
| 73 | // Removes the reference at the head of a circular queue of |
| 74 | // references. |
| 75 | static Object* DequeuePendingReference(Object** list); |
| 76 | |
| 77 | // Sets the referent field of a reference object to null. |
| 78 | static void ClearReference(Object* reference); |
| 79 | |
| 80 | // Returns true if the reference object has not yet been enqueued. |
| 81 | static bool IsEnqueuable(const Object* ref); |
| 82 | |
| 83 | void EnqueueReference(Object* ref); |
| 84 | |
| 85 | void EnqueueFinalizerReferences(Object** ref); |
| 86 | |
| 87 | void PreserveSomeSoftReferences(Object** ref); |
| 88 | |
| 89 | void EnqueueClearedReferences(Object** cleared_references); |
| 90 | |
| 91 | void ClearWhiteReferences(Object** list); |
| 92 | |
| 93 | void ProcessReferences(Object** soft_references, bool clear_soft, |
| 94 | Object** weak_references, |
| 95 | Object** finalizer_references, |
| 96 | Object** phantom_references); |
| 97 | |
| 98 | MarkStack* mark_stack_; |
| 99 | |
| 100 | HeapBitmap* mark_bitmap_; |
| 101 | |
| 102 | // HeapBitmap* alloc_bitmap_; |
| 103 | |
| 104 | Object* finger_; |
| 105 | |
| 106 | Object* condemned_; |
| 107 | |
| 108 | Object* soft_reference_list_; |
| 109 | |
| 110 | Object* weak_reference_list_; |
| 111 | |
| 112 | Object* finalizer_reference_list_; |
| 113 | |
| 114 | Object* phantom_reference_list_; |
| 115 | |
| 116 | Object* cleared_reference_list_; |
| 117 | |
| 118 | static size_t reference_referent_offset_; |
| 119 | |
| 120 | static size_t reference_queue_offset_; |
| 121 | |
| 122 | static size_t reference_queueNext_offset_; |
| 123 | |
| 124 | static size_t reference_pendingNext_offset_; |
| 125 | |
| 126 | static size_t finalizer_reference_zombie_offset_; |
| 127 | |
| 128 | DISALLOW_COPY_AND_ASSIGN(MarkSweep); |
| 129 | }; |
| 130 | |
| 131 | } // namespace art |
| 132 | |
| 133 | #endif // ART_SRC_MARK_SWEEP_H_ |