--- a/src/hotspot/share/gc/epsilon/epsilonHeap.cpp Fri Dec 08 13:45:22 2017 +0100
+++ b/src/hotspot/share/gc/epsilon/epsilonHeap.cpp Fri Dec 08 15:44:08 2017 +0100
@@ -126,9 +126,24 @@
while (res == NULL) {
// Allocation failed, attempt expansion, and retry:
MutexLockerEx ml(Heap_lock);
- if (!_virtual_space.expand_by(MAX2(size, EpsilonMinHeapExpand))) {
+
+ size_t space_left = max_capacity() - capacity();
+ size_t want_space = MAX2(size, EpsilonMinHeapExpand);
+
+ if (want_space < space_left) {
+ // Enough space to expand in bulk:
+ bool expand = _virtual_space.expand_by(want_space);
+ assert(expand, "Should be able to expand");
+ } else if (size < space_left) {
+ // No space to expand in bulk, and this allocation is still possible,
+ // take all the space left:
+ bool expand = _virtual_space.expand_by(space_left);
+ assert(expand, "Should be able to expand");
+ } else {
+ // No space left:
return NULL;
}
+
_space->set_end((HeapWord *) _virtual_space.high());
res = _space->par_allocate(size);
}