Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CODETOOLS-7902944: JMH: Avoid direct weak references in Blackhole.consume(Object) #42

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

shipilev
Copy link
Collaborator

@shipilev shipilev commented May 26, 2021

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.


Progress

  • Change must not contain extraneous whitespace
  • Change must be properly reviewed

Issue

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jmh pull/42/head:pull/42
$ git checkout pull/42

Update a local copy of the PR:
$ git checkout pull/42
$ git pull https://git.openjdk.java.net/jmh pull/42/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 42

View PR using the GUI difftool:
$ git pr show -t 42

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jmh/pull/42.diff

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented May 26, 2021

👋 Welcome back shade! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr label May 26, 2021
@mlbridge
Copy link

@mlbridge mlbridge bot commented May 26, 2021

Webrevs

@shipilev shipilev changed the title CODETOOLS-7902944: JMH: Avoid weak references in Blackhole.consume(Object) CODETOOLS-7902944: JMH: Avoid direct weak references in Blackhole.consume(Object) May 26, 2021
@shipilev
Copy link
Collaborator Author

@shipilev shipilev commented May 26, 2021

This seems to have implications on performance. On hold.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rfr
1 participant