mirror of
https://github.com/openjdk/jdk.git
synced 2026-04-17 10:20:33 +00:00
8259231: Epsilon: improve performance under contention during virtual space expansion
Reviewed-by: shade
This commit is contained in:
parent
f6cb8c558b
commit
722f23610e
@ -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);
|
||||
|
||||
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;
|
||||
HeapWord* res = NULL;
|
||||
while (true) {
|
||||
// Try to allocate, assume space is available
|
||||
res = _space->par_allocate(size);
|
||||
if (res != NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
_space->set_end((HeapWord *) _virtual_space.high());
|
||||
res = _space->par_allocate(size);
|
||||
// Allocation failed, attempt expansion, and retry:
|
||||
{
|
||||
MutexLocker ml(Heap_lock);
|
||||
|
||||
// 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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user