blob: db845b7fc8c2e3fa852837b1a7c9e912b80652c8 [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;
Mathieu Chartier357e9be2012-08-01 11:00:14 -070036class TimingLogger;
Carl Shapiro69759ea2011-07-21 18:13:35 -070037
38class MarkSweep {
39 public:
Elliott Hughes74847412012-06-20 18:10:21 -070040 explicit MarkSweep(MarkStack* mark_stack);
Carl Shapiro58551df2011-07-24 03:09:51 -070041
Carl Shapiro69759ea2011-07-21 18:13:35 -070042 ~MarkSweep();
43
Carl Shapiro58551df2011-07-24 03:09:51 -070044 // Initializes internal structures.
Jesse Wilson078f9b02011-11-18 17:51:47 -050045 void Init();
Carl Shapiro58551df2011-07-24 03:09:51 -070046
Carl Shapiro69759ea2011-07-21 18:13:35 -070047 // Marks the root set at the start of a garbage collection.
Ian Rogers00f7d0e2012-07-19 15:28:27 -070048 void MarkRoots()
49 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
50 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -070051
Mathieu Chartier262e5ff2012-06-01 17:35:38 -070052 // Marks the roots in the image space on dirty cards.
Ian Rogers00f7d0e2012-07-19 15:28:27 -070053 void ScanDirtyImageRoots() EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Ian Rogers5d76c432011-10-31 21:42:49 -070054
Mathieu Chartier262e5ff2012-06-01 17:35:38 -070055 // Verify that image roots point to only marked objects within the alloc space.
Ian Rogers00f7d0e2012-07-19 15:28:27 -070056 void VerifyImageRoots() EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Mathieu Chartier262e5ff2012-06-01 17:35:38 -070057
Ian Rogers5d76c432011-10-31 21:42:49 -070058 bool IsMarkStackEmpty() const {
59 return mark_stack_->IsEmpty();
60 }
61
Carl Shapiro58551df2011-07-24 03:09:51 -070062 // Builds a mark stack and recursively mark until it empties.
Mathieu Chartier357e9be2012-08-01 11:00:14 -070063 void RecursiveMark(bool partial, TimingLogger& timings)
Ian Rogers00f7d0e2012-07-19 15:28:27 -070064 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
65 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Mathieu Chartiercc236d72012-07-20 10:29:05 -070066
Mathieu Chartier357e9be2012-08-01 11:00:14 -070067 // Copies mark bits from live bitmap of ZygoteSpace to mark bitmap for partial GCs.
68 void CopyMarkBits(Space* space);
Carl Shapiro58551df2011-07-24 03:09:51 -070069
Mathieu Chartier262e5ff2012-06-01 17:35:38 -070070 // Builds a mark stack with objects on dirty cards and recursively mark
71 // until it empties.
Mathieu Chartier357e9be2012-08-01 11:00:14 -070072 void RecursiveMarkDirtyObjects(bool update_finger)
Ian Rogers00f7d0e2012-07-19 15:28:27 -070073 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
74 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Mathieu Chartier262e5ff2012-06-01 17:35:38 -070075
Mathieu Chartier357e9be2012-08-01 11:00:14 -070076 // Recursive mark objects on specified cards. Updates finger.
77 void RecursiveMarkCards(CardTable* card_table, const std::vector<byte*>& cards,
78 TimingLogger& timings)
79 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
80 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);;
81
Carl Shapiro69759ea2011-07-21 18:13:35 -070082 // Remarks the root set after completing the concurrent mark.
Ian Rogers00f7d0e2012-07-19 15:28:27 -070083 void ReMarkRoots()
84 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
85 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -070086
Mathieu Chartiercc236d72012-07-20 10:29:05 -070087 Heap* GetHeap() {
88 return heap_;
89 }
90
Ian Rogers00f7d0e2012-07-19 15:28:27 -070091 void ProcessReferences(bool clear_soft_references)
92 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
93 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
Carl Shapiro58551df2011-07-24 03:09:51 -070094 ProcessReferences(&soft_reference_list_, clear_soft_references,
95 &weak_reference_list_,
96 &finalizer_reference_list_,
97 &phantom_reference_list_);
98 }
99
Carl Shapiro69759ea2011-07-21 18:13:35 -0700100 // Sweeps unmarked objects to complete the garbage collection.
Mathieu Chartier357e9be2012-08-01 11:00:14 -0700101 void Sweep(bool partial, bool swap_bitmaps)
102 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
103
104 // Sweep only pointers within an array. WARNING: Trashes objects.
105 void SweepArray(TimingLogger& logger, MarkStack* allocation_stack_, bool swap_bitmaps)
106 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700107
Elliott Hughesadb460d2011-10-05 17:02:34 -0700108 Object* GetClearedReferences() {
109 return cleared_reference_list_;
110 }
111
Mathieu Chartier357e9be2012-08-01 11:00:14 -0700112 // Proxy for external access to ScanObject.
113 void ScanRoot(const Object* obj)
114 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
115 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
116
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700117 // Blackens an object.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700118 void ScanObject(const Object* obj)
119 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
120 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700121
Mathieu Chartier357e9be2012-08-01 11:00:14 -0700122 void SetFinger(Object* new_finger) {
123 finger_ = new_finger;
124 }
125
126 void DisableFinger() {
127 SetFinger(reinterpret_cast<Object*>(~static_cast<uintptr_t>(0)));
128 }
129
130 size_t GetFreedBytes() const {
131 return freed_bytes_;
132 }
133
134 size_t GetFreedObjects() const {
135 return freed_objects_;
136 }
137
138 void SetCondemned(Object* condemned) {
139 condemned_ = condemned;
140 }
141
142 void SweepSystemWeaks(bool swap_bitmaps)
143 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
144
Carl Shapiro69759ea2011-07-21 18:13:35 -0700145 private:
146 // Returns true if the object has its bit set in the mark bitmap.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700147 bool IsMarked(const Object* object) const
148 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_) {
Mathieu Chartier357e9be2012-08-01 11:00:14 -0700149 DCHECK(current_mark_bitmap_ != NULL);
Mathieu Chartierb062fdd2012-07-03 09:51:48 -0700150 if (current_mark_bitmap_->HasAddress(object)) {
151 return current_mark_bitmap_->Test(object);
152 }
153 return heap_->GetMarkBitmap()->Test(object);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700154 }
155
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700156 static bool IsMarkedCallback(const Object* object, void* arg)
Mathieu Chartier357e9be2012-08-01 11:00:14 -0700157 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Elliott Hughesc33a32b2011-10-11 18:18:07 -0700158
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700159 static bool IsLiveCallback(const Object* object, void* arg)
Mathieu Chartier357e9be2012-08-01 11:00:14 -0700160 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Mathieu Chartier46a23632012-08-07 18:44:40 -0700161
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700162 static void MarkObjectVisitor(const Object* root, void* arg)
163 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Brian Carlstrom1f870082011-08-23 16:02:11 -0700164
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700165 static void ReMarkObjectVisitor(const Object* root, void* arg)
166 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Mathieu Chartier262e5ff2012-06-01 17:35:38 -0700167
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700168 static void VerifyImageRootVisitor(Object* root, void* arg)
169 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_,
170 GlobalSynchronization::mutator_lock_);
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700171
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700172 static void ScanDirtyCardCallback(Object* obj, void* arg)
173 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
174 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Mathieu Chartier262e5ff2012-06-01 17:35:38 -0700175
Carl Shapiro69759ea2011-07-21 18:13:35 -0700176 // Marks an object.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700177 void MarkObject(const Object* obj)
178 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700179
180 // Yuck.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700181 void MarkObject0(const Object* obj, bool check_finger)
182 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700183
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700184 static void ScanBitmapCallback(Object* obj, void* finger, void* arg)
185 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
186 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro58551df2011-07-24 03:09:51 -0700187
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700188 static void SweepCallback(size_t num_ptrs, Object** ptrs, void* arg)
189 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Carl Shapiro58551df2011-07-24 03:09:51 -0700190
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700191 // Special sweep for zygote that just marks objects / dirties cards.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700192 static void ZygoteSweepCallback(size_t num_ptrs, Object** ptrs, void* arg)
193 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Ian Rogers5d76c432011-10-31 21:42:49 -0700194
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700195 void CheckReference(const Object* obj, const Object* ref, MemberOffset offset, bool is_static)
196 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_,
197 GlobalSynchronization::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700198
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700199 void CheckObject(const Object* obj)
200 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_,
201 GlobalSynchronization::mutator_lock_);
Ian Rogers5d76c432011-10-31 21:42:49 -0700202
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700203 template <typename Visitor>
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700204 void VisitObjectReferences(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 DCHECK(obj != NULL);
208 DCHECK(obj->GetClass() != NULL);
209 if (obj->IsClass()) {
210 VisitClassReferences(obj, visitor);
211 } else if (obj->IsArrayInstance()) {
212 VisitArrayReferences(obj, visitor);
213 } else {
214 VisitOtherReferences(obj, visitor);
215 }
216 }
217
Carl Shapiro69759ea2011-07-21 18:13:35 -0700218 // Grays references in instance fields.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700219 void ScanInstanceFields(const Object* obj)
220 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
221 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700222
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700223 template <typename Visitor>
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700224 void VisitInstanceFieldsReferences(const Object* obj, const Visitor& visitor)
225 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
226 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700227 DCHECK(obj != NULL);
228 Class* klass = obj->GetClass();
229 DCHECK(klass != NULL);
230 VisitFieldsReferences(obj, klass->GetReferenceInstanceOffsets(), false, visitor);
231 }
Ian Rogers5d76c432011-10-31 21:42:49 -0700232
Carl Shapiro69759ea2011-07-21 18:13:35 -0700233 // Blackens a class object.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700234 void ScanClass(const Object* obj)
235 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
236 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
237
Carl Shapiro69759ea2011-07-21 18:13:35 -0700238
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700239 template <typename Visitor>
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700240 void VisitClassReferences(const Object* obj, const Visitor& visitor)
241 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_,
242 GlobalSynchronization::mutator_lock_) {
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700243 VisitInstanceFieldsReferences(obj, visitor);
244 VisitStaticFieldsReferences(obj->AsClass(), visitor);
245 }
Ian Rogers5d76c432011-10-31 21:42:49 -0700246
Carl Shapiro69759ea2011-07-21 18:13:35 -0700247 // Grays references in static fields.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700248 void ScanStaticFields(const Class* klass)
249 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
250 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700251
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700252 template <typename Visitor>
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700253 void VisitStaticFieldsReferences(const Class* klass, const Visitor& visitor)
254 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_,
255 GlobalSynchronization::mutator_lock_) {\
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700256 DCHECK(klass != NULL);
257 VisitFieldsReferences(klass, klass->GetReferenceStaticOffsets(), true, visitor);
258 }
Ian Rogers5d76c432011-10-31 21:42:49 -0700259
Brian Carlstrom4873d462011-08-21 15:23:39 -0700260 // Used by ScanInstanceFields and ScanStaticFields
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700261 void ScanFields(const Object* obj, uint32_t ref_offsets, bool is_static)
262 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
263 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstrom4873d462011-08-21 15:23:39 -0700264
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700265 template <typename Visitor>
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700266 void VisitFieldsReferences(const Object* obj, uint32_t ref_offsets, bool is_static,
267 const Visitor& visitor)
268 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_,
269 GlobalSynchronization::mutator_lock_) {
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700270 if (ref_offsets != CLASS_WALK_SUPER) {
271 // Found a reference offset bitmap. Mark the specified offsets.
272 while (ref_offsets != 0) {
273 size_t right_shift = CLZ(ref_offsets);
274 MemberOffset field_offset = CLASS_OFFSET_FROM_CLZ(right_shift);
275 const Object* ref = obj->GetFieldObject<const Object*>(field_offset, false);
276 visitor(obj, ref, field_offset, is_static);
277 ref_offsets &= ~(CLASS_HIGH_BIT >> right_shift);
278 }
279 } else {
280 // There is no reference offset bitmap. In the non-static case,
281 // walk up the class inheritance hierarchy and find reference
282 // offsets the hard way. In the static case, just consider this
283 // class.
284 for (const Class* klass = is_static ? obj->AsClass() : obj->GetClass();
285 klass != NULL;
286 klass = is_static ? NULL : klass->GetSuperClass()) {
287 size_t num_reference_fields = (is_static
288 ? klass->NumReferenceStaticFields()
289 : klass->NumReferenceInstanceFields());
290 for (size_t i = 0; i < num_reference_fields; ++i) {
291 Field* field = (is_static
292 ? klass->GetStaticField(i)
293 : klass->GetInstanceField(i));
294 MemberOffset field_offset = field->GetOffset();
295 const Object* ref = obj->GetFieldObject<const Object*>(field_offset, false);
296 visitor(obj, ref, field_offset, is_static);
297 }
298 }
299 }
300 }
Ian Rogers5d76c432011-10-31 21:42:49 -0700301
Carl Shapiro69759ea2011-07-21 18:13:35 -0700302 // Grays references in an array.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700303 void ScanArray(const Object* obj)
304 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
305 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700306
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700307 template <typename Visitor>
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700308 void VisitArrayReferences(const Object* obj, const Visitor& visitor)
309 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_,
310 GlobalSynchronization::mutator_lock_) {
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700311 visitor(obj, obj->GetClass(), Object::ClassOffset(), false);
312 if (obj->IsObjectArray()) {
313 const ObjectArray<Object>* array = obj->AsObjectArray<Object>();
314 for (int32_t i = 0; i < array->GetLength(); ++i) {
315 const Object* element = array->GetWithoutChecks(i);
316 size_t width = sizeof(Object*);
317 visitor(obj, element, MemberOffset(i * width + Array::DataOffset(width).Int32Value()), false);
318 }
319 }
320 }
Ian Rogers5d76c432011-10-31 21:42:49 -0700321
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700322 void ScanOther(const Object* obj)
323 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
324 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700325
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700326 template <typename Visitor>
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700327 void VisitOtherReferences(const Object* obj, const Visitor& visitor)
328 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_,
329 GlobalSynchronization::mutator_lock_) {
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700330 return VisitInstanceFieldsReferences(obj, visitor);
331 }
Ian Rogers5d76c432011-10-31 21:42:49 -0700332
Carl Shapiro69759ea2011-07-21 18:13:35 -0700333 // Blackens objects grayed during a garbage collection.
Mathieu Chartier357e9be2012-08-01 11:00:14 -0700334 void ScanGrayObjects(bool update_finger)
335 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700336
337 // Schedules an unmarked object for reference processing.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700338 void DelayReferenceReferent(Object* reference)
339 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700340
341 // Recursively blackens objects on the mark stack.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700342 void ProcessMarkStack()
343 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
344 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700345
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700346 void EnqueueFinalizerReferences(Object** ref)
347 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
348 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700349
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700350 void PreserveSomeSoftReferences(Object** ref)
351 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
352 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700353
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700354 void ClearWhiteReferences(Object** list)
355 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700356
Carl Shapiro58551df2011-07-24 03:09:51 -0700357 void ProcessReferences(Object** soft_references, bool clear_soft_references,
Carl Shapiro69759ea2011-07-21 18:13:35 -0700358 Object** weak_references,
359 Object** finalizer_references,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700360 Object** phantom_references)
361 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
362 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700363
Mathieu Chartier357e9be2012-08-01 11:00:14 -0700364 void SweepJniWeakGlobals(bool swap_bitmaps)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700365 SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
Carl Shapiro58551df2011-07-24 03:09:51 -0700366
Mathieu Chartierb062fdd2012-07-03 09:51:48 -0700367 // Current space, we check this space first to avoid searching for the appropriate space for an object.
368 SpaceBitmap* current_mark_bitmap_;
369
Carl Shapiro69759ea2011-07-21 18:13:35 -0700370 MarkStack* mark_stack_;
371
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800372 Heap* heap_;
Carl Shapiro69759ea2011-07-21 18:13:35 -0700373
374 Object* finger_;
375
376 Object* condemned_;
377
378 Object* soft_reference_list_;
379
380 Object* weak_reference_list_;
381
382 Object* finalizer_reference_list_;
383
384 Object* phantom_reference_list_;
385
386 Object* cleared_reference_list_;
387
Mathieu Chartier357e9be2012-08-01 11:00:14 -0700388 size_t freed_bytes_;
389 size_t freed_objects_;
390
Elliott Hughes352a4242011-10-31 15:15:21 -0700391 size_t class_count_;
392 size_t array_count_;
393 size_t other_count_;
394
Mathieu Chartiere6e06512012-06-26 15:00:26 -0700395 friend class AddIfReachesAllocSpaceVisitor; // Used by mod-union table.
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700396 friend class CheckBitmapVisitor;
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700397 friend class CheckObjectVisitor;
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700398 friend class CheckReferenceVisitor;
Elliott Hughes410c0c82011-09-01 17:58:25 -0700399 friend class InternTableEntryIsUnmarked;
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700400 friend class MarkIfReachesAllocspaceVisitor;
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700401 friend class ModUnionCheckReferences;
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700402 friend class ModUnionClearCardVisitor;
Mathieu Chartiere6e06512012-06-26 15:00:26 -0700403 friend class ModUnionReferenceVisitor;
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700404 friend class ModUnionVisitor;
405 friend class ModUnionTableBitmap;
Mathieu Chartiere6e06512012-06-26 15:00:26 -0700406 friend class ModUnionTableReferenceCache;
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700407 friend class ModUnionScanImageRootVisitor;
408 friend class ScanBitmapVisitor;
409 friend class ScanImageRootVisitor;
Elliott Hughes410c0c82011-09-01 17:58:25 -0700410
Carl Shapiro69759ea2011-07-21 18:13:35 -0700411 DISALLOW_COPY_AND_ASSIGN(MarkSweep);
412};
413
414} // namespace art
415
416#endif // ART_SRC_MARK_SWEEP_H_