author | mchung |
Wed, 27 May 2015 13:25:18 -0700 | |
changeset 30846 | 2b3f379840f0 |
parent 30730 | d3ce7619db2c |
child 35424 | 96661d1df628 |
permissions | -rw-r--r-- |
3553
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
23120
diff
changeset
|
2 |
* Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved. |
3553
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
4 |
* |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
8 |
* |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
14 |
* |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
18 |
* |
5520 | 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. |
|
3553
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
22 |
*/ |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
23 |
|
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
24 |
/* |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
25 |
* @test |
23120
6e12870d6652
8035364: An extra space in the comments of constant pool entries
jjg
parents:
7681
diff
changeset
|
26 |
* @bug 6868539 6868548 8035364 |
3553
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
27 |
* @summary javap should use current names for constant pool entries, |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
28 |
* remove spurious ';' from constant pool entries |
30846 | 29 |
* @modules jdk.jdeps |
3553
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
30 |
*/ |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
31 |
|
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
32 |
import java.io.*; |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
33 |
import java.util.*; |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
34 |
|
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
35 |
public class T6868539 |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
36 |
|
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
37 |
{ |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
38 |
public static void main(String... args) { |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
39 |
new T6868539().run(); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
40 |
} |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
41 |
|
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
42 |
void run() { |
6601 | 43 |
String output = javap("T6868539"); |
44 |
verify(output, "Utf8 +java/lang/String"); // 1: Utf8 |
|
23120
6e12870d6652
8035364: An extra space in the comments of constant pool entries
jjg
parents:
7681
diff
changeset
|
45 |
// 2: currently unused |
6601 | 46 |
verify(output, "Integer +123456"); // 3: Integer |
47 |
verify(output, "Float +123456.0f"); // 4: Float |
|
48 |
verify(output, "Long +123456l"); // 5: Long |
|
49 |
verify(output, "Double +123456.0d"); // 6: Double |
|
23120
6e12870d6652
8035364: An extra space in the comments of constant pool entries
jjg
parents:
7681
diff
changeset
|
50 |
verify(output, "Class +#[0-9]+ +// +T6868539"); // 7: Class |
6e12870d6652
8035364: An extra space in the comments of constant pool entries
jjg
parents:
7681
diff
changeset
|
51 |
verify(output, "String +#[0-9]+ +// +not found"); // 8: String |
6601 | 52 |
verify(output, "Fieldref +#[0-9]+\\.#[0-9]+ +// +T6868539.errors:I"); // 9: Fieldref |
53 |
verify(output, "Methodref +#[0-9]+\\.#[0-9]+ +// +T6868539.run:\\(\\)V"); // 10: Methodref |
|
54 |
verify(output, "InterfaceMethodref +#[0-9]+\\.#[0-9]+ +// +java/lang/Runnable\\.run:\\(\\)V"); |
|
23120
6e12870d6652
8035364: An extra space in the comments of constant pool entries
jjg
parents:
7681
diff
changeset
|
55 |
// 11: InterfaceMethodref |
6601 | 56 |
verify(output, "NameAndType +#[0-9]+:#[0-9]+ +// +run:\\(\\)V"); // 12: NameAndType |
3553
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
57 |
if (errors > 0) |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
58 |
throw new Error(errors + " found."); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
59 |
} |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
60 |
|
6601 | 61 |
void verify(String output, String... expects) { |
3553
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
62 |
for (String expect: expects) { |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
63 |
if (!output.matches("(?s).*" + expect + ".*")) |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
64 |
error(expect + " not found"); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
65 |
} |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
66 |
} |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
67 |
|
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
68 |
void error(String msg) { |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
69 |
System.err.println(msg); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
70 |
errors++; |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
71 |
} |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
72 |
|
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
73 |
int errors; |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
74 |
|
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
75 |
String javap(String className) { |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
76 |
String testClasses = System.getProperty("test.classes", "."); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
77 |
StringWriter sw = new StringWriter(); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
78 |
PrintWriter out = new PrintWriter(sw); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
79 |
String[] args = { "-v", "-classpath", testClasses, className }; |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
80 |
int rc = com.sun.tools.javap.Main.run(args, out); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
81 |
if (rc != 0) |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
82 |
throw new Error("javap failed. rc=" + rc); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
83 |
out.close(); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
84 |
String output = sw.toString(); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
85 |
System.out.println("class " + className); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
86 |
System.out.println(output); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
87 |
return output; |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
88 |
} |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
89 |
|
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
90 |
int i = 123456; |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
91 |
float f = 123456.f; |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
92 |
double d = 123456.; |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
93 |
long l = 123456L; |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
94 |
|
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
95 |
void m(Runnable r) { r.run(); } |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
96 |
} |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
97 |