-
Enhancement
-
Resolution: Unresolved
-
P4
-
9, 10
Below is a very frequent code pattern that is used to conditionalize the execution.
static final boolean FLAG = Boolean.getBoolean("flag");
if (somePredicate || FLAG) { ... }
In many cases, users expect the expression with FLAG to be completely folded away, or in other words, the original statement to be translated to something like:
FLAG=false: if (somePredicate) { ... }
FLAG=true: if (true) { ... } // and then the branch eliminated
Even though this plays games with logical/binary "or" semantics, it seems to be doable when "somePredicate" does not have any side effects. However, simple experiments show that current compiler only does this kind of transformation for some specific code shapes only. We need to figure out whether all basic forms are covered, and if not, if the optimizations can be extended to more code shapes.
static final boolean FLAG = Boolean.getBoolean("flag");
if (somePredicate || FLAG) { ... }
In many cases, users expect the expression with FLAG to be completely folded away, or in other words, the original statement to be translated to something like:
FLAG=false: if (somePredicate) { ... }
FLAG=true: if (true) { ... } // and then the branch eliminated
Even though this plays games with logical/binary "or" semantics, it seems to be doable when "somePredicate" does not have any side effects. However, simple experiments show that current compiler only does this kind of transformation for some specific code shapes only. We need to figure out whether all basic forms are covered, and if not, if the optimizations can be extended to more code shapes.
- relates to
-
JDK-8081736 Figure out the best code shape for a kill switch
- Resolved