Make sure Epsilon is able to use the last bit of expanded heap epsilon-gc-branch
authorshade
Fri, 08 Dec 2017 15:44:08 +0100
branchepsilon-gc-branch
changeset 55980 67d289ae67f5
parent 55979 669f8c047c9c
child 56021 864ee22719af
Make sure Epsilon is able to use the last bit of expanded heap
src/hotspot/share/gc/epsilon/epsilonHeap.cpp
--- 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);
   }