blob: 4cc6b223390bffffa9a350517b4a9048046bd377 [file] [log] [blame]
Carl Shapiro69759ea2011-07-21 18:13:35 -07001// Copyright 2011 Google Inc. All Rights Reserved.
Carl Shapiro69759ea2011-07-21 18:13:35 -07002
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07003#include "mark_sweep.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -07004
Carl Shapiro58551df2011-07-24 03:09:51 -07005#include <climits>
6#include <vector>
7
Elliott Hughes410c0c82011-09-01 17:58:25 -07008#include "class_loader.h"
Brian Carlstrom693267a2011-09-06 09:25:34 -07009#include "dex_cache.h"
Carl Shapiro58551df2011-07-24 03:09:51 -070010#include "heap.h"
Elliott Hughes410c0c82011-09-01 17:58:25 -070011#include "indirect_reference_table.h"
12#include "intern_table.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070013#include "logging.h"
14#include "macros.h"
15#include "mark_stack.h"
Elliott Hughesc33a32b2011-10-11 18:18:07 -070016#include "monitor.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070017#include "object.h"
Brian Carlstrom1f870082011-08-23 16:02:11 -070018#include "runtime.h"
Carl Shapiro58551df2011-07-24 03:09:51 -070019#include "space.h"
Elliott Hughes307f75d2011-10-12 18:04:40 -070020#include "timing_logger.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070021#include "thread.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -070022
Carl Shapiro69759ea2011-07-21 18:13:35 -070023namespace art {
24
Carl Shapiro58551df2011-07-24 03:09:51 -070025bool MarkSweep::Init() {
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070026 mark_stack_ = MarkStack::Create();
Carl Shapiro58551df2011-07-24 03:09:51 -070027 if (mark_stack_ == NULL) {
28 return false;
29 }
30
31 mark_bitmap_ = Heap::GetMarkBits();
32 live_bitmap_ = Heap::GetLiveBits();
33
34 // TODO: if concurrent, clear the card table.
35
buzbee0d966cf2011-09-08 17:34:58 -070036 // TODO: if concurrent, enable card marking in compiler
37
Carl Shapiro58551df2011-07-24 03:09:51 -070038 // TODO: check that the mark bitmap is entirely clear.
39
40 return true;
41}
42
Elliott Hughesb0663112011-10-19 18:16:37 -070043inline void MarkSweep::MarkObject0(const Object* obj, bool check_finger) {
Carl Shapiro69759ea2011-07-21 18:13:35 -070044 DCHECK(obj != NULL);
45 if (obj < condemned_) {
46 DCHECK(IsMarked(obj));
47 return;
48 }
49 bool is_marked = mark_bitmap_->Test(obj);
50 // This object was not previously marked.
51 if (!is_marked) {
52 mark_bitmap_->Set(obj);
53 if (check_finger && obj < finger_) {
54 // The object must be pushed on to the mark stack.
55 mark_stack_->Push(obj);
56 }
57 }
58}
59
60// Used to mark objects when recursing. Recursion is done by moving
61// the finger across the bitmaps in address order and marking child
62// objects. Any newly-marked objects whose addresses are lower than
63// the finger won't be visited by the bitmap scan, so those objects
64// need to be added to the mark stack.
Elliott Hughesb0663112011-10-19 18:16:37 -070065inline void MarkSweep::MarkObject(const Object* obj) {
Carl Shapiro69759ea2011-07-21 18:13:35 -070066 if (obj != NULL) {
67 MarkObject0(obj, true);
68 }
69}
70
Elliott Hughescf4c6c42011-09-01 15:16:42 -070071void MarkSweep::MarkObjectVisitor(const Object* root, void* arg) {
Brian Carlstrom1f870082011-08-23 16:02:11 -070072 DCHECK(root != NULL);
73 DCHECK(arg != NULL);
74 MarkSweep* mark_sweep = reinterpret_cast<MarkSweep*>(arg);
75 mark_sweep->MarkObject0(root, true);
76}
77
Carl Shapiro69759ea2011-07-21 18:13:35 -070078// Marks all objects in the root set.
79void MarkSweep::MarkRoots() {
Brian Carlstrom1f870082011-08-23 16:02:11 -070080 Runtime::Current()->VisitRoots(MarkObjectVisitor, this);
Carl Shapiro69759ea2011-07-21 18:13:35 -070081}
82
Carl Shapiro58551df2011-07-24 03:09:51 -070083void MarkSweep::ScanBitmapCallback(Object* obj, void* finger, void* arg) {
84 MarkSweep* mark_sweep = reinterpret_cast<MarkSweep*>(arg);
85 mark_sweep->finger_ = reinterpret_cast<Object*>(finger);
86 mark_sweep->ScanObject(obj);
87}
88
89// Populates the mark stack based on the set of marked objects and
90// recursively marks until the mark stack is emptied.
91void MarkSweep::RecursiveMark() {
Brian Carlstrom1f870082011-08-23 16:02:11 -070092 // RecursiveMark will build the lists of known instances of the Reference classes.
93 // See DelayReferenceReferent for details.
94 CHECK(soft_reference_list_ == NULL);
95 CHECK(weak_reference_list_ == NULL);
96 CHECK(finalizer_reference_list_ == NULL);
97 CHECK(phantom_reference_list_ == NULL);
98 CHECK(cleared_reference_list_ == NULL);
99
Elliott Hughes307f75d2011-10-12 18:04:40 -0700100 TimingLogger timings("MarkSweep::RecursiveMark");
Carl Shapiro58551df2011-07-24 03:09:51 -0700101 void* arg = reinterpret_cast<void*>(this);
102 const std::vector<Space*>& spaces = Heap::GetSpaces();
103 for (size_t i = 0; i < spaces.size(); ++i) {
Elliott Hughes307f75d2011-10-12 18:04:40 -0700104 if (!spaces[i]->IsImageSpace()) {
Carl Shapiro58551df2011-07-24 03:09:51 -0700105 uintptr_t base = reinterpret_cast<uintptr_t>(spaces[i]->GetBase());
Brian Carlstrom1f870082011-08-23 16:02:11 -0700106 mark_bitmap_->ScanWalk(base, &MarkSweep::ScanBitmapCallback, arg);
Carl Shapiro58551df2011-07-24 03:09:51 -0700107 }
Elliott Hughes307f75d2011-10-12 18:04:40 -0700108 timings.AddSplit(StringPrintf("ScanWalk space #%i (%s)", i, spaces[i]->GetName().c_str()));
Carl Shapiro58551df2011-07-24 03:09:51 -0700109 }
110 finger_ = reinterpret_cast<Object*>(~0);
111 ProcessMarkStack();
Elliott Hughes307f75d2011-10-12 18:04:40 -0700112 timings.AddSplit("ProcessMarkStack");
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700113 if (Heap::IsVerboseHeap()) {
114 timings.Dump();
115 }
Carl Shapiro58551df2011-07-24 03:09:51 -0700116}
117
118void MarkSweep::ReMarkRoots() {
Elliott Hughes53b61312011-08-12 18:28:20 -0700119 UNIMPLEMENTED(FATAL);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700120}
121
Elliott Hughes410c0c82011-09-01 17:58:25 -0700122void MarkSweep::SweepJniWeakGlobals() {
123 JavaVMExt* vm = Runtime::Current()->GetJavaVM();
124 MutexLock mu(vm->weak_globals_lock);
125 IndirectReferenceTable* table = &vm->weak_globals;
126 typedef IndirectReferenceTable::iterator It; // TODO: C++0x auto
127 for (It it = table->begin(), end = table->end(); it != end; ++it) {
128 const Object** entry = *it;
129 if (!IsMarked(*entry)) {
130 *entry = kClearedJniWeakGlobal;
131 }
132 }
133}
134
Elliott Hughes410c0c82011-09-01 17:58:25 -0700135void MarkSweep::SweepSystemWeaks() {
Elliott Hughesc33a32b2011-10-11 18:18:07 -0700136 Runtime::Current()->GetInternTable()->SweepInternTableWeaks(IsMarked, this);
137 Runtime::Current()->GetMonitorList()->SweepMonitorList(IsMarked, this);
Elliott Hughes410c0c82011-09-01 17:58:25 -0700138 SweepJniWeakGlobals();
Carl Shapiro58551df2011-07-24 03:09:51 -0700139}
140
Brian Carlstrom78128a62011-09-15 17:21:19 -0700141void MarkSweep::SweepCallback(size_t num_ptrs, void** ptrs, void* arg) {
Elliott Hughes362f9bc2011-10-17 18:56:41 -0700142 // TODO: lock heap if concurrent
Elliott Hughes307f75d2011-10-12 18:04:40 -0700143 size_t freed_objects = num_ptrs;
144 size_t freed_bytes = 0;
Carl Shapiro58551df2011-07-24 03:09:51 -0700145 Space* space = static_cast<Space*>(arg);
146 for (size_t i = 0; i < num_ptrs; ++i) {
147 Object* obj = static_cast<Object*>(ptrs[i]);
Elliott Hughes307f75d2011-10-12 18:04:40 -0700148 freed_bytes += space->AllocationSize(obj);
Elliott Hughes1e200942011-10-12 18:59:24 -0700149 Heap::GetLiveBits()->Clear(obj);
Carl Shapiro58551df2011-07-24 03:09:51 -0700150 space->Free(obj);
151 }
Elliott Hughes307f75d2011-10-12 18:04:40 -0700152 Heap::RecordFreeLocked(freed_objects, freed_bytes);
Elliott Hughes362f9bc2011-10-17 18:56:41 -0700153 // TODO: unlock heap if concurrent
Carl Shapiro58551df2011-07-24 03:09:51 -0700154}
155
156void MarkSweep::Sweep() {
Elliott Hughes2da50362011-10-10 16:57:08 -0700157 SweepSystemWeaks();
158
Carl Shapiro58551df2011-07-24 03:09:51 -0700159 const std::vector<Space*>& spaces = Heap::GetSpaces();
160 for (size_t i = 0; i < spaces.size(); ++i) {
Elliott Hughes307f75d2011-10-12 18:04:40 -0700161 if (!spaces[i]->IsImageSpace()) {
Carl Shapiro58551df2011-07-24 03:09:51 -0700162 uintptr_t base = reinterpret_cast<uintptr_t>(spaces[i]->GetBase());
163 uintptr_t limit = reinterpret_cast<uintptr_t>(spaces[i]->GetLimit());
164 void* arg = static_cast<void*>(spaces[i]);
165 HeapBitmap::SweepWalk(*live_bitmap_, *mark_bitmap_, base, limit,
166 &MarkSweep::SweepCallback, arg);
167 }
168 }
169}
170
Carl Shapiro69759ea2011-07-21 18:13:35 -0700171// Scans instance fields.
Elliott Hughesb0663112011-10-19 18:16:37 -0700172inline void MarkSweep::ScanInstanceFields(const Object* obj) {
Carl Shapiro69759ea2011-07-21 18:13:35 -0700173 DCHECK(obj != NULL);
Brian Carlstrom4873d462011-08-21 15:23:39 -0700174 Class* klass = obj->GetClass();
175 DCHECK(klass != NULL);
Elliott Hughes2da50362011-10-10 16:57:08 -0700176 ScanFields(obj, klass->GetReferenceInstanceOffsets(), false);
Brian Carlstrom4873d462011-08-21 15:23:39 -0700177}
178
179// Scans static storage on a Class.
Elliott Hughesb0663112011-10-19 18:16:37 -0700180inline void MarkSweep::ScanStaticFields(const Class* klass) {
Brian Carlstrom4873d462011-08-21 15:23:39 -0700181 DCHECK(klass != NULL);
Elliott Hughesadb460d2011-10-05 17:02:34 -0700182 ScanFields(klass, klass->GetReferenceStaticOffsets(), true);
Brian Carlstrom4873d462011-08-21 15:23:39 -0700183}
184
Elliott Hughesb0663112011-10-19 18:16:37 -0700185inline void MarkSweep::ScanFields(const Object* obj, uint32_t ref_offsets, bool is_static) {
Carl Shapiro69759ea2011-07-21 18:13:35 -0700186 if (ref_offsets != CLASS_WALK_SUPER) {
187 // Found a reference offset bitmap. Mark the specified offsets.
188 while (ref_offsets != 0) {
189 size_t right_shift = CLZ(ref_offsets);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700190 MemberOffset byte_offset = CLASS_OFFSET_FROM_CLZ(right_shift);
191 const Object* ref = obj->GetFieldObject<const Object*>(byte_offset, false);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700192 MarkObject(ref);
193 ref_offsets &= ~(CLASS_HIGH_BIT >> right_shift);
194 }
195 } else {
Brian Carlstrom4873d462011-08-21 15:23:39 -0700196 // There is no reference offset bitmap. In the non-static case,
197 // walk up the class inheritance hierarchy and find reference
198 // offsets the hard way. In the static case, just consider this
199 // class.
200 for (const Class* klass = is_static ? obj->AsClass() : obj->GetClass();
Carl Shapiro69759ea2011-07-21 18:13:35 -0700201 klass != NULL;
Brian Carlstrom4873d462011-08-21 15:23:39 -0700202 klass = is_static ? NULL : klass->GetSuperClass()) {
203 size_t num_reference_fields = (is_static
204 ? klass->NumReferenceStaticFields()
205 : klass->NumReferenceInstanceFields());
206 for (size_t i = 0; i < num_reference_fields; ++i) {
207 Field* field = (is_static
208 ? klass->GetStaticField(i)
209 : klass->GetInstanceField(i));
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700210 MemberOffset field_offset = field->GetOffset();
211 const Object* ref = obj->GetFieldObject<const Object*>(field_offset, false);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700212 MarkObject(ref);
213 }
214 }
215 }
216}
217
Carl Shapiro69759ea2011-07-21 18:13:35 -0700218// Scans the header, static field references, and interface pointers
219// of a class object.
Elliott Hughesb0663112011-10-19 18:16:37 -0700220inline void MarkSweep::ScanClass(const Object* obj) {
Brian Carlstrom693267a2011-09-06 09:25:34 -0700221 ScanInstanceFields(obj);
Brian Carlstrom40381fb2011-10-19 14:13:40 -0700222 ScanStaticFields(obj->AsClass());
Carl Shapiro69759ea2011-07-21 18:13:35 -0700223}
224
225// Scans the header of all array objects. If the array object is
226// specialized to a reference type, scans the array data as well.
Elliott Hughesb0663112011-10-19 18:16:37 -0700227inline void MarkSweep::ScanArray(const Object* obj) {
Carl Shapiro69759ea2011-07-21 18:13:35 -0700228 DCHECK(obj != NULL);
229 DCHECK(obj->GetClass() != NULL);
230 MarkObject(obj->GetClass());
231 if (obj->IsObjectArray()) {
Brian Carlstromdb4d5402011-08-09 12:18:28 -0700232 const ObjectArray<Object>* array = obj->AsObjectArray<Object>();
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700233 for (int32_t i = 0; i < array->GetLength(); ++i) {
Carl Shapiro69759ea2011-07-21 18:13:35 -0700234 const Object* element = array->Get(i);
235 MarkObject(element);
236 }
237 }
238}
239
Carl Shapiro69759ea2011-07-21 18:13:35 -0700240// Process the "referent" field in a java.lang.ref.Reference. If the
241// referent has not yet been marked, put it on the appropriate list in
242// the gcHeap for later processing.
243void MarkSweep::DelayReferenceReferent(Object* obj) {
244 DCHECK(obj != NULL);
Brian Carlstrom1f870082011-08-23 16:02:11 -0700245 Class* klass = obj->GetClass();
246 DCHECK(klass != NULL);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700247 DCHECK(klass->IsReferenceClass());
248 Object* pending = obj->GetFieldObject<Object*>(Heap::GetReferencePendingNextOffset(), false);
Elliott Hughesadb460d2011-10-05 17:02:34 -0700249 Object* referent = Heap::GetReferenceReferent(obj);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700250 if (pending == NULL && referent != NULL && !IsMarked(referent)) {
Brian Carlstrom4873d462011-08-21 15:23:39 -0700251 Object** list = NULL;
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700252 if (klass->IsSoftReferenceClass()) {
Carl Shapiro69759ea2011-07-21 18:13:35 -0700253 list = &soft_reference_list_;
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700254 } else if (klass->IsWeakReferenceClass()) {
Carl Shapiro69759ea2011-07-21 18:13:35 -0700255 list = &weak_reference_list_;
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700256 } else if (klass->IsFinalizerReferenceClass()) {
Carl Shapiro69759ea2011-07-21 18:13:35 -0700257 list = &finalizer_reference_list_;
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700258 } else if (klass->IsPhantomReferenceClass()) {
Carl Shapiro69759ea2011-07-21 18:13:35 -0700259 list = &phantom_reference_list_;
260 }
Brian Carlstrom0796af02011-10-12 14:31:45 -0700261 DCHECK(list != NULL) << PrettyClass(klass) << " " << std::hex << klass->GetAccessFlags();
Elliott Hughesadb460d2011-10-05 17:02:34 -0700262 Heap::EnqueuePendingReference(obj, list);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700263 }
264}
265
266// Scans the header and field references of a data object. If the
267// scanned object is a reference subclass, it is scheduled for later
Elliott Hughesadb460d2011-10-05 17:02:34 -0700268// processing.
Elliott Hughesb0663112011-10-19 18:16:37 -0700269inline void MarkSweep::ScanOther(const Object* obj) {
Carl Shapiro69759ea2011-07-21 18:13:35 -0700270 DCHECK(obj != NULL);
Brian Carlstrom1f870082011-08-23 16:02:11 -0700271 Class* klass = obj->GetClass();
272 DCHECK(klass != NULL);
273 MarkObject(klass);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700274 ScanInstanceFields(obj);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700275 if (klass->IsReferenceClass()) {
Carl Shapiro69759ea2011-07-21 18:13:35 -0700276 DelayReferenceReferent(const_cast<Object*>(obj));
277 }
278}
279
280// Scans an object reference. Determines the type of the reference
281// and dispatches to a specialized scanning routine.
Elliott Hughesb0663112011-10-19 18:16:37 -0700282inline void MarkSweep::ScanObject(const Object* obj) {
Carl Shapiro69759ea2011-07-21 18:13:35 -0700283 DCHECK(obj != NULL);
284 DCHECK(obj->GetClass() != NULL);
285 DCHECK(IsMarked(obj));
286 if (obj->IsClass()) {
287 ScanClass(obj);
Brian Carlstromb63ec392011-08-27 17:38:27 -0700288 } else if (obj->IsArrayInstance()) {
Carl Shapiro69759ea2011-07-21 18:13:35 -0700289 ScanArray(obj);
290 } else {
Carl Shapiro58551df2011-07-24 03:09:51 -0700291 ScanOther(obj);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700292 }
293}
294
295// Scan anything that's on the mark stack. We can't use the bitmaps
296// anymore, so use a finger that points past the end of them.
297void MarkSweep::ProcessMarkStack() {
298 while (!mark_stack_->IsEmpty()) {
Brian Carlstrom4873d462011-08-21 15:23:39 -0700299 const Object* obj = mark_stack_->Pop();
Carl Shapiro69759ea2011-07-21 18:13:35 -0700300 ScanObject(obj);
301 }
302}
303
304void MarkSweep::ScanDirtyObjects() {
305 ProcessMarkStack();
306}
307
Carl Shapiro69759ea2011-07-21 18:13:35 -0700308// Walks the reference list marking any references subject to the
309// reference clearing policy. References with a black referent are
310// removed from the list. References with white referents biased
311// toward saving are blackened and also removed from the list.
312void MarkSweep::PreserveSomeSoftReferences(Object** list) {
313 DCHECK(list != NULL);
314 Object* clear = NULL;
315 size_t counter = 0;
316 while (*list != NULL) {
Elliott Hughesadb460d2011-10-05 17:02:34 -0700317 Object* ref = Heap::DequeuePendingReference(list);
318 Object* referent = Heap::GetReferenceReferent(ref);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700319 if (referent == NULL) {
320 // Referent was cleared by the user during marking.
321 continue;
322 }
323 bool is_marked = IsMarked(referent);
324 if (!is_marked && ((++counter) & 1)) {
325 // Referent is white and biased toward saving, mark it.
326 MarkObject(referent);
327 is_marked = true;
328 }
329 if (!is_marked) {
330 // Referent is white, queue it for clearing.
Elliott Hughesadb460d2011-10-05 17:02:34 -0700331 Heap::EnqueuePendingReference(ref, &clear);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700332 }
333 }
334 *list = clear;
335 // Restart the mark with the newly black references added to the
336 // root set.
337 ProcessMarkStack();
338}
339
340// Unlink the reference list clearing references objects with white
341// referents. Cleared references registered to a reference queue are
342// scheduled for appending by the heap worker thread.
343void MarkSweep::ClearWhiteReferences(Object** list) {
344 DCHECK(list != NULL);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700345 while (*list != NULL) {
Elliott Hughesadb460d2011-10-05 17:02:34 -0700346 Object* ref = Heap::DequeuePendingReference(list);
347 Object* referent = Heap::GetReferenceReferent(ref);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700348 if (referent != NULL && !IsMarked(referent)) {
349 // Referent is white, clear it.
Elliott Hughesadb460d2011-10-05 17:02:34 -0700350 Heap::ClearReferenceReferent(ref);
351 if (Heap::IsEnqueuable(ref)) {
352 Heap::EnqueueReference(ref, &cleared_reference_list_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700353 }
354 }
355 }
356 DCHECK(*list == NULL);
357}
358
359// Enqueues finalizer references with white referents. White
360// referents are blackened, moved to the zombie field, and the
361// referent field is cleared.
362void MarkSweep::EnqueueFinalizerReferences(Object** list) {
363 DCHECK(list != NULL);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700364 MemberOffset zombie_offset = Heap::GetFinalizerReferenceZombieOffset();
Carl Shapiro69759ea2011-07-21 18:13:35 -0700365 bool has_enqueued = false;
366 while (*list != NULL) {
Elliott Hughesadb460d2011-10-05 17:02:34 -0700367 Object* ref = Heap::DequeuePendingReference(list);
368 Object* referent = Heap::GetReferenceReferent(ref);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700369 if (referent != NULL && !IsMarked(referent)) {
370 MarkObject(referent);
371 // If the referent is non-null the reference must queuable.
Elliott Hughesadb460d2011-10-05 17:02:34 -0700372 DCHECK(Heap::IsEnqueuable(ref));
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700373 ref->SetFieldObject(zombie_offset, referent, false);
Elliott Hughesadb460d2011-10-05 17:02:34 -0700374 Heap::ClearReferenceReferent(ref);
375 Heap::EnqueueReference(ref, &cleared_reference_list_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700376 has_enqueued = true;
377 }
378 }
379 if (has_enqueued) {
380 ProcessMarkStack();
381 }
382 DCHECK(*list == NULL);
383}
384
Carl Shapiro58551df2011-07-24 03:09:51 -0700385// Process reference class instances and schedule finalizations.
Carl Shapiro69759ea2011-07-21 18:13:35 -0700386void MarkSweep::ProcessReferences(Object** soft_references, bool clear_soft,
387 Object** weak_references,
388 Object** finalizer_references,
389 Object** phantom_references) {
390 DCHECK(soft_references != NULL);
391 DCHECK(weak_references != NULL);
392 DCHECK(finalizer_references != NULL);
393 DCHECK(phantom_references != NULL);
394
395 // Unless we are in the zygote or required to clear soft references
396 // with white references, preserve some white referents.
397 if (clear_soft) {
398 PreserveSomeSoftReferences(soft_references);
399 }
400
401 // Clear all remaining soft and weak references with white
402 // referents.
403 ClearWhiteReferences(soft_references);
404 ClearWhiteReferences(weak_references);
405
406 // Preserve all white objects with finalize methods and schedule
407 // them for finalization.
408 EnqueueFinalizerReferences(finalizer_references);
409
410 // Clear all f-reachable soft and weak references with white
411 // referents.
412 ClearWhiteReferences(soft_references);
413 ClearWhiteReferences(weak_references);
414
415 // Clear all phantom references with white referents.
416 ClearWhiteReferences(phantom_references);
417
418 // At this point all reference lists should be empty.
419 DCHECK(*soft_references == NULL);
420 DCHECK(*weak_references == NULL);
421 DCHECK(*finalizer_references == NULL);
422 DCHECK(*phantom_references == NULL);
423}
424
Carl Shapiro69759ea2011-07-21 18:13:35 -0700425MarkSweep::~MarkSweep() {
Carl Shapiro58551df2011-07-24 03:09:51 -0700426 delete mark_stack_;
Carl Shapiro69759ea2011-07-21 18:13:35 -0700427 mark_bitmap_->Clear();
428}
429
430} // namespace art