Creating a Blackhole

Dawid Weiss dawid.weiss at gmail.com
Thu Jun 18 16:25:24 UTC 2015


This may not be the quickest solution... but you can postprocess your
bytecode after compilation (with asmlib, aspectj or whatever) and
remove blackhole calls.

With AspectJ it's a relatively easy call pointcut and an "around"
advice that doesn't
propagate the call. You could replace the default compiler with ajc
and apply test-specific aspects during compilation.

Dawid

On Thu, Jun 18, 2015 at 6:17 PM, Andrew Brampton <me at bramp.net> wrote:
> I have a complex benchmark, that takes >1 hour to run. I kept hitting an
> issue where the benchmark would crash during one of the setup/teardown
> phase (due to mistakes in my code). So I figured why don't I unit test my
> benchmark, to ensure the assumptions I make hold true.
>
> During my unit tests I wanted to create a Blackhole to pass to one of the
> benchmark methods. However, I found out that I'm not allowed to create a
> Blackhole: IllegalStateException("Blackholes should not be instantiated
> directly.").
>
> I can either do a nasty hack to create the Blackhole, or I'm requesting you
> add a new static method,  Blackhole.newBlackholeYesIdoKnowWhatImDoing(), or
> similar. Since in my case, I don't care about the benchmarking, and I'm
> calling this from a single junit thread, and just testing the correctness
> of my benchmark code. Alternatively if you create a Blackhole interface, I
> could easily create mock blackhole, for my testing.
>
> Suggestions?
> thanks
> Andrew
>
> P.S For the curious, my code lives here https://github.com/bramp/unsafe
> under unsafe-benchmark.


More information about the jmh-dev mailing list