Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javap/T8032814.java
32285 views
1
/*
2
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
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 8032814
27
* @summary LineNumberTable/LocalVariableTable tables duplication for the
28
* "-v -l" combination of options
29
* @compile -g T8032814.java
30
* @run main T8032814
31
*/
32
33
import java.io.*;
34
import java.util.*;
35
36
public class T8032814 {
37
public static void main(String... args) throws Exception {
38
new T8032814().run();
39
}
40
41
void run() throws Exception {
42
Class<?> clazz = T8032814.class;
43
int count = clazz.getDeclaredConstructors().length
44
+ clazz.getDeclaredMethods().length;
45
test(clazz, 0);
46
test(clazz, count, "-v");
47
test(clazz, count, "-l");
48
test(clazz, count, "-v", "-l");
49
50
if (errors > 0)
51
throw new Exception(errors + " errors occurred");
52
}
53
54
void test(Class<?> clazz, int expectedCount, String... opts) throws Exception {
55
System.err.println("test class " + clazz.getName() + " " + Arrays.asList(opts) + ": expect: " + expectedCount);
56
List<String> args = new ArrayList<String>();
57
args.addAll(Arrays.asList(opts));
58
args.addAll(Arrays.asList("-classpath", System.getProperty("test.classes")));
59
args.add(clazz.getName());
60
StringWriter sw = new StringWriter();
61
PrintWriter pw = new PrintWriter(sw);
62
int rc = com.sun.tools.javap.Main.run(args.toArray(new String[args.size()]), pw);
63
pw.close();
64
String out = sw.toString();
65
if (rc != 0)
66
throw new Exception("javap failed unexpectedly: rc=" + rc);
67
68
int lntCount = 0, lvtCount = 0;
69
for (String line: out.split("[\r\n]+")) {
70
if (line.matches("^ *LineNumberTable:$"))
71
lntCount++;
72
if (line.matches("^ *LocalVariableTable:$"))
73
lvtCount++;
74
}
75
checkEqual("LineNumberTable", lntCount, expectedCount);
76
checkEqual("LocalVariableTable", lvtCount, expectedCount);
77
}
78
79
void checkEqual(String attr, int found, int expect) {
80
if (found != expect) {
81
error("Unexpected number of occurrences of " + attr + "\n" +
82
"found: " + found + ", expected: " + expect);
83
}
84
}
85
86
void error(String msg) {
87
System.err.println("Error: " + msg);
88
errors++;
89
}
90
91
int errors = 0;
92
}
93
94
95