Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8087309

Constant folding "static final boolean" in boolean expressions is incomplete

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 9, 10
    • hotspot

      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.

            vlivanov Vladimir Ivanov
            shade Aleksey Shipilev
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: