Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 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 | // TODO: C++0x auto |
| 27 | typedef std::vector<SpaceBitmap*>::iterator It; |
| 28 | for (It it = continuous_space_bitmaps_.begin(), end = continuous_space_bitmaps_.end(); |
| 29 | it != end; ++it) { |
| 30 | if (*it == old_bitmap) { |
| 31 | *it = new_bitmap; |
| 32 | return; |
| 33 | } |
| 34 | } |
| 35 | LOG(FATAL) << "bitmap " << static_cast<const void*>(old_bitmap) << " not found"; |
| 36 | } |
| 37 | |
| 38 | void HeapBitmap::ReplaceObjectSet(SpaceSetMap* old_set, SpaceSetMap* new_set) { |
| 39 | // TODO: C++0x auto |
| 40 | typedef std::vector<SpaceSetMap*>::iterator It; |
| 41 | for (It it = discontinuous_space_sets_.begin(), end = discontinuous_space_sets_.end(); |
| 42 | it != end; ++it) { |
| 43 | if (*it == old_set) { |
| 44 | *it = new_set; |
| 45 | return; |
| 46 | } |
| 47 | } |
| 48 | LOG(FATAL) << "object set " << static_cast<const void*>(old_set) << " not found"; |
| 49 | } |
| 50 | |
| 51 | void HeapBitmap::AddContinuousSpaceBitmap(accounting::SpaceBitmap* bitmap) { |
| 52 | DCHECK(bitmap != NULL); |
| 53 | |
| 54 | // Check for interval overlap. |
| 55 | typedef std::vector<SpaceBitmap*>::iterator It; |
| 56 | for (It it = continuous_space_bitmaps_.begin(), end = continuous_space_bitmaps_.end(); |
| 57 | it != end; ++it) { |
| 58 | SpaceBitmap* bitmap = *it; |
| 59 | SpaceBitmap* cur_bitmap = *it; |
| 60 | CHECK(bitmap->HeapBegin() < cur_bitmap->HeapLimit() && |
| 61 | bitmap->HeapLimit() > cur_bitmap->HeapBegin()) |
| 62 | << "Bitmap " << bitmap->Dump() << " overlaps with existing bitmap " << cur_bitmap->Dump(); |
| 63 | } |
| 64 | continuous_space_bitmaps_.push_back(bitmap); |
| 65 | } |
| 66 | |
| 67 | void HeapBitmap::AddDiscontinuousObjectSet(SpaceSetMap* set) { |
| 68 | DCHECK(set != NULL); |
| 69 | discontinuous_space_sets_.push_back(set); |
| 70 | } |
| 71 | |
| 72 | void HeapBitmap::Walk(SpaceBitmap::Callback* callback, void* arg) { |
| 73 | // TODO: C++0x auto |
| 74 | typedef std::vector<SpaceBitmap*>::iterator It; |
| 75 | for (It it = continuous_space_bitmaps_.begin(), end = continuous_space_bitmaps_.end(); |
| 76 | it != end; ++it) { |
| 77 | SpaceBitmap* bitmap = *it; |
| 78 | bitmap->Walk(callback, arg); |
| 79 | } |
| 80 | // TODO: C++0x auto |
| 81 | typedef std::vector<SpaceSetMap*>::iterator It2; |
| 82 | DCHECK(discontinuous_space_sets_.begin() != discontinuous_space_sets_.end()); |
| 83 | for (It2 it = discontinuous_space_sets_.begin(), end = discontinuous_space_sets_.end(); |
| 84 | it != end; ++it) { |
| 85 | SpaceSetMap* set = *it; |
| 86 | set->Walk(callback, arg); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | } // namespace accounting |
| 91 | } // namespace gc |
| 92 | } // namespace art |