author | vromero |
Mon, 22 May 2017 12:49:05 -0700 | |
changeset 45220 | 7c775294b6f1 |
parent 36778 | e04318f39f92 |
permissions | -rw-r--r-- |
18658 | 1 |
/* |
45220 | 2 |
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. |
18658 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 7008643 |
|
27 |
* @summary inlined finally clauses confuse debuggers |
|
26100 | 28 |
* @library /tools/lib |
30846 | 29 |
* @modules jdk.jdeps/com.sun.tools.classfile |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
26100
diff
changeset
|
30 |
* jdk.compiler/com.sun.tools.javac.api |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
26100
diff
changeset
|
31 |
* jdk.compiler/com.sun.tools.javac.main |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
26100
diff
changeset
|
32 |
* jdk.compiler/com.sun.tools.javac.util |
36526 | 33 |
* jdk.jdeps/com.sun.tools.javap |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
34 |
* @build toolbox.ToolBox toolbox.JavacTask |
18658 | 35 |
* @run main InlinedFinallyConfuseDebuggersTest |
36 |
*/ |
|
37 |
||
38 |
import java.io.File; |
|
39 |
import java.nio.file.Paths; |
|
40 |
||
41 |
import com.sun.tools.classfile.ClassFile; |
|
42 |
import com.sun.tools.classfile.Code_attribute; |
|
43 |
import com.sun.tools.classfile.LineNumberTable_attribute; |
|
44 |
import com.sun.tools.classfile.Method; |
|
45 |
import com.sun.tools.javac.util.Assert; |
|
46 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
47 |
import toolbox.JavacTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
48 |
import toolbox.ToolBox; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
49 |
|
18658 | 50 |
public class InlinedFinallyConfuseDebuggersTest { |
51 |
||
52 |
static final String testSource = |
|
53 |
/* 01 */ "public class InlinedFinallyTest {\n" + |
|
54 |
/* 02 */ " void lookForThisMethod(int value) {\n" + |
|
55 |
/* 03 */ " try {\n" + |
|
56 |
/* 04 */ " if (value > 0) {\n" + |
|
57 |
/* 05 */ " System.out.println(\"if\");\n" + |
|
58 |
/* 06 */ " return;\n" + |
|
59 |
/* 07 */ " }\n" + |
|
60 |
/* 08 */ " } finally {\n" + |
|
61 |
/* 09 */ " System.out.println(\"finally\");\n" + |
|
62 |
/* 10 */ " }\n" + |
|
63 |
/* 11 */ " }\n" + |
|
64 |
/* 12 */ "}"; |
|
65 |
||
66 |
static final int[][] expectedLNT = { |
|
67 |
// {line-number, start-pc}, |
|
68 |
{4, 0}, //if (value > 0) { |
|
69 |
{5, 4}, // System.out.println("if"); |
|
70 |
{9, 12}, //System.out.println("finally"); |
|
71 |
{6, 20}, // return; |
|
72 |
{9, 21}, //System.out.println("finally"); |
|
73 |
{10, 29}, |
|
74 |
{9, 32}, //System.out.println("finally"); |
|
45220 | 75 |
{10, 41}, //} |
18658 | 76 |
{11, 43}, |
77 |
}; |
|
78 |
||
79 |
static final String methodToLookFor = "lookForThisMethod"; |
|
80 |
||
81 |
public static void main(String[] args) throws Exception { |
|
82 |
new InlinedFinallyConfuseDebuggersTest().run(); |
|
83 |
} |
|
84 |
||
26100 | 85 |
ToolBox tb = new ToolBox(); |
86 |
||
18658 | 87 |
void run() throws Exception { |
88 |
compileTestClass(); |
|
89 |
checkClassFile(new File(Paths.get(System.getProperty("user.dir"), |
|
90 |
"InlinedFinallyTest.class").toUri()), methodToLookFor); |
|
91 |
} |
|
92 |
||
93 |
void compileTestClass() throws Exception { |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
94 |
new JavacTask(tb) |
26100 | 95 |
.sources(testSource) |
96 |
.run(); |
|
18658 | 97 |
} |
98 |
||
99 |
void checkClassFile(final File cfile, String methodToFind) throws Exception { |
|
100 |
ClassFile classFile = ClassFile.read(cfile); |
|
101 |
boolean methodFound = false; |
|
102 |
for (Method method : classFile.methods) { |
|
103 |
if (method.getName(classFile.constant_pool).equals(methodToFind)) { |
|
104 |
methodFound = true; |
|
105 |
Code_attribute code = (Code_attribute) method.attributes.get("Code"); |
|
106 |
LineNumberTable_attribute lnt = |
|
107 |
(LineNumberTable_attribute) code.attributes.get("LineNumberTable"); |
|
108 |
Assert.check(lnt.line_number_table_length == expectedLNT.length, |
|
109 |
"The LineNumberTable found has a length different to the expected one"); |
|
110 |
int i = 0; |
|
111 |
for (LineNumberTable_attribute.Entry entry: lnt.line_number_table) { |
|
112 |
Assert.check(entry.line_number == expectedLNT[i][0] && |
|
113 |
entry.start_pc == expectedLNT[i][1], |
|
114 |
"LNT entry at pos " + i + " differ from expected." + |
|
115 |
"Found " + entry.line_number + ":" + entry.start_pc + |
|
116 |
". Expected " + expectedLNT[i][0] + ":" + expectedLNT[i][1]); |
|
117 |
i++; |
|
118 |
} |
|
119 |
} |
|
120 |
} |
|
121 |
Assert.check(methodFound, "The seek method was not found"); |
|
122 |
} |
|
123 |
||
124 |
void error(String msg) { |
|
125 |
throw new AssertionError(msg); |
|
126 |
} |
|
127 |
||
128 |
} |