author | goetz |
Wed, 27 Jan 2016 10:35:49 +0100 | |
changeset 35775 | 00710c1b504a |
parent 30846 | 2b3f379840f0 |
child 36526 | 3b41f1c69604 |
permissions | -rw-r--r-- |
22693
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
22693
diff
changeset
|
2 |
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
22693
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
4 |
* |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
8 |
* |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
14 |
* |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
18 |
* |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
21 |
* questions. |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
22 |
*/ |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
23 |
|
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
24 |
/* |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
25 |
* @test |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
26 |
* @bug 8032814 |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
27 |
* @summary LineNumberTable/LocalVariableTable tables duplication for the |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
28 |
* "-v -l" combination of options |
30846 | 29 |
* @modules jdk.jdeps |
22693
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
30 |
* @compile -g T8032814.java |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
31 |
* @run main T8032814 |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
32 |
*/ |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
33 |
|
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
34 |
import java.io.*; |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
35 |
import java.util.*; |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
36 |
|
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
37 |
public class T8032814 { |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
38 |
public static void main(String... args) throws Exception { |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
39 |
new T8032814().run(); |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
40 |
} |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
41 |
|
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
42 |
void run() throws Exception { |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
43 |
Class<?> clazz = T8032814.class; |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
44 |
int count = clazz.getDeclaredConstructors().length |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
45 |
+ clazz.getDeclaredMethods().length; |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
46 |
test(clazz, 0); |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
47 |
test(clazz, count, "-v"); |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
48 |
test(clazz, count, "-l"); |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
49 |
test(clazz, count, "-v", "-l"); |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
50 |
|
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
51 |
if (errors > 0) |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
52 |
throw new Exception(errors + " errors occurred"); |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
53 |
} |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
54 |
|
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
55 |
void test(Class<?> clazz, int expectedCount, String... opts) throws Exception { |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
56 |
System.err.println("test class " + clazz.getName() + " " + Arrays.asList(opts) + ": expect: " + expectedCount); |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
57 |
List<String> args = new ArrayList<String>(); |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
58 |
args.addAll(Arrays.asList(opts)); |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
59 |
args.addAll(Arrays.asList("-classpath", System.getProperty("test.classes"))); |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
60 |
args.add(clazz.getName()); |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
61 |
StringWriter sw = new StringWriter(); |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
62 |
PrintWriter pw = new PrintWriter(sw); |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
63 |
int rc = com.sun.tools.javap.Main.run(args.toArray(new String[args.size()]), pw); |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
64 |
pw.close(); |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
65 |
String out = sw.toString(); |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
66 |
if (rc != 0) |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
67 |
throw new Exception("javap failed unexpectedly: rc=" + rc); |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
68 |
|
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
69 |
int lntCount = 0, lvtCount = 0; |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
70 |
for (String line: out.split("[\r\n]+")) { |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
71 |
if (line.matches("^ *LineNumberTable:$")) |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
72 |
lntCount++; |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
73 |
if (line.matches("^ *LocalVariableTable:$")) |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
74 |
lvtCount++; |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
75 |
} |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
76 |
checkEqual("LineNumberTable", lntCount, expectedCount); |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
77 |
checkEqual("LocalVariableTable", lvtCount, expectedCount); |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
78 |
} |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
79 |
|
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
80 |
void checkEqual(String attr, int found, int expect) { |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
81 |
if (found != expect) { |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
82 |
error("Unexpected number of occurrences of " + attr + "\n" + |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
83 |
"found: " + found + ", expected: " + expect); |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
84 |
} |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
85 |
} |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
86 |
|
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
87 |
void error(String msg) { |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
88 |
System.err.println("Error: " + msg); |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
89 |
errors++; |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
90 |
} |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
91 |
|
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
92 |
int errors = 0; |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
93 |
} |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff
changeset
|
94 |