blob: b787327c80f4373d83e4c608607c95e19d045633 [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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_GC_COLLECTOR_MARK_SWEEP_H_
18#define ART_RUNTIME_GC_COLLECTOR_MARK_SWEEP_H_
Carl Shapiro69759ea2011-07-21 18:13:35 -070019
Ian Rogers700a4022014-05-19 16:49:03 -070020#include <memory>
21
Ian Rogersef7d42f2014-01-06 12:55:46 -080022#include "atomic.h"
Sameer Abu Asal4aeb5672013-02-19 15:30:35 -080023#include "barrier.h"
Elliott Hughes76160052012-12-12 16:31:20 -080024#include "base/macros.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080025#include "base/mutex.h"
Mathieu Chartier2b82db42012-11-14 17:29:05 -080026#include "garbage_collector.h"
Mathieu Chartiere34fa1d2015-01-14 14:55:47 -080027#include "gc_root.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070028#include "gc/accounting/heap_bitmap.h"
Mathieu Chartier8d562102014-03-12 17:42:10 -070029#include "immune_region.h"
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080030#include "object_callbacks.h"
Ian Rogers0cfe1fb2011-08-26 03:29:44 -070031#include "offsets.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -070032
33namespace art {
Ian Rogers1d54e732013-05-02 21:10:01 -070034
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080035namespace mirror {
Ian Rogers1d54e732013-05-02 21:10:01 -070036 class Class;
37 class Object;
Mathieu Chartier407f7022014-02-18 14:37:05 -080038 class Reference;
Ian Rogers1d54e732013-05-02 21:10:01 -070039} // namespace mirror
40
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080041class Thread;
Mathieu Chartier893263b2014-03-04 11:07:42 -080042enum VisitRootFlags : uint8_t;
Ian Rogers1d54e732013-05-02 21:10:01 -070043
44namespace gc {
45
Mathieu Chartier4aeec172014-03-27 16:09:46 -070046class Heap;
47
Ian Rogers1d54e732013-05-02 21:10:01 -070048namespace accounting {
Mathieu Chartier4aeec172014-03-27 16:09:46 -070049 template<typename T> class AtomicStack;
Ian Rogers1d54e732013-05-02 21:10:01 -070050 typedef AtomicStack<mirror::Object*> ObjectStack;
Ian Rogers1d54e732013-05-02 21:10:01 -070051} // namespace accounting
52
Ian Rogers1d54e732013-05-02 21:10:01 -070053namespace collector {
Carl Shapiro69759ea2011-07-21 18:13:35 -070054
Mathieu Chartier2b82db42012-11-14 17:29:05 -080055class MarkSweep : public GarbageCollector {
Carl Shapiro69759ea2011-07-21 18:13:35 -070056 public:
Ian Rogers1d54e732013-05-02 21:10:01 -070057 explicit MarkSweep(Heap* heap, bool is_concurrent, const std::string& name_prefix = "");
Carl Shapiro58551df2011-07-24 03:09:51 -070058
Ian Rogers1d54e732013-05-02 21:10:01 -070059 ~MarkSweep() {}
Carl Shapiro69759ea2011-07-21 18:13:35 -070060
Mathieu Chartier6f365cc2014-04-23 12:42:27 -070061 virtual void RunPhases() OVERRIDE NO_THREAD_SAFETY_ANALYSIS;
62 void InitializePhase();
63 void MarkingPhase() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
64 void PausePhase() EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_);
65 void ReclaimPhase() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
66 void FinishPhase() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier2b82db42012-11-14 17:29:05 -080067 virtual void MarkReachableObjects()
68 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
69 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
Ian Rogers6fac4472014-02-25 17:01:10 -080070
Hiroshi Yamauchi3e417802014-03-20 12:03:02 -070071 bool IsConcurrent() const {
72 return is_concurrent_;
73 }
Ian Rogers6fac4472014-02-25 17:01:10 -080074
75 virtual GcType GetGcType() const OVERRIDE {
Mathieu Chartier2b82db42012-11-14 17:29:05 -080076 return kGcTypeFull;
77 }
78
Hiroshi Yamauchi3e417802014-03-20 12:03:02 -070079 virtual CollectorType GetCollectorType() const OVERRIDE {
80 return is_concurrent_ ? kCollectorTypeCMS : kCollectorTypeMS;
81 }
82
Carl Shapiro58551df2011-07-24 03:09:51 -070083 // Initializes internal structures.
Jesse Wilson078f9b02011-11-18 17:51:47 -050084 void Init();
Carl Shapiro58551df2011-07-24 03:09:51 -070085
Mathieu Chartier7469ebf2012-09-24 16:28:36 -070086 // Find the default mark bitmap.
Mathieu Chartier0e54cd02014-03-20 12:41:23 -070087 void FindDefaultSpaceBitmap();
Mathieu Chartier7469ebf2012-09-24 16:28:36 -070088
Mathieu Chartier893263b2014-03-04 11:07:42 -080089 // Marks all objects in the root set at the start of a garbage collection.
90 void MarkRoots(Thread* self)
Ian Rogersb726dcb2012-09-05 08:57:23 -070091 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_)
92 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -070093
Mathieu Chartier858f1c52012-10-17 17:45:55 -070094 void MarkNonThreadRoots()
Mathieu Chartierc528dba2013-11-26 12:00:11 -080095 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_)
96 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier858f1c52012-10-17 17:45:55 -070097
Mathieu Chartier893263b2014-03-04 11:07:42 -080098 void MarkConcurrentRoots(VisitRootFlags flags)
Mathieu Chartierc528dba2013-11-26 12:00:11 -080099 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_)
100 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier9ebae1f2012-10-15 17:38:16 -0700101
Mathieu Chartier0f7bf6a2014-03-28 10:05:39 -0700102 void MarkRootsCheckpoint(Thread* self, bool revoke_ros_alloc_thread_local_buffers_at_checkpoint)
Ian Rogers1d54e732013-05-02 21:10:01 -0700103 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_)
104 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier858f1c52012-10-17 17:45:55 -0700105
Carl Shapiro58551df2011-07-24 03:09:51 -0700106 // Builds a mark stack and recursively mark until it empties.
Mathieu Chartier2b82db42012-11-14 17:29:05 -0800107 void RecursiveMark()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700108 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_)
109 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700110
Ian Rogers1d54e732013-05-02 21:10:01 -0700111 // Bind the live bits to the mark bits of bitmaps for spaces that are never collected, ie
112 // the image. Mark that portion of the heap as immune.
113 virtual void BindBitmaps() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier7469ebf2012-09-24 16:28:36 -0700114
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700115 // Builds a mark stack with objects on dirty cards and recursively mark until it empties.
Ian Rogers13735952014-10-08 12:43:28 -0700116 void RecursiveMarkDirtyObjects(bool paused, uint8_t minimum_age)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700117 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_)
118 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier262e5ff2012-06-01 17:35:38 -0700119
Carl Shapiro69759ea2011-07-21 18:13:35 -0700120 // Remarks the root set after completing the concurrent mark.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700121 void ReMarkRoots()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700122 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_)
123 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700124
Mathieu Chartier2b82db42012-11-14 17:29:05 -0800125 void ProcessReferences(Thread* self)
126 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro58551df2011-07-24 03:09:51 -0700127
Mathieu Chartier4aeec172014-03-27 16:09:46 -0700128 // Update and mark references from immune spaces.
129 void UpdateAndMarkModUnion()
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700130 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
131
Mathieu Chartierdda54f52014-02-24 09:58:40 -0800132 // Pre clean cards to reduce how much work is needed in the pause.
133 void PreCleanCards()
134 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_)
135 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
136
Ian Rogers6fac4472014-02-25 17:01:10 -0800137 // Sweeps unmarked objects to complete the garbage collection. Virtual as by default it sweeps
138 // all allocation spaces. Partial and sticky GCs want to just sweep a subset of the heap.
Ian Rogers1d54e732013-05-02 21:10:01 -0700139 virtual void Sweep(bool swap_bitmaps) EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
Mathieu Chartier357e9be2012-08-01 11:00:14 -0700140
Mathieu Chartiere0f0cb32012-08-28 11:26:00 -0700141 // Sweeps unmarked objects to complete the garbage collection.
Ian Rogers1d54e732013-05-02 21:10:01 -0700142 void SweepLargeObjects(bool swap_bitmaps) EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
Mathieu Chartiere0f0cb32012-08-28 11:26:00 -0700143
Mathieu Chartier357e9be2012-08-01 11:00:14 -0700144 // Sweep only pointers within an array. WARNING: Trashes objects.
Ian Rogers1d54e732013-05-02 21:10:01 -0700145 void SweepArray(accounting::ObjectStack* allocation_stack_, bool swap_bitmaps)
Ian Rogers719d1a32014-03-06 12:13:39 -0800146 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700147 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700148
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700149 // Blackens an object.
Mathieu Chartier590fee92013-09-13 13:46:47 -0700150 void ScanObject(mirror::Object* obj)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700151 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_)
152 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700153
Mathieu Chartier407f7022014-02-18 14:37:05 -0800154 // No thread safety analysis due to lambdas.
155 template<typename MarkVisitor, typename ReferenceVisitor>
156 void ScanObjectVisit(mirror::Object* obj, const MarkVisitor& visitor,
157 const ReferenceVisitor& ref_visitor)
158 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
159 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700160
Mathieu Chartier0f7bf6a2014-03-28 10:05:39 -0700161 void SweepSystemWeaks(Thread* self)
162 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) LOCKS_EXCLUDED(Locks::heap_bitmap_lock_);
Mathieu Chartier7469ebf2012-09-24 16:28:36 -0700163
Mathieu Chartier6aa3df92013-09-17 15:17:28 -0700164 static mirror::Object* VerifySystemWeakIsLiveCallback(mirror::Object* obj, void* arg)
Mathieu Chartierc7b83a02012-09-11 18:07:39 -0700165 SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
166
167 void VerifySystemWeaks()
Mathieu Chartierad2541a2013-10-25 10:05:23 -0700168 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_, Locks::heap_bitmap_lock_);
Mathieu Chartierc7b83a02012-09-11 18:07:39 -0700169
170 // Verify that an object is live, either in a live bitmap or in the allocation stack.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800171 void VerifyIsLive(const mirror::Object* obj)
Mathieu Chartierc7b83a02012-09-11 18:07:39 -0700172 SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
173
Mathieu Chartier3bb57c72014-02-18 11:38:45 -0800174 static mirror::Object* MarkObjectCallback(mirror::Object* obj, void* arg)
Mathieu Chartier39e32612013-11-12 16:28:05 -0800175 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
176 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
177
Mathieu Chartier407f7022014-02-18 14:37:05 -0800178 static void MarkHeapReferenceCallback(mirror::HeapReference<mirror::Object>* ref, void* arg)
179 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
180 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
181
Mathieu Chartier308351a2014-06-15 12:39:02 -0700182 static bool HeapReferenceMarkedCallback(mirror::HeapReference<mirror::Object>* ref, void* arg)
183 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
184 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
185
Mathieu Chartiere34fa1d2015-01-14 14:55:47 -0800186 static void MarkRootCallback(mirror::Object** root, void* arg, const RootInfo& root_info)
Mathieu Chartier2b82db42012-11-14 17:29:05 -0800187 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700188 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
189
Mathieu Chartiere34fa1d2015-01-14 14:55:47 -0800190 static void VerifyRootMarked(mirror::Object** root, void* arg, const RootInfo& root_info)
Mathieu Chartier893263b2014-03-04 11:07:42 -0800191 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
192 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
193
Mathieu Chartier78f7b4c2014-05-06 10:57:27 -0700194 static void ProcessMarkStackCallback(void* arg)
195 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_)
196 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier815873e2014-02-13 18:02:13 -0800197
Mathieu Chartiere34fa1d2015-01-14 14:55:47 -0800198 static void MarkRootParallelCallback(mirror::Object** root, void* arg, const RootInfo& root_info)
Mathieu Chartier815873e2014-02-13 18:02:13 -0800199 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierac86a7c2012-11-12 15:03:16 -0800200
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700201 // Marks an object.
Mathieu Chartier0e54cd02014-03-20 12:41:23 -0700202 void MarkObject(mirror::Object* obj)
Mathieu Chartier2b82db42012-11-14 17:29:05 -0800203 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
204 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
205
Sameer Abu Asala8439542013-02-14 16:06:42 -0800206 Barrier& GetBarrier() {
207 return *gc_barrier_;
208 }
209
Mathieu Chartier407f7022014-02-18 14:37:05 -0800210 // Schedules an unmarked object for reference processing.
211 void DelayReferenceReferent(mirror::Class* klass, mirror::Reference* reference)
212 SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_, Locks::mutator_lock_);
213
Mathieu Chartier2b82db42012-11-14 17:29:05 -0800214 protected:
Carl Shapiro69759ea2011-07-21 18:13:35 -0700215 // Returns true if the object has its bit set in the mark bitmap.
Mathieu Chartier52e4b432014-06-10 11:22:31 -0700216 bool IsMarked(const mirror::Object* object) const
217 SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700218
Mathieu Chartier39e32612013-11-12 16:28:05 -0800219 static mirror::Object* IsMarkedCallback(mirror::Object* object, void* arg)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700220 SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
Mathieu Chartier46a23632012-08-07 18:44:40 -0700221
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800222 static void VerifyImageRootVisitor(mirror::Object* root, void* arg)
Mathieu Chartier0e54cd02014-03-20 12:41:23 -0700223 SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_, Locks::mutator_lock_);
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700224
Mathieu Chartier0e54cd02014-03-20 12:41:23 -0700225 void MarkObjectNonNull(mirror::Object* obj)
Mathieu Chartier9642c962013-08-05 17:40:36 -0700226 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
227 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700228
Mathieu Chartier9642c962013-08-05 17:40:36 -0700229 // Marks an object atomically, safe to use from multiple threads.
Mathieu Chartier0e54cd02014-03-20 12:41:23 -0700230 void MarkObjectNonNullParallel(mirror::Object* obj);
Mathieu Chartier9642c962013-08-05 17:40:36 -0700231
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700232 // Returns true if we need to add obj to a mark stack.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800233 bool MarkObjectParallel(const mirror::Object* obj) NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700234
Mathieu Chartier6f1c9492012-10-15 12:08:41 -0700235 // Verify the roots of the heap and print out information related to any invalid roots.
236 // Called in MarkObject, so may we may not hold the mutator lock.
237 void VerifyRoots()
238 NO_THREAD_SAFETY_ANALYSIS;
239
Mathieu Chartierba311b42013-08-27 13:02:30 -0700240 // Expand mark stack to 2x its current size.
241 void ExpandMarkStack() EXCLUSIVE_LOCKS_REQUIRED(mark_stack_lock_);
242 void ResizeMarkStack(size_t new_size) EXCLUSIVE_LOCKS_REQUIRED(mark_stack_lock_);
Mathieu Chartierac86a7c2012-11-12 15:03:16 -0800243
Mathieu Chartier2775ee42013-08-20 17:43:47 -0700244 // Returns how many threads we should use for the current GC phase based on if we are paused,
245 // whether or not we care about pauses.
246 size_t GetThreadCount(bool paused) const;
247
Mathieu Chartiere34fa1d2015-01-14 14:55:47 -0800248 static void VerifyRootCallback(mirror::Object** root, void* arg, const RootInfo& root_info);
Mathieu Chartier6f1c9492012-10-15 12:08:41 -0700249
Mathieu Chartiere34fa1d2015-01-14 14:55:47 -0800250 void VerifyRoot(const mirror::Object* root, const RootInfo& root_info) NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartier6f1c9492012-10-15 12:08:41 -0700251
Mathieu Chartier0e54cd02014-03-20 12:41:23 -0700252 // Push a single reference on a mark stack.
253 void PushOnMarkStack(mirror::Object* obj);
Ian Rogers5d76c432011-10-31 21:42:49 -0700254
Carl Shapiro69759ea2011-07-21 18:13:35 -0700255 // Blackens objects grayed during a garbage collection.
Ian Rogers13735952014-10-08 12:43:28 -0700256 void ScanGrayObjects(bool paused, uint8_t minimum_age)
Mathieu Chartierd22d5482012-11-06 17:14:12 -0800257 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_)
258 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700259
Carl Shapiro69759ea2011-07-21 18:13:35 -0700260 // Recursively blackens objects on the mark stack.
Mathieu Chartier94c32c52013-08-09 11:14:04 -0700261 void ProcessMarkStack(bool paused)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700262 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_)
263 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700264
Mathieu Chartier2775ee42013-08-20 17:43:47 -0700265 void ProcessMarkStackParallel(size_t thread_count)
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700266 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_)
267 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
268
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700269 // Used to Get around thread safety annotations. The call is from MarkingPhase and is guarded by
Mathieu Chartierc22c59e2014-02-24 15:16:06 -0800270 // IsExclusiveHeld.
271 void RevokeAllThreadLocalAllocationStacks(Thread* self) NO_THREAD_SAFETY_ANALYSIS;
272
Hiroshi Yamauchic93c5302014-03-20 16:15:37 -0700273 // Revoke all the thread-local buffers.
274 void RevokeAllThreadLocalBuffers();
275
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700276 // Whether or not we count how many of each type of object were scanned.
277 static const bool kCountScannedTypes = false;
278
Ian Rogers1d54e732013-05-02 21:10:01 -0700279 // Current space, we check this space first to avoid searching for the appropriate space for an
280 // object.
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -0700281 accounting::ContinuousSpaceBitmap* current_space_bitmap_;
Mathieu Chartier0e54cd02014-03-20 12:41:23 -0700282 // Cache the heap's mark bitmap to prevent having to do 2 loads during slow path marking.
283 accounting::HeapBitmap* mark_bitmap_;
Mathieu Chartierb062fdd2012-07-03 09:51:48 -0700284
Ian Rogers1d54e732013-05-02 21:10:01 -0700285 accounting::ObjectStack* mark_stack_;
Carl Shapiro69759ea2011-07-21 18:13:35 -0700286
Mathieu Chartier4aeec172014-03-27 16:09:46 -0700287 // Immune region, every object inside the immune range is assumed to be marked.
Mathieu Chartier8d562102014-03-12 17:42:10 -0700288 ImmuneRegion immune_region_;
Carl Shapiro69759ea2011-07-21 18:13:35 -0700289
Mathieu Chartier94c32c52013-08-09 11:14:04 -0700290 // Parallel finger.
291 AtomicInteger atomic_finger_;
Ian Rogers1d54e732013-05-02 21:10:01 -0700292 // Number of classes scanned, if kCountScannedTypes.
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700293 AtomicInteger class_count_;
Ian Rogers1d54e732013-05-02 21:10:01 -0700294 // Number of arrays scanned, if kCountScannedTypes.
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700295 AtomicInteger array_count_;
Ian Rogers1d54e732013-05-02 21:10:01 -0700296 // Number of non-class/arrays scanned, if kCountScannedTypes.
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700297 AtomicInteger other_count_;
298 AtomicInteger large_object_test_;
299 AtomicInteger large_object_mark_;
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700300 AtomicInteger overhead_time_;
301 AtomicInteger work_chunks_created_;
302 AtomicInteger work_chunks_deleted_;
Mathieu Chartierd22d5482012-11-06 17:14:12 -0800303 AtomicInteger reference_count_;
Mathieu Chartier0e54cd02014-03-20 12:41:23 -0700304 AtomicInteger mark_null_count_;
305 AtomicInteger mark_immune_count_;
306 AtomicInteger mark_fastpath_count_;
307 AtomicInteger mark_slowpath_count_;
Mathieu Chartier0f72e412013-09-06 16:40:01 -0700308
Ian Rogers700a4022014-05-19 16:49:03 -0700309 std::unique_ptr<Barrier> gc_barrier_;
Mathieu Chartier958291c2013-08-27 18:14:55 -0700310 Mutex mark_stack_lock_ ACQUIRED_AFTER(Locks::classlinker_classes_lock_);
Ian Rogers1bd4b4c2013-04-18 17:47:42 -0700311
312 const bool is_concurrent_;
313
Ian Rogers3e5cf302014-05-20 16:40:37 -0700314 // Verification.
315 size_t live_stack_freeze_size_;
316
Hiroshi Yamauchibbdc5bc2014-05-28 14:04:59 -0700317 std::unique_ptr<MemMap> sweep_array_free_buffer_mem_map_;
318
Mathieu Chartier02e25112013-08-14 16:14:24 -0700319 private:
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700320 friend class AddIfReachesAllocSpaceVisitor; // Used by mod-union table.
Mathieu Chartier0f72e412013-09-06 16:40:01 -0700321 friend class CardScanTask;
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700322 friend class CheckBitmapVisitor;
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700323 friend class CheckReferenceVisitor;
Ian Rogers1d54e732013-05-02 21:10:01 -0700324 friend class art::gc::Heap;
Mathieu Chartier0e54cd02014-03-20 12:41:23 -0700325 friend class MarkObjectVisitor;
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700326 friend class ModUnionCheckReferences;
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700327 friend class ModUnionClearCardVisitor;
Mathieu Chartiere6e06512012-06-26 15:00:26 -0700328 friend class ModUnionReferenceVisitor;
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700329 friend class ModUnionVisitor;
330 friend class ModUnionTableBitmap;
Mathieu Chartiere6e06512012-06-26 15:00:26 -0700331 friend class ModUnionTableReferenceCache;
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700332 friend class ModUnionScanImageRootVisitor;
Mathieu Chartier94c32c52013-08-09 11:14:04 -0700333 template<bool kUseFinger> friend class MarkStackTask;
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700334 friend class FifoMarkStackChunk;
Mathieu Chartierbbd695c2014-04-16 09:48:48 -0700335 friend class MarkSweepMarkObjectSlowPath;
Elliott Hughes410c0c82011-09-01 17:58:25 -0700336
Carl Shapiro69759ea2011-07-21 18:13:35 -0700337 DISALLOW_COPY_AND_ASSIGN(MarkSweep);
338};
339
Ian Rogers1d54e732013-05-02 21:10:01 -0700340} // namespace collector
341} // namespace gc
Carl Shapiro69759ea2011-07-21 18:13:35 -0700342} // namespace art
343
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700344#endif // ART_RUNTIME_GC_COLLECTOR_MARK_SWEEP_H_