ConstantDynamic in unvisited catch causes 74X slowdown

Eirik Bjørsnøs eirbjo at gmail.com
Tue Jan 25 19:19:27 UTC 2022


Hi,

I'm looking at a JMH benchmark which shows a 74X slowdown when a
single invokeDynamic instruction is replaced by an equivalent
ConstantDynamic LDC instruction.

An interesting side note is that the LDC/invokeDynamic instructions live
inside a catch block which wraps the method being run.  So the
LDC/invokeDynamic instructions are actually never executed when running the
benchmark (because no exception was thrown/catched).

I was expecting ConstantDynamic to be as fast as (or faster than)
invokeDynamic, so this one is a bit of a puzzle. Does it make sense that
simply having a ConstantDynamic instruction present in the code prevents
some Hotspot optimizations from kicking in?

I've made a Maven project [1] with a minimal reproducer [2] for the issue.
(Minimal does not mean small, since there is a good amount of code for
setting up the instrumentation and class loading magic)

With Java 17.0.1 on my Intel Macbook pro, the JMH benchmark runs at ~350
ops/s using ConstantDynamic, and around 27000 ops/s when switching to
invokeDynamic.

What is going on here?

[1] https://github.com/eirbjo/constant-dynamic-cliff
[2]
https://github.com/eirbjo/constant-dynamic-cliff/blob/main/src/test/java/com/eirbjo/cpc/ConstantDynamicCliff.java

Thanks,
Eirik.


More information about the hotspot-compiler-dev mailing list