blob: f94cf24ce6189f044296979dbfbf47cf8345408e [file] [log] [blame]
Ian Rogers1d54e732013-05-02 21:10:01 -07001/*
2 * Copyright (C) 2012 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#include "heap_bitmap.h"
18
19#include "gc/space/space.h"
20
21namespace art {
22namespace gc {
23namespace accounting {
24
25void HeapBitmap::ReplaceBitmap(SpaceBitmap* old_bitmap, SpaceBitmap* new_bitmap) {
Mathieu Chartier02e25112013-08-14 16:14:24 -070026 for (auto& bitmap : continuous_space_bitmaps_) {
27 if (bitmap == old_bitmap) {
28 bitmap = new_bitmap;
Ian Rogers1d54e732013-05-02 21:10:01 -070029 return;
30 }
31 }
32 LOG(FATAL) << "bitmap " << static_cast<const void*>(old_bitmap) << " not found";
33}
34
Mathieu Chartierdb7f37d2014-01-10 11:09:06 -080035void HeapBitmap::ReplaceObjectSet(ObjectSet* old_set, ObjectSet* new_set) {
Mathieu Chartier02e25112013-08-14 16:14:24 -070036 for (auto& space_set : discontinuous_space_sets_) {
37 if (space_set == old_set) {
38 space_set = new_set;
Ian Rogers1d54e732013-05-02 21:10:01 -070039 return;
40 }
41 }
42 LOG(FATAL) << "object set " << static_cast<const void*>(old_set) << " not found";
43}
44
45void HeapBitmap::AddContinuousSpaceBitmap(accounting::SpaceBitmap* bitmap) {
46 DCHECK(bitmap != NULL);
47
48 // Check for interval overlap.
Mathieu Chartier02e25112013-08-14 16:14:24 -070049 for (const auto& cur_bitmap : continuous_space_bitmaps_) {
50 CHECK(!(
51 bitmap->HeapBegin() < cur_bitmap->HeapLimit() &&
52 bitmap->HeapLimit() > cur_bitmap->HeapBegin()))
Ian Rogers1d54e732013-05-02 21:10:01 -070053 << "Bitmap " << bitmap->Dump() << " overlaps with existing bitmap " << cur_bitmap->Dump();
54 }
55 continuous_space_bitmaps_.push_back(bitmap);
56}
57
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080058void HeapBitmap::RemoveContinuousSpaceBitmap(accounting::SpaceBitmap* bitmap) {
59 auto it = std::find(continuous_space_bitmaps_.begin(), continuous_space_bitmaps_.end(), bitmap);
60 DCHECK(it != continuous_space_bitmaps_.end());
61 continuous_space_bitmaps_.erase(it);
62}
63
Mathieu Chartierdb7f37d2014-01-10 11:09:06 -080064void HeapBitmap::AddDiscontinuousObjectSet(ObjectSet* set) {
Ian Rogers1d54e732013-05-02 21:10:01 -070065 DCHECK(set != NULL);
66 discontinuous_space_sets_.push_back(set);
67}
68
Mathieu Chartierdb7f37d2014-01-10 11:09:06 -080069void HeapBitmap::RemoveDiscontinuousObjectSet(ObjectSet* set) {
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080070 auto it = std::find(discontinuous_space_sets_.begin(), discontinuous_space_sets_.end(), set);
71 DCHECK(it != discontinuous_space_sets_.end());
72 discontinuous_space_sets_.erase(it);
73}
74
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080075void HeapBitmap::Walk(ObjectCallback* callback, void* arg) {
Mathieu Chartier02e25112013-08-14 16:14:24 -070076 for (const auto& bitmap : continuous_space_bitmaps_) {
Ian Rogers1d54e732013-05-02 21:10:01 -070077 bitmap->Walk(callback, arg);
78 }
Mathieu Chartier02e25112013-08-14 16:14:24 -070079 for (const auto& space_set : discontinuous_space_sets_) {
80 space_set->Walk(callback, arg);
Ian Rogers1d54e732013-05-02 21:10:01 -070081 }
82}
83
84} // namespace accounting
85} // namespace gc
86} // namespace art