• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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/accounting/space_bitmap-inl.h"
20 #include "gc/space/space.h"
21 
22 namespace art {
23 namespace gc {
24 namespace accounting {
25 
ReplaceBitmap(ContinuousSpaceBitmap * old_bitmap,ContinuousSpaceBitmap * new_bitmap)26 void HeapBitmap::ReplaceBitmap(ContinuousSpaceBitmap* old_bitmap,
27                                ContinuousSpaceBitmap* new_bitmap) {
28   auto it = std::find(continuous_space_bitmaps_.begin(), continuous_space_bitmaps_.end(),
29                       old_bitmap);
30   CHECK(it != continuous_space_bitmaps_.end()) << " continuous space bitmap " << old_bitmap
31       << " not found";
32   *it = new_bitmap;
33 }
34 
ReplaceLargeObjectBitmap(LargeObjectBitmap * old_bitmap,LargeObjectBitmap * new_bitmap)35 void HeapBitmap::ReplaceLargeObjectBitmap(LargeObjectBitmap* old_bitmap,
36                                           LargeObjectBitmap* new_bitmap) {
37   auto it = std::find(large_object_bitmaps_.begin(), large_object_bitmaps_.end(), old_bitmap);
38   CHECK(it != large_object_bitmaps_.end()) << " large object bitmap " << old_bitmap
39       << " not found";
40   *it = new_bitmap;
41 }
42 
AddContinuousSpaceBitmap(accounting::ContinuousSpaceBitmap * bitmap)43 void HeapBitmap::AddContinuousSpaceBitmap(accounting::ContinuousSpaceBitmap* bitmap) {
44   DCHECK(bitmap != nullptr);
45   // Check that there is no bitmap overlap.
46   for (const auto& cur_bitmap : continuous_space_bitmaps_) {
47     CHECK(bitmap->HeapBegin() >= cur_bitmap->HeapLimit() ||
48           bitmap->HeapLimit() <= cur_bitmap->HeapBegin())
49               << "Bitmap " << bitmap->Dump() << " overlaps with existing bitmap "
50               << cur_bitmap->Dump();
51   }
52   continuous_space_bitmaps_.push_back(bitmap);
53 }
54 
RemoveContinuousSpaceBitmap(accounting::ContinuousSpaceBitmap * bitmap)55 void HeapBitmap::RemoveContinuousSpaceBitmap(accounting::ContinuousSpaceBitmap* bitmap) {
56   DCHECK(bitmap != nullptr);
57   auto it = std::find(continuous_space_bitmaps_.begin(), continuous_space_bitmaps_.end(), bitmap);
58   DCHECK(it != continuous_space_bitmaps_.end());
59   continuous_space_bitmaps_.erase(it);
60 }
61 
AddLargeObjectBitmap(LargeObjectBitmap * bitmap)62 void HeapBitmap::AddLargeObjectBitmap(LargeObjectBitmap* bitmap) {
63   DCHECK(bitmap != nullptr);
64   large_object_bitmaps_.push_back(bitmap);
65 }
66 
RemoveLargeObjectBitmap(LargeObjectBitmap * bitmap)67 void HeapBitmap::RemoveLargeObjectBitmap(LargeObjectBitmap* bitmap) {
68   DCHECK(bitmap != nullptr);
69   auto it = std::find(large_object_bitmaps_.begin(), large_object_bitmaps_.end(), bitmap);
70   DCHECK(it != large_object_bitmaps_.end());
71   large_object_bitmaps_.erase(it);
72 }
73 
74 }  // namespace accounting
75 }  // namespace gc
76 }  // namespace art
77