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

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

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 9, 10
    • Fix Version/s: tbd
    • Component/s: hotspot
    • Labels:

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated: