xref: /aosp_15_r20/art/runtime/gc/accounting/remembered_set.h (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2014 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker  *
4*795d594fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker  *
8*795d594fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker  *
10*795d594fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker  * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker  */
16*795d594fSAndroid Build Coastguard Worker 
17*795d594fSAndroid Build Coastguard Worker #ifndef ART_RUNTIME_GC_ACCOUNTING_REMEMBERED_SET_H_
18*795d594fSAndroid Build Coastguard Worker #define ART_RUNTIME_GC_ACCOUNTING_REMEMBERED_SET_H_
19*795d594fSAndroid Build Coastguard Worker 
20*795d594fSAndroid Build Coastguard Worker #include "base/allocator.h"
21*795d594fSAndroid Build Coastguard Worker #include "base/locks.h"
22*795d594fSAndroid Build Coastguard Worker #include "base/safe_map.h"
23*795d594fSAndroid Build Coastguard Worker #include "runtime_globals.h"
24*795d594fSAndroid Build Coastguard Worker 
25*795d594fSAndroid Build Coastguard Worker #include <set>
26*795d594fSAndroid Build Coastguard Worker #include <vector>
27*795d594fSAndroid Build Coastguard Worker 
28*795d594fSAndroid Build Coastguard Worker namespace art HIDDEN {
29*795d594fSAndroid Build Coastguard Worker namespace gc {
30*795d594fSAndroid Build Coastguard Worker 
31*795d594fSAndroid Build Coastguard Worker namespace collector {
32*795d594fSAndroid Build Coastguard Worker class GarbageCollector;
33*795d594fSAndroid Build Coastguard Worker class MarkSweep;
34*795d594fSAndroid Build Coastguard Worker }  // namespace collector
35*795d594fSAndroid Build Coastguard Worker namespace space {
36*795d594fSAndroid Build Coastguard Worker class ContinuousSpace;
37*795d594fSAndroid Build Coastguard Worker }  // namespace space
38*795d594fSAndroid Build Coastguard Worker 
39*795d594fSAndroid Build Coastguard Worker class Heap;
40*795d594fSAndroid Build Coastguard Worker 
41*795d594fSAndroid Build Coastguard Worker namespace accounting {
42*795d594fSAndroid Build Coastguard Worker 
43*795d594fSAndroid Build Coastguard Worker // The remembered set keeps track of cards that may contain references
44*795d594fSAndroid Build Coastguard Worker // from the free list spaces to the bump pointer spaces.
45*795d594fSAndroid Build Coastguard Worker class RememberedSet {
46*795d594fSAndroid Build Coastguard Worker  public:
47*795d594fSAndroid Build Coastguard Worker   using CardSet = std::set<uint8_t*,
48*795d594fSAndroid Build Coastguard Worker                            std::less<uint8_t*>,
49*795d594fSAndroid Build Coastguard Worker                            TrackingAllocator<uint8_t*, kAllocatorTagRememberedSet>>;
50*795d594fSAndroid Build Coastguard Worker 
RememberedSet(const std::string & name,Heap * heap,space::ContinuousSpace * space)51*795d594fSAndroid Build Coastguard Worker   explicit RememberedSet(const std::string& name, Heap* heap, space::ContinuousSpace* space)
52*795d594fSAndroid Build Coastguard Worker       : name_(name), heap_(heap), space_(space) {}
53*795d594fSAndroid Build Coastguard Worker 
54*795d594fSAndroid Build Coastguard Worker   // Clear dirty cards and add them to the dirty card set.
55*795d594fSAndroid Build Coastguard Worker   void ClearCards();
56*795d594fSAndroid Build Coastguard Worker 
57*795d594fSAndroid Build Coastguard Worker   // Mark through all references to the target space.
58*795d594fSAndroid Build Coastguard Worker   void UpdateAndMarkReferences(space::ContinuousSpace* target_space,
59*795d594fSAndroid Build Coastguard Worker                                collector::GarbageCollector* collector)
60*795d594fSAndroid Build Coastguard Worker       REQUIRES(Locks::heap_bitmap_lock_)
61*795d594fSAndroid Build Coastguard Worker       REQUIRES_SHARED(Locks::mutator_lock_);
62*795d594fSAndroid Build Coastguard Worker 
63*795d594fSAndroid Build Coastguard Worker   void Dump(std::ostream& os);
64*795d594fSAndroid Build Coastguard Worker 
GetSpace()65*795d594fSAndroid Build Coastguard Worker   space::ContinuousSpace* GetSpace() {
66*795d594fSAndroid Build Coastguard Worker     return space_;
67*795d594fSAndroid Build Coastguard Worker   }
GetHeap()68*795d594fSAndroid Build Coastguard Worker   Heap* GetHeap() const {
69*795d594fSAndroid Build Coastguard Worker     return heap_;
70*795d594fSAndroid Build Coastguard Worker   }
GetName()71*795d594fSAndroid Build Coastguard Worker   const std::string& GetName() const {
72*795d594fSAndroid Build Coastguard Worker     return name_;
73*795d594fSAndroid Build Coastguard Worker   }
74*795d594fSAndroid Build Coastguard Worker   void AssertAllDirtyCardsAreWithinSpace() const;
75*795d594fSAndroid Build Coastguard Worker 
76*795d594fSAndroid Build Coastguard Worker  private:
77*795d594fSAndroid Build Coastguard Worker   const std::string name_;
78*795d594fSAndroid Build Coastguard Worker   Heap* const heap_;
79*795d594fSAndroid Build Coastguard Worker   space::ContinuousSpace* const space_;
80*795d594fSAndroid Build Coastguard Worker 
81*795d594fSAndroid Build Coastguard Worker   CardSet dirty_cards_;
82*795d594fSAndroid Build Coastguard Worker };
83*795d594fSAndroid Build Coastguard Worker 
84*795d594fSAndroid Build Coastguard Worker }  // namespace accounting
85*795d594fSAndroid Build Coastguard Worker }  // namespace gc
86*795d594fSAndroid Build Coastguard Worker }  // namespace art
87*795d594fSAndroid Build Coastguard Worker 
88*795d594fSAndroid Build Coastguard Worker #endif  // ART_RUNTIME_GC_ACCOUNTING_REMEMBERED_SET_H_
89