MethodHandle performance with JMH
Sergey Tselovalnikov
sergeicelov at gmail.com
Sun Mar 16 08:29:01 UTC 2014
Hello.
I tried to measure performance of MethodHandle in comparison with
reflection, but get Exception, because jmh uses generated code.
java.lang.invoke.WrongMethodTypeException: cannot convert
MethodHandle()Integer to (Object[])Object
I also tried compile latest version of JMH, but it does not help.
Test project:
https://github.com/SerCeMan/reflection-access-tests
I run tests from the terminal with command:
mvn clean install && java -jar target/microbenchmarks.jar
".*MethodStatic.*" -wi 5 -i 5 -f 1 > compiled.txt
I have attached full log of test to mail.
--
Best regards,
Sergey Tselovalnikov
-------------- next part --------------
# Run progress: 0.00% complete, ETA 00:01:00
# VM invoker: /usr/lib/jvm/jdk1.7.0/jre/bin/java
# VM options: <none>
# Fork: 1 of 1
# Warmup: 5 iterations, 1 s each
# Measurement: 5 iterations, 1 s each
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: ru.serce.jmh.ReflectionMethodStaticAccess.testFastMethod
# Warmup Iteration 1: 202985523.617 ops/s
# Warmup Iteration 2: 212347894.800 ops/s
# Warmup Iteration 3: 212196359.267 ops/s
# Warmup Iteration 4: 213447013.067 ops/s
# Warmup Iteration 5: 213471461.150 ops/s
Iteration 1: 213924226.650 ops/s
Iteration 2: 209880137.350 ops/s
Iteration 3: 213515409.050 ops/s
Iteration 4: 213751700.700 ops/s
Iteration 5: 213135858.433 ops/s
Result : 212841466.437 ±(99.9%) 6475276.350 ops/s
Statistics: (min, avg, max) = (209880137.350, 212841466.437, 213924226.650), stdev = 1681608.705
Confidence interval (99.9%): [206366190.087, 219316742.787]
# Run progress: 16.67% complete, ETA 00:00:51
# VM invoker: /usr/lib/jvm/jdk1.7.0/jre/bin/java
# VM options: <none>
# Fork: 1 of 1
# Warmup: 5 iterations, 1 s each
# Measurement: 5 iterations, 1 s each
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: ru.serce.jmh.ReflectionMethodStaticAccess.testMethodAccessible
# Warmup Iteration 1: 418036723.767 ops/s
# Warmup Iteration 2: 422600293.717 ops/s
# Warmup Iteration 3: 395042401.767 ops/s
# Warmup Iteration 4: 391001383.817 ops/s
# Warmup Iteration 5: 395369056.417 ops/s
Iteration 1: 394491492.767 ops/s
Iteration 2: 395177629.467 ops/s
Iteration 3: 390742806.883 ops/s
Iteration 4: 394611685.600 ops/s
Iteration 5: 396597208.000 ops/s
Result : 394324164.543 ±(99.9%) 8355080.734 ops/s
Statistics: (min, avg, max) = (390742806.883, 394324164.543, 396597208.000), stdev = 2169787.934
Confidence interval (99.9%): [385969083.809, 402679245.277]
# Run progress: 33.33% complete, ETA 00:00:41
# VM invoker: /usr/lib/jvm/jdk1.7.0/jre/bin/java
# VM options: <none>
# Fork: 1 of 1
# Warmup: 5 iterations, 1 s each
# Measurement: 5 iterations, 1 s each
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: ru.serce.jmh.ReflectionMethodStaticAccess.testMethodDirect
# Warmup Iteration 1: 405525600.917 ops/s
# Warmup Iteration 2: 408839118.000 ops/s
# Warmup Iteration 3: 410968837.417 ops/s
# Warmup Iteration 4: 402962379.233 ops/s
# Warmup Iteration 5: 407941400.617 ops/s
Iteration 1: 412409446.533 ops/s
Iteration 2: 420323281.717 ops/s
Iteration 3: 415267937.433 ops/s
Iteration 4: 422684416.917 ops/s
Iteration 5: 422254001.167 ops/s
Result : 418587816.753 ±(99.9%) 17480050.701 ops/s
Statistics: (min, avg, max) = (412409446.533, 418587816.753, 422684416.917), stdev = 4539513.657
Confidence interval (99.9%): [401107766.052, 436067867.455]
# Run progress: 50.00% complete, ETA 00:00:31
# VM invoker: /usr/lib/jvm/jdk1.7.0/jre/bin/java
# VM options: <none>
# Fork: 1 of 1
# Warmup: 5 iterations, 1 s each
# Measurement: 5 iterations, 1 s each
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: ru.serce.jmh.ReflectionMethodStaticAccess.testMethodHandle
# Warmup Iteration 1: <failure>
java.lang.invoke.WrongMethodTypeException: cannot convert MethodHandle()Integer to (Object[])Object
at java.lang.invoke.MethodHandle.asType(MethodHandle.java:724)
at java.lang.invoke.InvokeGeneric.dispatch(InvokeGeneric.java:103)
at java.lang.invoke.InvokeGeneric.dispatchWithConversion(InvokeGeneric.java:117)
at ru.serce.jmh.ReflectionMethodStaticAccess.testMethodHandle(ReflectionMethodStaticAccess.java:72)
at ru.serce.jmh.generated.ReflectionMethodStaticAccess.testMethodHandle_Throughput_measurementLoop(ReflectionMethodStaticAccess.java:766)
at ru.serce.jmh.generated.ReflectionMethodStaticAccess.testMethodHandle_Throughput(ReflectionMethodStaticAccess.java:735)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.openjdk.jmh.runner.LoopMicroBenchmarkHandler$BenchmarkTask.invokeBenchmark(LoopMicroBenchmarkHandler.java:231)
at org.openjdk.jmh.runner.LoopMicroBenchmarkHandler$BenchmarkTask.call(LoopMicroBenchmarkHandler.java:199)
at org.openjdk.jmh.runner.LoopMicroBenchmarkHandler$BenchmarkTask.call(LoopMicroBenchmarkHandler.java:184)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
# Run progress: 66.67% complete, ETA 00:00:16
# VM invoker: /usr/lib/jvm/jdk1.7.0/jre/bin/java
# VM options: <none>
# Fork: 1 of 1
# Warmup: 5 iterations, 1 s each
# Measurement: 5 iterations, 1 s each
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: ru.serce.jmh.ReflectionMethodStaticAccess.testMethodHandleExact
# Warmup Iteration 1: <failure>
java.lang.invoke.WrongMethodTypeException: expected ()Integer but found (Object[])Object
at java.lang.invoke.Invokers.newWrongMethodTypeException(Invokers.java:349)
at java.lang.invoke.Invokers.checkExactType(Invokers.java:360)
at ru.serce.jmh.ReflectionMethodStaticAccess.testMethodHandleExact(ReflectionMethodStaticAccess.java:67)
at ru.serce.jmh.generated.ReflectionMethodStaticAccess.testMethodHandleExact_Throughput_measurementLoop(ReflectionMethodStaticAccess.java:988)
at ru.serce.jmh.generated.ReflectionMethodStaticAccess.testMethodHandleExact_Throughput(ReflectionMethodStaticAccess.java:957)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.openjdk.jmh.runner.LoopMicroBenchmarkHandler$BenchmarkTask.invokeBenchmark(LoopMicroBenchmarkHandler.java:231)
at org.openjdk.jmh.runner.LoopMicroBenchmarkHandler$BenchmarkTask.call(LoopMicroBenchmarkHandler.java:199)
at org.openjdk.jmh.runner.LoopMicroBenchmarkHandler$BenchmarkTask.call(LoopMicroBenchmarkHandler.java:184)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
# Run progress: 83.33% complete, ETA 00:00:06
# VM invoker: /usr/lib/jvm/jdk1.7.0/jre/bin/java
# VM options: <none>
# Fork: 1 of 1
# Warmup: 5 iterations, 1 s each
# Measurement: 5 iterations, 1 s each
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: ru.serce.jmh.ReflectionMethodStaticAccess.testMethodNotAccessible
# Warmup Iteration 1: 348737465.767 ops/s
# Warmup Iteration 2: 352646818.650 ops/s
# Warmup Iteration 3: 283695365.783 ops/s
# Warmup Iteration 4: 281531651.700 ops/s
# Warmup Iteration 5: 282486767.733 ops/s
Iteration 1: 280791666.967 ops/s
Iteration 2: 282225697.500 ops/s
Iteration 3: 270797514.467 ops/s
Iteration 4: 271152573.767 ops/s
Iteration 5: 276548159.333 ops/s
Result : 276303122.407 ±(99.9%) 20386954.287 ops/s
Statistics: (min, avg, max) = (270797514.467, 276303122.407, 282225697.500), stdev = 5294427.287
Confidence interval (99.9%): [255916168.120, 296690076.694]
Benchmark Mode Samples Mean Mean error Units
r.s.j.ReflectionMethodStaticAccess.testFastMethod thrpt 5 212841466.437 6475276.350 ops/s
r.s.j.ReflectionMethodStaticAccess.testMethodAccessible thrpt 5 394324164.543 8355080.734 ops/s
r.s.j.ReflectionMethodStaticAccess.testMethodDirect thrpt 5 418587816.753 17480050.701 ops/s
r.s.j.ReflectionMethodStaticAccess.testMethodNotAccessible thrpt 5 276303122.407 20386954.287 ops/s
More information about the jmh-dev
mailing list