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