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 | |
| 20 | #include "gc_allocator.h" |
| 21 | #include "globals.h" |
| 22 | #include "object_callbacks.h" |
| 23 | #include "safe_map.h" |
| 24 | |
| 25 | #include <set> |
| 26 | #include <vector> |
| 27 | |
| 28 | namespace art { |
| 29 | namespace gc { |
| 30 | |
| 31 | namespace collector { |
| 32 | class MarkSweep; |
| 33 | } // namespace collector |
| 34 | namespace space { |
| 35 | class ContinuousSpace; |
| 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: |
| 46 | typedef std::set<byte*, std::less<byte*>, GcAllocator<byte*> > CardSet; |
| 47 | |
| 48 | explicit RememberedSet(const std::string& name, Heap* heap, space::ContinuousSpace* space) |
| 49 | : name_(name), heap_(heap), space_(space) {} |
| 50 | |
| 51 | // Clear dirty cards and add them to the dirty card set. |
| 52 | void ClearCards(); |
| 53 | |
| 54 | // Mark through all references to the target space. |
| 55 | void UpdateAndMarkReferences(MarkObjectCallback* callback, |
| 56 | space::ContinuousSpace* target_space, void* arg) |
| 57 | EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_) |
| 58 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 59 | |
| 60 | void Dump(std::ostream& os); |
| 61 | |
| 62 | space::ContinuousSpace* GetSpace() { |
| 63 | return space_; |
| 64 | } |
| 65 | Heap* GetHeap() const { |
| 66 | return heap_; |
| 67 | } |
| 68 | const std::string& GetName() const { |
| 69 | return name_; |
| 70 | } |
| 71 | void AssertAllDirtyCardsAreWithinSpace() const; |
| 72 | |
| 73 | private: |
| 74 | const std::string name_; |
| 75 | Heap* const heap_; |
| 76 | space::ContinuousSpace* const space_; |
| 77 | |
| 78 | CardSet dirty_cards_; |
| 79 | }; |
| 80 | |
| 81 | } // namespace accounting |
| 82 | } // namespace gc |
| 83 | } // namespace art |
| 84 | |
| 85 | #endif // ART_RUNTIME_GC_ACCOUNTING_REMEMBERED_SET_H_ |