blob: 844bb450ccf166d3be5a35269fd8b3496ef2d36f [file] [log] [blame]
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -07001/*
2 * Copyright (C) 2014 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 */
16
17#ifndef ART_RUNTIME_GC_COLLECTOR_CONCURRENT_COPYING_H_
18#define ART_RUNTIME_GC_COLLECTOR_CONCURRENT_COPYING_H_
19
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080020#include "barrier.h"
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -070021#include "garbage_collector.h"
Mathieu Chartier763a31e2015-11-16 16:05:55 -080022#include "immune_spaces.h"
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080023#include "jni.h"
24#include "object_callbacks.h"
25#include "offsets.h"
26#include "gc/accounting/atomic_stack.h"
27#include "gc/accounting/read_barrier_table.h"
28#include "gc/accounting/space_bitmap.h"
29#include "mirror/object.h"
30#include "mirror/object_reference.h"
31#include "safe_map.h"
32
33#include <unordered_map>
34#include <vector>
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -070035
36namespace art {
Hiroshi Yamauchifebd0cf2016-09-14 19:31:25 -070037class Closure;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080038class RootInfo;
39
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -070040namespace gc {
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080041
42namespace accounting {
43 typedef SpaceBitmap<kObjectAlignment> ContinuousSpaceBitmap;
44 class HeapBitmap;
45} // namespace accounting
46
47namespace space {
48 class RegionSpace;
49} // namespace space
50
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -070051namespace collector {
52
53class ConcurrentCopying : public GarbageCollector {
54 public:
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080055 // Enable the no-from-space-refs verification at the pause.
Hiroshi Yamauchidaf61a12016-06-10 14:27:38 -070056 static constexpr bool kEnableNoFromSpaceRefsVerification = kIsDebugBuild;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080057 // Enable the from-space bytes/objects check.
Hiroshi Yamauchidaf61a12016-06-10 14:27:38 -070058 static constexpr bool kEnableFromSpaceAccountingCheck = kIsDebugBuild;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080059 // Enable verbose mode.
Hiroshi Yamauchi3c448932016-01-22 16:26:50 -080060 static constexpr bool kVerboseMode = false;
Mathieu Chartier36a270a2016-07-28 18:08:51 -070061 // If kGrayDirtyImmuneObjects is true then we gray dirty objects in the GC pause to prevent dirty
62 // pages.
63 static constexpr bool kGrayDirtyImmuneObjects = true;
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -070064
Chih-Hung Hsieha5931182016-09-01 15:08:13 -070065 explicit ConcurrentCopying(Heap* heap,
66 const std::string& name_prefix = "",
67 bool measure_read_barrier_slow_path = false);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080068 ~ConcurrentCopying();
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -070069
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -070070 virtual void RunPhases() OVERRIDE
Mathieu Chartier56fe2582016-07-14 13:30:03 -070071 REQUIRES(!immune_gray_stack_lock_,
72 !mark_stack_lock_,
73 !rb_slow_path_histogram_lock_,
74 !skipped_blocks_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070075 void InitializePhase() REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -070076 REQUIRES(!mark_stack_lock_, !immune_gray_stack_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070077 void MarkingPhase() REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -070078 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070079 void ReclaimPhase() REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_);
Mathieu Chartier56fe2582016-07-14 13:30:03 -070080 void FinishPhase() REQUIRES(!mark_stack_lock_,
81 !rb_slow_path_histogram_lock_,
82 !skipped_blocks_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080083
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070084 void BindBitmaps() REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -070085 REQUIRES(!Locks::heap_bitmap_lock_);
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -070086 virtual GcType GetGcType() const OVERRIDE {
87 return kGcTypePartial;
88 }
89 virtual CollectorType GetCollectorType() const OVERRIDE {
90 return kCollectorTypeCC;
91 }
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080092 virtual void RevokeAllThreadLocalBuffers() OVERRIDE;
93 void SetRegionSpace(space::RegionSpace* region_space) {
94 DCHECK(region_space != nullptr);
95 region_space_ = region_space;
96 }
97 space::RegionSpace* RegionSpace() {
98 return region_space_;
99 }
100 void AssertToSpaceInvariant(mirror::Object* obj, MemberOffset offset, mirror::Object* ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700101 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi3f64f252015-06-12 18:35:06 -0700102 void AssertToSpaceInvariant(GcRootSource* gc_root_source, mirror::Object* ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700103 REQUIRES_SHARED(Locks::mutator_lock_);
104 bool IsInToSpace(mirror::Object* ref) REQUIRES_SHARED(Locks::mutator_lock_) {
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800105 DCHECK(ref != nullptr);
106 return IsMarked(ref) == ref;
107 }
Mathieu Chartierc381c362016-08-23 13:27:53 -0700108 template<bool kGrayImmuneObject = true, bool kFromGCThread = false>
Mathieu Chartier56fe2582016-07-14 13:30:03 -0700109 ALWAYS_INLINE mirror::Object* Mark(mirror::Object* from_ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700110 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier56fe2582016-07-14 13:30:03 -0700111 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
112 ALWAYS_INLINE mirror::Object* MarkFromReadBarrier(mirror::Object* from_ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700113 REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700114 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800115 bool IsMarking() const {
116 return is_marking_;
117 }
118 bool IsActive() const {
119 return is_active_;
120 }
121 Barrier& GetBarrier() {
122 return *gc_barrier_;
123 }
Hiroshi Yamauchifebd0cf2016-09-14 19:31:25 -0700124 bool IsWeakRefAccessEnabled() REQUIRES(Locks::thread_list_lock_) {
125 return weak_ref_access_enabled_;
Hiroshi Yamauchi0b713572015-06-16 18:29:23 -0700126 }
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700127 void RevokeThreadLocalMarkStack(Thread* thread) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700128 REQUIRES(!mark_stack_lock_);
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -0700129
130 private:
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700131 void PushOntoMarkStack(mirror::Object* obj) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700132 REQUIRES(!mark_stack_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700133 mirror::Object* Copy(mirror::Object* from_ref) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartierd6636d32016-07-28 11:02:38 -0700134 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700135 void Scan(mirror::Object* to_ref) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700136 REQUIRES(!mark_stack_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800137 void Process(mirror::Object* obj, MemberOffset offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700138 REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700139 REQUIRES(!mark_stack_lock_ , !skipped_blocks_lock_, !immune_gray_stack_lock_);
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700140 virtual void VisitRoots(mirror::Object*** roots, size_t count, const RootInfo& info)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700141 OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700142 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
143 template<bool kGrayImmuneObject>
Mathieu Chartierda7c6502015-07-23 16:01:26 -0700144 void MarkRoot(mirror::CompressedReference<mirror::Object>* root)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700145 REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700146 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700147 virtual void VisitRoots(mirror::CompressedReference<mirror::Object>** roots, size_t count,
148 const RootInfo& info)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700149 OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700150 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
Mathieu Chartier90443472015-07-16 20:32:27 -0700151 void VerifyNoFromSpaceReferences() REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800152 accounting::ObjectStack* GetAllocationStack();
153 accounting::ObjectStack* GetLiveStack();
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700154 virtual void ProcessMarkStack() OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700155 REQUIRES(!mark_stack_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700156 bool ProcessMarkStackOnce() REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_);
157 void ProcessMarkStackRef(mirror::Object* to_ref) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700158 REQUIRES(!mark_stack_lock_);
Mathieu Chartier21328a12016-07-22 10:47:45 -0700159 void GrayAllDirtyImmuneObjects()
160 REQUIRES(Locks::mutator_lock_)
161 REQUIRES(!mark_stack_lock_);
162 void VerifyGrayImmuneObjects()
163 REQUIRES(Locks::mutator_lock_)
164 REQUIRES(!mark_stack_lock_);
Hiroshi Yamauchifebd0cf2016-09-14 19:31:25 -0700165 size_t ProcessThreadLocalMarkStacks(bool disable_weak_ref_access, Closure* checkpoint_callback)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700166 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_);
Hiroshi Yamauchifebd0cf2016-09-14 19:31:25 -0700167 void RevokeThreadLocalMarkStacks(bool disable_weak_ref_access, Closure* checkpoint_callback)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700168 REQUIRES_SHARED(Locks::mutator_lock_);
169 void SwitchToSharedMarkStackMode() REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700170 REQUIRES(!mark_stack_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700171 void SwitchToGcExclusiveMarkStackMode() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier31e88222016-10-14 18:43:19 -0700172 virtual void DelayReferenceReferent(ObjPtr<mirror::Class> klass,
173 ObjPtr<mirror::Reference> reference) OVERRIDE
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700174 REQUIRES_SHARED(Locks::mutator_lock_);
175 void ProcessReferences(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier97509952015-07-13 14:35:43 -0700176 virtual mirror::Object* MarkObject(mirror::Object* from_ref) OVERRIDE
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700177 REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700178 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
Mathieu Chartier97509952015-07-13 14:35:43 -0700179 virtual void MarkHeapReference(mirror::HeapReference<mirror::Object>* from_ref) OVERRIDE
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700180 REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700181 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
Mathieu Chartier97509952015-07-13 14:35:43 -0700182 virtual mirror::Object* IsMarked(mirror::Object* from_ref) OVERRIDE
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700183 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierc381c362016-08-23 13:27:53 -0700184 bool IsMarkedInUnevacFromSpace(mirror::Object* from_ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700185 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi65f5f242016-12-19 11:44:47 -0800186 virtual bool IsNullOrMarkedHeapReference(mirror::HeapReference<mirror::Object>* field,
187 bool do_atomic_update) OVERRIDE
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700188 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800189 void SweepSystemWeaks(Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700190 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::heap_bitmap_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800191 void Sweep(bool swap_bitmaps)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700192 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800193 void SweepLargeObjects(bool swap_bitmaps)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700194 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_);
Mathieu Chartier962cd7a2016-08-16 12:15:59 -0700195 void MarkZygoteLargeObjects()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700196 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800197 void FillWithDummyObject(mirror::Object* dummy_obj, size_t byte_size)
Mathieu Chartierd6636d32016-07-28 11:02:38 -0700198 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700199 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800200 mirror::Object* AllocateInSkippedBlock(size_t alloc_size)
Mathieu Chartierd6636d32016-07-28 11:02:38 -0700201 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700202 REQUIRES_SHARED(Locks::mutator_lock_);
203 void CheckEmptyMarkStack() REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_);
204 void IssueEmptyCheckpoint() REQUIRES_SHARED(Locks::mutator_lock_);
205 bool IsOnAllocStack(mirror::Object* ref) REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800206 mirror::Object* GetFwdPtr(mirror::Object* from_ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700207 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier90443472015-07-16 20:32:27 -0700208 void FlipThreadRoots() REQUIRES(!Locks::mutator_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700209 void SwapStacks() REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800210 void RecordLiveStackFreezeSize(Thread* self);
211 void ComputeUnevacFromSpaceLiveRatio();
Hiroshi Yamauchi3f64f252015-06-12 18:35:06 -0700212 void LogFromSpaceRefHolder(mirror::Object* obj, MemberOffset offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700213 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi3f64f252015-06-12 18:35:06 -0700214 void AssertToSpaceInvariantInNonMovingSpace(mirror::Object* obj, mirror::Object* ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700215 REQUIRES_SHARED(Locks::mutator_lock_);
216 void ReenableWeakRefAccess(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_);
217 void DisableMarking() REQUIRES_SHARED(Locks::mutator_lock_);
218 void IssueDisableMarkingCheckpoint() REQUIRES_SHARED(Locks::mutator_lock_);
219 void ExpandGcMarkStack() REQUIRES_SHARED(Locks::mutator_lock_);
220 mirror::Object* MarkNonMoving(mirror::Object* from_ref) REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchi723e6ce2015-10-28 20:59:47 -0700221 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_);
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700222 ALWAYS_INLINE mirror::Object* MarkUnevacFromSpaceRegion(mirror::Object* from_ref,
Hiroshi Yamauchi8e674652015-12-22 11:09:18 -0800223 accounting::SpaceBitmap<kObjectAlignment>* bitmap)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700224 REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchi8e674652015-12-22 11:09:18 -0800225 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_);
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700226 template<bool kGrayImmuneObject>
227 ALWAYS_INLINE mirror::Object* MarkImmuneSpace(mirror::Object* from_ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700228 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!immune_gray_stack_lock_);
229 void PushOntoFalseGrayStack(mirror::Object* obj) REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchi8e674652015-12-22 11:09:18 -0800230 REQUIRES(!mark_stack_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700231 void ProcessFalseGrayStack() REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchi8e674652015-12-22 11:09:18 -0800232 REQUIRES(!mark_stack_lock_);
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700233 void ScanImmuneObject(mirror::Object* obj)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700234 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_);
Mathieu Chartier56fe2582016-07-14 13:30:03 -0700235 mirror::Object* MarkFromReadBarrierWithMeasurements(mirror::Object* from_ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700236 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier56fe2582016-07-14 13:30:03 -0700237 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
238 void DumpPerformanceInfo(std::ostream& os) OVERRIDE REQUIRES(!rb_slow_path_histogram_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800239
240 space::RegionSpace* region_space_; // The underlying region space.
241 std::unique_ptr<Barrier> gc_barrier_;
Hiroshi Yamauchi0b713572015-06-16 18:29:23 -0700242 std::unique_ptr<accounting::ObjectStack> gc_mark_stack_;
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700243 std::unique_ptr<accounting::ObjectStack> rb_mark_bit_stack_;
244 bool rb_mark_bit_stack_full_;
Hiroshi Yamauchi8e674652015-12-22 11:09:18 -0800245 std::vector<mirror::Object*> false_gray_stack_ GUARDED_BY(mark_stack_lock_);
Hiroshi Yamauchi0b713572015-06-16 18:29:23 -0700246 Mutex mark_stack_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
247 std::vector<accounting::ObjectStack*> revoked_mark_stacks_
248 GUARDED_BY(mark_stack_lock_);
249 static constexpr size_t kMarkStackSize = kPageSize;
250 static constexpr size_t kMarkStackPoolSize = 256;
251 std::vector<accounting::ObjectStack*> pooled_mark_stacks_
252 GUARDED_BY(mark_stack_lock_);
253 Thread* thread_running_gc_;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800254 bool is_marking_; // True while marking is ongoing.
255 bool is_active_; // True while the collection is ongoing.
256 bool is_asserting_to_space_invariant_; // True while asserting the to-space invariant.
Mathieu Chartier763a31e2015-11-16 16:05:55 -0800257 ImmuneSpaces immune_spaces_;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800258 accounting::SpaceBitmap<kObjectAlignment>* region_space_bitmap_;
259 // A cache of Heap::GetMarkBitmap().
260 accounting::HeapBitmap* heap_mark_bitmap_;
261 size_t live_stack_freeze_size_;
262 size_t from_space_num_objects_at_first_pause_;
263 size_t from_space_num_bytes_at_first_pause_;
Hiroshi Yamauchi0b713572015-06-16 18:29:23 -0700264 Atomic<int> is_mark_stack_push_disallowed_;
265 enum MarkStackMode {
266 kMarkStackModeOff = 0, // Mark stack is off.
267 kMarkStackModeThreadLocal, // All threads except for the GC-running thread push refs onto
268 // thread-local mark stacks. The GC-running thread pushes onto and
269 // pops off the GC mark stack without a lock.
270 kMarkStackModeShared, // All threads share the GC mark stack with a lock.
271 kMarkStackModeGcExclusive // The GC-running thread pushes onto and pops from the GC mark stack
272 // without a lock. Other threads won't access the mark stack.
273 };
274 Atomic<MarkStackMode> mark_stack_mode_;
Hiroshi Yamauchifebd0cf2016-09-14 19:31:25 -0700275 bool weak_ref_access_enabled_ GUARDED_BY(Locks::thread_list_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800276
277 // How many objects and bytes we moved. Used for accounting.
278 Atomic<size_t> bytes_moved_;
279 Atomic<size_t> objects_moved_;
Mathieu Chartiercca44a02016-08-17 10:07:29 -0700280 Atomic<uint64_t> cumulative_bytes_moved_;
281 Atomic<uint64_t> cumulative_objects_moved_;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800282
283 // The skipped blocks are memory blocks/chucks that were copies of
284 // objects that were unused due to lost races (cas failures) at
285 // object copy/forward pointer install. They are reused.
286 Mutex skipped_blocks_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
287 std::multimap<size_t, uint8_t*> skipped_blocks_map_ GUARDED_BY(skipped_blocks_lock_);
288 Atomic<size_t> to_space_bytes_skipped_;
289 Atomic<size_t> to_space_objects_skipped_;
290
Mathieu Chartier56fe2582016-07-14 13:30:03 -0700291 // If measure_read_barrier_slow_path_ is true, we count how long is spent in MarkFromReadBarrier
292 // and also log.
293 bool measure_read_barrier_slow_path_;
294 // mark_from_read_barrier_measurements_ is true if systrace is enabled or
295 // measure_read_barrier_time_ is true.
296 bool mark_from_read_barrier_measurements_;
297 Atomic<uint64_t> rb_slow_path_ns_;
298 Atomic<uint64_t> rb_slow_path_count_;
299 Atomic<uint64_t> rb_slow_path_count_gc_;
300 mutable Mutex rb_slow_path_histogram_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
301 Histogram<uint64_t> rb_slow_path_time_histogram_ GUARDED_BY(rb_slow_path_histogram_lock_);
302 uint64_t rb_slow_path_count_total_ GUARDED_BY(rb_slow_path_histogram_lock_);
303 uint64_t rb_slow_path_count_gc_total_ GUARDED_BY(rb_slow_path_histogram_lock_);
304
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800305 accounting::ReadBarrierTable* rb_table_;
306 bool force_evacuate_all_; // True if all regions are evacuated.
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700307 Atomic<bool> updated_all_immune_objects_;
308 bool gc_grays_immune_objects_;
309 Mutex immune_gray_stack_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
310 std::vector<mirror::Object*> immune_gray_stack_ GUARDED_BY(immune_gray_stack_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800311
Mathieu Chartiera07f5592016-06-16 11:44:28 -0700312 class AssertToSpaceInvariantFieldVisitor;
313 class AssertToSpaceInvariantObjectVisitor;
314 class AssertToSpaceInvariantRefsVisitor;
315 class ClearBlackPtrsVisitor;
316 class ComputeUnevacFromSpaceLiveRatioVisitor;
Hiroshi Yamauchifebd0cf2016-09-14 19:31:25 -0700317 class DisableMarkingCallback;
Mathieu Chartiera07f5592016-06-16 11:44:28 -0700318 class DisableMarkingCheckpoint;
Hiroshi Yamauchifebd0cf2016-09-14 19:31:25 -0700319 class DisableWeakRefAccessCallback;
Mathieu Chartiera07f5592016-06-16 11:44:28 -0700320 class FlipCallback;
Mathieu Chartier21328a12016-07-22 10:47:45 -0700321 class GrayImmuneObjectVisitor;
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700322 class ImmuneSpaceScanObjVisitor;
Mathieu Chartiera07f5592016-06-16 11:44:28 -0700323 class LostCopyVisitor;
324 class RefFieldsVisitor;
325 class RevokeThreadLocalMarkStackCheckpoint;
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700326 class ScopedGcGraysImmuneObjects;
327 class ThreadFlipVisitor;
Mathieu Chartier21328a12016-07-22 10:47:45 -0700328 class VerifyGrayImmuneObjectsVisitor;
Mathieu Chartiera07f5592016-06-16 11:44:28 -0700329 class VerifyNoFromSpaceRefsFieldVisitor;
330 class VerifyNoFromSpaceRefsObjectVisitor;
331 class VerifyNoFromSpaceRefsVisitor;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800332
Mathieu Chartier3130cdf2015-05-03 15:20:23 -0700333 DISALLOW_IMPLICIT_CONSTRUCTORS(ConcurrentCopying);
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -0700334};
335
336} // namespace collector
337} // namespace gc
338} // namespace art
339
340#endif // ART_RUNTIME_GC_COLLECTOR_CONCURRENT_COPYING_H_