Uploaded image for project: 'Code Tools'
  1. Code Tools
  2. CODETOOLS-7902944

JMH: Avoid direct weak references in Blackhole.consume(Object)

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: New
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: tools
    • Labels:
      None
    • Subcomponent:
      jmh

      Description

      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 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.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              shade Aleksey Shipilev
              Reporter:
              shade Aleksey Shipilev
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: