summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author Ian Rogers <irogers@google.com> 2012-11-27 17:46:54 -0800
committer Android (Google) Code Review <android-gerrit@google.com> 2012-11-27 17:46:54 -0800
commitddde37cfd44ccd49816776236a279e742bc9819d (patch)
tree9828bc9d0340b97fd911cf2f2608c1493f19d3c6 /src
parentdf1ce91ba97bc79a0637e5504b39318fb1c9f577 (diff)
parent80de7a684be3c320e9e1d3bf8c9d145fe7c2f7c3 (diff)
Merge "Fix clear growth limit not working." into dalvik-dev
Diffstat (limited to 'src')
-rw-r--r--src/heap.cc28
-rw-r--r--src/heap.h1
2 files changed, 20 insertions, 9 deletions
diff --git a/src/heap.cc b/src/heap.cc
index 472031b9eb..13f6ee8fc1 100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -145,6 +145,7 @@ Heap::Heap(size_t initial_size, size_t growth_limit, size_t min_free, size_t max
is_gc_running_(false),
last_gc_type_(kGcTypeNone),
enforce_heap_growth_rate_(false),
+ capacity_(capacity),
growth_limit_(growth_limit),
max_allowed_footprint_(initial_size),
concurrent_start_size_(128 * KB),
@@ -521,18 +522,26 @@ Object* Heap::AllocObject(Thread* self, Class* c, size_t byte_count) {
return obj;
}
+ std::ostringstream oss;
int64_t total_bytes_free = GetFreeMemory();
- size_t max_contiguous_allocation = 0;
- // TODO: C++0x auto
- for (Spaces::const_iterator it = spaces_.begin(); it != spaces_.end(); ++it) {
- if ((*it)->IsAllocSpace()) {
- (*it)->AsAllocSpace()->Walk(MSpaceChunkCallback, &max_contiguous_allocation);
+ uint64_t alloc_space_size = alloc_space_->GetNumBytesAllocated();
+ uint64_t large_object_size = large_object_space_->GetNumObjectsAllocated();
+ oss << "Failed to allocate a " << byte_count << " byte allocation with " << total_bytes_free
+ << " free bytes; allocation space size " << alloc_space_size
+ << "; large object space size " << large_object_size;
+ // If the allocation failed due to fragmentation, print out the largest continuous allocation.
+ if (total_bytes_free >= byte_count) {
+ size_t max_contiguous_allocation = 0;
+ // TODO: C++0x auto
+ for (Spaces::const_iterator it = spaces_.begin(); it != spaces_.end(); ++it) {
+ if ((*it)->IsAllocSpace()) {
+ (*it)->AsAllocSpace()->Walk(MSpaceChunkCallback, &max_contiguous_allocation);
+ }
}
+ oss << "; failed due to fragmentation (largest possible contiguous allocation "
+ << max_contiguous_allocation << " bytes)";
}
-
- std::string msg(StringPrintf("Failed to allocate a %zd-byte %s (%lld total bytes free; largest possible contiguous allocation %zd bytes)",
- byte_count, PrettyDescriptor(c).c_str(), total_bytes_free, max_contiguous_allocation));
- self->ThrowOutOfMemoryError(msg.c_str());
+ self->ThrowOutOfMemoryError(oss.str().c_str());
return NULL;
}
@@ -1515,6 +1524,7 @@ void Heap::GrowForUtilization(uint64_t gc_duration) {
}
void Heap::ClearGrowthLimit() {
+ growth_limit_ = capacity_;
alloc_space_->ClearGrowthLimit();
}
diff --git a/src/heap.h b/src/heap.h
index a302405398..68ee9233bf 100644
--- a/src/heap.h
+++ b/src/heap.h
@@ -438,6 +438,7 @@ class Heap {
const bool enforce_heap_growth_rate_;
// Maximum size that the heap can reach.
+ size_t capacity_;
size_t growth_limit_;
size_t max_allowed_footprint_;