Scope.Thread and @Setup bug?

Aleksey Shipilev shade at redhat.com
Wed Sep 28 13:08:21 UTC 2016


On 09/28/2016 03:02 PM, Lev Serebryakov wrote:
>  I'll try to compile minimal example where I got this.

If that reproduces only with your payload, I would appreciate if you can
publish that, if MCVE does not reproduce the failure. I'll stare at
generated code for a while...

> Maybe, problem is that EVERY thread-local state setup is called at
> EVERY thread? I've tried to construct benchmark in such way, that reader
> and writer needs different states and I've hoped, that JMH will not
> setup thread-local state which is not needed by this particular thread,
> so I could distinguish between "reader" and "writer" threads, what I
> need, because these threads need different setup. Are my assumptions
> correct?

For Scope.Thread, each thread gets its own state object (that is, the
object is thread-local), and the worker thread is responsible for
calling @Setup/@TearDown on it. In your example, all those objects share
the same buf from the Scope.Group object, though.

"Needed" is defined by the arguments list. If the @State object is in
method argument list for @Benchmark and/or @Setup/@TearDown methods,
then it is considered needed, and will be forced to initialize.

Thanks,
-Aleksey



More information about the jmh-dev mailing list