RFR: 8301403: Eliminate memory allocations in JVMFlag::printFlags during signal handling [v7]

Gerard Ziemski gziemski at openjdk.org
Thu Jul 25 22:45:08 UTC 2024


On Thu, 25 Jul 2024 17:19:08 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 with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains eight additional commits since the last revision:
> 
>  - Merge remote-tracking branch 'upstream/master' into JDK-8301403
>  - move include
>  - use local stack storage for the sorting indicies
>  - can not use new
>  - switch to CHeapBitMap
>  - remove unused header
>  - change name from max to best
>  - do not presort to avoid memory allocation

There was a compile error on Windows:

d:\a\jdk\jdk\src\hotspot\share\runtime\flags\jvmFlag.cpp(705): error C2131: expression did not evaluate to a constant
d:\a\jdk\jdk\src\hotspot\share\runtime\flags\jvmFlag.cpp(696): note: failure was caused by non-constant arguments or reference to a non-constant symbol
d:\a\jdk\jdk\src\hotspot\share\runtime\flags\jvmFlag.cpp(696): note: see usage of 'numFlags'
make[3]: *** [lib/CompileJvm.gmk:168: /d/a/jdk/jdk/build/windows-x64/hotspot/variant-server/libjvm/objs/jvmFlag.obj] Error 1

so I had to push a fix.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/20202#issuecomment-2251518955


More information about the hotspot-runtime-dev mailing list