Home | History | Annotate | Download | only in accounting
      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/space/space.h"
     20 
     21 namespace art {
     22 namespace gc {
     23 namespace accounting {
     24 
     25 void HeapBitmap::ReplaceBitmap(SpaceBitmap* old_bitmap, SpaceBitmap* new_bitmap) {
     26   for (auto& bitmap : continuous_space_bitmaps_) {
     27     if (bitmap == old_bitmap) {
     28       bitmap = new_bitmap;
     29       return;
     30     }
     31   }
     32   LOG(FATAL) << "bitmap " << static_cast<const void*>(old_bitmap) << " not found";
     33 }
     34 
     35 void HeapBitmap::ReplaceObjectSet(SpaceSetMap* old_set, SpaceSetMap* new_set) {
     36   for (auto& space_set : discontinuous_space_sets_) {
     37     if (space_set == old_set) {
     38       space_set = new_set;
     39       return;
     40     }
     41   }
     42   LOG(FATAL) << "object set " << static_cast<const void*>(old_set) << " not found";
     43 }
     44 
     45 void HeapBitmap::AddContinuousSpaceBitmap(accounting::SpaceBitmap* bitmap) {
     46   DCHECK(bitmap != NULL);
     47 
     48   // Check for interval overlap.
     49   for (const auto& cur_bitmap : continuous_space_bitmaps_) {
     50     CHECK(!(
     51         bitmap->HeapBegin() < cur_bitmap->HeapLimit() &&
     52         bitmap->HeapLimit() > cur_bitmap->HeapBegin()))
     53         << "Bitmap " << bitmap->Dump() << " overlaps with existing bitmap " << cur_bitmap->Dump();
     54   }
     55   continuous_space_bitmaps_.push_back(bitmap);
     56 }
     57 
     58 void HeapBitmap::AddDiscontinuousObjectSet(SpaceSetMap* set) {
     59   DCHECK(set != NULL);
     60   discontinuous_space_sets_.push_back(set);
     61 }
     62 
     63 void HeapBitmap::Walk(SpaceBitmap::Callback* callback, void* arg) {
     64   for (const auto& bitmap : continuous_space_bitmaps_) {
     65     bitmap->Walk(callback, arg);
     66   }
     67 
     68   DCHECK(!discontinuous_space_sets_.empty());
     69   for (const auto& space_set : discontinuous_space_sets_) {
     70     space_set->Walk(callback, arg);
     71   }
     72 }
     73 
     74 }  // namespace accounting
     75 }  // namespace gc
     76 }  // namespace art
     77