blob: cef688437475e26d149420656bc53cb8b12ea240 [file] [log] [blame]
Elliott Hughes5e71b522011-10-20 13:12:32 -07001#include "heap_bitmap.h"
Mathieu Chartiercc236d72012-07-20 10:29:05 -07002#include "space.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -07003
Mathieu Chartier654d3a22012-07-11 17:54:18 -07004namespace art {
5
6void HeapBitmap::ReplaceBitmap(SpaceBitmap* old_bitmap, SpaceBitmap* new_bitmap) {
7 // TODO: C++0x auto
Mathieu Chartiercc236d72012-07-20 10:29:05 -07008 for (Bitmaps::iterator it = bitmaps_.begin(); it != bitmaps_.end(); ++it) {
9 if (*it == old_bitmap) {
10 *it = new_bitmap;
Mathieu Chartier654d3a22012-07-11 17:54:18 -070011 return;
12 }
13 }
14 LOG(FATAL) << "bitmap " << static_cast<const void*>(old_bitmap) << " not found";
15}
16
Mathieu Chartiercc236d72012-07-20 10:29:05 -070017void 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 Chartier357e9be2012-08-01 11:00:14 -070023 if (bitmap->HeapBegin() < cur_bitmap->HeapLimit() &&
24 bitmap->HeapLimit() > cur_bitmap->HeapBegin()) {
Mathieu Chartiercc236d72012-07-20 10:29:05 -070025 LOG(FATAL) << "Overlapping space bitmaps added to heap bitmap!";
26 }
27 }
28 bitmaps_.push_back(bitmap);
29}
30
Mathieu Chartiere0f0cb32012-08-28 11:26:00 -070031void HeapBitmap::SetLargeObjects(SpaceSetMap* large_objects) {
32 DCHECK(large_objects != NULL);
33 large_objects_ = large_objects;
34}
35
36HeapBitmap::HeapBitmap(Heap* heap) : heap_(heap), large_objects_(NULL) {
37
38}
39
40void 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 Chartier654d3a22012-07-11 17:54:18 -070049} // namespace art