blob: 1db886c06a575a38a7ab048bb8b8b221142dc1a2 [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
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070019#include "gc/accounting/space_bitmap-inl.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070020#include "gc/space/space.h"
21
22namespace art {
23namespace gc {
24namespace accounting {
25
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070026void HeapBitmap::ReplaceBitmap(ContinuousSpaceBitmap* old_bitmap,
27 ContinuousSpaceBitmap* new_bitmap) {
Mathieu Chartier02e25112013-08-14 16:14:24 -070028 for (auto& bitmap : continuous_space_bitmaps_) {
29 if (bitmap == old_bitmap) {
30 bitmap = new_bitmap;
Ian Rogers1d54e732013-05-02 21:10:01 -070031 return;
32 }
33 }
34 LOG(FATAL) << "bitmap " << static_cast<const void*>(old_bitmap) << " not found";
35}
36
Mathieu Chartierdb7f37d2014-01-10 11:09:06 -080037void HeapBitmap::ReplaceObjectSet(ObjectSet* old_set, ObjectSet* new_set) {
Mathieu Chartier02e25112013-08-14 16:14:24 -070038 for (auto& space_set : discontinuous_space_sets_) {
39 if (space_set == old_set) {
40 space_set = new_set;
Ian Rogers1d54e732013-05-02 21:10:01 -070041 return;
42 }
43 }
44 LOG(FATAL) << "object set " << static_cast<const void*>(old_set) << " not found";
45}
46
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070047void HeapBitmap::AddContinuousSpaceBitmap(accounting::ContinuousSpaceBitmap* bitmap) {
Ian Rogers1d54e732013-05-02 21:10:01 -070048 DCHECK(bitmap != NULL);
49
50 // Check for interval overlap.
Mathieu Chartier02e25112013-08-14 16:14:24 -070051 for (const auto& cur_bitmap : continuous_space_bitmaps_) {
52 CHECK(!(
53 bitmap->HeapBegin() < cur_bitmap->HeapLimit() &&
54 bitmap->HeapLimit() > cur_bitmap->HeapBegin()))
Ian Rogers1d54e732013-05-02 21:10:01 -070055 << "Bitmap " << bitmap->Dump() << " overlaps with existing bitmap " << cur_bitmap->Dump();
56 }
57 continuous_space_bitmaps_.push_back(bitmap);
58}
59
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070060void HeapBitmap::RemoveContinuousSpaceBitmap(accounting::ContinuousSpaceBitmap* bitmap) {
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080061 auto it = std::find(continuous_space_bitmaps_.begin(), continuous_space_bitmaps_.end(), bitmap);
62 DCHECK(it != continuous_space_bitmaps_.end());
63 continuous_space_bitmaps_.erase(it);
64}
65
Mathieu Chartierdb7f37d2014-01-10 11:09:06 -080066void HeapBitmap::AddDiscontinuousObjectSet(ObjectSet* set) {
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070067 DCHECK(set != nullptr);
Ian Rogers1d54e732013-05-02 21:10:01 -070068 discontinuous_space_sets_.push_back(set);
69}
70
Mathieu Chartierdb7f37d2014-01-10 11:09:06 -080071void HeapBitmap::RemoveDiscontinuousObjectSet(ObjectSet* set) {
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080072 auto it = std::find(discontinuous_space_sets_.begin(), discontinuous_space_sets_.end(), set);
73 DCHECK(it != discontinuous_space_sets_.end());
74 discontinuous_space_sets_.erase(it);
75}
76
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080077void HeapBitmap::Walk(ObjectCallback* callback, void* arg) {
Mathieu Chartier02e25112013-08-14 16:14:24 -070078 for (const auto& bitmap : continuous_space_bitmaps_) {
Ian Rogers1d54e732013-05-02 21:10:01 -070079 bitmap->Walk(callback, arg);
80 }
Mathieu Chartier02e25112013-08-14 16:14:24 -070081 for (const auto& space_set : discontinuous_space_sets_) {
82 space_set->Walk(callback, arg);
Ian Rogers1d54e732013-05-02 21:10:01 -070083 }
84}
85
86} // namespace accounting
87} // namespace gc
88} // namespace art