blob: 1ef0aeac243747d4f59928a233b077dc8f3e1a34 [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 Yamauchi2cd334a2015-01-09 14:03:35 -080037class RootInfo;
38
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -070039namespace gc {
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080040
41namespace accounting {
42 typedef SpaceBitmap<kObjectAlignment> ContinuousSpaceBitmap;
43 class HeapBitmap;
44} // namespace accounting
45
46namespace space {
47 class RegionSpace;
48} // namespace space
49
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -070050namespace collector {
51
52class ConcurrentCopying : public GarbageCollector {
53 public:
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080054 // Enable the no-from-space-refs verification at the pause.
Hiroshi Yamauchidaf61a12016-06-10 14:27:38 -070055 static constexpr bool kEnableNoFromSpaceRefsVerification = kIsDebugBuild;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080056 // Enable the from-space bytes/objects check.
Hiroshi Yamauchidaf61a12016-06-10 14:27:38 -070057 static constexpr bool kEnableFromSpaceAccountingCheck = kIsDebugBuild;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080058 // Enable verbose mode.
Hiroshi Yamauchi3c448932016-01-22 16:26:50 -080059 static constexpr bool kVerboseMode = false;
Mathieu Chartier36a270a2016-07-28 18:08:51 -070060 // If kGrayDirtyImmuneObjects is true then we gray dirty objects in the GC pause to prevent dirty
61 // pages.
62 static constexpr bool kGrayDirtyImmuneObjects = true;
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -070063
Mathieu Chartier56fe2582016-07-14 13:30:03 -070064 ConcurrentCopying(Heap* heap,
65 const std::string& name_prefix = "",
66 bool measure_read_barrier_slow_path = false);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080067 ~ConcurrentCopying();
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -070068
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -070069 virtual void RunPhases() OVERRIDE
Mathieu Chartier56fe2582016-07-14 13:30:03 -070070 REQUIRES(!immune_gray_stack_lock_,
71 !mark_stack_lock_,
72 !rb_slow_path_histogram_lock_,
73 !skipped_blocks_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070074 void InitializePhase() REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -070075 REQUIRES(!mark_stack_lock_, !immune_gray_stack_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070076 void MarkingPhase() REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -070077 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070078 void ReclaimPhase() REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_);
Mathieu Chartier56fe2582016-07-14 13:30:03 -070079 void FinishPhase() REQUIRES(!mark_stack_lock_,
80 !rb_slow_path_histogram_lock_,
81 !skipped_blocks_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080082
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070083 void BindBitmaps() REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -070084 REQUIRES(!Locks::heap_bitmap_lock_);
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -070085 virtual GcType GetGcType() const OVERRIDE {
86 return kGcTypePartial;
87 }
88 virtual CollectorType GetCollectorType() const OVERRIDE {
89 return kCollectorTypeCC;
90 }
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080091 virtual void RevokeAllThreadLocalBuffers() OVERRIDE;
92 void SetRegionSpace(space::RegionSpace* region_space) {
93 DCHECK(region_space != nullptr);
94 region_space_ = region_space;
95 }
96 space::RegionSpace* RegionSpace() {
97 return region_space_;
98 }
99 void AssertToSpaceInvariant(mirror::Object* obj, MemberOffset offset, mirror::Object* ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700100 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi3f64f252015-06-12 18:35:06 -0700101 void AssertToSpaceInvariant(GcRootSource* gc_root_source, mirror::Object* ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700102 REQUIRES_SHARED(Locks::mutator_lock_);
103 bool IsInToSpace(mirror::Object* ref) REQUIRES_SHARED(Locks::mutator_lock_) {
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800104 DCHECK(ref != nullptr);
105 return IsMarked(ref) == ref;
106 }
Mathieu Chartierc381c362016-08-23 13:27:53 -0700107 template<bool kGrayImmuneObject = true, bool kFromGCThread = false>
Mathieu Chartier56fe2582016-07-14 13:30:03 -0700108 ALWAYS_INLINE mirror::Object* Mark(mirror::Object* from_ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700109 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier56fe2582016-07-14 13:30:03 -0700110 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
111 ALWAYS_INLINE mirror::Object* MarkFromReadBarrier(mirror::Object* from_ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700112 REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700113 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800114 bool IsMarking() const {
115 return is_marking_;
116 }
117 bool IsActive() const {
118 return is_active_;
119 }
120 Barrier& GetBarrier() {
121 return *gc_barrier_;
122 }
Hiroshi Yamauchi0b713572015-06-16 18:29:23 -0700123 bool IsWeakRefAccessEnabled() {
124 return weak_ref_access_enabled_.LoadRelaxed();
125 }
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700126 void RevokeThreadLocalMarkStack(Thread* thread) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700127 REQUIRES(!mark_stack_lock_);
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -0700128
129 private:
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700130 void PushOntoMarkStack(mirror::Object* obj) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700131 REQUIRES(!mark_stack_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700132 mirror::Object* Copy(mirror::Object* from_ref) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartierd6636d32016-07-28 11:02:38 -0700133 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700134 void Scan(mirror::Object* to_ref) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700135 REQUIRES(!mark_stack_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800136 void Process(mirror::Object* obj, MemberOffset offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700137 REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700138 REQUIRES(!mark_stack_lock_ , !skipped_blocks_lock_, !immune_gray_stack_lock_);
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700139 virtual void VisitRoots(mirror::Object*** roots, size_t count, const RootInfo& info)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700140 OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700141 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
142 template<bool kGrayImmuneObject>
Mathieu Chartierda7c6502015-07-23 16:01:26 -0700143 void MarkRoot(mirror::CompressedReference<mirror::Object>* root)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700144 REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700145 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700146 virtual void VisitRoots(mirror::CompressedReference<mirror::Object>** roots, size_t count,
147 const RootInfo& info)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700148 OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700149 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
Mathieu Chartier90443472015-07-16 20:32:27 -0700150 void VerifyNoFromSpaceReferences() REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800151 accounting::ObjectStack* GetAllocationStack();
152 accounting::ObjectStack* GetLiveStack();
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700153 virtual void ProcessMarkStack() OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700154 REQUIRES(!mark_stack_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700155 bool ProcessMarkStackOnce() REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_);
156 void ProcessMarkStackRef(mirror::Object* to_ref) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700157 REQUIRES(!mark_stack_lock_);
Mathieu Chartier21328a12016-07-22 10:47:45 -0700158 void GrayAllDirtyImmuneObjects()
159 REQUIRES(Locks::mutator_lock_)
160 REQUIRES(!mark_stack_lock_);
161 void VerifyGrayImmuneObjects()
162 REQUIRES(Locks::mutator_lock_)
163 REQUIRES(!mark_stack_lock_);
Hiroshi Yamauchi0b713572015-06-16 18:29:23 -0700164 size_t ProcessThreadLocalMarkStacks(bool disable_weak_ref_access)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700165 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_);
Hiroshi Yamauchi0b713572015-06-16 18:29:23 -0700166 void RevokeThreadLocalMarkStacks(bool disable_weak_ref_access)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700167 REQUIRES_SHARED(Locks::mutator_lock_);
168 void SwitchToSharedMarkStackMode() REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700169 REQUIRES(!mark_stack_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700170 void SwitchToGcExclusiveMarkStackMode() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier97509952015-07-13 14:35:43 -0700171 virtual void DelayReferenceReferent(mirror::Class* klass, mirror::Reference* reference) OVERRIDE
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700172 REQUIRES_SHARED(Locks::mutator_lock_);
173 void ProcessReferences(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier97509952015-07-13 14:35:43 -0700174 virtual mirror::Object* MarkObject(mirror::Object* from_ref) OVERRIDE
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700175 REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700176 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
Mathieu Chartier97509952015-07-13 14:35:43 -0700177 virtual void MarkHeapReference(mirror::HeapReference<mirror::Object>* from_ref) OVERRIDE
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700178 REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700179 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
Mathieu Chartier97509952015-07-13 14:35:43 -0700180 virtual mirror::Object* IsMarked(mirror::Object* from_ref) OVERRIDE
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700181 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierc381c362016-08-23 13:27:53 -0700182 bool IsMarkedInUnevacFromSpace(mirror::Object* from_ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700183 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier97509952015-07-13 14:35:43 -0700184 virtual bool IsMarkedHeapReference(mirror::HeapReference<mirror::Object>* field) OVERRIDE
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700185 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800186 void SweepSystemWeaks(Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700187 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::heap_bitmap_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800188 void Sweep(bool swap_bitmaps)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700189 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800190 void SweepLargeObjects(bool swap_bitmaps)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700191 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_);
Mathieu Chartier962cd7a2016-08-16 12:15:59 -0700192 void MarkZygoteLargeObjects()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700193 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800194 void FillWithDummyObject(mirror::Object* dummy_obj, size_t byte_size)
Mathieu Chartierd6636d32016-07-28 11:02:38 -0700195 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700196 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800197 mirror::Object* AllocateInSkippedBlock(size_t alloc_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_);
200 void CheckEmptyMarkStack() REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_);
201 void IssueEmptyCheckpoint() REQUIRES_SHARED(Locks::mutator_lock_);
202 bool IsOnAllocStack(mirror::Object* ref) REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800203 mirror::Object* GetFwdPtr(mirror::Object* from_ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700204 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier90443472015-07-16 20:32:27 -0700205 void FlipThreadRoots() REQUIRES(!Locks::mutator_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700206 void SwapStacks() REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800207 void RecordLiveStackFreezeSize(Thread* self);
208 void ComputeUnevacFromSpaceLiveRatio();
Hiroshi Yamauchi3f64f252015-06-12 18:35:06 -0700209 void LogFromSpaceRefHolder(mirror::Object* obj, MemberOffset offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700210 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi3f64f252015-06-12 18:35:06 -0700211 void AssertToSpaceInvariantInNonMovingSpace(mirror::Object* obj, mirror::Object* ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700212 REQUIRES_SHARED(Locks::mutator_lock_);
213 void ReenableWeakRefAccess(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_);
214 void DisableMarking() REQUIRES_SHARED(Locks::mutator_lock_);
215 void IssueDisableMarkingCheckpoint() REQUIRES_SHARED(Locks::mutator_lock_);
216 void ExpandGcMarkStack() REQUIRES_SHARED(Locks::mutator_lock_);
217 mirror::Object* MarkNonMoving(mirror::Object* from_ref) REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchi723e6ce2015-10-28 20:59:47 -0700218 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_);
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700219 ALWAYS_INLINE mirror::Object* MarkUnevacFromSpaceRegion(mirror::Object* from_ref,
Hiroshi Yamauchi8e674652015-12-22 11:09:18 -0800220 accounting::SpaceBitmap<kObjectAlignment>* bitmap)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700221 REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchi8e674652015-12-22 11:09:18 -0800222 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_);
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700223 template<bool kGrayImmuneObject>
224 ALWAYS_INLINE mirror::Object* MarkImmuneSpace(mirror::Object* from_ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700225 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!immune_gray_stack_lock_);
226 void PushOntoFalseGrayStack(mirror::Object* obj) REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchi8e674652015-12-22 11:09:18 -0800227 REQUIRES(!mark_stack_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700228 void ProcessFalseGrayStack() REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchi8e674652015-12-22 11:09:18 -0800229 REQUIRES(!mark_stack_lock_);
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700230 void ScanImmuneObject(mirror::Object* obj)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700231 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_);
Mathieu Chartier56fe2582016-07-14 13:30:03 -0700232 mirror::Object* MarkFromReadBarrierWithMeasurements(mirror::Object* from_ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700233 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier56fe2582016-07-14 13:30:03 -0700234 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
235 void DumpPerformanceInfo(std::ostream& os) OVERRIDE REQUIRES(!rb_slow_path_histogram_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800236
237 space::RegionSpace* region_space_; // The underlying region space.
238 std::unique_ptr<Barrier> gc_barrier_;
Hiroshi Yamauchi0b713572015-06-16 18:29:23 -0700239 std::unique_ptr<accounting::ObjectStack> gc_mark_stack_;
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700240 std::unique_ptr<accounting::ObjectStack> rb_mark_bit_stack_;
241 bool rb_mark_bit_stack_full_;
Hiroshi Yamauchi8e674652015-12-22 11:09:18 -0800242 std::vector<mirror::Object*> false_gray_stack_ GUARDED_BY(mark_stack_lock_);
Hiroshi Yamauchi0b713572015-06-16 18:29:23 -0700243 Mutex mark_stack_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
244 std::vector<accounting::ObjectStack*> revoked_mark_stacks_
245 GUARDED_BY(mark_stack_lock_);
246 static constexpr size_t kMarkStackSize = kPageSize;
247 static constexpr size_t kMarkStackPoolSize = 256;
248 std::vector<accounting::ObjectStack*> pooled_mark_stacks_
249 GUARDED_BY(mark_stack_lock_);
250 Thread* thread_running_gc_;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800251 bool is_marking_; // True while marking is ongoing.
252 bool is_active_; // True while the collection is ongoing.
253 bool is_asserting_to_space_invariant_; // True while asserting the to-space invariant.
Mathieu Chartier763a31e2015-11-16 16:05:55 -0800254 ImmuneSpaces immune_spaces_;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800255 accounting::SpaceBitmap<kObjectAlignment>* region_space_bitmap_;
256 // A cache of Heap::GetMarkBitmap().
257 accounting::HeapBitmap* heap_mark_bitmap_;
258 size_t live_stack_freeze_size_;
259 size_t from_space_num_objects_at_first_pause_;
260 size_t from_space_num_bytes_at_first_pause_;
Hiroshi Yamauchi0b713572015-06-16 18:29:23 -0700261 Atomic<int> is_mark_stack_push_disallowed_;
262 enum MarkStackMode {
263 kMarkStackModeOff = 0, // Mark stack is off.
264 kMarkStackModeThreadLocal, // All threads except for the GC-running thread push refs onto
265 // thread-local mark stacks. The GC-running thread pushes onto and
266 // pops off the GC mark stack without a lock.
267 kMarkStackModeShared, // All threads share the GC mark stack with a lock.
268 kMarkStackModeGcExclusive // The GC-running thread pushes onto and pops from the GC mark stack
269 // without a lock. Other threads won't access the mark stack.
270 };
271 Atomic<MarkStackMode> mark_stack_mode_;
272 Atomic<bool> weak_ref_access_enabled_;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800273
274 // How many objects and bytes we moved. Used for accounting.
275 Atomic<size_t> bytes_moved_;
276 Atomic<size_t> objects_moved_;
Mathieu Chartiercca44a02016-08-17 10:07:29 -0700277 Atomic<uint64_t> cumulative_bytes_moved_;
278 Atomic<uint64_t> cumulative_objects_moved_;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800279
280 // The skipped blocks are memory blocks/chucks that were copies of
281 // objects that were unused due to lost races (cas failures) at
282 // object copy/forward pointer install. They are reused.
283 Mutex skipped_blocks_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
284 std::multimap<size_t, uint8_t*> skipped_blocks_map_ GUARDED_BY(skipped_blocks_lock_);
285 Atomic<size_t> to_space_bytes_skipped_;
286 Atomic<size_t> to_space_objects_skipped_;
287
Mathieu Chartier56fe2582016-07-14 13:30:03 -0700288 // If measure_read_barrier_slow_path_ is true, we count how long is spent in MarkFromReadBarrier
289 // and also log.
290 bool measure_read_barrier_slow_path_;
291 // mark_from_read_barrier_measurements_ is true if systrace is enabled or
292 // measure_read_barrier_time_ is true.
293 bool mark_from_read_barrier_measurements_;
294 Atomic<uint64_t> rb_slow_path_ns_;
295 Atomic<uint64_t> rb_slow_path_count_;
296 Atomic<uint64_t> rb_slow_path_count_gc_;
297 mutable Mutex rb_slow_path_histogram_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
298 Histogram<uint64_t> rb_slow_path_time_histogram_ GUARDED_BY(rb_slow_path_histogram_lock_);
299 uint64_t rb_slow_path_count_total_ GUARDED_BY(rb_slow_path_histogram_lock_);
300 uint64_t rb_slow_path_count_gc_total_ GUARDED_BY(rb_slow_path_histogram_lock_);
301
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800302 accounting::ReadBarrierTable* rb_table_;
303 bool force_evacuate_all_; // True if all regions are evacuated.
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700304 Atomic<bool> updated_all_immune_objects_;
305 bool gc_grays_immune_objects_;
306 Mutex immune_gray_stack_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
307 std::vector<mirror::Object*> immune_gray_stack_ GUARDED_BY(immune_gray_stack_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800308
Mathieu Chartiera07f5592016-06-16 11:44:28 -0700309 class AssertToSpaceInvariantFieldVisitor;
310 class AssertToSpaceInvariantObjectVisitor;
311 class AssertToSpaceInvariantRefsVisitor;
312 class ClearBlackPtrsVisitor;
313 class ComputeUnevacFromSpaceLiveRatioVisitor;
314 class DisableMarkingCheckpoint;
315 class FlipCallback;
Mathieu Chartier21328a12016-07-22 10:47:45 -0700316 class GrayImmuneObjectVisitor;
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700317 class ImmuneSpaceScanObjVisitor;
Mathieu Chartiera07f5592016-06-16 11:44:28 -0700318 class LostCopyVisitor;
319 class RefFieldsVisitor;
320 class RevokeThreadLocalMarkStackCheckpoint;
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700321 class ScopedGcGraysImmuneObjects;
322 class ThreadFlipVisitor;
Mathieu Chartier21328a12016-07-22 10:47:45 -0700323 class VerifyGrayImmuneObjectsVisitor;
Mathieu Chartiera07f5592016-06-16 11:44:28 -0700324 class VerifyNoFromSpaceRefsFieldVisitor;
325 class VerifyNoFromSpaceRefsObjectVisitor;
326 class VerifyNoFromSpaceRefsVisitor;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800327
Mathieu Chartier3130cdf2015-05-03 15:20:23 -0700328 DISALLOW_IMPLICIT_CONSTRUCTORS(ConcurrentCopying);
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -0700329};
330
331} // namespace collector
332} // namespace gc
333} // namespace art
334
335#endif // ART_RUNTIME_GC_COLLECTOR_CONCURRENT_COPYING_H_