Hiroshi Yamauchi | 38e68e9 | 2014-03-07 13:59:08 -0800 | [diff] [blame] | 1 | /* |
| 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_ACCOUNTING_REMEMBERED_SET_H_ |
| 18 | #define ART_RUNTIME_GC_ACCOUNTING_REMEMBERED_SET_H_ |
| 19 | |
Mathieu Chartier | bad0267 | 2014-08-25 13:08:22 -0700 | [diff] [blame] | 20 | #include "base/allocator.h" |
Hiroshi Yamauchi | 38e68e9 | 2014-03-07 13:59:08 -0800 | [diff] [blame] | 21 | #include "globals.h" |
Hiroshi Yamauchi | 38e68e9 | 2014-03-07 13:59:08 -0800 | [diff] [blame] | 22 | #include "safe_map.h" |
| 23 | |
| 24 | #include <set> |
| 25 | #include <vector> |
| 26 | |
| 27 | namespace art { |
| 28 | namespace gc { |
| 29 | |
| 30 | namespace collector { |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame^] | 31 | class GarbageCollector; |
| 32 | class MarkSweep; |
Hiroshi Yamauchi | 38e68e9 | 2014-03-07 13:59:08 -0800 | [diff] [blame] | 33 | } // namespace collector |
| 34 | namespace space { |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame^] | 35 | class ContinuousSpace; |
Hiroshi Yamauchi | 38e68e9 | 2014-03-07 13:59:08 -0800 | [diff] [blame] | 36 | } // namespace space |
| 37 | |
| 38 | class Heap; |
| 39 | |
| 40 | namespace accounting { |
| 41 | |
| 42 | // The remembered set keeps track of cards that may contain references |
| 43 | // from the free list spaces to the bump pointer spaces. |
| 44 | class RememberedSet { |
| 45 | public: |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 46 | typedef std::set<uint8_t*, std::less<uint8_t*>, |
| 47 | TrackingAllocator<uint8_t*, kAllocatorTagRememberedSet>> CardSet; |
Hiroshi Yamauchi | 38e68e9 | 2014-03-07 13:59:08 -0800 | [diff] [blame] | 48 | |
| 49 | explicit RememberedSet(const std::string& name, Heap* heap, space::ContinuousSpace* space) |
| 50 | : name_(name), heap_(heap), space_(space) {} |
| 51 | |
| 52 | // Clear dirty cards and add them to the dirty card set. |
| 53 | void ClearCards(); |
| 54 | |
| 55 | // Mark through all references to the target space. |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 56 | void UpdateAndMarkReferences(space::ContinuousSpace* target_space, |
| 57 | collector::GarbageCollector* collector) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 58 | REQUIRES(Locks::heap_bitmap_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 59 | REQUIRES_SHARED(Locks::mutator_lock_); |
Hiroshi Yamauchi | 38e68e9 | 2014-03-07 13:59:08 -0800 | [diff] [blame] | 60 | |
| 61 | void Dump(std::ostream& os); |
| 62 | |
| 63 | space::ContinuousSpace* GetSpace() { |
| 64 | return space_; |
| 65 | } |
| 66 | Heap* GetHeap() const { |
| 67 | return heap_; |
| 68 | } |
| 69 | const std::string& GetName() const { |
| 70 | return name_; |
| 71 | } |
| 72 | void AssertAllDirtyCardsAreWithinSpace() const; |
| 73 | |
| 74 | private: |
| 75 | const std::string name_; |
| 76 | Heap* const heap_; |
| 77 | space::ContinuousSpace* const space_; |
| 78 | |
| 79 | CardSet dirty_cards_; |
| 80 | }; |
| 81 | |
| 82 | } // namespace accounting |
| 83 | } // namespace gc |
| 84 | } // namespace art |
| 85 | |
| 86 | #endif // ART_RUNTIME_GC_ACCOUNTING_REMEMBERED_SET_H_ |