author | jjg |
Sat, 08 Aug 2009 17:56:37 -0700 | |
changeset 3553 | 5daeeb71ee78 |
child 5520 | 86e4b9a9da40 |
permissions | -rw-r--r-- |
3553
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
1 |
/* |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
2 |
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. |
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 |
* |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
21 |
* have any questions. |
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 |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
26 |
* @bug 6868539 6868548 |
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 |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
29 |
*/ |
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 |
import java.io.*; |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
32 |
import java.util.*; |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
33 |
|
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
34 |
public class T6868539 |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
35 |
|
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 |
public static void main(String... args) { |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
38 |
new T6868539().run(); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
39 |
} |
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 |
void run() { |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
42 |
verify("T6868539", "Utf8 +java/lang/String"); // 1: Utf8 |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
43 |
// 2: currently unused |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
44 |
verify("T6868539", "Integer +123456"); // 3: Integer |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
45 |
verify("T6868539", "Float +123456.0f"); // 4: Float |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
46 |
verify("T6868539", "Long +123456l"); // 5: Long |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
47 |
verify("T6868539", "Double +123456.0d"); // 6: Double |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
48 |
verify("T6868539", "Class +#[0-9]+ +// + T6868539"); // 7: Class |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
49 |
verify("T6868539", "String +#[0-9]+ +// + not found"); // 8: String |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
50 |
verify("T6868539", "Fieldref +#[0-9]+\\.#[0-9]+ +// +T6868539.errors:I"); // 9: Fieldref |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
51 |
verify("T6868539", "Methodref +#[0-9]+\\.#[0-9]+ +// +T6868539.run:\\(\\)V"); // 10: Methodref |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
52 |
verify("T6868539", "InterfaceMethodref +#[0-9]+\\.#[0-9]+ +// +java/lang/Runnable\\.run:\\(\\)V"); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
53 |
// 11: InterfaceMethodref |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
54 |
verify("T6868539", "NameAndType +#[0-9]+:#[0-9]+ +// +run:\\(\\)V"); // 12: NameAndType |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
55 |
if (errors > 0) |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
56 |
throw new Error(errors + " found."); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
57 |
} |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
58 |
|
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
59 |
void verify(String className, String... expects) { |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
60 |
String output = javap(className); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
61 |
for (String expect: expects) { |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
62 |
if (!output.matches("(?s).*" + expect + ".*")) |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
63 |
error(expect + " not found"); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
64 |
} |
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 |
void error(String msg) { |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
68 |
System.err.println(msg); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
69 |
errors++; |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
70 |
} |
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 |
int errors; |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
73 |
|
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
74 |
String javap(String className) { |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
75 |
String testClasses = System.getProperty("test.classes", "."); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
76 |
StringWriter sw = new StringWriter(); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
77 |
PrintWriter out = new PrintWriter(sw); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
78 |
String[] args = { "-v", "-classpath", testClasses, className }; |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
79 |
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
|
80 |
if (rc != 0) |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
81 |
throw new Error("javap failed. rc=" + rc); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
82 |
out.close(); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
83 |
String output = sw.toString(); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
84 |
System.out.println("class " + className); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
85 |
System.out.println(output); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
86 |
return output; |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
87 |
} |
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 |
int i = 123456; |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
90 |
float f = 123456.f; |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
91 |
double d = 123456.; |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
92 |
long l = 123456L; |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
93 |
|
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
94 |
void m(Runnable r) { r.run(); } |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
95 |
} |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
diff
changeset
|
96 |