Details
-
Improvement
-
Status: Resolved
-
Low
-
Resolution: Fixed
-
None
-
None
Description
Hotspot is able to optimize condition checks on `static final` fields. But the compiler can only optimize if the referenced "constant" is the first condition to check. (If I understood the optimization in Hotspot correctly.)
I.e. the first if block can be "eliminated" whereas the second cannot:
class Foo { static final boolean CONST = /* some fragment evaluating to false */; public void doSomeStuff(boolean param) { if (!CONST) { // this code block can be eliminated } if (!CONST && param) { // this code block can be eliminated } if (param && !CONST) { // this code block cannot be eliminated due to some compiler logic } } }
Linked patch changes the order in some if statements and migrates a few methods to static final fields.