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

Effectively-constant local variables not eliminated in generation

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 24
    • tools
    • None

      If a local variable is a constant, the subsequent code will be constant folded, but the local variable is not eliminated after constant folding.

      It seems in Gen.visitVarDef, there is this line:
      ```
      if (v.getConstValue() == null || varDebugInfo) {
      ```
      to eliminate such local variables. Clearly, this apparently does not work.

      For example, the following hashCode Java code

      ```java
      package jdk.vm.ci.meta;

      class AbstractProfiledItem {
          public int hashCode() {
              int prime = 31;
              int result = prime + Double.hashCode(probability);
              return prime * result + item.hashCode();
          }
      }
      ```


      The generated bytecode is

      ```
        public int hashCode();
          Code:
             0: bipush 31
             2: istore_1
             3: bipush 31
             5: aload_0
             6: getfield #20 // Field probability:D
             9: invokestatic #34 // Method java/lang/Double.hashCode:(D)I
            12: iadd
            13: istore_2
            14: bipush 31
            16: iload_2
            17: imul
            18: aload_0
            19: getfield #16 // Field item:Ljava/lang/Object;
            22: invokevirtual #38 // Method java/lang/Object.hashCode:()I
            25: iadd
            26: ireturn
      ```

      The bytecodes 0 to 2 are not needed.

            Unassigned Unassigned
            swen Shaojin Wen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: