This is a work-in-progress set of tests to compare the runtime overhead of different dynamic invocation and lookup primitives on the JVM, such as:
Class.getMethod()
Lookup.findStatic()
andLookup.findVirtual()
(java.lang.invoke
)Method.invoke()
(java.lang.reflect
)MethodHandle.invoke()
(java.lang.invoke
)invokedynamic
This benchmark wouldn't be possible without two great tools:
- The Java Microbenchmarking Harness is used in order to get reliable results and to avoid some common benchmarking pitfalls on the HotSpot JVM.
- JiteScript is used to dynamically generate code leveraging the
invokedynamic
instruction (which would otherwise not be possible with pure Java).
Other sources of inspiration include:
- https://github.com/golo-lang/golo-jmh-benchmarks
- https://github.com/shipilev/article-method-dispatch
See the results of benchmark runs on my machine.
./mvnw clean package
./run_benchmarks.sh ...
or
java -jar target/benchmarks.jar ...