Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8259231: Epsilon: improve performance under contention during virtual…
… space expansion

Reviewed-by: shade
  • Loading branch information
lhtin authored and shipilev committed Jan 6, 2021
1 parent f6cb8c5 commit 722f23610e128991e21ba1b56ddf2b7eec99e5c2
Showing with 35 additions and 22 deletions.
  1. +35 −22 src/hotspot/share/gc/epsilon/epsilonHeap.cpp
@@ -106,31 +106,44 @@ EpsilonHeap* EpsilonHeap::heap() {
HeapWord* EpsilonHeap::allocate_work(size_t size) {
assert(is_object_aligned(size), "Allocation size should be aligned: " SIZE_FORMAT, size);

HeapWord* res = _space->par_allocate(size);
HeapWord* res = NULL;
while (true) {
// Try to allocate, assume space is available
res = _space->par_allocate(size);
if (res != NULL) {
break;
}

while (res == NULL) {
// Allocation failed, attempt expansion, and retry:
MutexLocker ml(Heap_lock);

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 remaining space:
bool expand = _virtual_space.expand_by(space_left);
assert(expand, "Should be able to expand");
} else {
// No space left:
return NULL;
}
{
MutexLocker ml(Heap_lock);

_space->set_end((HeapWord *) _virtual_space.high());
res = _space->par_allocate(size);
// Try to allocate under the lock, assume another thread was able to expand
res = _space->par_allocate(size);
if (res != NULL) {
break;
}

// Expand and loop back if space is available
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 remaining space:
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());
}
}

size_t used = _space->used();

0 comments on commit 722f236

Please sign in to comment.