summaryrefslogtreecommitdiffstats
path: root/runtime/gc/accounting
diff options
context:
space:
mode:
authorMathieu Chartier <mathieuc@google.com>2013-08-28 11:29:12 -0700
committerMathieu Chartier <mathieuc@google.com>2013-08-29 15:52:42 -0700
commit31e8925781c2302f1d1a9b39e216ba415bfe0d7e (patch)
tree12a9173c7134bc08712e46f11ee897072b7afb61 /runtime/gc/accounting
parentc6dfdacea2fd9e268f70328805b0366cdd6b7b9e (diff)
downloadandroid_art-31e8925781c2302f1d1a9b39e216ba415bfe0d7e.tar.gz
android_art-31e8925781c2302f1d1a9b39e216ba415bfe0d7e.tar.bz2
android_art-31e8925781c2302f1d1a9b39e216ba415bfe0d7e.zip
Write out image bitmap inside of image file.
We now create the image bitmap when we generate the image. The image bitmap is written after the image inside of the image file. This speeds up dex2oat by making walking the image during heap creation unnecessary. This should also help memory pressure by enabling the image bitmap to be swappable. Bug: 10432288 Change-Id: Idebf459ed15edbb41a7d9b9b353934155bce2f19
Diffstat (limited to 'runtime/gc/accounting')
-rw-r--r--runtime/gc/accounting/space_bitmap.cc20
-rw-r--r--runtime/gc/accounting/space_bitmap.h8
2 files changed, 19 insertions, 9 deletions
diff --git a/runtime/gc/accounting/space_bitmap.cc b/runtime/gc/accounting/space_bitmap.cc
index 702e162262..63b24ffb4e 100644
--- a/runtime/gc/accounting/space_bitmap.cc
+++ b/runtime/gc/accounting/space_bitmap.cc
@@ -45,11 +45,19 @@ std::string SpaceBitmap::Dump() const {
}
void SpaceSetMap::Walk(SpaceBitmap::Callback* callback, void* arg) {
- for (Objects::iterator it = contained_.begin(); it != contained_.end(); ++it) {
- callback(const_cast<mirror::Object*>(*it), arg);
+ for (const mirror::Object* obj : contained_) {
+ callback(const_cast<mirror::Object*>(obj), arg);
}
}
+SpaceBitmap* SpaceBitmap::CreateFromMemMap(const std::string& name, MemMap* mem_map,
+ byte* heap_begin, size_t heap_capacity) {
+ CHECK(mem_map != nullptr);
+ word* bitmap_begin = reinterpret_cast<word*>(mem_map->Begin());
+ size_t bitmap_size = OffsetToIndex(RoundUp(heap_capacity, kAlignment * kBitsPerWord)) * kWordSize;
+ return new SpaceBitmap(name, mem_map, bitmap_begin, bitmap_size, heap_begin);
+}
+
SpaceBitmap* SpaceBitmap::Create(const std::string& name, byte* heap_begin, size_t heap_capacity) {
CHECK(heap_begin != NULL);
// Round up since heap_capacity is not necessarily a multiple of kAlignment * kBitsPerWord.
@@ -59,8 +67,7 @@ SpaceBitmap* SpaceBitmap::Create(const std::string& name, byte* heap_begin, size
LOG(ERROR) << "Failed to allocate bitmap " << name;
return NULL;
}
- word* bitmap_begin = reinterpret_cast<word*>(mem_map->Begin());
- return new SpaceBitmap(name, mem_map.release(), bitmap_begin, bitmap_size, heap_begin);
+ return CreateFromMemMap(name, mem_map.release(), heap_begin, heap_capacity);
}
// Clean up any resources associated with the bitmap.
@@ -74,14 +81,11 @@ void SpaceBitmap::SetHeapLimit(uintptr_t new_end) {
}
// Not sure if doing this trim is necessary, since nothing past the end of the heap capacity
// should be marked.
- // TODO: Fix this code is, it broken and causes rare heap corruption!
- // mem_map_->Trim(reinterpret_cast<byte*>(heap_begin_ + bitmap_size_));
}
void SpaceBitmap::Clear() {
if (bitmap_begin_ != NULL) {
- // This returns the memory to the system. Successive page faults
- // will return zeroed memory.
+ // This returns the memory to the system. Successive page faults will return zeroed memory.
int result = madvise(bitmap_begin_, bitmap_size_, MADV_DONTNEED);
if (result == -1) {
PLOG(FATAL) << "madvise failed";
diff --git a/runtime/gc/accounting/space_bitmap.h b/runtime/gc/accounting/space_bitmap.h
index 26ab1ded96..f975692a3f 100644
--- a/runtime/gc/accounting/space_bitmap.h
+++ b/runtime/gc/accounting/space_bitmap.h
@@ -48,10 +48,16 @@ class SpaceBitmap {
typedef void SweepCallback(size_t ptr_count, mirror::Object** ptrs, void* arg);
- // Initialize a HeapBitmap so that it points to a bitmap large enough to cover a heap at
+ // Initialize a space bitmap so that it points to a bitmap large enough to cover a heap at
// heap_begin of heap_capacity bytes, where objects are guaranteed to be kAlignment-aligned.
static SpaceBitmap* Create(const std::string& name, byte* heap_begin, size_t heap_capacity);
+ // Initialize a space bitmap using the provided mem_map as the live bits. Takes ownership of the
+ // mem map. The address range covered starts at heap_begin and is of size equal to heap_capacity.
+ // Objects are kAlignement-aligned.
+ static SpaceBitmap* CreateFromMemMap(const std::string& name, MemMap* mem_map,
+ byte* heap_begin, size_t heap_capacity);
+
~SpaceBitmap();
// <offset> is the difference from .base to a pointer address.