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 20 #include "base/allocator.h" 21 #include "base/locks.h" 22 #include "base/safe_map.h" 23 #include "runtime_globals.h" 24 25 #include <set> 26 #include <vector> 27 28 namespace art HIDDEN { 29 namespace gc { 30 31 namespace collector { 32 class GarbageCollector; 33 class MarkSweep; 34 } // namespace collector 35 namespace space { 36 class ContinuousSpace; 37 } // namespace space 38 39 class Heap; 40 41 namespace accounting { 42 43 // The remembered set keeps track of cards that may contain references 44 // from the free list spaces to the bump pointer spaces. 45 class RememberedSet { 46 public: 47 using CardSet = std::set<uint8_t*, 48 std::less<uint8_t*>, 49 TrackingAllocator<uint8_t*, kAllocatorTagRememberedSet>>; 50 RememberedSet(const std::string & name,Heap * heap,space::ContinuousSpace * space)51 explicit RememberedSet(const std::string& name, Heap* heap, space::ContinuousSpace* space) 52 : name_(name), heap_(heap), space_(space) {} 53 54 // Clear dirty cards and add them to the dirty card set. 55 void ClearCards(); 56 57 // Mark through all references to the target space. 58 void UpdateAndMarkReferences(space::ContinuousSpace* target_space, 59 collector::GarbageCollector* collector) 60 REQUIRES(Locks::heap_bitmap_lock_) 61 REQUIRES_SHARED(Locks::mutator_lock_); 62 63 void Dump(std::ostream& os); 64 GetSpace()65 space::ContinuousSpace* GetSpace() { 66 return space_; 67 } GetHeap()68 Heap* GetHeap() const { 69 return heap_; 70 } GetName()71 const std::string& GetName() const { 72 return name_; 73 } 74 void AssertAllDirtyCardsAreWithinSpace() const; 75 76 private: 77 const std::string name_; 78 Heap* const heap_; 79 space::ContinuousSpace* const space_; 80 81 CardSet dirty_cards_; 82 }; 83 84 } // namespace accounting 85 } // namespace gc 86 } // namespace art 87 88 #endif // ART_RUNTIME_GC_ACCOUNTING_REMEMBERED_SET_H_ 89