blob: 559478167265f678e460936ce491359688f1601b [file] [log] [blame]
Hiroshi Yamauchi38e68e92014-03-07 13:59:08 -08001/*
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 Chartierbad02672014-08-25 13:08:22 -070020#include "base/allocator.h"
Hiroshi Yamauchi38e68e92014-03-07 13:59:08 -080021#include "globals.h"
22#include "object_callbacks.h"
23#include "safe_map.h"
24
25#include <set>
26#include <vector>
27
28namespace art {
29namespace gc {
30
31namespace collector {
Mathieu Chartier97509952015-07-13 14:35:43 -070032 class GarbageCollector;
Hiroshi Yamauchi38e68e92014-03-07 13:59:08 -080033 class MarkSweep;
34} // namespace collector
35namespace space {
36 class ContinuousSpace;
37} // namespace space
38
39class Heap;
40
41namespace 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.
45class RememberedSet {
46 public:
Ian Rogers13735952014-10-08 12:43:28 -070047 typedef std::set<uint8_t*, std::less<uint8_t*>,
48 TrackingAllocator<uint8_t*, kAllocatorTagRememberedSet>> CardSet;
Hiroshi Yamauchi38e68e92014-03-07 13:59:08 -080049
50 explicit RememberedSet(const std::string& name, Heap* heap, space::ContinuousSpace* space)
51 : name_(name), heap_(heap), space_(space) {}
52
53 // Clear dirty cards and add them to the dirty card set.
54 void ClearCards();
55
56 // Mark through all references to the target space.
Mathieu Chartier97509952015-07-13 14:35:43 -070057 void UpdateAndMarkReferences(space::ContinuousSpace* target_space,
58 collector::GarbageCollector* collector)
Mathieu Chartier90443472015-07-16 20:32:27 -070059 REQUIRES(Locks::heap_bitmap_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070060 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi38e68e92014-03-07 13:59:08 -080061
62 void Dump(std::ostream& os);
63
64 space::ContinuousSpace* GetSpace() {
65 return space_;
66 }
67 Heap* GetHeap() const {
68 return heap_;
69 }
70 const std::string& GetName() const {
71 return name_;
72 }
73 void AssertAllDirtyCardsAreWithinSpace() const;
74
75 private:
76 const std::string name_;
77 Heap* const heap_;
78 space::ContinuousSpace* const space_;
79
80 CardSet dirty_cards_;
81};
82
83} // namespace accounting
84} // namespace gc
85} // namespace art
86
87#endif // ART_RUNTIME_GC_ACCOUNTING_REMEMBERED_SET_H_