Elliott Hughes | 5e71b52 | 2011-10-20 13:12:32 -0700 | [diff] [blame] | 1 | #include "heap_bitmap.h" |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 2 | #include "space.h" |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 3 | |
Mathieu Chartier | 654d3a2 | 2012-07-11 17:54:18 -0700 | [diff] [blame] | 4 | namespace art { |
| 5 | |
| 6 | void HeapBitmap::ReplaceBitmap(SpaceBitmap* old_bitmap, SpaceBitmap* new_bitmap) { |
| 7 | // TODO: C++0x auto |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 8 | for (Bitmaps::iterator it = bitmaps_.begin(); it != bitmaps_.end(); ++it) { |
| 9 | if (*it == old_bitmap) { |
| 10 | *it = new_bitmap; |
Mathieu Chartier | 654d3a2 | 2012-07-11 17:54:18 -0700 | [diff] [blame] | 11 | return; |
| 12 | } |
| 13 | } |
| 14 | LOG(FATAL) << "bitmap " << static_cast<const void*>(old_bitmap) << " not found"; |
| 15 | } |
| 16 | |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 17 | void HeapBitmap::AddSpaceBitmap(SpaceBitmap* bitmap) { |
| 18 | DCHECK(bitmap != NULL); |
| 19 | |
| 20 | // Check for interval overlap. |
| 21 | for (Bitmaps::const_iterator it = bitmaps_.begin(); it != bitmaps_.end(); ++it) { |
| 22 | SpaceBitmap* cur_bitmap = *it; |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 23 | if (bitmap->HeapBegin() < cur_bitmap->HeapLimit() && |
| 24 | bitmap->HeapLimit() > cur_bitmap->HeapBegin()) { |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 25 | LOG(FATAL) << "Overlapping space bitmaps added to heap bitmap!"; |
| 26 | } |
| 27 | } |
| 28 | bitmaps_.push_back(bitmap); |
| 29 | } |
| 30 | |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 31 | void HeapBitmap::SetLargeObjects(SpaceSetMap* large_objects) { |
| 32 | DCHECK(large_objects != NULL); |
| 33 | large_objects_ = large_objects; |
| 34 | } |
| 35 | |
| 36 | HeapBitmap::HeapBitmap(Heap* heap) : heap_(heap), large_objects_(NULL) { |
| 37 | |
| 38 | } |
| 39 | |
| 40 | void HeapBitmap::Walk(SpaceBitmap::Callback* callback, void* arg) { |
| 41 | // TODO: C++0x auto |
| 42 | for (Bitmaps::iterator it = bitmaps_.begin(); it != bitmaps_.end(); ++it) { |
| 43 | (*it)->Walk(callback, arg); |
| 44 | } |
| 45 | |
| 46 | large_objects_->Walk(callback, arg); |
| 47 | } |
| 48 | |
Mathieu Chartier | 654d3a2 | 2012-07-11 17:54:18 -0700 | [diff] [blame] | 49 | } // namespace art |