java.lang.IllegalArgumentException: cannot reference a primitive type: org.openjdk.PrimitiveClasses$Value
at java.base/java.lang.ref.Reference.<init>(Reference.java:495)
at java.base/java.lang.ref.Reference.<init>(Reference.java:489)
at java.base/java.lang.ref.WeakReference.<init>(WeakReference.java:62)
at org.openjdk.jmh.infra.Blackhole.consumeFull(Blackhole.java:515)
at org.openjdk.jmh.infra.Blackhole.consume(Blackhole.java:315)
at org.openjdk.jmh_generated.PrimitiveClasses_test_jmhTest.test_avgt_jmhStub(PrimitiveClasses_test_jmhTest.java:190)
at org.openjdk.jmh_generated.PrimitiveClasses_test_jmhTest.test_AverageTime(PrimitiveClasses_test_jmhTest.java:152)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.openjdk.jmh.runner.BenchmarkHandler$BenchmarkTask.call(BenchmarkHandler.java:470)
at org.openjdk.jmh.runner.BenchmarkHandler$BenchmarkTask.call(BenchmarkHandler.java:453)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:831)
Wrapping in WeakReference is not very reliably, but it is an important defense-in-depth strategy: if it hoards a large object, then a GC in the middle of benchmark would drop it. To handle inline types, it might make some sense to wrap the instance with another holder.
- relates to
-
JDK-8223582 [lworld] WeakReference of an inline type should throw
- Resolved
-
CODETOOLS-7901867 Blackhole.consume(Object) should additionally protect from retaining objects forever
- Resolved
- links to
-
Review openjdk/jmh/42