JMH v0.6

Aleksey Shipilev aleksey.shipilev at oracle.com
Mon Apr 28 10:25:32 UTC 2014


On 04/28/2014 02:15 PM, Dmitry Chuyko wrote:
> On 04/25/2014 11:11 AM, Aleksey Shipilev wrote:
>>   * Since some users were burned on this, "new BlackHole()" is forbidden
>> now, and will throw an exception at runtime [2]. Use injected Blackholes
>> instead.
> What about '@State MyState extends BlackHole'?

I think it is allowed now, if MyState is injected by JMH itself. But
otherwise it will throw from BlackHole super-constructor. That makes me
thinking about marking BlackHole class final to avoid confusion.
Extending library classes which are *accidentally* open is no fun.

> It is sometimes convenient to encapsulate some black hole inside state.
> For example consider passing this stream to some constructor:
> 
> final OutputStream nullos = new OutputStream() {
>     @Override
>     public void write(int b) throws IOException {
>         consume(b);
>     }
>     @Override
>     public void write(byte[] b, int off, int len) throws IOException {
>         consume(b);
>     }
> };

This only works reliably if the enclosing instance is escaped. There is
only a tiny syntactic inconvenience in passing the injected BlackHole
into anonymous class, instead of relying on implicit "this" binding.

-Aleksey.


More information about the jmh-dev mailing list