RFR: 8334866: Improve Speed of ElfDecoder source search [v4]

Kerem Kat krk at openjdk.org
Fri Oct 24 17:17:07 UTC 2025


On Tue, 21 Oct 2025 16:31:48 GMT, Kerem Kat <krk at openjdk.org> wrote:

>> Right now, looking up source file and line number info is slow because we do a full linear scan of the `.debug_aranges` section for every single call. This can be a major bottleneck on large binaries, especially during frequent native stack walking, e.g. while writing an hs_err.
>> 
>> This change fixes that by caching the address ranges on the first lookup, and keeping it in memory for the lifetime of the `DwarfFile` object.
>> 
>> All subsequent lookups on that object now use a binary search instead of the slow linear scan. If caching fails for any reason, it just falls back to the old method.
>
> Kerem Kat 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 four additional commits since the last revision:
> 
>  - Merge branch 'master' into elfdecoder-JDK-8334866
>  - Merge remote-tracking branch 'upstream/master' into elfdecoder-JDK-8334866
>  - Merge remote-tracking branch 'upstream/master' into elfdecoder-JDK-8334866
>  - 8334866: Cache debug_aranges for faster address lookups

Benchmarking an arbitrary test from `TestDwarf.java`, on a noisy laptop:


hyperfine -i -N --warmup=1 -r 10 -L JDK build/fastdebug-no-cache/jdk,build/fastdebug-cache/jdk '{JDK}/bin/java -cp /ws/jdk/JTwork/classes/0/runtime/ErrorHandling/TestDwarf.d:/ws/jdk/test/hotspot/jtreg/runtime/ErrorHandling:/ws/jdk/test/hotspot/jtreg:/ws/jdk/JTwork/classes/0/runtime/ErrorHandling/TestDwarf.d/test/lib:/ws/jdk/test/lib:/ws/jtreg/jtreg/build/images/jtreg/lib/javatest.jar:/ws/jtreg/jtreg/build/images/jtreg/lib/jtreg.jar -XX:TraceDwarfLevel=2 -XX:+CrashGCForDumpingJavaThread --version'
Benchmark 1: <fastdebug-no-cache>
  Time (mean ± σ):      2.232 s ±  0.051 s    [User: 2.652 s, System: 0.208 s]
  Range (min … max):    2.184 s …  2.345 s    10 runs

  Warning: Ignoring non-zero exit code.

Benchmark 2: <fastdebug-cache>
  Time (mean ± σ):      2.196 s ±  0.021 s    [User: 2.650 s, System: 0.201 s]
  Range (min … max):    2.160 s …  2.236 s    10 runs

  Warning: Ignoring non-zero exit code.

Summary
  <fastdebug-cache> ran
    1.02 ± 0.03 times faster than <fastdebug-no-cache>


The test finishes ~35 ms faster with cache.

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

PR Comment: https://git.openjdk.org/jdk/pull/27337#issuecomment-3444146503


More information about the hotspot-dev mailing list