blob: bb48b7a3da060c164fef326ea02923f13c57ccf0 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Carl Shapiro69759ea2011-07-21 18:13:35 -070016
17#ifndef ART_SRC_MARK_SWEEP_H_
18#define ART_SRC_MARK_SWEEP_H_
19
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070020#include "macros.h"
21#include "mark_stack.h"
Elliott Hughes5e71b522011-10-20 13:12:32 -070022#include "heap_bitmap.h"
Mathieu Chartierb43b7d42012-06-19 13:15:09 -070023#include "object.h"
Ian Rogers0cfe1fb2011-08-26 03:29:44 -070024#include "offsets.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -070025
26namespace art {
27
Mathieu Chartierb43b7d42012-06-19 13:15:09 -070028class CheckObjectVisitor;
Carl Shapiro69759ea2011-07-21 18:13:35 -070029class Class;
Elliott Hughesb3bd5f02012-03-08 21:05:27 -080030class Heap;
Mathieu Chartierb43b7d42012-06-19 13:15:09 -070031class MarkIfReachesAllocspaceVisitor;
32class ModUnionClearCardVisitor;
33class ModUnionVisitor;
34class ModUnionTableBitmap;
Carl Shapiro69759ea2011-07-21 18:13:35 -070035class Object;
36
37class MarkSweep {
38 public:
Elliott Hughes74847412012-06-20 18:10:21 -070039 explicit MarkSweep(MarkStack* mark_stack);
Carl Shapiro58551df2011-07-24 03:09:51 -070040
Carl Shapiro69759ea2011-07-21 18:13:35 -070041 ~MarkSweep();
42
Carl Shapiro58551df2011-07-24 03:09:51 -070043 // Initializes internal structures.
Jesse Wilson078f9b02011-11-18 17:51:47 -050044 void Init();
Carl Shapiro58551df2011-07-24 03:09:51 -070045
Carl Shapiro69759ea2011-07-21 18:13:35 -070046 // Marks the root set at the start of a garbage collection.
Ian Rogers00f7d0e2012-07-19 15:28:27 -070047 void MarkRoots()
48 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
49 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -070050
Mathieu Chartier262e5ff2012-06-01 17:35:38 -070051 // Marks the roots in the image space on dirty cards.
Ian Rogers00f7d0e2012-07-19 15:28:27 -070052 void ScanDirtyImageRoots() EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Ian Rogers5d76c432011-10-31 21:42:49 -070053
Mathieu Chartier262e5ff2012-06-01 17:35:38 -070054 // Verify that image roots point to only marked objects within the alloc space.
Ian Rogers00f7d0e2012-07-19 15:28:27 -070055 void VerifyImageRoots() EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Mathieu Chartier262e5ff2012-06-01 17:35:38 -070056
Ian Rogers5d76c432011-10-31 21:42:49 -070057 bool IsMarkStackEmpty() const {
58 return mark_stack_->IsEmpty();
59 }
60
Carl Shapiro58551df2011-07-24 03:09:51 -070061 // Builds a mark stack and recursively mark until it empties.
Ian Rogers00f7d0e2012-07-19 15:28:27 -070062 void RecursiveMark(bool partial)
63 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
64 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Mathieu Chartiercc236d72012-07-20 10:29:05 -070065
66 // Copies mark bits from live bitmap of zygote space to mark bitmap for partial GCs.
67 void CopyMarkBits();
Carl Shapiro58551df2011-07-24 03:09:51 -070068
Mathieu Chartier262e5ff2012-06-01 17:35:38 -070069 // Builds a mark stack with objects on dirty cards and recursively mark
70 // until it empties.
Ian Rogers00f7d0e2012-07-19 15:28:27 -070071 void RecursiveMarkDirtyObjects()
72 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
73 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Mathieu Chartier262e5ff2012-06-01 17:35:38 -070074
Carl Shapiro69759ea2011-07-21 18:13:35 -070075 // Remarks the root set after completing the concurrent mark.
Ian Rogers00f7d0e2012-07-19 15:28:27 -070076 void ReMarkRoots()
77 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
78 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -070079
Mathieu Chartiercc236d72012-07-20 10:29:05 -070080 Heap* GetHeap() {
81 return heap_;
82 }
83
Ian Rogers00f7d0e2012-07-19 15:28:27 -070084 void ProcessReferences(bool clear_soft_references)
85 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
86 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
Carl Shapiro58551df2011-07-24 03:09:51 -070087 ProcessReferences(&soft_reference_list_, clear_soft_references,
88 &weak_reference_list_,
89 &finalizer_reference_list_,
90 &phantom_reference_list_);
91 }
92
Carl Shapiro69759ea2011-07-21 18:13:35 -070093 // Sweeps unmarked objects to complete the garbage collection.
Ian Rogers00f7d0e2012-07-19 15:28:27 -070094 void Sweep(bool partial) EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -070095
Elliott Hughesadb460d2011-10-05 17:02:34 -070096 Object* GetClearedReferences() {
97 return cleared_reference_list_;
98 }
99
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700100 // Blackens an object.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700101 void ScanObject(const Object* obj)
102 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
103 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700104
Carl Shapiro69759ea2011-07-21 18:13:35 -0700105 private:
106 // Returns true if the object has its bit set in the mark bitmap.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700107 bool IsMarked(const Object* object) const
108 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_) {
Mathieu Chartierb062fdd2012-07-03 09:51:48 -0700109 if (current_mark_bitmap_->HasAddress(object)) {
110 return current_mark_bitmap_->Test(object);
111 }
112 return heap_->GetMarkBitmap()->Test(object);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700113 }
114
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700115 static bool IsMarkedCallback(const Object* object, void* arg)
116 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_) {
Elliott Hughesc33a32b2011-10-11 18:18:07 -0700117 return reinterpret_cast<MarkSweep*>(arg)->IsMarked(object);
118 }
119
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700120 static bool IsLiveCallback(const Object* object, void* arg)
121 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_) {
Mathieu Chartier46a23632012-08-07 18:44:40 -0700122 return reinterpret_cast<MarkSweep*>(arg)->GetHeap()->GetLiveBitmap()->Test(object);
123 }
124
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700125 static void MarkObjectVisitor(const Object* root, void* arg)
126 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Brian Carlstrom1f870082011-08-23 16:02:11 -0700127
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700128 static void ReMarkObjectVisitor(const Object* root, void* arg)
129 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Mathieu Chartier262e5ff2012-06-01 17:35:38 -0700130
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700131 static void VerifyImageRootVisitor(Object* root, void* arg)
132 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_,
133 GlobalSynchronization::mutator_lock_);
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700134
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700135 static void ScanDirtyCardCallback(Object* obj, void* arg)
136 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
137 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Mathieu Chartier262e5ff2012-06-01 17:35:38 -0700138
Carl Shapiro69759ea2011-07-21 18:13:35 -0700139 // Marks an object.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700140 void MarkObject(const Object* obj)
141 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700142
143 // Yuck.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700144 void MarkObject0(const Object* obj, bool check_finger)
145 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700146
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700147 static void ScanBitmapCallback(Object* obj, void* finger, void* arg)
148 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
149 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro58551df2011-07-24 03:09:51 -0700150
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700151
152 static void SweepCallback(size_t num_ptrs, Object** ptrs, void* arg)
153 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Carl Shapiro58551df2011-07-24 03:09:51 -0700154
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700155 // Special sweep for zygote that just marks objects / dirties cards.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700156 static void ZygoteSweepCallback(size_t num_ptrs, Object** ptrs, void* arg)
157 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Ian Rogers5d76c432011-10-31 21:42:49 -0700158
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700159 void CheckReference(const Object* obj, const Object* ref, MemberOffset offset, bool is_static)
160 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_,
161 GlobalSynchronization::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700162
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700163 void CheckObject(const Object* obj)
164 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_,
165 GlobalSynchronization::mutator_lock_);
Ian Rogers5d76c432011-10-31 21:42:49 -0700166
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700167 template <typename Visitor>
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700168 void VisitObjectReferences(const Object* obj, const Visitor& visitor)
169 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_,
170 GlobalSynchronization::mutator_lock_) {
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700171 DCHECK(obj != NULL);
172 DCHECK(obj->GetClass() != NULL);
173 if (obj->IsClass()) {
174 VisitClassReferences(obj, visitor);
175 } else if (obj->IsArrayInstance()) {
176 VisitArrayReferences(obj, visitor);
177 } else {
178 VisitOtherReferences(obj, visitor);
179 }
180 }
181
Carl Shapiro69759ea2011-07-21 18:13:35 -0700182 // Grays references in instance fields.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700183 void ScanInstanceFields(const Object* obj)
184 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
185 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700186
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700187 template <typename Visitor>
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700188 void VisitInstanceFieldsReferences(const Object* obj, const Visitor& visitor)
189 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
190 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700191 DCHECK(obj != NULL);
192 Class* klass = obj->GetClass();
193 DCHECK(klass != NULL);
194 VisitFieldsReferences(obj, klass->GetReferenceInstanceOffsets(), false, visitor);
195 }
Ian Rogers5d76c432011-10-31 21:42:49 -0700196
Carl Shapiro69759ea2011-07-21 18:13:35 -0700197 // Blackens a class object.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700198 void ScanClass(const Object* obj)
199 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
200 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
201
Carl Shapiro69759ea2011-07-21 18:13:35 -0700202
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700203 template <typename Visitor>
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700204 void VisitClassReferences(const Object* obj, const Visitor& visitor)
205 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_,
206 GlobalSynchronization::mutator_lock_) {
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700207 VisitInstanceFieldsReferences(obj, visitor);
208 VisitStaticFieldsReferences(obj->AsClass(), visitor);
209 }
Ian Rogers5d76c432011-10-31 21:42:49 -0700210
Carl Shapiro69759ea2011-07-21 18:13:35 -0700211 // Grays references in static fields.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700212 void ScanStaticFields(const Class* klass)
213 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
214 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700215
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700216 template <typename Visitor>
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700217 void VisitStaticFieldsReferences(const Class* klass, const Visitor& visitor)
218 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_,
219 GlobalSynchronization::mutator_lock_) {\
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700220 DCHECK(klass != NULL);
221 VisitFieldsReferences(klass, klass->GetReferenceStaticOffsets(), true, visitor);
222 }
Ian Rogers5d76c432011-10-31 21:42:49 -0700223
Brian Carlstrom4873d462011-08-21 15:23:39 -0700224 // Used by ScanInstanceFields and ScanStaticFields
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700225 void ScanFields(const Object* obj, uint32_t ref_offsets, bool is_static)
226 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
227 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstrom4873d462011-08-21 15:23:39 -0700228
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700229 template <typename Visitor>
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700230 void VisitFieldsReferences(const Object* obj, uint32_t ref_offsets, bool is_static,
231 const Visitor& visitor)
232 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_,
233 GlobalSynchronization::mutator_lock_) {
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700234 if (ref_offsets != CLASS_WALK_SUPER) {
235 // Found a reference offset bitmap. Mark the specified offsets.
236 while (ref_offsets != 0) {
237 size_t right_shift = CLZ(ref_offsets);
238 MemberOffset field_offset = CLASS_OFFSET_FROM_CLZ(right_shift);
239 const Object* ref = obj->GetFieldObject<const Object*>(field_offset, false);
240 visitor(obj, ref, field_offset, is_static);
241 ref_offsets &= ~(CLASS_HIGH_BIT >> right_shift);
242 }
243 } else {
244 // There is no reference offset bitmap. In the non-static case,
245 // walk up the class inheritance hierarchy and find reference
246 // offsets the hard way. In the static case, just consider this
247 // class.
248 for (const Class* klass = is_static ? obj->AsClass() : obj->GetClass();
249 klass != NULL;
250 klass = is_static ? NULL : klass->GetSuperClass()) {
251 size_t num_reference_fields = (is_static
252 ? klass->NumReferenceStaticFields()
253 : klass->NumReferenceInstanceFields());
254 for (size_t i = 0; i < num_reference_fields; ++i) {
255 Field* field = (is_static
256 ? klass->GetStaticField(i)
257 : klass->GetInstanceField(i));
258 MemberOffset field_offset = field->GetOffset();
259 const Object* ref = obj->GetFieldObject<const Object*>(field_offset, false);
260 visitor(obj, ref, field_offset, is_static);
261 }
262 }
263 }
264 }
Ian Rogers5d76c432011-10-31 21:42:49 -0700265
Carl Shapiro69759ea2011-07-21 18:13:35 -0700266 // Grays references in an array.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700267 void ScanArray(const Object* obj)
268 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
269 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700270
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700271 template <typename Visitor>
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700272 void VisitArrayReferences(const Object* obj, const Visitor& visitor)
273 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_,
274 GlobalSynchronization::mutator_lock_) {
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700275 visitor(obj, obj->GetClass(), Object::ClassOffset(), false);
276 if (obj->IsObjectArray()) {
277 const ObjectArray<Object>* array = obj->AsObjectArray<Object>();
278 for (int32_t i = 0; i < array->GetLength(); ++i) {
279 const Object* element = array->GetWithoutChecks(i);
280 size_t width = sizeof(Object*);
281 visitor(obj, element, MemberOffset(i * width + Array::DataOffset(width).Int32Value()), false);
282 }
283 }
284 }
Ian Rogers5d76c432011-10-31 21:42:49 -0700285
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700286 void ScanOther(const Object* obj)
287 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
288 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700289
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700290 template <typename Visitor>
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700291 void VisitOtherReferences(const Object* obj, const Visitor& visitor)
292 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_,
293 GlobalSynchronization::mutator_lock_) {
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700294 return VisitInstanceFieldsReferences(obj, visitor);
295 }
Ian Rogers5d76c432011-10-31 21:42:49 -0700296
Carl Shapiro69759ea2011-07-21 18:13:35 -0700297 // Blackens objects grayed during a garbage collection.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700298 void ScanGrayObjects() EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700299
300 // Schedules an unmarked object for reference processing.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700301 void DelayReferenceReferent(Object* reference)
302 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700303
304 // Recursively blackens objects on the mark stack.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700305 void ProcessMarkStack()
306 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
307 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700308
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700309 void EnqueueFinalizerReferences(Object** ref)
310 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
311 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700312
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700313 void PreserveSomeSoftReferences(Object** ref)
314 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
315 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700316
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700317 void ClearWhiteReferences(Object** list)
318 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700319
Carl Shapiro58551df2011-07-24 03:09:51 -0700320 void ProcessReferences(Object** soft_references, bool clear_soft_references,
Carl Shapiro69759ea2011-07-21 18:13:35 -0700321 Object** weak_references,
322 Object** finalizer_references,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700323 Object** phantom_references)
324 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
325 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700326
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700327 void SweepSystemWeaks(bool swap_bitmaps)
328 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
329 void SweepJniWeakGlobals(HeapBitmap* bitmap)
330 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Carl Shapiro58551df2011-07-24 03:09:51 -0700331
Mathieu Chartierb062fdd2012-07-03 09:51:48 -0700332 // Current space, we check this space first to avoid searching for the appropriate space for an object.
333 SpaceBitmap* current_mark_bitmap_;
334
Carl Shapiro69759ea2011-07-21 18:13:35 -0700335 MarkStack* mark_stack_;
336
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800337 Heap* heap_;
Carl Shapiro69759ea2011-07-21 18:13:35 -0700338
339 Object* finger_;
340
341 Object* condemned_;
342
343 Object* soft_reference_list_;
344
345 Object* weak_reference_list_;
346
347 Object* finalizer_reference_list_;
348
349 Object* phantom_reference_list_;
350
351 Object* cleared_reference_list_;
352
Elliott Hughes352a4242011-10-31 15:15:21 -0700353 size_t class_count_;
354 size_t array_count_;
355 size_t other_count_;
356
Mathieu Chartiere6e06512012-06-26 15:00:26 -0700357 friend class AddIfReachesAllocSpaceVisitor; // Used by mod-union table.
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700358 friend class CheckBitmapVisitor;
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700359 friend class CheckObjectVisitor;
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700360 friend class CheckReferenceVisitor;
Elliott Hughes410c0c82011-09-01 17:58:25 -0700361 friend class InternTableEntryIsUnmarked;
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700362 friend class MarkIfReachesAllocspaceVisitor;
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700363 friend class ModUnionCheckReferences;
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700364 friend class ModUnionClearCardVisitor;
Mathieu Chartiere6e06512012-06-26 15:00:26 -0700365 friend class ModUnionReferenceVisitor;
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700366 friend class ModUnionVisitor;
367 friend class ModUnionTableBitmap;
Mathieu Chartiere6e06512012-06-26 15:00:26 -0700368 friend class ModUnionTableReferenceCache;
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700369 friend class ModUnionScanImageRootVisitor;
370 friend class ScanBitmapVisitor;
371 friend class ScanImageRootVisitor;
Elliott Hughes410c0c82011-09-01 17:58:25 -0700372
Carl Shapiro69759ea2011-07-21 18:13:35 -0700373 DISALLOW_COPY_AND_ASSIGN(MarkSweep);
374};
375
376} // namespace art
377
378#endif // ART_SRC_MARK_SWEEP_H_