blob: 99e00f9fd9eaee3d7b48a9b2134f06d4ab3de363 [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;
Mathieu Chartiercb535da2015-01-23 13:50:03 -080050 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();
Mathieu Chartier90443472015-07-16 20:32:27 -070063 void MarkingPhase() SHARED_REQUIRES(Locks::mutator_lock_, !mark_stack_lock_);
64 void PausePhase() REQUIRES(Locks::mutator_lock_, !mark_stack_lock_);
65 void ReclaimPhase() SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_);
66 void FinishPhase() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier2b82db42012-11-14 17:29:05 -080067 virtual void MarkReachableObjects()
Mathieu Chartier90443472015-07-16 20:32:27 -070068 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_);
Ian Rogers6fac4472014-02-25 17:01:10 -080069
Hiroshi Yamauchi3e417802014-03-20 12:03:02 -070070 bool IsConcurrent() const {
71 return is_concurrent_;
72 }
Ian Rogers6fac4472014-02-25 17:01:10 -080073
74 virtual GcType GetGcType() const OVERRIDE {
Mathieu Chartier2b82db42012-11-14 17:29:05 -080075 return kGcTypeFull;
76 }
77
Hiroshi Yamauchi3e417802014-03-20 12:03:02 -070078 virtual CollectorType GetCollectorType() const OVERRIDE {
79 return is_concurrent_ ? kCollectorTypeCMS : kCollectorTypeMS;
80 }
81
Carl Shapiro58551df2011-07-24 03:09:51 -070082 // Initializes internal structures.
Jesse Wilson078f9b02011-11-18 17:51:47 -050083 void Init();
Carl Shapiro58551df2011-07-24 03:09:51 -070084
Mathieu Chartier7469ebf2012-09-24 16:28:36 -070085 // Find the default mark bitmap.
Mathieu Chartier0e54cd02014-03-20 12:41:23 -070086 void FindDefaultSpaceBitmap();
Mathieu Chartier7469ebf2012-09-24 16:28:36 -070087
Mathieu Chartier893263b2014-03-04 11:07:42 -080088 // Marks all objects in the root set at the start of a garbage collection.
89 void MarkRoots(Thread* self)
Mathieu Chartier90443472015-07-16 20:32:27 -070090 REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -070091
Mathieu Chartier858f1c52012-10-17 17:45:55 -070092 void MarkNonThreadRoots()
Mathieu Chartier90443472015-07-16 20:32:27 -070093 REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier858f1c52012-10-17 17:45:55 -070094
Mathieu Chartier893263b2014-03-04 11:07:42 -080095 void MarkConcurrentRoots(VisitRootFlags flags)
Mathieu Chartier90443472015-07-16 20:32:27 -070096 REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier9ebae1f2012-10-15 17:38:16 -070097
Mathieu Chartier0f7bf6a2014-03-28 10:05:39 -070098 void MarkRootsCheckpoint(Thread* self, bool revoke_ros_alloc_thread_local_buffers_at_checkpoint)
Mathieu Chartier90443472015-07-16 20:32:27 -070099 REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier858f1c52012-10-17 17:45:55 -0700100
Carl Shapiro58551df2011-07-24 03:09:51 -0700101 // Builds a mark stack and recursively mark until it empties.
Mathieu Chartier2b82db42012-11-14 17:29:05 -0800102 void RecursiveMark()
Mathieu Chartier90443472015-07-16 20:32:27 -0700103 REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700104
Ian Rogers1d54e732013-05-02 21:10:01 -0700105 // Bind the live bits to the mark bits of bitmaps for spaces that are never collected, ie
106 // the image. Mark that portion of the heap as immune.
Mathieu Chartier90443472015-07-16 20:32:27 -0700107 virtual void BindBitmaps() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier7469ebf2012-09-24 16:28:36 -0700108
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700109 // Builds a mark stack with objects on dirty cards and recursively mark until it empties.
Ian Rogers13735952014-10-08 12:43:28 -0700110 void RecursiveMarkDirtyObjects(bool paused, uint8_t minimum_age)
Mathieu Chartier90443472015-07-16 20:32:27 -0700111 REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier262e5ff2012-06-01 17:35:38 -0700112
Carl Shapiro69759ea2011-07-21 18:13:35 -0700113 // Remarks the root set after completing the concurrent mark.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700114 void ReMarkRoots()
Mathieu Chartier90443472015-07-16 20:32:27 -0700115 REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700116
Mathieu Chartier2b82db42012-11-14 17:29:05 -0800117 void ProcessReferences(Thread* self)
Mathieu Chartier90443472015-07-16 20:32:27 -0700118 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_);
Carl Shapiro58551df2011-07-24 03:09:51 -0700119
Mathieu Chartier4aeec172014-03-27 16:09:46 -0700120 // Update and mark references from immune spaces.
121 void UpdateAndMarkModUnion()
Mathieu Chartier90443472015-07-16 20:32:27 -0700122 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_);
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700123
Mathieu Chartierdda54f52014-02-24 09:58:40 -0800124 // Pre clean cards to reduce how much work is needed in the pause.
125 void PreCleanCards()
Mathieu Chartier90443472015-07-16 20:32:27 -0700126 REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierdda54f52014-02-24 09:58:40 -0800127
Ian Rogers6fac4472014-02-25 17:01:10 -0800128 // Sweeps unmarked objects to complete the garbage collection. Virtual as by default it sweeps
129 // all allocation spaces. Partial and sticky GCs want to just sweep a subset of the heap.
Mathieu Chartier90443472015-07-16 20:32:27 -0700130 virtual void Sweep(bool swap_bitmaps) REQUIRES(Locks::heap_bitmap_lock_)
131 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier357e9be2012-08-01 11:00:14 -0700132
Mathieu Chartiere0f0cb32012-08-28 11:26:00 -0700133 // Sweeps unmarked objects to complete the garbage collection.
Mathieu Chartier90443472015-07-16 20:32:27 -0700134 void SweepLargeObjects(bool swap_bitmaps) REQUIRES(Locks::heap_bitmap_lock_);
Mathieu Chartiere0f0cb32012-08-28 11:26:00 -0700135
Mathieu Chartier357e9be2012-08-01 11:00:14 -0700136 // Sweep only pointers within an array. WARNING: Trashes objects.
Ian Rogers1d54e732013-05-02 21:10:01 -0700137 void SweepArray(accounting::ObjectStack* allocation_stack_, bool swap_bitmaps)
Mathieu Chartier90443472015-07-16 20:32:27 -0700138 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700139
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700140 // Blackens an object.
Mathieu Chartier590fee92013-09-13 13:46:47 -0700141 void ScanObject(mirror::Object* obj)
Mathieu Chartier90443472015-07-16 20:32:27 -0700142 REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700143
Mathieu Chartier407f7022014-02-18 14:37:05 -0800144 // No thread safety analysis due to lambdas.
145 template<typename MarkVisitor, typename ReferenceVisitor>
146 void ScanObjectVisit(mirror::Object* obj, const MarkVisitor& visitor,
147 const ReferenceVisitor& ref_visitor)
Mathieu Chartier90443472015-07-16 20:32:27 -0700148 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_);
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700149
Mathieu Chartier0f7bf6a2014-03-28 10:05:39 -0700150 void SweepSystemWeaks(Thread* self)
Mathieu Chartier90443472015-07-16 20:32:27 -0700151 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Locks::heap_bitmap_lock_);
Mathieu Chartier7469ebf2012-09-24 16:28:36 -0700152
Mathieu Chartier6aa3df92013-09-17 15:17:28 -0700153 static mirror::Object* VerifySystemWeakIsLiveCallback(mirror::Object* obj, void* arg)
Mathieu Chartier90443472015-07-16 20:32:27 -0700154 SHARED_REQUIRES(Locks::heap_bitmap_lock_, Locks::mutator_lock_);
Mathieu Chartierc7b83a02012-09-11 18:07:39 -0700155
156 void VerifySystemWeaks()
Mathieu Chartier90443472015-07-16 20:32:27 -0700157 SHARED_REQUIRES(Locks::mutator_lock_, Locks::heap_bitmap_lock_);
Mathieu Chartierc7b83a02012-09-11 18:07:39 -0700158
159 // Verify that an object is live, either in a live bitmap or in the allocation stack.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800160 void VerifyIsLive(const mirror::Object* obj)
Mathieu Chartier90443472015-07-16 20:32:27 -0700161 SHARED_REQUIRES(Locks::mutator_lock_, Locks::heap_bitmap_lock_);
Mathieu Chartierc7b83a02012-09-11 18:07:39 -0700162
Mathieu Chartier97509952015-07-13 14:35:43 -0700163 virtual bool IsMarkedHeapReference(mirror::HeapReference<mirror::Object>* ref) OVERRIDE
Mathieu Chartier90443472015-07-16 20:32:27 -0700164 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_);
Mathieu Chartier308351a2014-06-15 12:39:02 -0700165
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700166 virtual void VisitRoots(mirror::Object*** roots, size_t count, const RootInfo& info) OVERRIDE
Mathieu Chartier90443472015-07-16 20:32:27 -0700167 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_);
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700168
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700169 virtual void VisitRoots(mirror::CompressedReference<mirror::Object>** roots, size_t count,
170 const RootInfo& info) OVERRIDE
Mathieu Chartier90443472015-07-16 20:32:27 -0700171 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_);
Mathieu Chartier893263b2014-03-04 11:07:42 -0800172
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700173 // Marks an object.
Mathieu Chartier97509952015-07-13 14:35:43 -0700174 virtual mirror::Object* MarkObject(mirror::Object* obj) OVERRIDE
Mathieu Chartier90443472015-07-16 20:32:27 -0700175 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_);
Mathieu Chartier97509952015-07-13 14:35:43 -0700176 void MarkObject(mirror::Object* obj, mirror::Object* holder, MemberOffset offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700177 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_);
Mathieu Chartier97509952015-07-13 14:35:43 -0700178 virtual void MarkHeapReference(mirror::HeapReference<mirror::Object>* ref) OVERRIDE
Mathieu Chartier90443472015-07-16 20:32:27 -0700179 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_);
Mathieu Chartier2b82db42012-11-14 17:29:05 -0800180
Sameer Abu Asala8439542013-02-14 16:06:42 -0800181 Barrier& GetBarrier() {
182 return *gc_barrier_;
183 }
184
Mathieu Chartier407f7022014-02-18 14:37:05 -0800185 // Schedules an unmarked object for reference processing.
186 void DelayReferenceReferent(mirror::Class* klass, mirror::Reference* reference)
Mathieu Chartier90443472015-07-16 20:32:27 -0700187 SHARED_REQUIRES(Locks::heap_bitmap_lock_, Locks::mutator_lock_);
Mathieu Chartier407f7022014-02-18 14:37:05 -0800188
Mathieu Chartier2b82db42012-11-14 17:29:05 -0800189 protected:
Mathieu Chartier81187812015-07-15 14:24:07 -0700190 // Returns object if the object is marked in the heap bitmap, otherwise null.
Mathieu Chartier97509952015-07-13 14:35:43 -0700191 virtual mirror::Object* IsMarked(mirror::Object* object) OVERRIDE
Mathieu Chartier90443472015-07-16 20:32:27 -0700192 SHARED_REQUIRES(Locks::heap_bitmap_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700193
Hiroshi Yamauchieb2baaf2015-05-13 21:14:22 -0700194 void MarkObjectNonNull(mirror::Object* obj, mirror::Object* holder = nullptr,
195 MemberOffset offset = MemberOffset(0))
Mathieu Chartier90443472015-07-16 20:32:27 -0700196 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700197
Mathieu Chartier9642c962013-08-05 17:40:36 -0700198 // Marks an object atomically, safe to use from multiple threads.
Mathieu Chartiercb535da2015-01-23 13:50:03 -0800199 void MarkObjectNonNullParallel(mirror::Object* obj)
Mathieu Chartier90443472015-07-16 20:32:27 -0700200 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_);
Mathieu Chartier9642c962013-08-05 17:40:36 -0700201
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700202 // Returns true if we need to add obj to a mark stack.
Mathieu Chartier97509952015-07-13 14:35:43 -0700203 bool MarkObjectParallel(mirror::Object* obj) NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700204
Mathieu Chartier6f1c9492012-10-15 12:08:41 -0700205 // Verify the roots of the heap and print out information related to any invalid roots.
206 // Called in MarkObject, so may we may not hold the mutator lock.
207 void VerifyRoots()
208 NO_THREAD_SAFETY_ANALYSIS;
209
Mathieu Chartierba311b42013-08-27 13:02:30 -0700210 // Expand mark stack to 2x its current size.
Mathieu Chartier90443472015-07-16 20:32:27 -0700211 void ExpandMarkStack() REQUIRES(mark_stack_lock_)
212 SHARED_REQUIRES(Locks::mutator_lock_);
213 void ResizeMarkStack(size_t new_size) REQUIRES(mark_stack_lock_)
214 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierac86a7c2012-11-12 15:03:16 -0800215
Mathieu Chartier2775ee42013-08-20 17:43:47 -0700216 // Returns how many threads we should use for the current GC phase based on if we are paused,
217 // whether or not we care about pauses.
218 size_t GetThreadCount(bool paused) const;
219
Mathieu Chartier0e54cd02014-03-20 12:41:23 -0700220 // Push a single reference on a mark stack.
Mathieu Chartier90443472015-07-16 20:32:27 -0700221 void PushOnMarkStack(mirror::Object* obj) SHARED_REQUIRES(Locks::mutator_lock_)
222 REQUIRES(!mark_stack_lock_);
Ian Rogers5d76c432011-10-31 21:42:49 -0700223
Carl Shapiro69759ea2011-07-21 18:13:35 -0700224 // Blackens objects grayed during a garbage collection.
Ian Rogers13735952014-10-08 12:43:28 -0700225 void ScanGrayObjects(bool paused, uint8_t minimum_age)
Mathieu Chartier90443472015-07-16 20:32:27 -0700226 REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700227
Mathieu Chartier90443472015-07-16 20:32:27 -0700228 virtual void ProcessMarkStack() OVERRIDE REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_)
229 SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier97509952015-07-13 14:35:43 -0700230 ProcessMarkStack(false);
231 }
232
Carl Shapiro69759ea2011-07-21 18:13:35 -0700233 // Recursively blackens objects on the mark stack.
Mathieu Chartier94c32c52013-08-09 11:14:04 -0700234 void ProcessMarkStack(bool paused)
Mathieu Chartier90443472015-07-16 20:32:27 -0700235 REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700236
Mathieu Chartier2775ee42013-08-20 17:43:47 -0700237 void ProcessMarkStackParallel(size_t thread_count)
Mathieu Chartier90443472015-07-16 20:32:27 -0700238 REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700239
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700240 // Used to Get around thread safety annotations. The call is from MarkingPhase and is guarded by
Mathieu Chartierc22c59e2014-02-24 15:16:06 -0800241 // IsExclusiveHeld.
242 void RevokeAllThreadLocalAllocationStacks(Thread* self) NO_THREAD_SAFETY_ANALYSIS;
243
Hiroshi Yamauchic93c5302014-03-20 16:15:37 -0700244 // Revoke all the thread-local buffers.
245 void RevokeAllThreadLocalBuffers();
246
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700247 // Whether or not we count how many of each type of object were scanned.
248 static const bool kCountScannedTypes = false;
249
Ian Rogers1d54e732013-05-02 21:10:01 -0700250 // Current space, we check this space first to avoid searching for the appropriate space for an
251 // object.
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -0700252 accounting::ContinuousSpaceBitmap* current_space_bitmap_;
Mathieu Chartier0e54cd02014-03-20 12:41:23 -0700253 // Cache the heap's mark bitmap to prevent having to do 2 loads during slow path marking.
254 accounting::HeapBitmap* mark_bitmap_;
Mathieu Chartierb062fdd2012-07-03 09:51:48 -0700255
Ian Rogers1d54e732013-05-02 21:10:01 -0700256 accounting::ObjectStack* mark_stack_;
Carl Shapiro69759ea2011-07-21 18:13:35 -0700257
Mathieu Chartier4aeec172014-03-27 16:09:46 -0700258 // Immune region, every object inside the immune range is assumed to be marked.
Mathieu Chartier8d562102014-03-12 17:42:10 -0700259 ImmuneRegion immune_region_;
Carl Shapiro69759ea2011-07-21 18:13:35 -0700260
Mathieu Chartier94c32c52013-08-09 11:14:04 -0700261 // Parallel finger.
262 AtomicInteger atomic_finger_;
Ian Rogers1d54e732013-05-02 21:10:01 -0700263 // Number of classes scanned, if kCountScannedTypes.
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700264 AtomicInteger class_count_;
Ian Rogers1d54e732013-05-02 21:10:01 -0700265 // Number of arrays scanned, if kCountScannedTypes.
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700266 AtomicInteger array_count_;
Ian Rogers1d54e732013-05-02 21:10:01 -0700267 // Number of non-class/arrays scanned, if kCountScannedTypes.
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700268 AtomicInteger other_count_;
269 AtomicInteger large_object_test_;
270 AtomicInteger large_object_mark_;
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700271 AtomicInteger overhead_time_;
272 AtomicInteger work_chunks_created_;
273 AtomicInteger work_chunks_deleted_;
Mathieu Chartierd22d5482012-11-06 17:14:12 -0800274 AtomicInteger reference_count_;
Mathieu Chartier0e54cd02014-03-20 12:41:23 -0700275 AtomicInteger mark_null_count_;
276 AtomicInteger mark_immune_count_;
277 AtomicInteger mark_fastpath_count_;
278 AtomicInteger mark_slowpath_count_;
Mathieu Chartier0f72e412013-09-06 16:40:01 -0700279
Ian Rogers700a4022014-05-19 16:49:03 -0700280 std::unique_ptr<Barrier> gc_barrier_;
Mathieu Chartier958291c2013-08-27 18:14:55 -0700281 Mutex mark_stack_lock_ ACQUIRED_AFTER(Locks::classlinker_classes_lock_);
Ian Rogers1bd4b4c2013-04-18 17:47:42 -0700282
283 const bool is_concurrent_;
284
Ian Rogers3e5cf302014-05-20 16:40:37 -0700285 // Verification.
286 size_t live_stack_freeze_size_;
287
Hiroshi Yamauchibbdc5bc2014-05-28 14:04:59 -0700288 std::unique_ptr<MemMap> sweep_array_free_buffer_mem_map_;
289
Mathieu Chartier02e25112013-08-14 16:14:24 -0700290 private:
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700291 friend class AddIfReachesAllocSpaceVisitor; // Used by mod-union table.
Mathieu Chartier0f72e412013-09-06 16:40:01 -0700292 friend class CardScanTask;
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700293 friend class CheckBitmapVisitor;
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700294 friend class CheckReferenceVisitor;
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700295 friend class CheckpointMarkThreadRoots;
Ian Rogers1d54e732013-05-02 21:10:01 -0700296 friend class art::gc::Heap;
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700297 friend class FifoMarkStackChunk;
Mathieu Chartier0e54cd02014-03-20 12:41:23 -0700298 friend class MarkObjectVisitor;
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700299 template<bool kUseFinger> friend class MarkStackTask;
300 friend class MarkSweepMarkObjectSlowPath;
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700301 friend class ModUnionCheckReferences;
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700302 friend class ModUnionClearCardVisitor;
Mathieu Chartiere6e06512012-06-26 15:00:26 -0700303 friend class ModUnionReferenceVisitor;
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700304 friend class ModUnionScanImageRootVisitor;
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700305 friend class ModUnionTableBitmap;
Mathieu Chartiere6e06512012-06-26 15:00:26 -0700306 friend class ModUnionTableReferenceCache;
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700307 friend class ModUnionVisitor;
308 friend class VerifyRootMarkedVisitor;
309 friend class VerifyRootVisitor;
Elliott Hughes410c0c82011-09-01 17:58:25 -0700310
Mathieu Chartier3130cdf2015-05-03 15:20:23 -0700311 DISALLOW_IMPLICIT_CONSTRUCTORS(MarkSweep);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700312};
313
Ian Rogers1d54e732013-05-02 21:10:01 -0700314} // namespace collector
315} // namespace gc
Carl Shapiro69759ea2011-07-21 18:13:35 -0700316} // namespace art
317
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700318#endif // ART_RUNTIME_GC_COLLECTOR_MARK_SWEEP_H_