blob: 90d4ffb368ba155d78b2c66e12383a309e7be7c1 [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"
Hiroshi Yamauchi38e68e92014-03-07 13:59:08 -080022#include "safe_map.h"
23
24#include <set>
25#include <vector>
26
27namespace art {
28namespace gc {
29
30namespace collector {
Igor Murashkin2ffb7032017-11-08 13:35:21 -080031class GarbageCollector;
32class MarkSweep;
Hiroshi Yamauchi38e68e92014-03-07 13:59:08 -080033} // namespace collector
34namespace space {
Igor Murashkin2ffb7032017-11-08 13:35:21 -080035class ContinuousSpace;
Hiroshi Yamauchi38e68e92014-03-07 13:59:08 -080036} // namespace space
37
38class Heap;
39
40namespace 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.
44class RememberedSet {
45 public:
Ian Rogers13735952014-10-08 12:43:28 -070046 typedef std::set<uint8_t*, std::less<uint8_t*>,
47 TrackingAllocator<uint8_t*, kAllocatorTagRememberedSet>> CardSet;
Hiroshi Yamauchi38e68e92014-03-07 13:59:08 -080048
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 Chartier97509952015-07-13 14:35:43 -070056 void UpdateAndMarkReferences(space::ContinuousSpace* target_space,
57 collector::GarbageCollector* collector)
Mathieu Chartier90443472015-07-16 20:32:27 -070058 REQUIRES(Locks::heap_bitmap_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070059 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi38e68e92014-03-07 13:59:08 -080060
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_