RFR: 8259231: Fix the chance to allocate failure and improve the speed and quality of EpsilonHeap::allocate_work
Aleksey Shipilev
shade at openjdk.java.net
Tue Jan 5 13:44:55 UTC 2021
On Wed, 16 Dec 2020 01:29:55 GMT, Lehua Ding <github.com+13173904+lhtin at openjdk.org> wrote:
> Hi all,
>
> The `EpsilonHeap::allocate_work` method maybe can be fixed and improved by this:
> 1. it can prevent allocate failure by retry `_space->par_allocate` before expanding virtual space, when there not enough virtual space but another thread expanding succeeded just and has enough space.
> 2. it can reduce the lock time by move `res = _space->par_allocate(size);` out of lock scope.
>
> Test on macosx-x86_64-server-{release, fastdebug, slowdebug} with current test case.
Good find! Comments below:
src/hotspot/share/gc/epsilon/epsilon_globals.hpp line 67:
> 65: \
> 66: product(bool, EpsilonElasticTLABDecay, true, EXPERIMENTAL, \
> 67: "Use timed decays to shrink TLAB sizes. This conserves memory " \
Let's not do the typo fixes in this PR. Maybe there are other spelling problems elsewhere in `gc/epsilon` that we could fix wholesale in another PR?
src/hotspot/share/gc/epsilon/epsilonHeap.cpp line 113:
> 111: while (res == NULL) {
> 112: // Allocation failed, attempt expansion, and retry:
> 113: {
I see what you are trying to do, and it makes sense. I believe this form would be cleaner:
HeapWord* res = NULL;
while (true) {
// Try to allocate, assume space is available
res = par_allocate(size);
if (res != NULL) {
break;
}
MutexLocker ml(Heap_Lock);
// Try to allocate under the lock, assume another thread was able to expand
res = 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);
...
}
-------------
Changes requested by shade (Reviewer).
PR: https://git.openjdk.java.net/jdk/pull/1794
More information about the hotspot-gc-dev
mailing list