RFR: CODETOOLS-7902944: JMH: Avoid direct weak references in Blackhole.consume(Object) [v3]
Aleksey Shipilev
shade at openjdk.java.net
Wed May 26 17:39:23 UTC 2021
On Wed, 26 May 2021 15:09:41 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:
>> CODETOOLS-7901867 wrapped the stored object reference with a `WeakReference`. This unfortunately fails with inline type boxes that throw the exceptions like:
>>
>>
>> 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 reliable, 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.
>
> Aleksey Shipilev has updated the pull request incrementally with two additional commits since the last revision:
>
> - Rename Holder -> Box
> - Update comments
This seems to have implications on performance. On hold.
-------------
PR: https://git.openjdk.java.net/jmh/pull/42
More information about the jmh-dev
mailing list