Sat, 22 Dec 2018 13:10:38 -0800
Added tag jdk8u202-b25 for changeset 15d8c732039b
vromero@2009 | 1 | /* |
vromero@2009 | 2 | * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
vromero@2009 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
vromero@2009 | 4 | * |
vromero@2009 | 5 | * This code is free software; you can redistribute it and/or modify it |
vromero@2009 | 6 | * under the terms of the GNU General Public License version 2 only, as |
vromero@2009 | 7 | * published by the Free Software Foundation. Oracle designates this |
vromero@2009 | 8 | * particular file as subject to the "Classpath" exception as provided |
vromero@2009 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
vromero@2009 | 10 | * |
vromero@2009 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
vromero@2009 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
vromero@2009 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
vromero@2009 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
vromero@2009 | 15 | * accompanied this code). |
vromero@2009 | 16 | * |
vromero@2009 | 17 | * You should have received a copy of the GNU General Public License version |
vromero@2009 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
vromero@2009 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
vromero@2009 | 20 | * |
vromero@2009 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
vromero@2009 | 22 | * or visit www.oracle.com if you need additional information or have any |
vromero@2009 | 23 | * questions. |
vromero@2009 | 24 | */ |
vromero@2009 | 25 | |
vromero@2009 | 26 | /* |
vromero@2009 | 27 | * @test |
vromero@2009 | 28 | * @bug 8024039 |
vromero@2009 | 29 | * @summary javac, previous solution for JDK-8022186 was incorrect |
vromero@2009 | 30 | * @library /tools/javac/lib |
vromero@2009 | 31 | * @build ToolBox |
vromero@2009 | 32 | * @run main NoDeadCodeGenerationOnTrySmtTest |
vromero@2009 | 33 | */ |
vromero@2009 | 34 | |
vromero@2009 | 35 | import java.io.File; |
vromero@2009 | 36 | import java.nio.file.Paths; |
vromero@2009 | 37 | |
vromero@2009 | 38 | import com.sun.tools.classfile.ClassFile; |
vromero@2009 | 39 | import com.sun.tools.classfile.Code_attribute; |
vromero@2009 | 40 | import com.sun.tools.classfile.Code_attribute.Exception_data; |
vromero@2009 | 41 | import com.sun.tools.classfile.Method; |
vromero@2009 | 42 | import com.sun.tools.javac.util.Assert; |
vromero@2009 | 43 | |
vromero@2009 | 44 | public class NoDeadCodeGenerationOnTrySmtTest { |
vromero@2009 | 45 | |
vromero@2009 | 46 | static final String testSource = |
vromero@2009 | 47 | "public class Test {\n" + |
vromero@2009 | 48 | " void m1(int arg) {\n" + |
vromero@2009 | 49 | " synchronized (new Integer(arg)) {\n" + |
vromero@2009 | 50 | " {\n" + |
vromero@2009 | 51 | " label0:\n" + |
vromero@2009 | 52 | " do {\n" + |
vromero@2009 | 53 | " break label0;\n" + |
vromero@2009 | 54 | " } while (arg != 0);\n" + |
vromero@2009 | 55 | " }\n" + |
vromero@2009 | 56 | " }\n" + |
vromero@2009 | 57 | " }\n" + |
vromero@2009 | 58 | |
vromero@2009 | 59 | " void m2(int arg) {\n" + |
vromero@2009 | 60 | " synchronized (new Integer(arg)) {\n" + |
vromero@2009 | 61 | " {\n" + |
vromero@2009 | 62 | " label0:\n" + |
vromero@2009 | 63 | " {\n" + |
vromero@2009 | 64 | " break label0;\n" + |
vromero@2009 | 65 | " }\n" + |
vromero@2009 | 66 | " }\n" + |
vromero@2009 | 67 | " }\n" + |
vromero@2009 | 68 | " }\n" + |
vromero@2009 | 69 | "}"; |
vromero@2009 | 70 | |
vromero@2009 | 71 | static final int[][] expectedExceptionTable = { |
vromero@2009 | 72 | // {from, to, target, type}, |
vromero@2009 | 73 | {11, 13, 16, 0}, |
vromero@2009 | 74 | {16, 19, 16, 0} |
vromero@2009 | 75 | }; |
vromero@2009 | 76 | |
vromero@2009 | 77 | static final String[] methodsToLookFor = {"m1", "m2"}; |
vromero@2009 | 78 | |
vromero@2009 | 79 | public static void main(String[] args) throws Exception { |
vromero@2009 | 80 | new NoDeadCodeGenerationOnTrySmtTest().run(); |
vromero@2009 | 81 | } |
vromero@2009 | 82 | |
vromero@2009 | 83 | void run() throws Exception { |
vromero@2009 | 84 | compileTestClass(); |
vromero@2009 | 85 | checkClassFile(new File(Paths.get(System.getProperty("user.dir"), |
vromero@2009 | 86 | "Test.class").toUri()), methodsToLookFor); |
vromero@2009 | 87 | } |
vromero@2009 | 88 | |
vromero@2009 | 89 | void compileTestClass() throws Exception { |
vromero@2009 | 90 | ToolBox.JavaToolArgs javacSuccessArgs = |
vromero@2009 | 91 | new ToolBox.JavaToolArgs().setSources(testSource); |
vromero@2009 | 92 | ToolBox.javac(javacSuccessArgs); |
vromero@2009 | 93 | } |
vromero@2009 | 94 | |
vromero@2009 | 95 | void checkClassFile(final File cfile, String[] methodsToFind) throws Exception { |
vromero@2009 | 96 | ClassFile classFile = ClassFile.read(cfile); |
vromero@2009 | 97 | int numberOfmethodsFound = 0; |
vromero@2009 | 98 | for (String methodToFind : methodsToFind) { |
vromero@2009 | 99 | for (Method method : classFile.methods) { |
vromero@2009 | 100 | if (method.getName(classFile.constant_pool).equals(methodToFind)) { |
vromero@2009 | 101 | numberOfmethodsFound++; |
vromero@2009 | 102 | Code_attribute code = (Code_attribute) method.attributes.get("Code"); |
alundblad@2034 | 103 | Assert.check(code.exception_table_length == expectedExceptionTable.length, |
vromero@2009 | 104 | "The ExceptionTable found has a length different to the expected one"); |
vromero@2009 | 105 | int i = 0; |
vromero@2009 | 106 | for (Exception_data entry: code.exception_table) { |
vromero@2009 | 107 | Assert.check(entry.start_pc == expectedExceptionTable[i][0] && |
vromero@2009 | 108 | entry.end_pc == expectedExceptionTable[i][1] && |
vromero@2009 | 109 | entry.handler_pc == expectedExceptionTable[i][2] && |
vromero@2009 | 110 | entry.catch_type == expectedExceptionTable[i][3], |
vromero@2009 | 111 | "Exception table entry at pos " + i + " differ from expected."); |
vromero@2009 | 112 | i++; |
vromero@2009 | 113 | } |
vromero@2009 | 114 | } |
vromero@2009 | 115 | } |
vromero@2009 | 116 | } |
vromero@2009 | 117 | Assert.check(numberOfmethodsFound == 2, "Some seek methods were not found"); |
vromero@2009 | 118 | } |
vromero@2009 | 119 | |
vromero@2009 | 120 | void error(String msg) { |
vromero@2009 | 121 | throw new AssertionError(msg); |
vromero@2009 | 122 | } |
vromero@2009 | 123 | |
vromero@2009 | 124 | } |