We have a simple benchmark to measure increment ++ operation:
@Benchmark
public void measureInc() {
int i = 0;
i++;
}
Java compiler may eliminate the i variable because it is updated but never used. This called Dead-Code Elimination (DCE).
To avoid this JMH has a special class Blackhole that makes compiler think that the variable is used:
@Benchmark
public void measureInc(Blackhole bh) {
int i = 0;
i++;
bh.consume(i);
}
How plugin should help to solve it
We may inspect code to detect eliminated variables and propose to use the Blackhole. But such detection may be not so easy to implement or maybe we can just use "Unused variable" inspection. Not sure here.
But at least we may propose an intention for this. The intention may work like:
Select variable e.g. var1
Click on the intention "Throw into Black Hole"
If not already exists then a new argument Blackhole bh
This is a "good first issue" for newcomers.
Problem description
We have a simple benchmark to measure increment
++
operation:Java compiler may eliminate the
i
variable because it is updated but never used. This called Dead-Code Elimination (DCE).To avoid this JMH has a special class Blackhole that makes compiler think that the variable is used:
How plugin should help to solve it
We may inspect code to detect eliminated variables and propose to use the
Blackhole
. But such detection may be not so easy to implement or maybe we can just use "Unused variable" inspection. Not sure here.But at least we may propose an intention for this. The intention may work like:
var1
Blackhole bh
bh
:bh.consume(var1)
Intentions tutorial https://jetbrains.org/intellij/sdk/docs/tutorials/code_intentions.html Feel free to contact me directly by skype/tg stokito in case of any questions