RFR: 8301403: Eliminate memory allocations in JVMFlag::printFlags during signal handling [v5]
Johan Sjölen
jsjolen at openjdk.org
Sun Jul 21 09:13:32 UTC 2024
On Fri, 19 Jul 2024 20:18:47 GMT, Gerard Ziemski <gziemski at openjdk.org> wrote:
>> Allocating memory while handling an error should be avoided, however `JVMFlag::printFlags()` is used by crash log and it allocates memory to print flags sorted (using qsort).
>>
>> We avoid memory allocation by using a simple in place algorithm that uses JVMFlag 1 bit of unused data from its private `Flags` enum data member. It is O(n^2) algorithm, compared to O(n*log(n)) for qsort, however, it's called while handling an error log, so the speed here is not paramount. Also, I measured the real impact on a simple test case and I actually observed performance improvement of about x2.5 faster (2,885,973ns in place ordered printing vs 7,389,456ns for qsort). This is because we ended up having to qsort all flags when only a fraction of them actually end up being printed.
>>
>> Running MACH5 tests...
>
> Gerard Ziemski has updated the pull request incrementally with one additional commit since the last revision:
>
> can not use new
src/hotspot/share/runtime/flags/jvmFlag.cpp line 710:
> 708: size_t best_i = 0;
> 709: for (size_t i = 0; i < length; i++) {
> 710: if (!iteratorMarkers.at(i) && flagTable[i].is_unlocked() && !(skipDefaults && flagTable[i].is_default())) {
Why does `!(skipDefaults && flagTable[i].is_default())` compute `flagTable[i].is_default()` if `skipDefaults = true`?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20202#discussion_r1685690815
More information about the hotspot-runtime-dev
mailing list