Update JMH and Review Use of Blackhole
The TeeTime Benchmarks project currently uses version 1.9.2
, which is a bit outdated. Latest version is 1.19
.
However, when updating to 1.19
, Blackhole
cannot longer be used as before since new Blackhole()
is forbidden and a Blackhole can only be instantiated with a password.
JavaDoc of Blackhole:
Prevent instantiation by user code. Without additional countermeasures
to properly escape Blackhole, its magic is not working. The instances
of Blackholes which are injected into benchmark methods are treated by JMH,
and users are supposed to only use the injected instances.
It only *seems* simple to make the constructor non-public, but then
there is a lot of infrastructure code which assumes @State has a default
constructor. One might suggest doing the internal factory method to instantiate,
but that does not help when extending the Blackhole. There is a *messy* way to
special-case most of these problems within the JMH code, but it does not seem
to worth the effort.
Therefore, we choose to fail at runtime. It will only affect the users who thought
"new Blackhole()" is a good idea, and these users are rare. If you are reading this
comment, you might be one of those users. Stay cool! Don't instantiate Blackholes
directly though.
It think the correct use of Blackhole is to pass it as an argument to the benchmarks method annotated by @Benchmark
- Without any warranty and based on http://java-performance.info/jmh . However, I have no clue how to modify the TeeTime benchmarks accordingly.
The reason for reporting this issue is, first, that instantiating Blackhole directly semms to have been always wrong (also in older versions) and, second, I want RadarGun to use the latest JMH version.