aoqi@0: /* shshahma@3371: * Copyright (c) 2013, 2017, 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. 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 7008643 aoqi@0: * @summary inlined finally clauses confuse debuggers aoqi@0: * @library /tools/javac/lib aoqi@0: * @build ToolBox aoqi@0: * @run main InlinedFinallyConfuseDebuggersTest 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.LineNumberTable_attribute; aoqi@0: import com.sun.tools.classfile.Method; aoqi@0: import com.sun.tools.javac.util.Assert; aoqi@0: aoqi@0: public class InlinedFinallyConfuseDebuggersTest { aoqi@0: aoqi@0: static final String testSource = aoqi@0: /* 01 */ "public class InlinedFinallyTest {\n" + aoqi@0: /* 02 */ " void lookForThisMethod(int value) {\n" + aoqi@0: /* 03 */ " try {\n" + aoqi@0: /* 04 */ " if (value > 0) {\n" + aoqi@0: /* 05 */ " System.out.println(\"if\");\n" + aoqi@0: /* 06 */ " return;\n" + aoqi@0: /* 07 */ " }\n" + aoqi@0: /* 08 */ " } finally {\n" + aoqi@0: /* 09 */ " System.out.println(\"finally\");\n" + aoqi@0: /* 10 */ " }\n" + aoqi@0: /* 11 */ " }\n" + aoqi@0: /* 12 */ "}"; aoqi@0: aoqi@0: static final int[][] expectedLNT = { aoqi@0: // {line-number, start-pc}, aoqi@0: {4, 0}, //if (value > 0) { aoqi@0: {5, 4}, // System.out.println("if"); aoqi@0: {9, 12}, //System.out.println("finally"); aoqi@0: {6, 20}, // return; aoqi@0: {9, 21}, //System.out.println("finally"); aoqi@0: {10, 29}, aoqi@0: {9, 32}, //System.out.println("finally"); shshahma@3371: {10, 41}, //} aoqi@0: {11, 43}, aoqi@0: }; aoqi@0: aoqi@0: static final String methodToLookFor = "lookForThisMethod"; aoqi@0: aoqi@0: public static void main(String[] args) throws Exception { aoqi@0: new InlinedFinallyConfuseDebuggersTest().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: "InlinedFinallyTest.class").toUri()), methodToLookFor); 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 methodToFind) throws Exception { aoqi@0: ClassFile classFile = ClassFile.read(cfile); aoqi@0: boolean methodFound = false; aoqi@0: for (Method method : classFile.methods) { aoqi@0: if (method.getName(classFile.constant_pool).equals(methodToFind)) { aoqi@0: methodFound = true; aoqi@0: Code_attribute code = (Code_attribute) method.attributes.get("Code"); aoqi@0: LineNumberTable_attribute lnt = aoqi@0: (LineNumberTable_attribute) code.attributes.get("LineNumberTable"); aoqi@0: Assert.check(lnt.line_number_table_length == expectedLNT.length, aoqi@0: "The LineNumberTable found has a length different to the expected one"); aoqi@0: int i = 0; aoqi@0: for (LineNumberTable_attribute.Entry entry: lnt.line_number_table) { aoqi@0: Assert.check(entry.line_number == expectedLNT[i][0] && aoqi@0: entry.start_pc == expectedLNT[i][1], aoqi@0: "LNT entry at pos " + i + " differ from expected." + aoqi@0: "Found " + entry.line_number + ":" + entry.start_pc + aoqi@0: ". Expected " + expectedLNT[i][0] + ":" + expectedLNT[i][1]); aoqi@0: i++; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: Assert.check(methodFound, "The seek method was not found"); aoqi@0: } aoqi@0: aoqi@0: void error(String msg) { aoqi@0: throw new AssertionError(msg); aoqi@0: } aoqi@0: aoqi@0: }