Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_GC_COLLECTOR_MARK_SWEEP_H_ |
| 18 | #define ART_RUNTIME_GC_COLLECTOR_MARK_SWEEP_H_ |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 19 | |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 20 | #include <memory> |
| 21 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 22 | #include "atomic.h" |
Sameer Abu Asal | 4aeb567 | 2013-02-19 15:30:35 -0800 | [diff] [blame] | 23 | #include "barrier.h" |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 24 | #include "base/macros.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 25 | #include "base/mutex.h" |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 26 | #include "garbage_collector.h" |
Mathieu Chartier | e34fa1d | 2015-01-14 14:55:47 -0800 | [diff] [blame] | 27 | #include "gc_root.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 28 | #include "gc/accounting/heap_bitmap.h" |
Mathieu Chartier | 8d56210 | 2014-03-12 17:42:10 -0700 | [diff] [blame] | 29 | #include "immune_region.h" |
Mathieu Chartier | 83c8ee0 | 2014-01-28 14:50:23 -0800 | [diff] [blame] | 30 | #include "object_callbacks.h" |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 31 | #include "offsets.h" |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 32 | |
| 33 | namespace art { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 34 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 35 | namespace mirror { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 36 | class Class; |
| 37 | class Object; |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 38 | class Reference; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 39 | } // namespace mirror |
| 40 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 41 | class Thread; |
Mathieu Chartier | 893263b | 2014-03-04 11:07:42 -0800 | [diff] [blame] | 42 | enum VisitRootFlags : uint8_t; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 43 | |
| 44 | namespace gc { |
| 45 | |
Mathieu Chartier | 4aeec17 | 2014-03-27 16:09:46 -0700 | [diff] [blame] | 46 | class Heap; |
| 47 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 48 | namespace accounting { |
Mathieu Chartier | 4aeec17 | 2014-03-27 16:09:46 -0700 | [diff] [blame] | 49 | template<typename T> class AtomicStack; |
Mathieu Chartier | cb535da | 2015-01-23 13:50:03 -0800 | [diff] [blame] | 50 | typedef AtomicStack<mirror::Object> ObjectStack; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 51 | } // namespace accounting |
| 52 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 53 | namespace collector { |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 54 | |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 55 | class MarkSweep : public GarbageCollector { |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 56 | public: |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 57 | explicit MarkSweep(Heap* heap, bool is_concurrent, const std::string& name_prefix = ""); |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 58 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 59 | ~MarkSweep() {} |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 60 | |
Mathieu Chartier | 6f365cc | 2014-04-23 12:42:27 -0700 | [diff] [blame] | 61 | virtual void RunPhases() OVERRIDE NO_THREAD_SAFETY_ANALYSIS; |
| 62 | void InitializePhase(); |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 63 | void MarkingPhase() SHARED_REQUIRES(Locks::mutator_lock_, !mark_stack_lock_); |
| 64 | void PausePhase() REQUIRES(Locks::mutator_lock_, !mark_stack_lock_); |
| 65 | void ReclaimPhase() SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_); |
| 66 | void FinishPhase() SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 67 | virtual void MarkReachableObjects() |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 68 | SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_); |
Ian Rogers | 6fac447 | 2014-02-25 17:01:10 -0800 | [diff] [blame] | 69 | |
Hiroshi Yamauchi | 3e41780 | 2014-03-20 12:03:02 -0700 | [diff] [blame] | 70 | bool IsConcurrent() const { |
| 71 | return is_concurrent_; |
| 72 | } |
Ian Rogers | 6fac447 | 2014-02-25 17:01:10 -0800 | [diff] [blame] | 73 | |
| 74 | virtual GcType GetGcType() const OVERRIDE { |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 75 | return kGcTypeFull; |
| 76 | } |
| 77 | |
Hiroshi Yamauchi | 3e41780 | 2014-03-20 12:03:02 -0700 | [diff] [blame] | 78 | virtual CollectorType GetCollectorType() const OVERRIDE { |
| 79 | return is_concurrent_ ? kCollectorTypeCMS : kCollectorTypeMS; |
| 80 | } |
| 81 | |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 82 | // Initializes internal structures. |
Jesse Wilson | 078f9b0 | 2011-11-18 17:51:47 -0500 | [diff] [blame] | 83 | void Init(); |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 84 | |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 85 | // Find the default mark bitmap. |
Mathieu Chartier | 0e54cd0 | 2014-03-20 12:41:23 -0700 | [diff] [blame] | 86 | void FindDefaultSpaceBitmap(); |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 87 | |
Mathieu Chartier | 893263b | 2014-03-04 11:07:42 -0800 | [diff] [blame] | 88 | // Marks all objects in the root set at the start of a garbage collection. |
| 89 | void MarkRoots(Thread* self) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 90 | REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_) SHARED_REQUIRES(Locks::mutator_lock_); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 91 | |
Mathieu Chartier | 858f1c5 | 2012-10-17 17:45:55 -0700 | [diff] [blame] | 92 | void MarkNonThreadRoots() |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 93 | REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_) SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | 858f1c5 | 2012-10-17 17:45:55 -0700 | [diff] [blame] | 94 | |
Mathieu Chartier | 893263b | 2014-03-04 11:07:42 -0800 | [diff] [blame] | 95 | void MarkConcurrentRoots(VisitRootFlags flags) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 96 | REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_) SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | 9ebae1f | 2012-10-15 17:38:16 -0700 | [diff] [blame] | 97 | |
Mathieu Chartier | 0f7bf6a | 2014-03-28 10:05:39 -0700 | [diff] [blame] | 98 | void MarkRootsCheckpoint(Thread* self, bool revoke_ros_alloc_thread_local_buffers_at_checkpoint) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 99 | REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_) SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | 858f1c5 | 2012-10-17 17:45:55 -0700 | [diff] [blame] | 100 | |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 101 | // Builds a mark stack and recursively mark until it empties. |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 102 | void RecursiveMark() |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 103 | REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_) SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 104 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 105 | // Bind the live bits to the mark bits of bitmaps for spaces that are never collected, ie |
| 106 | // the image. Mark that portion of the heap as immune. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 107 | virtual void BindBitmaps() SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 108 | |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 109 | // Builds a mark stack with objects on dirty cards and recursively mark until it empties. |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 110 | void RecursiveMarkDirtyObjects(bool paused, uint8_t minimum_age) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 111 | REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_) SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | 262e5ff | 2012-06-01 17:35:38 -0700 | [diff] [blame] | 112 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 113 | // Remarks the root set after completing the concurrent mark. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 114 | void ReMarkRoots() |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 115 | REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_) SHARED_REQUIRES(Locks::mutator_lock_); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 116 | |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 117 | void ProcessReferences(Thread* self) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 118 | SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_); |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 119 | |
Mathieu Chartier | 4aeec17 | 2014-03-27 16:09:46 -0700 | [diff] [blame] | 120 | // Update and mark references from immune spaces. |
| 121 | void UpdateAndMarkModUnion() |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 122 | SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_); |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame] | 123 | |
Mathieu Chartier | dda54f5 | 2014-02-24 09:58:40 -0800 | [diff] [blame] | 124 | // Pre clean cards to reduce how much work is needed in the pause. |
| 125 | void PreCleanCards() |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 126 | REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_) SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | dda54f5 | 2014-02-24 09:58:40 -0800 | [diff] [blame] | 127 | |
Ian Rogers | 6fac447 | 2014-02-25 17:01:10 -0800 | [diff] [blame] | 128 | // Sweeps unmarked objects to complete the garbage collection. Virtual as by default it sweeps |
| 129 | // all allocation spaces. Partial and sticky GCs want to just sweep a subset of the heap. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 130 | virtual void Sweep(bool swap_bitmaps) REQUIRES(Locks::heap_bitmap_lock_) |
| 131 | SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 132 | |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 133 | // Sweeps unmarked objects to complete the garbage collection. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 134 | void SweepLargeObjects(bool swap_bitmaps) REQUIRES(Locks::heap_bitmap_lock_); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 135 | |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 136 | // Sweep only pointers within an array. WARNING: Trashes objects. |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 137 | void SweepArray(accounting::ObjectStack* allocation_stack_, bool swap_bitmaps) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 138 | SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 139 | |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 140 | // Blackens an object. |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 141 | void ScanObject(mirror::Object* obj) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 142 | REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_) SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 143 | |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 144 | // No thread safety analysis due to lambdas. |
| 145 | template<typename MarkVisitor, typename ReferenceVisitor> |
| 146 | void ScanObjectVisit(mirror::Object* obj, const MarkVisitor& visitor, |
| 147 | const ReferenceVisitor& ref_visitor) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 148 | SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_); |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 149 | |
Mathieu Chartier | 0f7bf6a | 2014-03-28 10:05:39 -0700 | [diff] [blame] | 150 | void SweepSystemWeaks(Thread* self) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 151 | SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Locks::heap_bitmap_lock_); |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 152 | |
Mathieu Chartier | 6aa3df9 | 2013-09-17 15:17:28 -0700 | [diff] [blame] | 153 | static mirror::Object* VerifySystemWeakIsLiveCallback(mirror::Object* obj, void* arg) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 154 | SHARED_REQUIRES(Locks::heap_bitmap_lock_, Locks::mutator_lock_); |
Mathieu Chartier | c7b83a0 | 2012-09-11 18:07:39 -0700 | [diff] [blame] | 155 | |
| 156 | void VerifySystemWeaks() |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 157 | SHARED_REQUIRES(Locks::mutator_lock_, Locks::heap_bitmap_lock_); |
Mathieu Chartier | c7b83a0 | 2012-09-11 18:07:39 -0700 | [diff] [blame] | 158 | |
| 159 | // Verify that an object is live, either in a live bitmap or in the allocation stack. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 160 | void VerifyIsLive(const mirror::Object* obj) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 161 | SHARED_REQUIRES(Locks::mutator_lock_, Locks::heap_bitmap_lock_); |
Mathieu Chartier | c7b83a0 | 2012-09-11 18:07:39 -0700 | [diff] [blame] | 162 | |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 163 | virtual bool IsMarkedHeapReference(mirror::HeapReference<mirror::Object>* ref) OVERRIDE |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 164 | SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_); |
Mathieu Chartier | 308351a | 2014-06-15 12:39:02 -0700 | [diff] [blame] | 165 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 166 | virtual void VisitRoots(mirror::Object*** roots, size_t count, const RootInfo& info) OVERRIDE |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 167 | SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_); |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 168 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 169 | virtual void VisitRoots(mirror::CompressedReference<mirror::Object>** roots, size_t count, |
| 170 | const RootInfo& info) OVERRIDE |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 171 | SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_); |
Mathieu Chartier | 893263b | 2014-03-04 11:07:42 -0800 | [diff] [blame] | 172 | |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 173 | // Marks an object. |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 174 | virtual mirror::Object* MarkObject(mirror::Object* obj) OVERRIDE |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 175 | SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_); |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 176 | void MarkObject(mirror::Object* obj, mirror::Object* holder, MemberOffset offset) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 177 | SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_); |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 178 | virtual void MarkHeapReference(mirror::HeapReference<mirror::Object>* ref) OVERRIDE |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 179 | SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_); |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 180 | |
Sameer Abu Asal | a843954 | 2013-02-14 16:06:42 -0800 | [diff] [blame] | 181 | Barrier& GetBarrier() { |
| 182 | return *gc_barrier_; |
| 183 | } |
| 184 | |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 185 | // Schedules an unmarked object for reference processing. |
| 186 | void DelayReferenceReferent(mirror::Class* klass, mirror::Reference* reference) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 187 | SHARED_REQUIRES(Locks::heap_bitmap_lock_, Locks::mutator_lock_); |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 188 | |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 189 | protected: |
Mathieu Chartier | 8118781 | 2015-07-15 14:24:07 -0700 | [diff] [blame] | 190 | // Returns object if the object is marked in the heap bitmap, otherwise null. |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 191 | virtual mirror::Object* IsMarked(mirror::Object* object) OVERRIDE |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 192 | SHARED_REQUIRES(Locks::heap_bitmap_lock_); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 193 | |
Hiroshi Yamauchi | eb2baaf | 2015-05-13 21:14:22 -0700 | [diff] [blame] | 194 | void MarkObjectNonNull(mirror::Object* obj, mirror::Object* holder = nullptr, |
| 195 | MemberOffset offset = MemberOffset(0)) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 196 | SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 197 | |
Mathieu Chartier | 9642c96 | 2013-08-05 17:40:36 -0700 | [diff] [blame] | 198 | // Marks an object atomically, safe to use from multiple threads. |
Mathieu Chartier | cb535da | 2015-01-23 13:50:03 -0800 | [diff] [blame] | 199 | void MarkObjectNonNullParallel(mirror::Object* obj) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 200 | SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!mark_stack_lock_); |
Mathieu Chartier | 9642c96 | 2013-08-05 17:40:36 -0700 | [diff] [blame] | 201 | |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 202 | // Returns true if we need to add obj to a mark stack. |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 203 | bool MarkObjectParallel(mirror::Object* obj) NO_THREAD_SAFETY_ANALYSIS; |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 204 | |
Mathieu Chartier | 6f1c949 | 2012-10-15 12:08:41 -0700 | [diff] [blame] | 205 | // Verify the roots of the heap and print out information related to any invalid roots. |
| 206 | // Called in MarkObject, so may we may not hold the mutator lock. |
| 207 | void VerifyRoots() |
| 208 | NO_THREAD_SAFETY_ANALYSIS; |
| 209 | |
Mathieu Chartier | ba311b4 | 2013-08-27 13:02:30 -0700 | [diff] [blame] | 210 | // Expand mark stack to 2x its current size. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 211 | void ExpandMarkStack() REQUIRES(mark_stack_lock_) |
| 212 | SHARED_REQUIRES(Locks::mutator_lock_); |
| 213 | void ResizeMarkStack(size_t new_size) REQUIRES(mark_stack_lock_) |
| 214 | SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | ac86a7c | 2012-11-12 15:03:16 -0800 | [diff] [blame] | 215 | |
Mathieu Chartier | 2775ee4 | 2013-08-20 17:43:47 -0700 | [diff] [blame] | 216 | // Returns how many threads we should use for the current GC phase based on if we are paused, |
| 217 | // whether or not we care about pauses. |
| 218 | size_t GetThreadCount(bool paused) const; |
| 219 | |
Mathieu Chartier | 0e54cd0 | 2014-03-20 12:41:23 -0700 | [diff] [blame] | 220 | // Push a single reference on a mark stack. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 221 | void PushOnMarkStack(mirror::Object* obj) SHARED_REQUIRES(Locks::mutator_lock_) |
| 222 | REQUIRES(!mark_stack_lock_); |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 223 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 224 | // Blackens objects grayed during a garbage collection. |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 225 | void ScanGrayObjects(bool paused, uint8_t minimum_age) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 226 | REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_) SHARED_REQUIRES(Locks::mutator_lock_); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 227 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 228 | virtual void ProcessMarkStack() OVERRIDE REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_) |
| 229 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 230 | ProcessMarkStack(false); |
| 231 | } |
| 232 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 233 | // Recursively blackens objects on the mark stack. |
Mathieu Chartier | 94c32c5 | 2013-08-09 11:14:04 -0700 | [diff] [blame] | 234 | void ProcessMarkStack(bool paused) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 235 | REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_) SHARED_REQUIRES(Locks::mutator_lock_); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 236 | |
Mathieu Chartier | 2775ee4 | 2013-08-20 17:43:47 -0700 | [diff] [blame] | 237 | void ProcessMarkStackParallel(size_t thread_count) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame^] | 238 | REQUIRES(Locks::heap_bitmap_lock_, !mark_stack_lock_) SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 239 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 240 | // Used to Get around thread safety annotations. The call is from MarkingPhase and is guarded by |
Mathieu Chartier | c22c59e | 2014-02-24 15:16:06 -0800 | [diff] [blame] | 241 | // IsExclusiveHeld. |
| 242 | void RevokeAllThreadLocalAllocationStacks(Thread* self) NO_THREAD_SAFETY_ANALYSIS; |
| 243 | |
Hiroshi Yamauchi | c93c530 | 2014-03-20 16:15:37 -0700 | [diff] [blame] | 244 | // Revoke all the thread-local buffers. |
| 245 | void RevokeAllThreadLocalBuffers(); |
| 246 | |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 247 | // Whether or not we count how many of each type of object were scanned. |
| 248 | static const bool kCountScannedTypes = false; |
| 249 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 250 | // Current space, we check this space first to avoid searching for the appropriate space for an |
| 251 | // object. |
Mathieu Chartier | a8e8f9c | 2014-04-09 14:51:05 -0700 | [diff] [blame] | 252 | accounting::ContinuousSpaceBitmap* current_space_bitmap_; |
Mathieu Chartier | 0e54cd0 | 2014-03-20 12:41:23 -0700 | [diff] [blame] | 253 | // Cache the heap's mark bitmap to prevent having to do 2 loads during slow path marking. |
| 254 | accounting::HeapBitmap* mark_bitmap_; |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 255 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 256 | accounting::ObjectStack* mark_stack_; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 257 | |
Mathieu Chartier | 4aeec17 | 2014-03-27 16:09:46 -0700 | [diff] [blame] | 258 | // Immune region, every object inside the immune range is assumed to be marked. |
Mathieu Chartier | 8d56210 | 2014-03-12 17:42:10 -0700 | [diff] [blame] | 259 | ImmuneRegion immune_region_; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 260 | |
Mathieu Chartier | 94c32c5 | 2013-08-09 11:14:04 -0700 | [diff] [blame] | 261 | // Parallel finger. |
| 262 | AtomicInteger atomic_finger_; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 263 | // Number of classes scanned, if kCountScannedTypes. |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 264 | AtomicInteger class_count_; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 265 | // Number of arrays scanned, if kCountScannedTypes. |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 266 | AtomicInteger array_count_; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 267 | // Number of non-class/arrays scanned, if kCountScannedTypes. |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 268 | AtomicInteger other_count_; |
| 269 | AtomicInteger large_object_test_; |
| 270 | AtomicInteger large_object_mark_; |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 271 | AtomicInteger overhead_time_; |
| 272 | AtomicInteger work_chunks_created_; |
| 273 | AtomicInteger work_chunks_deleted_; |
Mathieu Chartier | d22d548 | 2012-11-06 17:14:12 -0800 | [diff] [blame] | 274 | AtomicInteger reference_count_; |
Mathieu Chartier | 0e54cd0 | 2014-03-20 12:41:23 -0700 | [diff] [blame] | 275 | AtomicInteger mark_null_count_; |
| 276 | AtomicInteger mark_immune_count_; |
| 277 | AtomicInteger mark_fastpath_count_; |
| 278 | AtomicInteger mark_slowpath_count_; |
Mathieu Chartier | 0f72e41 | 2013-09-06 16:40:01 -0700 | [diff] [blame] | 279 | |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 280 | std::unique_ptr<Barrier> gc_barrier_; |
Mathieu Chartier | 958291c | 2013-08-27 18:14:55 -0700 | [diff] [blame] | 281 | Mutex mark_stack_lock_ ACQUIRED_AFTER(Locks::classlinker_classes_lock_); |
Ian Rogers | 1bd4b4c | 2013-04-18 17:47:42 -0700 | [diff] [blame] | 282 | |
| 283 | const bool is_concurrent_; |
| 284 | |
Ian Rogers | 3e5cf30 | 2014-05-20 16:40:37 -0700 | [diff] [blame] | 285 | // Verification. |
| 286 | size_t live_stack_freeze_size_; |
| 287 | |
Hiroshi Yamauchi | bbdc5bc | 2014-05-28 14:04:59 -0700 | [diff] [blame] | 288 | std::unique_ptr<MemMap> sweep_array_free_buffer_mem_map_; |
| 289 | |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 290 | private: |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 291 | friend class AddIfReachesAllocSpaceVisitor; // Used by mod-union table. |
Mathieu Chartier | 0f72e41 | 2013-09-06 16:40:01 -0700 | [diff] [blame] | 292 | friend class CardScanTask; |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 293 | friend class CheckBitmapVisitor; |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 294 | friend class CheckReferenceVisitor; |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 295 | friend class CheckpointMarkThreadRoots; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 296 | friend class art::gc::Heap; |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 297 | friend class FifoMarkStackChunk; |
Mathieu Chartier | 0e54cd0 | 2014-03-20 12:41:23 -0700 | [diff] [blame] | 298 | friend class MarkObjectVisitor; |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 299 | template<bool kUseFinger> friend class MarkStackTask; |
| 300 | friend class MarkSweepMarkObjectSlowPath; |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 301 | friend class ModUnionCheckReferences; |
Mathieu Chartier | b43b7d4 | 2012-06-19 13:15:09 -0700 | [diff] [blame] | 302 | friend class ModUnionClearCardVisitor; |
Mathieu Chartier | e6e0651 | 2012-06-26 15:00:26 -0700 | [diff] [blame] | 303 | friend class ModUnionReferenceVisitor; |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 304 | friend class ModUnionScanImageRootVisitor; |
Mathieu Chartier | b43b7d4 | 2012-06-19 13:15:09 -0700 | [diff] [blame] | 305 | friend class ModUnionTableBitmap; |
Mathieu Chartier | e6e0651 | 2012-06-26 15:00:26 -0700 | [diff] [blame] | 306 | friend class ModUnionTableReferenceCache; |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 307 | friend class ModUnionVisitor; |
| 308 | friend class VerifyRootMarkedVisitor; |
| 309 | friend class VerifyRootVisitor; |
Elliott Hughes | 410c0c8 | 2011-09-01 17:58:25 -0700 | [diff] [blame] | 310 | |
Mathieu Chartier | 3130cdf | 2015-05-03 15:20:23 -0700 | [diff] [blame] | 311 | DISALLOW_IMPLICIT_CONSTRUCTORS(MarkSweep); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 312 | }; |
| 313 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 314 | } // namespace collector |
| 315 | } // namespace gc |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 316 | } // namespace art |
| 317 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 318 | #endif // ART_RUNTIME_GC_COLLECTOR_MARK_SWEEP_H_ |