Uploaded image for project: 'Apache Cassandra'
  1. Apache Cassandra
  2. CASSANDRA-12343

Make 'static final boolean' easier to optimize for Hotspot

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Low
    • Resolution: Fixed
    • 3.10
    • 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.

      Attachments

        Activity

          People

            snazy Robert Stupp
            snazy Robert Stupp
            Robert Stupp
            Branimir Lambov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: