RFR: 8334866: Improve Speed of ElfDecoder source search [v6]
Kerem Kat
krk at openjdk.org
Wed Oct 29 14:47:33 UTC 2025
On Fri, 24 Oct 2025 17:38:35 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 incrementally with one additional commit since the last revision:
>
> Fix comments, delete copy ctor
New benchmark results with 100 threads created:
hyperfine -i -N --warmup=1 -r 20 -L JDK build/release-no-cache/jdk,build/release-cache/jdk -L THREADS 100 '{JDK}/bin/java -Xbatch DerefNullCrash {THREADS}'
Benchmark 1: build/release-no-cache/jdk/bin/java -Xbatch DerefNullCrash 100
Time (mean ± σ): 4.150 s ± 0.304 s [User: 5.589 s, System: 2.506 s]
Range (min … max): 3.804 s … 4.874 s 20 runs
Benchmark 2: build/release-cache/jdk/bin/java DerefNullCrash 100
Warning: Ignoring non-zero exit code.
Time (mean ± σ): 3.963 s ± 0.065 s [User: 5.499 s, System: 2.504 s]
Range (min … max): 3.804 s … 4.062 s 20 runs
Summary
build/release-cache/jdk/bin/java -Xbatch DerefNullCrash 100 ran
1.05 ± 0.08 times faster than build/release-no-cache/jdk/bin/java -cp /ws/stress/src/AsprofStressTests/stress-apps -Xbatch DerefNullCrash 100
import java.lang.reflect.Field;
import sun.misc.Unsafe;
public class DerefNullCrash {
public static void main(String[] args) throws Exception {
int NUM_THREADS = Integer.parseInt(args[0]);
for (int i = 0; i < NUM_THREADS; i++) {
Thread t = new Thread(() -> {
double res = 0;
for (;;) {
res += Math.random() * Math.cos(res);
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
t.start();
}
getUnsafe().putLong(0L, 0L);
}
private static Unsafe getUnsafe() throws NoSuchFieldException, IllegalAccessException {
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
return (Unsafe) f.get(null);
}
}
-------------
PR Comment: https://git.openjdk.org/jdk/pull/27337#issuecomment-3461966366
More information about the hotspot-dev
mailing list