aoqi@0: /* aoqi@0: * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: /* aoqi@0: * @test aoqi@0: * @bug 8024039 aoqi@0: * @summary javac, previous solution for JDK-8022186 was incorrect aoqi@0: * @library /tools/javac/lib aoqi@0: * @build ToolBox aoqi@0: * @run main NoDeadCodeGenerationOnTrySmtTest aoqi@0: */ aoqi@0: aoqi@0: import java.io.File; aoqi@0: import java.nio.file.Paths; aoqi@0: aoqi@0: import com.sun.tools.classfile.ClassFile; aoqi@0: import com.sun.tools.classfile.Code_attribute; aoqi@0: import com.sun.tools.classfile.Code_attribute.Exception_data; aoqi@0: import com.sun.tools.classfile.Method; aoqi@0: import com.sun.tools.javac.util.Assert; aoqi@0: aoqi@0: public class NoDeadCodeGenerationOnTrySmtTest { aoqi@0: aoqi@0: static final String testSource = aoqi@0: "public class Test {\n" + aoqi@0: " void m1(int arg) {\n" + aoqi@0: " synchronized (new Integer(arg)) {\n" + aoqi@0: " {\n" + aoqi@0: " label0:\n" + aoqi@0: " do {\n" + aoqi@0: " break label0;\n" + aoqi@0: " } while (arg != 0);\n" + aoqi@0: " }\n" + aoqi@0: " }\n" + aoqi@0: " }\n" + aoqi@0: aoqi@0: " void m2(int arg) {\n" + aoqi@0: " synchronized (new Integer(arg)) {\n" + aoqi@0: " {\n" + aoqi@0: " label0:\n" + aoqi@0: " {\n" + aoqi@0: " break label0;\n" + aoqi@0: " }\n" + aoqi@0: " }\n" + aoqi@0: " }\n" + aoqi@0: " }\n" + aoqi@0: "}"; aoqi@0: aoqi@0: static final int[][] expectedExceptionTable = { aoqi@0: // {from, to, target, type}, aoqi@0: {11, 13, 16, 0}, aoqi@0: {16, 19, 16, 0} aoqi@0: }; aoqi@0: aoqi@0: static final String[] methodsToLookFor = {"m1", "m2"}; aoqi@0: aoqi@0: public static void main(String[] args) throws Exception { aoqi@0: new NoDeadCodeGenerationOnTrySmtTest().run(); aoqi@0: } aoqi@0: aoqi@0: void run() throws Exception { aoqi@0: compileTestClass(); aoqi@0: checkClassFile(new File(Paths.get(System.getProperty("user.dir"), aoqi@0: "Test.class").toUri()), methodsToLookFor); aoqi@0: } aoqi@0: aoqi@0: void compileTestClass() throws Exception { aoqi@0: ToolBox.JavaToolArgs javacSuccessArgs = aoqi@0: new ToolBox.JavaToolArgs().setSources(testSource); aoqi@0: ToolBox.javac(javacSuccessArgs); aoqi@0: } aoqi@0: aoqi@0: void checkClassFile(final File cfile, String[] methodsToFind) throws Exception { aoqi@0: ClassFile classFile = ClassFile.read(cfile); aoqi@0: int numberOfmethodsFound = 0; aoqi@0: for (String methodToFind : methodsToFind) { aoqi@0: for (Method method : classFile.methods) { aoqi@0: if (method.getName(classFile.constant_pool).equals(methodToFind)) { aoqi@0: numberOfmethodsFound++; aoqi@0: Code_attribute code = (Code_attribute) method.attributes.get("Code"); aoqi@0: Assert.check(code.exception_table_length == expectedExceptionTable.length, aoqi@0: "The ExceptionTable found has a length different to the expected one"); aoqi@0: int i = 0; aoqi@0: for (Exception_data entry: code.exception_table) { aoqi@0: Assert.check(entry.start_pc == expectedExceptionTable[i][0] && aoqi@0: entry.end_pc == expectedExceptionTable[i][1] && aoqi@0: entry.handler_pc == expectedExceptionTable[i][2] && aoqi@0: entry.catch_type == expectedExceptionTable[i][3], aoqi@0: "Exception table entry at pos " + i + " differ from expected."); aoqi@0: i++; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: Assert.check(numberOfmethodsFound == 2, "Some seek methods were not found"); aoqi@0: } aoqi@0: aoqi@0: void error(String msg) { aoqi@0: throw new AssertionError(msg); aoqi@0: } aoqi@0: aoqi@0: }