Thu, 29 May 2014 15:28:01 +0100
8037937: javac: AssertionError during LVT generation, wrong variable ranges
Reviewed-by: mcimadamore
1.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Code.java Wed May 28 11:07:07 2014 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Code.java Thu May 29 15:28:01 2014 +0100 1.3 @@ -1925,6 +1925,13 @@ 1.4 return aliveRanges.isEmpty() ? null : aliveRanges.get(aliveRanges.size() - 1); 1.5 } 1.6 1.7 + void removeLastRange() { 1.8 + Range lastRange = lastRange(); 1.9 + if (lastRange != null) { 1.10 + aliveRanges.remove(lastRange); 1.11 + } 1.12 + } 1.13 + 1.14 @Override 1.15 public String toString() { 1.16 if (aliveRanges == null) { 1.17 @@ -1955,9 +1962,7 @@ 1.18 } 1.19 } 1.20 } else { 1.21 - if (!aliveRanges.isEmpty()) { 1.22 - aliveRanges.remove(aliveRanges.size() - 1); 1.23 - } 1.24 + removeLastRange(); 1.25 } 1.26 } 1.27 1.28 @@ -1965,16 +1970,14 @@ 1.29 if (aliveRanges.isEmpty()) { 1.30 return false; 1.31 } 1.32 - Range range = lastRange(); 1.33 - return range.length == Character.MAX_VALUE; 1.34 + return lastRange().length == Character.MAX_VALUE; 1.35 } 1.36 1.37 public boolean isLastRangeInitialized() { 1.38 if (aliveRanges.isEmpty()) { 1.39 return false; 1.40 } 1.41 - Range range = lastRange(); 1.42 - return range.start_pc != Character.MAX_VALUE; 1.43 + return lastRange().start_pc != Character.MAX_VALUE; 1.44 } 1.45 1.46 public Range getWidestRange() { 1.47 @@ -2095,7 +2098,7 @@ 1.48 v.closeRange(length); 1.49 putVar(v); 1.50 } else { 1.51 - v.lastRange().start_pc = Character.MAX_VALUE; 1.52 + v.removeLastRange(); 1.53 } 1.54 } 1.55 }
2.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java Wed May 28 11:07:07 2014 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java Thu May 29 15:28:01 2014 +0100 2.3 @@ -1811,8 +1811,7 @@ 2.4 genStat(tree.thenpart, env, CRT_STATEMENT | CRT_FLOW_TARGET); 2.5 thenExit = code.branch(goto_); 2.6 if (varDebugInfo && lvtRanges.containsKey(code.meth, tree.thenpart)) { 2.7 - code.closeAliveRanges(tree.thenpart, 2.8 - thenExit != null && tree.elsepart == null ? thenExit.pc : code.cp); 2.9 + code.closeAliveRanges(tree.thenpart, code.cp); 2.10 } 2.11 } 2.12 if (elseChain != null) {
3.1 --- a/test/tools/javac/flow/LVTHarness.java Wed May 28 11:07:07 2014 -0700 3.2 +++ b/test/tools/javac/flow/LVTHarness.java Thu May 29 15:28:01 2014 +0100 3.3 @@ -1,5 +1,5 @@ 3.4 /* 3.5 - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3.6 + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. 3.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.8 * 3.9 * This code is free software; you can redistribute it and/or modify it 3.10 @@ -23,8 +23,8 @@ 3.11 3.12 /* 3.13 * @test 3.14 - * @bug 7047734 8027660 3.15 - * @summary The LVT is not generated correctly during some try/catch scenarios; 3.16 + * @bug 7047734 8027660 8037937 3.17 + * @summary The LVT is not generated correctly during some try/catch scenarios 3.18 * javac crash while creating LVT entry for a local variable defined in 3.19 * an inner block 3.20 * @library /tools/javac/lib 3.21 @@ -120,7 +120,7 @@ 3.22 for (Map.Entry<ElementKey, AliveRanges> entry : aliveRangeMap.entrySet()) { 3.23 if (!seenAliveRanges.contains(entry.getKey())) { 3.24 error("Redundant @AliveRanges annotation on method " + 3.25 - entry.getKey().elem); 3.26 + entry.getKey().elem + " with key " + entry.getKey()); 3.27 } 3.28 } 3.29 } 3.30 @@ -134,7 +134,7 @@ 3.31 for (Method method : classFile.methods) { 3.32 for (ElementKey elementKey: aliveRangeMap.keySet()) { 3.33 String methodDesc = method.getName(constantPool) + 3.34 - method.descriptor.getParameterTypes(constantPool); 3.35 + method.descriptor.getParameterTypes(constantPool).replace(" ", ""); 3.36 if (methodDesc.equals(elementKey.elem.toString())) { 3.37 checkMethod(constantPool, method, aliveRangeMap.get(elementKey)); 3.38 seenAliveRanges.add(elementKey);
4.1 --- a/test/tools/javac/flow/tests/TestCaseIfElse.java Wed May 28 11:07:07 2014 -0700 4.2 +++ b/test/tools/javac/flow/tests/TestCaseIfElse.java Thu May 29 15:28:01 2014 +0100 4.3 @@ -33,7 +33,7 @@ 4.4 4.5 @AliveRange(varName="o", bytecodeStart=10, bytecodeLength=8) 4.6 @AliveRange(varName="o", bytecodeStart=21, bytecodeLength=9) 4.7 - void m2(String[] args) { 4.8 + void m2() { 4.9 Object o; 4.10 int i = 5; 4.11 if (i != 5) { 4.12 @@ -45,4 +45,19 @@ 4.13 } 4.14 o = "finish"; 4.15 } 4.16 + 4.17 + @AliveRange(varName="o", bytecodeStart=11, bytecodeLength=3) 4.18 + @AliveRange(varName="o", bytecodeStart=17, bytecodeLength=2) 4.19 + Object m3(boolean cond1, boolean cond2) { 4.20 + Object o; 4.21 + if (cond1) { 4.22 + if (cond2) { 4.23 + o = "then"; 4.24 + } else { 4.25 + o = "else"; 4.26 + return null; 4.27 + } 4.28 + } 4.29 + return null; 4.30 + } 4.31 }