Blackhole user instantiation

Aleksey Shipilev aleksey.shipilev at oracle.com
Tue Jul 12 19:34:12 UTC 2016


On 06/29/2016 11:14 AM, Radim Vansa wrote:
> I'd like to reuse Blackhole in project aimed at benchmarking distributed
> systems (RadarGun [1]), but rather than just being tricky bastard [2]
> I'd like to ask if there's any info what black magic does JMH use to
> instantiate Blackhole properly and where be the dragons.

First, you have to understand that Blackhole evolves along with JVM and
our understanding of JVMs. Blindly copying Blackhole code to a separate
project detaches the implementation from updates.

Current Blackhole needs to avoid DCE-ing itself. That is, this runs into
danger of not working:

  @Benchmark
  public void test() {
    new Blackhole().consume(someOp());
  }

...because some Blackhole implementations may choose to store the
consumed argument in the field. Inlining the BH instance runs at the
risk of DCEing that part of BH mechanics, which breaks the contract.

This is one realistic failure scenario, but there might be other bad
ones. For example, at some point we would have to split Blackhole
implementations on per-JVM/compiler version (e.g. Graal), trying to
accommodate different compiler details. Injecting Blackhole to JMH users
provide a simple and performant way to substitute BH implementations
without forcing users to recompile.

Thanks,
-Aleksey






More information about the jmh-dev mailing list