blob: 5b0e2d62743f6cf019f707dfb0a20f74343534eb [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_);
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -070074 void InitializePhase() SHARED_REQUIRES(Locks::mutator_lock_)
75 REQUIRES(!mark_stack_lock_, !immune_gray_stack_lock_);
Mathieu Chartier90443472015-07-16 20:32:27 -070076 void MarkingPhase() SHARED_REQUIRES(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -070077 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
Mathieu Chartier90443472015-07-16 20:32:27 -070078 void ReclaimPhase() SHARED_REQUIRES(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
Mathieu Chartier90443472015-07-16 20:32:27 -070083 void BindBitmaps() SHARED_REQUIRES(Locks::mutator_lock_)
84 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)
Mathieu Chartier90443472015-07-16 20:32:27 -0700100 SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi3f64f252015-06-12 18:35:06 -0700101 void AssertToSpaceInvariant(GcRootSource* gc_root_source, mirror::Object* ref)
Mathieu Chartier90443472015-07-16 20:32:27 -0700102 SHARED_REQUIRES(Locks::mutator_lock_);
103 bool IsInToSpace(mirror::Object* ref) SHARED_REQUIRES(Locks::mutator_lock_) {
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800104 DCHECK(ref != nullptr);
105 return IsMarked(ref) == ref;
106 }
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700107 template<bool kGrayImmuneObject = true>
Mathieu Chartier56fe2582016-07-14 13:30:03 -0700108 ALWAYS_INLINE mirror::Object* Mark(mirror::Object* from_ref)
109 SHARED_REQUIRES(Locks::mutator_lock_)
110 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
111 ALWAYS_INLINE mirror::Object* MarkFromReadBarrier(mirror::Object* from_ref)
112 SHARED_REQUIRES(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 }
Mathieu Chartier90443472015-07-16 20:32:27 -0700126 void RevokeThreadLocalMarkStack(Thread* thread) SHARED_REQUIRES(Locks::mutator_lock_)
127 REQUIRES(!mark_stack_lock_);
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -0700128
129 private:
Mathieu Chartier90443472015-07-16 20:32:27 -0700130 void PushOntoMarkStack(mirror::Object* obj) SHARED_REQUIRES(Locks::mutator_lock_)
131 REQUIRES(!mark_stack_lock_);
132 mirror::Object* Copy(mirror::Object* from_ref) SHARED_REQUIRES(Locks::mutator_lock_)
Mathieu Chartierd6636d32016-07-28 11:02:38 -0700133 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
Mathieu Chartier90443472015-07-16 20:32:27 -0700134 void Scan(mirror::Object* to_ref) SHARED_REQUIRES(Locks::mutator_lock_)
135 REQUIRES(!mark_stack_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800136 void Process(mirror::Object* obj, MemberOffset offset)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700137 SHARED_REQUIRES(Locks::mutator_lock_)
138 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)
Mathieu Chartier90443472015-07-16 20:32:27 -0700140 OVERRIDE SHARED_REQUIRES(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)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700144 SHARED_REQUIRES(Locks::mutator_lock_)
145 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)
Mathieu Chartier90443472015-07-16 20:32:27 -0700148 OVERRIDE SHARED_REQUIRES(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();
Mathieu Chartier90443472015-07-16 20:32:27 -0700153 virtual void ProcessMarkStack() OVERRIDE SHARED_REQUIRES(Locks::mutator_lock_)
154 REQUIRES(!mark_stack_lock_);
155 bool ProcessMarkStackOnce() SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_);
156 void ProcessMarkStackRef(mirror::Object* to_ref) SHARED_REQUIRES(Locks::mutator_lock_)
157 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)
Mathieu Chartier90443472015-07-16 20:32:27 -0700165 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_);
Hiroshi Yamauchi0b713572015-06-16 18:29:23 -0700166 void RevokeThreadLocalMarkStacks(bool disable_weak_ref_access)
Mathieu Chartier90443472015-07-16 20:32:27 -0700167 SHARED_REQUIRES(Locks::mutator_lock_);
168 void SwitchToSharedMarkStackMode() SHARED_REQUIRES(Locks::mutator_lock_)
169 REQUIRES(!mark_stack_lock_);
170 void SwitchToGcExclusiveMarkStackMode() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier97509952015-07-13 14:35:43 -0700171 virtual void DelayReferenceReferent(mirror::Class* klass, mirror::Reference* reference) OVERRIDE
Mathieu Chartier90443472015-07-16 20:32:27 -0700172 SHARED_REQUIRES(Locks::mutator_lock_);
173 void ProcessReferences(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier97509952015-07-13 14:35:43 -0700174 virtual mirror::Object* MarkObject(mirror::Object* from_ref) OVERRIDE
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700175 SHARED_REQUIRES(Locks::mutator_lock_)
176 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
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700178 SHARED_REQUIRES(Locks::mutator_lock_)
179 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
Mathieu Chartier90443472015-07-16 20:32:27 -0700181 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier97509952015-07-13 14:35:43 -0700182 virtual bool IsMarkedHeapReference(mirror::HeapReference<mirror::Object>* field) OVERRIDE
Mathieu Chartier90443472015-07-16 20:32:27 -0700183 SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800184 void SweepSystemWeaks(Thread* self)
Mathieu Chartier90443472015-07-16 20:32:27 -0700185 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Locks::heap_bitmap_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800186 void Sweep(bool swap_bitmaps)
Mathieu Chartier90443472015-07-16 20:32:27 -0700187 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800188 void SweepLargeObjects(bool swap_bitmaps)
Mathieu Chartier90443472015-07-16 20:32:27 -0700189 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_);
Mathieu Chartier962cd7a2016-08-16 12:15:59 -0700190 void MarkZygoteLargeObjects()
191 SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800192 void FillWithDummyObject(mirror::Object* dummy_obj, size_t byte_size)
Mathieu Chartierd6636d32016-07-28 11:02:38 -0700193 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700194 SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800195 mirror::Object* AllocateInSkippedBlock(size_t alloc_size)
Mathieu Chartierd6636d32016-07-28 11:02:38 -0700196 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_)
197 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier90443472015-07-16 20:32:27 -0700198 void CheckEmptyMarkStack() SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_);
199 void IssueEmptyCheckpoint() SHARED_REQUIRES(Locks::mutator_lock_);
200 bool IsOnAllocStack(mirror::Object* ref) SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800201 mirror::Object* GetFwdPtr(mirror::Object* from_ref)
Mathieu Chartier90443472015-07-16 20:32:27 -0700202 SHARED_REQUIRES(Locks::mutator_lock_);
203 void FlipThreadRoots() REQUIRES(!Locks::mutator_lock_);
Mathieu Chartiera4f6af92015-08-11 17:35:25 -0700204 void SwapStacks() SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800205 void RecordLiveStackFreezeSize(Thread* self);
206 void ComputeUnevacFromSpaceLiveRatio();
Hiroshi Yamauchi3f64f252015-06-12 18:35:06 -0700207 void LogFromSpaceRefHolder(mirror::Object* obj, MemberOffset offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700208 SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi3f64f252015-06-12 18:35:06 -0700209 void AssertToSpaceInvariantInNonMovingSpace(mirror::Object* obj, mirror::Object* ref)
Mathieu Chartier90443472015-07-16 20:32:27 -0700210 SHARED_REQUIRES(Locks::mutator_lock_);
211 void ReenableWeakRefAccess(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi00370822015-08-18 14:47:25 -0700212 void DisableMarking() SHARED_REQUIRES(Locks::mutator_lock_);
213 void IssueDisableMarkingCheckpoint() SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi19eab402015-10-23 19:59:58 -0700214 void ExpandGcMarkStack() SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi723e6ce2015-10-28 20:59:47 -0700215 mirror::Object* MarkNonMoving(mirror::Object* from_ref) SHARED_REQUIRES(Locks::mutator_lock_)
216 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_);
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700217 ALWAYS_INLINE mirror::Object* MarkUnevacFromSpaceRegion(mirror::Object* from_ref,
Hiroshi Yamauchi8e674652015-12-22 11:09:18 -0800218 accounting::SpaceBitmap<kObjectAlignment>* bitmap)
219 SHARED_REQUIRES(Locks::mutator_lock_)
220 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_);
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700221 template<bool kGrayImmuneObject>
222 ALWAYS_INLINE mirror::Object* MarkImmuneSpace(mirror::Object* from_ref)
223 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!immune_gray_stack_lock_);
Hiroshi Yamauchi8e674652015-12-22 11:09:18 -0800224 void PushOntoFalseGrayStack(mirror::Object* obj) SHARED_REQUIRES(Locks::mutator_lock_)
225 REQUIRES(!mark_stack_lock_);
226 void ProcessFalseGrayStack() SHARED_REQUIRES(Locks::mutator_lock_)
227 REQUIRES(!mark_stack_lock_);
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700228 void ScanImmuneObject(mirror::Object* obj)
229 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_);
Mathieu Chartier56fe2582016-07-14 13:30:03 -0700230 mirror::Object* MarkFromReadBarrierWithMeasurements(mirror::Object* from_ref)
231 SHARED_REQUIRES(Locks::mutator_lock_)
232 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
233 void DumpPerformanceInfo(std::ostream& os) OVERRIDE REQUIRES(!rb_slow_path_histogram_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800234
235 space::RegionSpace* region_space_; // The underlying region space.
236 std::unique_ptr<Barrier> gc_barrier_;
Hiroshi Yamauchi0b713572015-06-16 18:29:23 -0700237 std::unique_ptr<accounting::ObjectStack> gc_mark_stack_;
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700238 std::unique_ptr<accounting::ObjectStack> rb_mark_bit_stack_;
239 bool rb_mark_bit_stack_full_;
Hiroshi Yamauchi8e674652015-12-22 11:09:18 -0800240 std::vector<mirror::Object*> false_gray_stack_ GUARDED_BY(mark_stack_lock_);
Hiroshi Yamauchi0b713572015-06-16 18:29:23 -0700241 Mutex mark_stack_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
242 std::vector<accounting::ObjectStack*> revoked_mark_stacks_
243 GUARDED_BY(mark_stack_lock_);
244 static constexpr size_t kMarkStackSize = kPageSize;
245 static constexpr size_t kMarkStackPoolSize = 256;
246 std::vector<accounting::ObjectStack*> pooled_mark_stacks_
247 GUARDED_BY(mark_stack_lock_);
248 Thread* thread_running_gc_;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800249 bool is_marking_; // True while marking is ongoing.
250 bool is_active_; // True while the collection is ongoing.
251 bool is_asserting_to_space_invariant_; // True while asserting the to-space invariant.
Mathieu Chartier763a31e2015-11-16 16:05:55 -0800252 ImmuneSpaces immune_spaces_;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800253 accounting::SpaceBitmap<kObjectAlignment>* region_space_bitmap_;
254 // A cache of Heap::GetMarkBitmap().
255 accounting::HeapBitmap* heap_mark_bitmap_;
256 size_t live_stack_freeze_size_;
257 size_t from_space_num_objects_at_first_pause_;
258 size_t from_space_num_bytes_at_first_pause_;
Hiroshi Yamauchi0b713572015-06-16 18:29:23 -0700259 Atomic<int> is_mark_stack_push_disallowed_;
260 enum MarkStackMode {
261 kMarkStackModeOff = 0, // Mark stack is off.
262 kMarkStackModeThreadLocal, // All threads except for the GC-running thread push refs onto
263 // thread-local mark stacks. The GC-running thread pushes onto and
264 // pops off the GC mark stack without a lock.
265 kMarkStackModeShared, // All threads share the GC mark stack with a lock.
266 kMarkStackModeGcExclusive // The GC-running thread pushes onto and pops from the GC mark stack
267 // without a lock. Other threads won't access the mark stack.
268 };
269 Atomic<MarkStackMode> mark_stack_mode_;
270 Atomic<bool> weak_ref_access_enabled_;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800271
272 // How many objects and bytes we moved. Used for accounting.
273 Atomic<size_t> bytes_moved_;
274 Atomic<size_t> objects_moved_;
Mathieu Chartiercca44a02016-08-17 10:07:29 -0700275 Atomic<uint64_t> cumulative_bytes_moved_;
276 Atomic<uint64_t> cumulative_objects_moved_;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800277
278 // The skipped blocks are memory blocks/chucks that were copies of
279 // objects that were unused due to lost races (cas failures) at
280 // object copy/forward pointer install. They are reused.
281 Mutex skipped_blocks_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
282 std::multimap<size_t, uint8_t*> skipped_blocks_map_ GUARDED_BY(skipped_blocks_lock_);
283 Atomic<size_t> to_space_bytes_skipped_;
284 Atomic<size_t> to_space_objects_skipped_;
285
Mathieu Chartier56fe2582016-07-14 13:30:03 -0700286 // If measure_read_barrier_slow_path_ is true, we count how long is spent in MarkFromReadBarrier
287 // and also log.
288 bool measure_read_barrier_slow_path_;
289 // mark_from_read_barrier_measurements_ is true if systrace is enabled or
290 // measure_read_barrier_time_ is true.
291 bool mark_from_read_barrier_measurements_;
292 Atomic<uint64_t> rb_slow_path_ns_;
293 Atomic<uint64_t> rb_slow_path_count_;
294 Atomic<uint64_t> rb_slow_path_count_gc_;
295 mutable Mutex rb_slow_path_histogram_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
296 Histogram<uint64_t> rb_slow_path_time_histogram_ GUARDED_BY(rb_slow_path_histogram_lock_);
297 uint64_t rb_slow_path_count_total_ GUARDED_BY(rb_slow_path_histogram_lock_);
298 uint64_t rb_slow_path_count_gc_total_ GUARDED_BY(rb_slow_path_histogram_lock_);
299
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800300 accounting::ReadBarrierTable* rb_table_;
301 bool force_evacuate_all_; // True if all regions are evacuated.
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700302 Atomic<bool> updated_all_immune_objects_;
303 bool gc_grays_immune_objects_;
304 Mutex immune_gray_stack_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
305 std::vector<mirror::Object*> immune_gray_stack_ GUARDED_BY(immune_gray_stack_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800306
Mathieu Chartiera07f5592016-06-16 11:44:28 -0700307 class AssertToSpaceInvariantFieldVisitor;
308 class AssertToSpaceInvariantObjectVisitor;
309 class AssertToSpaceInvariantRefsVisitor;
310 class ClearBlackPtrsVisitor;
311 class ComputeUnevacFromSpaceLiveRatioVisitor;
312 class DisableMarkingCheckpoint;
313 class FlipCallback;
Mathieu Chartier21328a12016-07-22 10:47:45 -0700314 class GrayImmuneObjectVisitor;
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700315 class ImmuneSpaceScanObjVisitor;
Mathieu Chartiera07f5592016-06-16 11:44:28 -0700316 class LostCopyVisitor;
317 class RefFieldsVisitor;
318 class RevokeThreadLocalMarkStackCheckpoint;
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700319 class ScopedGcGraysImmuneObjects;
320 class ThreadFlipVisitor;
Mathieu Chartier21328a12016-07-22 10:47:45 -0700321 class VerifyGrayImmuneObjectsVisitor;
Mathieu Chartiera07f5592016-06-16 11:44:28 -0700322 class VerifyNoFromSpaceRefsFieldVisitor;
323 class VerifyNoFromSpaceRefsObjectVisitor;
324 class VerifyNoFromSpaceRefsVisitor;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800325
Mathieu Chartier3130cdf2015-05-03 15:20:23 -0700326 DISALLOW_IMPLICIT_CONSTRUCTORS(ConcurrentCopying);
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -0700327};
328
329} // namespace collector
330} // namespace gc
331} // namespace art
332
333#endif // ART_RUNTIME_GC_COLLECTOR_CONCURRENT_COPYING_H_