8047719: Incorrect LVT in switch statement
authorvromero
Fri, 27 Jun 2014 20:32:12 +0100
changeset 25298 7940437438b9
parent 25297 28ed439b96e9
child 25299 b4a7dcd657f5
8047719: Incorrect LVT in switch statement Reviewed-by: jjg, jlahoda
langtools/src/share/classes/com/sun/tools/javac/jvm/Code.java
langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java
langtools/test/tools/javac/classfiles/attributes/LocalVariableTable/LocalVariableTableTest.java
langtools/test/tools/javac/classfiles/attributes/LocalVariableTable/LocalVariableTypeTableTest.java
langtools/test/tools/javac/flow/LVTHarness.java
langtools/test/tools/javac/flow/tests/TestCaseSwitch.java
--- a/langtools/src/share/classes/com/sun/tools/javac/jvm/Code.java	Thu Jun 26 16:39:14 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/Code.java	Fri Jun 27 20:32:12 2014 +0100
@@ -1953,12 +1953,12 @@
             }
         }
 
-        public void closeRange(char end) {
-            if (isLastRangeInitialized()) {
+        public void closeRange(char length) {
+            if (isLastRangeInitialized() && length > 0) {
                 Range range = lastRange();
                 if (range != null) {
                     if (range.length == Character.MAX_VALUE) {
-                        range.length = end;
+                        range.length = length;
                     }
                 }
             } else {
@@ -2022,7 +2022,7 @@
                 }
                 if (localVar.sym == aliveLocal && localVar.lastRange() != null) {
                     char length = (char)(closingCP - localVar.lastRange().start_pc);
-                    if (length > 0 && length < Character.MAX_VALUE) {
+                    if (length < Character.MAX_VALUE) {
                         localVar.closeRange(length);
                     }
                 }
@@ -2093,7 +2093,7 @@
             lvar[adr].isLastRangeInitialized()) {
             LocalVar v = lvar[adr];
             char length = (char)(curCP() - v.lastRange().start_pc);
-            if (length > 0 && length < Character.MAX_VALUE) {
+            if (length < Character.MAX_VALUE) {
                 lvar[adr] = v.dup();
                 v.closeRange(length);
                 putVar(v);
--- a/langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Thu Jun 26 16:39:14 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Fri Jun 27 20:32:12 2014 +0100
@@ -2766,7 +2766,7 @@
 
             boolean trackVar(VarSymbol var) {
                 return (var.owner.kind == MTH &&
-                        (var.flags() & (PARAMETER | HASINIT)) == 0 &&
+                        (var.flags() & PARAMETER) == 0 &&
                         analyzer.trackable(var));
             }
 
--- a/langtools/test/tools/javac/classfiles/attributes/LocalVariableTable/LocalVariableTableTest.java	Thu Jun 26 16:39:14 2014 -0700
+++ b/langtools/test/tools/javac/classfiles/attributes/LocalVariableTable/LocalVariableTableTest.java	Fri Jun 27 20:32:12 2014 +0100
@@ -153,7 +153,6 @@
     @ExpectedLocals(name = "inTry", type = "D")
     @ExpectedLocals(name = "inSync", type = "F")
     @ExpectedLocals(name = "inDo", type = "B")
-    @ExpectedLocals(name = "inSwitch", type = "S")
     @ExpectedLocals(name = "inFor", type = "J")
     @ExpectedLocals(name = "s", type = "Ljava/util/stream/Stream;")
     public void deepScope() {
@@ -179,17 +178,6 @@
         }
     }
 
-    @ExpectedLocals(name = "i", type = "I", scope = 0)
-    @ExpectedLocals(name = "i", type = "J", scope = 1)
-    public void reuseByLong() {
-        {
-            int i = 0;
-        }
-        {
-            long i = 1;
-        }
-    }
-
     class LocalVariableTable implements VariableTable {
 
         final LocalVariableTable_attribute att;
--- a/langtools/test/tools/javac/classfiles/attributes/LocalVariableTable/LocalVariableTypeTableTest.java	Thu Jun 26 16:39:14 2014 -0700
+++ b/langtools/test/tools/javac/classfiles/attributes/LocalVariableTable/LocalVariableTypeTableTest.java	Fri Jun 27 20:32:12 2014 +0100
@@ -104,7 +104,6 @@
     @ExpectedLocals(name = "inTry", type = "TTHIS;")
     @ExpectedLocals(name = "inSync", type = "TTHIS;")
     @ExpectedLocals(name = "inDo", type = "TTHIS;")
-    @ExpectedLocals(name = "inSwitch", type = "TTHIS;")
     @ExpectedLocals(name = "inFor", type = "LLocalVariableTypeTableTest<-TTHIS;>;")
     @ExpectedLocals(name = "s", type = "Ljava/util/stream/Stream<+Ljava/lang/Integer;>;")
     public void deepScope() {
@@ -130,17 +129,6 @@
         }
     }
 
-    @ExpectedLocals(name = "i", type = "TTHIS;", scope = 0)
-    @ExpectedLocals(name = "i", type = "Ljava/util/List<TTHIS;>;", scope = 1)
-    public void reuseByLong() {
-        {
-            THIS i = null;
-        }
-        {
-            List<THIS> i = null;
-        }
-    }
-
     class LocalVariableTypeTable implements VariableTable {
 
         final LocalVariableTypeTable_attribute att;
--- a/langtools/test/tools/javac/flow/LVTHarness.java	Thu Jun 26 16:39:14 2014 -0700
+++ b/langtools/test/tools/javac/flow/LVTHarness.java	Fri Jun 27 20:32:12 2014 +0100
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 7047734 8027660 8037937
+ * @bug 7047734 8027660 8037937 8047719
  * @summary The LVT is not generated correctly during some try/catch scenarios
  *          javac crash while creating LVT entry for a local variable defined in
  *          an inner block
--- a/langtools/test/tools/javac/flow/tests/TestCaseSwitch.java	Thu Jun 26 16:39:14 2014 -0700
+++ b/langtools/test/tools/javac/flow/tests/TestCaseSwitch.java	Fri Jun 27 20:32:12 2014 +0100
@@ -5,7 +5,7 @@
     @AliveRange(varName="o", bytecodeStart=31, bytecodeLength=16)
     @AliveRange(varName="o", bytecodeStart=50, bytecodeLength=15)
     @AliveRange(varName="o", bytecodeStart=68, bytecodeLength=1)
-    @AliveRange(varName="oo", bytecodeStart=39, bytecodeLength=26)
+    @AliveRange(varName="oo", bytecodeStart=39, bytecodeLength=8)
     @AliveRange(varName="uu", bytecodeStart=59, bytecodeLength=6)
     void m1(String[] args) {
         Object o;
@@ -29,7 +29,7 @@
     @AliveRange(varName="o", bytecodeStart=95, bytecodeLength=18)
     @AliveRange(varName="o", bytecodeStart=116, bytecodeLength=15)
     @AliveRange(varName="o", bytecodeStart=134, bytecodeLength=1)
-    @AliveRange(varName="oo", bytecodeStart=104, bytecodeLength=27)
+    @AliveRange(varName="oo", bytecodeStart=104, bytecodeLength=9)
     @AliveRange(varName="uu", bytecodeStart=125, bytecodeLength=6)
     void m2(String[] args) {
         Object o;
@@ -50,12 +50,14 @@
         o = "return";
     }
 
-    @AliveRange(varName="o", bytecodeStart=31, bytecodeLength=8)
-    @AliveRange(varName="o", bytecodeStart=42, bytecodeLength=8)
-    @AliveRange(varName="o", bytecodeStart=53, bytecodeLength=9)
-    void m3(String[] args) {
+    @AliveRange(varName="o", bytecodeStart=35, bytecodeLength=8)
+    @AliveRange(varName="o", bytecodeStart=46, bytecodeLength=8)
+    @AliveRange(varName="o", bytecodeStart=78, bytecodeLength=5)
+    @AliveRange(varName="o", bytecodeStart=86, bytecodeLength=1)
+    @AliveRange(varName="oo", bytecodeStart=56, bytecodeLength=16)
+    void m3(int i) {
         Object o;
-        switch (args.length) {
+        switch (i) {
             case 0:
                     o = "0";
                     o.hashCode();
@@ -64,10 +66,19 @@
                     o = "1";
                     o.hashCode();
                     break;
+            case 2:
+                int oo = i;
+                if (oo > 1) {
+                    System.out.println("greater");
+                }
+                break;
+            case 3:
+                int uu = i;
             default:
                     o = "default";
                     o.hashCode();
         }
         o = "finish";
     }
+
 }