Wed, 16 Jul 2014 10:47:56 -0400
8050386: javac, follow-up of fix for JDK-8049305
Reviewed-by: mcimadamore
1.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java Tue Aug 26 11:15:28 2014 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java Wed Jul 16 10:47:56 2014 -0400 1.3 @@ -1194,7 +1194,7 @@ 1.4 boolean testFirst) { 1.5 Env<GenContext> loopEnv = env.dup(loop, new GenContext()); 1.6 int startpc = code.entryPoint(); 1.7 - if (testFirst) { 1.8 + if (testFirst) { //while or for loop 1.9 CondItem c; 1.10 if (cond != null) { 1.11 code.statBegin(cond.pos); 1.12 @@ -1240,6 +1240,9 @@ 1.13 code.resolve(c.falseJumps); 1.14 } 1.15 code.resolve(loopEnv.info.exit); 1.16 + if (loopEnv.info.exit != null) { 1.17 + loopEnv.info.exit.state.defined.excludeFrom(code.nextreg); 1.18 + } 1.19 } 1.20 1.21 private enum LoopLocalVarRangeEndingPoint {
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/T8049305/WrongStackframeGenerationTest1.java Wed Jul 16 10:47:56 2014 -0400 2.3 @@ -0,0 +1,47 @@ 2.4 +/* 2.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test 2.29 + * @bug 8049305 2.30 + * @summary Verification error due to a bad stackmap frame generated by javac 2.31 + */ 2.32 + 2.33 +public class WrongStackframeGenerationTest1 { 2.34 + public static void main(String[] args) {} 2.35 + 2.36 + static void foo(){ 2.37 + while (true) { 2.38 + int i = 0; 2.39 + break; 2.40 + } 2.41 + switch (1) { 2.42 + case 1: 2.43 + int j = 0; 2.44 + case 2: 2.45 + bar(); 2.46 + } 2.47 + } 2.48 + 2.49 + static void bar() {} 2.50 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/T8049305/WrongStackframeGenerationTest2.java Wed Jul 16 10:47:56 2014 -0400 3.3 @@ -0,0 +1,50 @@ 3.4 +/* 3.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.23 + * or visit www.oracle.com if you need additional information or have any 3.24 + * questions. 3.25 + */ 3.26 + 3.27 +/* 3.28 + * @test 3.29 + * @bug 8049305 3.30 + * @summary Verification error due to a bad stackmap frame generated by javac 3.31 + */ 3.32 + 3.33 +public class WrongStackframeGenerationTest2 { 3.34 + public static void main(String[] args) {} 3.35 + 3.36 + static void foo() { 3.37 + int len; 3.38 + for (;;) { 3.39 + try { 3.40 + len = 1; 3.41 + break; 3.42 + } catch (Exception e) { 3.43 + } 3.44 + } 3.45 + 3.46 + try { 3.47 + if (len == -1) { 3.48 + len = 0; 3.49 + } 3.50 + } finally { 3.51 + } 3.52 + } 3.53 +}