RFR: 8301403: Eliminate memory allocations during signal handling

Gerard Ziemski gziemski at openjdk.org
Tue Jul 16 21:06:13 UTC 2024


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)), however, it's called while handling an error message, 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 end up having to qsort all flags when only a fraction of them we actually end up printing.

Running MACH5 tests...

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

Commit messages:
 - do not presort to avoid memory allocation

Changes: https://git.openjdk.org/jdk/pull/20202/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=20202&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8301403
  Stats: 29 lines in 2 files changed: 13 ins; 5 del; 11 mod
  Patch: https://git.openjdk.org/jdk/pull/20202.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/20202/head:pull/20202

PR: https://git.openjdk.org/jdk/pull/20202


More information about the hotspot-runtime-dev mailing list