Skip to content

Commit

Permalink
8259231: Epsilon: improve performance under contention during virtual…
Browse files Browse the repository at this point in the history
… space expansion

Reviewed-by: shade
  • Loading branch information
lhtin authored and shipilev committed Jan 6, 2021
1 parent f6cb8c5 commit 722f236
Showing 1 changed file with 35 additions and 22 deletions.
57 changes: 35 additions & 22 deletions src/hotspot/share/gc/epsilon/epsilonHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

1 comment on commit 722f236

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.