blob: c58dd44648b28879890137239ef164d8bac44726 [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"
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080024#include "mirror/object_reference.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070025#include "offsets.h"
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080026#include "safe_map.h"
27
28#include <unordered_map>
29#include <vector>
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -070030
31namespace art {
Hiroshi Yamauchifebd0cf2016-09-14 19:31:25 -070032class Closure;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080033class RootInfo;
34
Andreas Gampe5d08fcc2017-06-05 17:56:46 -070035namespace mirror {
36class Object;
37} // namespace mirror
38
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -070039namespace gc {
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080040
41namespace accounting {
Igor Murashkin2ffb7032017-11-08 13:35:21 -080042template<typename T> class AtomicStack;
43typedef AtomicStack<mirror::Object> ObjectStack;
44template <size_t kAlignment> class SpaceBitmap;
45typedef SpaceBitmap<kObjectAlignment> ContinuousSpaceBitmap;
46class HeapBitmap;
47class ReadBarrierTable;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080048} // namespace accounting
49
50namespace space {
Igor Murashkin2ffb7032017-11-08 13:35:21 -080051class RegionSpace;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080052} // namespace space
53
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -070054namespace collector {
55
56class ConcurrentCopying : public GarbageCollector {
57 public:
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080058 // Enable the no-from-space-refs verification at the pause.
Hiroshi Yamauchidaf61a12016-06-10 14:27:38 -070059 static constexpr bool kEnableNoFromSpaceRefsVerification = kIsDebugBuild;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080060 // Enable the from-space bytes/objects check.
Hiroshi Yamauchidaf61a12016-06-10 14:27:38 -070061 static constexpr bool kEnableFromSpaceAccountingCheck = kIsDebugBuild;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080062 // Enable verbose mode.
Hiroshi Yamauchi3c448932016-01-22 16:26:50 -080063 static constexpr bool kVerboseMode = false;
Mathieu Chartier36a270a2016-07-28 18:08:51 -070064 // If kGrayDirtyImmuneObjects is true then we gray dirty objects in the GC pause to prevent dirty
65 // pages.
66 static constexpr bool kGrayDirtyImmuneObjects = true;
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -070067
Chih-Hung Hsieha5931182016-09-01 15:08:13 -070068 explicit ConcurrentCopying(Heap* heap,
69 const std::string& name_prefix = "",
70 bool measure_read_barrier_slow_path = false);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080071 ~ConcurrentCopying();
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -070072
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -070073 virtual void RunPhases() OVERRIDE
Mathieu Chartier56fe2582016-07-14 13:30:03 -070074 REQUIRES(!immune_gray_stack_lock_,
75 !mark_stack_lock_,
76 !rb_slow_path_histogram_lock_,
77 !skipped_blocks_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070078 void InitializePhase() REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -070079 REQUIRES(!mark_stack_lock_, !immune_gray_stack_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070080 void MarkingPhase() REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -070081 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070082 void ReclaimPhase() REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_);
Mathieu Chartier56fe2582016-07-14 13:30:03 -070083 void FinishPhase() REQUIRES(!mark_stack_lock_,
84 !rb_slow_path_histogram_lock_,
85 !skipped_blocks_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080086
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070087 void BindBitmaps() REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -070088 REQUIRES(!Locks::heap_bitmap_lock_);
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -070089 virtual GcType GetGcType() const OVERRIDE {
90 return kGcTypePartial;
91 }
92 virtual CollectorType GetCollectorType() const OVERRIDE {
93 return kCollectorTypeCC;
94 }
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080095 virtual void RevokeAllThreadLocalBuffers() OVERRIDE;
96 void SetRegionSpace(space::RegionSpace* region_space) {
97 DCHECK(region_space != nullptr);
98 region_space_ = region_space;
99 }
100 space::RegionSpace* RegionSpace() {
101 return region_space_;
102 }
Roland Levillain001eff92018-01-24 14:24:33 +0000103 // Assert the to-space invariant for a heap reference `ref` held in `obj` at offset `offset`.
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800104 void AssertToSpaceInvariant(mirror::Object* obj, MemberOffset offset, mirror::Object* ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700105 REQUIRES_SHARED(Locks::mutator_lock_);
Roland Levillain001eff92018-01-24 14:24:33 +0000106 // Assert the to-space invariant for a GC root reference `ref`.
Hiroshi Yamauchi3f64f252015-06-12 18:35:06 -0700107 void AssertToSpaceInvariant(GcRootSource* gc_root_source, mirror::Object* ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700108 REQUIRES_SHARED(Locks::mutator_lock_);
109 bool IsInToSpace(mirror::Object* ref) REQUIRES_SHARED(Locks::mutator_lock_) {
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800110 DCHECK(ref != nullptr);
111 return IsMarked(ref) == ref;
112 }
Mathieu Chartierc381c362016-08-23 13:27:53 -0700113 template<bool kGrayImmuneObject = true, bool kFromGCThread = false>
Roland Levillain8f7ea9a2018-01-26 17:27:59 +0000114 // Mark object `from_ref`, copying it to the to-space if needed.
Mathieu Chartier1ca68902017-04-18 11:26:22 -0700115 ALWAYS_INLINE mirror::Object* Mark(mirror::Object* from_ref,
116 mirror::Object* holder = nullptr,
117 MemberOffset offset = MemberOffset(0))
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700118 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier56fe2582016-07-14 13:30:03 -0700119 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
120 ALWAYS_INLINE mirror::Object* MarkFromReadBarrier(mirror::Object* from_ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700121 REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700122 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800123 bool IsMarking() const {
124 return is_marking_;
125 }
Mathieu Chartier3768ade2017-05-02 14:04:39 -0700126 // We may want to use read barrier entrypoints before is_marking_ is true since concurrent graying
127 // creates a small window where we might dispatch on these entrypoints.
128 bool IsUsingReadBarrierEntrypoints() const {
129 return is_using_read_barrier_entrypoints_;
130 }
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800131 bool IsActive() const {
132 return is_active_;
133 }
134 Barrier& GetBarrier() {
135 return *gc_barrier_;
136 }
Hiroshi Yamauchifebd0cf2016-09-14 19:31:25 -0700137 bool IsWeakRefAccessEnabled() REQUIRES(Locks::thread_list_lock_) {
138 return weak_ref_access_enabled_;
Hiroshi Yamauchi0b713572015-06-16 18:29:23 -0700139 }
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700140 void RevokeThreadLocalMarkStack(Thread* thread) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700141 REQUIRES(!mark_stack_lock_);
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -0700142
Nicolas Geoffray13056a12017-05-11 11:48:28 +0000143 virtual mirror::Object* IsMarked(mirror::Object* from_ref) OVERRIDE
144 REQUIRES_SHARED(Locks::mutator_lock_);
145
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -0700146 private:
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700147 void PushOntoMarkStack(mirror::Object* obj) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700148 REQUIRES(!mark_stack_lock_);
Mathieu Chartieref496d92017-04-28 18:58:59 -0700149 mirror::Object* Copy(mirror::Object* from_ref,
150 mirror::Object* holder,
151 MemberOffset offset)
152 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartierd6636d32016-07-28 11:02:38 -0700153 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
Roland Levillain8f7ea9a2018-01-26 17:27:59 +0000154 // Scan the reference fields of object `to_ref`.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700155 void Scan(mirror::Object* to_ref) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700156 REQUIRES(!mark_stack_lock_);
Roland Levillain8f7ea9a2018-01-26 17:27:59 +0000157 // Process a field.
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800158 void Process(mirror::Object* obj, MemberOffset offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700159 REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700160 REQUIRES(!mark_stack_lock_ , !skipped_blocks_lock_, !immune_gray_stack_lock_);
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700161 virtual void VisitRoots(mirror::Object*** roots, size_t count, const RootInfo& info)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700162 OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700163 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
164 template<bool kGrayImmuneObject>
Mathieu Chartierda7c6502015-07-23 16:01:26 -0700165 void MarkRoot(mirror::CompressedReference<mirror::Object>* root)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700166 REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700167 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700168 virtual void VisitRoots(mirror::CompressedReference<mirror::Object>** roots, size_t count,
169 const RootInfo& info)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700170 OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700171 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
Mathieu Chartier90443472015-07-16 20:32:27 -0700172 void VerifyNoFromSpaceReferences() REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800173 accounting::ObjectStack* GetAllocationStack();
174 accounting::ObjectStack* GetLiveStack();
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700175 virtual void ProcessMarkStack() OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700176 REQUIRES(!mark_stack_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700177 bool ProcessMarkStackOnce() REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_);
178 void ProcessMarkStackRef(mirror::Object* to_ref) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700179 REQUIRES(!mark_stack_lock_);
Mathieu Chartier21328a12016-07-22 10:47:45 -0700180 void GrayAllDirtyImmuneObjects()
181 REQUIRES(Locks::mutator_lock_)
182 REQUIRES(!mark_stack_lock_);
Mathieu Chartier3768ade2017-05-02 14:04:39 -0700183 void GrayAllNewlyDirtyImmuneObjects()
184 REQUIRES(Locks::mutator_lock_)
185 REQUIRES(!mark_stack_lock_);
Mathieu Chartier21328a12016-07-22 10:47:45 -0700186 void VerifyGrayImmuneObjects()
187 REQUIRES(Locks::mutator_lock_)
188 REQUIRES(!mark_stack_lock_);
Mathieu Chartiera1467d02017-02-22 09:22:50 -0800189 void VerifyNoMissingCardMarks()
190 REQUIRES(Locks::mutator_lock_)
191 REQUIRES(!mark_stack_lock_);
Hiroshi Yamauchifebd0cf2016-09-14 19:31:25 -0700192 size_t ProcessThreadLocalMarkStacks(bool disable_weak_ref_access, Closure* checkpoint_callback)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700193 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_);
Hiroshi Yamauchifebd0cf2016-09-14 19:31:25 -0700194 void RevokeThreadLocalMarkStacks(bool disable_weak_ref_access, Closure* checkpoint_callback)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700195 REQUIRES_SHARED(Locks::mutator_lock_);
196 void SwitchToSharedMarkStackMode() REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700197 REQUIRES(!mark_stack_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700198 void SwitchToGcExclusiveMarkStackMode() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier31e88222016-10-14 18:43:19 -0700199 virtual void DelayReferenceReferent(ObjPtr<mirror::Class> klass,
200 ObjPtr<mirror::Reference> reference) OVERRIDE
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700201 REQUIRES_SHARED(Locks::mutator_lock_);
202 void ProcessReferences(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier97509952015-07-13 14:35:43 -0700203 virtual mirror::Object* MarkObject(mirror::Object* from_ref) OVERRIDE
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700204 REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700205 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
Hiroshi Yamauchi057d9772017-02-17 15:33:23 -0800206 virtual void MarkHeapReference(mirror::HeapReference<mirror::Object>* from_ref,
207 bool do_atomic_update) OVERRIDE
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700208 REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700209 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
Mathieu Chartierc381c362016-08-23 13:27:53 -0700210 bool IsMarkedInUnevacFromSpace(mirror::Object* from_ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700211 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi65f5f242016-12-19 11:44:47 -0800212 virtual bool IsNullOrMarkedHeapReference(mirror::HeapReference<mirror::Object>* field,
213 bool do_atomic_update) OVERRIDE
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700214 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800215 void SweepSystemWeaks(Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700216 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::heap_bitmap_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800217 void Sweep(bool swap_bitmaps)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700218 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800219 void SweepLargeObjects(bool swap_bitmaps)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700220 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_);
Mathieu Chartier962cd7a2016-08-16 12:15:59 -0700221 void MarkZygoteLargeObjects()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700222 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800223 void FillWithDummyObject(mirror::Object* dummy_obj, size_t byte_size)
Mathieu Chartierd6636d32016-07-28 11:02:38 -0700224 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700225 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800226 mirror::Object* AllocateInSkippedBlock(size_t alloc_size)
Mathieu Chartierd6636d32016-07-28 11:02:38 -0700227 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700228 REQUIRES_SHARED(Locks::mutator_lock_);
229 void CheckEmptyMarkStack() REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_);
230 void IssueEmptyCheckpoint() REQUIRES_SHARED(Locks::mutator_lock_);
231 bool IsOnAllocStack(mirror::Object* ref) REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800232 mirror::Object* GetFwdPtr(mirror::Object* from_ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700233 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier90443472015-07-16 20:32:27 -0700234 void FlipThreadRoots() REQUIRES(!Locks::mutator_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700235 void SwapStacks() REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800236 void RecordLiveStackFreezeSize(Thread* self);
237 void ComputeUnevacFromSpaceLiveRatio();
Hiroshi Yamauchi3f64f252015-06-12 18:35:06 -0700238 void LogFromSpaceRefHolder(mirror::Object* obj, MemberOffset offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700239 REQUIRES_SHARED(Locks::mutator_lock_);
Roland Levillain001eff92018-01-24 14:24:33 +0000240 // Dump information about reference `ref` and return it as a string.
241 // Use `ref_name` to name the reference in messages. Each message is prefixed with `indent`.
242 std::string DumpReferenceInfo(mirror::Object* ref, const char* ref_name, std::string indent = "")
243 REQUIRES_SHARED(Locks::mutator_lock_);
244 // Dump information about heap reference `ref`, referenced from object `obj` at offset `offset`,
245 // and return it as a string.
246 std::string DumpHeapReference(mirror::Object* obj, MemberOffset offset, mirror::Object* ref)
247 REQUIRES_SHARED(Locks::mutator_lock_);
248 // Dump information about GC root `ref` and return it as a string.
249 std::string DumpGcRoot(mirror::Object* ref) REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi3f64f252015-06-12 18:35:06 -0700250 void AssertToSpaceInvariantInNonMovingSpace(mirror::Object* obj, mirror::Object* ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700251 REQUIRES_SHARED(Locks::mutator_lock_);
252 void ReenableWeakRefAccess(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_);
253 void DisableMarking() REQUIRES_SHARED(Locks::mutator_lock_);
254 void IssueDisableMarkingCheckpoint() REQUIRES_SHARED(Locks::mutator_lock_);
255 void ExpandGcMarkStack() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier1ca68902017-04-18 11:26:22 -0700256 mirror::Object* MarkNonMoving(mirror::Object* from_ref,
257 mirror::Object* holder = nullptr,
258 MemberOffset offset = MemberOffset(0))
259 REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchi723e6ce2015-10-28 20:59:47 -0700260 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_);
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700261 ALWAYS_INLINE mirror::Object* MarkUnevacFromSpaceRegion(mirror::Object* from_ref,
Hiroshi Yamauchi8e674652015-12-22 11:09:18 -0800262 accounting::SpaceBitmap<kObjectAlignment>* bitmap)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700263 REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchi8e674652015-12-22 11:09:18 -0800264 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_);
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700265 template<bool kGrayImmuneObject>
266 ALWAYS_INLINE mirror::Object* MarkImmuneSpace(mirror::Object* from_ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700267 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!immune_gray_stack_lock_);
268 void PushOntoFalseGrayStack(mirror::Object* obj) REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchi8e674652015-12-22 11:09:18 -0800269 REQUIRES(!mark_stack_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700270 void ProcessFalseGrayStack() REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchi8e674652015-12-22 11:09:18 -0800271 REQUIRES(!mark_stack_lock_);
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700272 void ScanImmuneObject(mirror::Object* obj)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700273 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_);
Mathieu Chartier56fe2582016-07-14 13:30:03 -0700274 mirror::Object* MarkFromReadBarrierWithMeasurements(mirror::Object* from_ref)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700275 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier56fe2582016-07-14 13:30:03 -0700276 REQUIRES(!mark_stack_lock_, !skipped_blocks_lock_, !immune_gray_stack_lock_);
277 void DumpPerformanceInfo(std::ostream& os) OVERRIDE REQUIRES(!rb_slow_path_histogram_lock_);
Mathieu Chartier3768ade2017-05-02 14:04:39 -0700278 // Set the read barrier mark entrypoints to non-null.
279 void ActivateReadBarrierEntrypoints();
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800280
281 space::RegionSpace* region_space_; // The underlying region space.
282 std::unique_ptr<Barrier> gc_barrier_;
Hiroshi Yamauchi0b713572015-06-16 18:29:23 -0700283 std::unique_ptr<accounting::ObjectStack> gc_mark_stack_;
Roland Levillain8f7ea9a2018-01-26 17:27:59 +0000284
285 // The read-barrier mark-bit stack. Stores object references whose
286 // mark bit has been set by ConcurrentCopying::MarkFromReadBarrier,
287 // so that this bit can be reset at the end of the collection in
288 // ConcurrentCopying::FinishPhase. The mark bit of an object can be
289 // used by mutator read barrier code to quickly test whether that
290 // object has been already marked.
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700291 std::unique_ptr<accounting::ObjectStack> rb_mark_bit_stack_;
Roland Levillain8f7ea9a2018-01-26 17:27:59 +0000292 // Thread-unsafe Boolean value hinting that `rb_mark_bit_stack_` is
293 // full. A thread-safe test of whether the read-barrier mark-bit
294 // stack is full is implemented by `rb_mark_bit_stack_->AtomicPushBack(ref)`
295 // (see use case in ConcurrentCopying::MarkFromReadBarrier).
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700296 bool rb_mark_bit_stack_full_;
Roland Levillain8f7ea9a2018-01-26 17:27:59 +0000297
Hiroshi Yamauchi8e674652015-12-22 11:09:18 -0800298 std::vector<mirror::Object*> false_gray_stack_ GUARDED_BY(mark_stack_lock_);
Hiroshi Yamauchi0b713572015-06-16 18:29:23 -0700299 Mutex mark_stack_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
300 std::vector<accounting::ObjectStack*> revoked_mark_stacks_
301 GUARDED_BY(mark_stack_lock_);
302 static constexpr size_t kMarkStackSize = kPageSize;
303 static constexpr size_t kMarkStackPoolSize = 256;
304 std::vector<accounting::ObjectStack*> pooled_mark_stacks_
305 GUARDED_BY(mark_stack_lock_);
306 Thread* thread_running_gc_;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800307 bool is_marking_; // True while marking is ongoing.
Mathieu Chartier3768ade2017-05-02 14:04:39 -0700308 // True while we might dispatch on the read barrier entrypoints.
309 bool is_using_read_barrier_entrypoints_;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800310 bool is_active_; // True while the collection is ongoing.
311 bool is_asserting_to_space_invariant_; // True while asserting the to-space invariant.
Mathieu Chartier763a31e2015-11-16 16:05:55 -0800312 ImmuneSpaces immune_spaces_;
Andreas Gamped4901292017-05-30 18:41:34 -0700313 accounting::ContinuousSpaceBitmap* region_space_bitmap_;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800314 // A cache of Heap::GetMarkBitmap().
315 accounting::HeapBitmap* heap_mark_bitmap_;
316 size_t live_stack_freeze_size_;
317 size_t from_space_num_objects_at_first_pause_;
318 size_t from_space_num_bytes_at_first_pause_;
Hiroshi Yamauchi0b713572015-06-16 18:29:23 -0700319 Atomic<int> is_mark_stack_push_disallowed_;
320 enum MarkStackMode {
321 kMarkStackModeOff = 0, // Mark stack is off.
322 kMarkStackModeThreadLocal, // All threads except for the GC-running thread push refs onto
323 // thread-local mark stacks. The GC-running thread pushes onto and
324 // pops off the GC mark stack without a lock.
325 kMarkStackModeShared, // All threads share the GC mark stack with a lock.
326 kMarkStackModeGcExclusive // The GC-running thread pushes onto and pops from the GC mark stack
327 // without a lock. Other threads won't access the mark stack.
328 };
329 Atomic<MarkStackMode> mark_stack_mode_;
Hiroshi Yamauchifebd0cf2016-09-14 19:31:25 -0700330 bool weak_ref_access_enabled_ GUARDED_BY(Locks::thread_list_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800331
332 // How many objects and bytes we moved. Used for accounting.
333 Atomic<size_t> bytes_moved_;
334 Atomic<size_t> objects_moved_;
Mathieu Chartiercca44a02016-08-17 10:07:29 -0700335 Atomic<uint64_t> cumulative_bytes_moved_;
336 Atomic<uint64_t> cumulative_objects_moved_;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800337
338 // The skipped blocks are memory blocks/chucks that were copies of
339 // objects that were unused due to lost races (cas failures) at
340 // object copy/forward pointer install. They are reused.
341 Mutex skipped_blocks_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
342 std::multimap<size_t, uint8_t*> skipped_blocks_map_ GUARDED_BY(skipped_blocks_lock_);
343 Atomic<size_t> to_space_bytes_skipped_;
344 Atomic<size_t> to_space_objects_skipped_;
345
Mathieu Chartier56fe2582016-07-14 13:30:03 -0700346 // If measure_read_barrier_slow_path_ is true, we count how long is spent in MarkFromReadBarrier
347 // and also log.
348 bool measure_read_barrier_slow_path_;
349 // mark_from_read_barrier_measurements_ is true if systrace is enabled or
350 // measure_read_barrier_time_ is true.
351 bool mark_from_read_barrier_measurements_;
352 Atomic<uint64_t> rb_slow_path_ns_;
353 Atomic<uint64_t> rb_slow_path_count_;
354 Atomic<uint64_t> rb_slow_path_count_gc_;
355 mutable Mutex rb_slow_path_histogram_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
356 Histogram<uint64_t> rb_slow_path_time_histogram_ GUARDED_BY(rb_slow_path_histogram_lock_);
357 uint64_t rb_slow_path_count_total_ GUARDED_BY(rb_slow_path_histogram_lock_);
358 uint64_t rb_slow_path_count_gc_total_ GUARDED_BY(rb_slow_path_histogram_lock_);
359
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800360 accounting::ReadBarrierTable* rb_table_;
361 bool force_evacuate_all_; // True if all regions are evacuated.
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700362 Atomic<bool> updated_all_immune_objects_;
363 bool gc_grays_immune_objects_;
364 Mutex immune_gray_stack_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
365 std::vector<mirror::Object*> immune_gray_stack_ GUARDED_BY(immune_gray_stack_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800366
Mathieu Chartier3ed8ec12017-04-20 19:28:54 -0700367 // Class of java.lang.Object. Filled in from WellKnownClasses in FlipCallback. Must
368 // be filled in before flipping thread roots so that FillDummyObject can run. Not
369 // ObjPtr since the GC may transition to suspended and runnable between phases.
370 mirror::Class* java_lang_Object_;
371
Mathieu Chartier3768ade2017-05-02 14:04:39 -0700372 class ActivateReadBarrierEntrypointsCallback;
373 class ActivateReadBarrierEntrypointsCheckpoint;
Mathieu Chartiera07f5592016-06-16 11:44:28 -0700374 class AssertToSpaceInvariantFieldVisitor;
Mathieu Chartiera07f5592016-06-16 11:44:28 -0700375 class AssertToSpaceInvariantRefsVisitor;
376 class ClearBlackPtrsVisitor;
377 class ComputeUnevacFromSpaceLiveRatioVisitor;
Hiroshi Yamauchifebd0cf2016-09-14 19:31:25 -0700378 class DisableMarkingCallback;
Mathieu Chartiera07f5592016-06-16 11:44:28 -0700379 class DisableMarkingCheckpoint;
Hiroshi Yamauchifebd0cf2016-09-14 19:31:25 -0700380 class DisableWeakRefAccessCallback;
Mathieu Chartiera07f5592016-06-16 11:44:28 -0700381 class FlipCallback;
Mathieu Chartier3768ade2017-05-02 14:04:39 -0700382 template <bool kConcurrent> class GrayImmuneObjectVisitor;
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700383 class ImmuneSpaceScanObjVisitor;
Mathieu Chartiera07f5592016-06-16 11:44:28 -0700384 class LostCopyVisitor;
385 class RefFieldsVisitor;
386 class RevokeThreadLocalMarkStackCheckpoint;
Hiroshi Yamauchid8db5a22016-06-28 14:07:41 -0700387 class ScopedGcGraysImmuneObjects;
388 class ThreadFlipVisitor;
Mathieu Chartier21328a12016-07-22 10:47:45 -0700389 class VerifyGrayImmuneObjectsVisitor;
Mathieu Chartiera07f5592016-06-16 11:44:28 -0700390 class VerifyNoFromSpaceRefsFieldVisitor;
Mathieu Chartiera07f5592016-06-16 11:44:28 -0700391 class VerifyNoFromSpaceRefsVisitor;
Mathieu Chartiera1467d02017-02-22 09:22:50 -0800392 class VerifyNoMissingCardMarkVisitor;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800393
Mathieu Chartier3130cdf2015-05-03 15:20:23 -0700394 DISALLOW_IMPLICIT_CONSTRUCTORS(ConcurrentCopying);
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -0700395};
396
397} // namespace collector
398} // namespace gc
399} // namespace art
400
401#endif // ART_RUNTIME_GC_COLLECTOR_CONCURRENT_COPYING_H_