test/tools/javap/T6868539.java

Sat, 08 Aug 2009 17:56:37 -0700

author
jjg
date
Sat, 08 Aug 2009 17:56:37 -0700
changeset 355
961dc3acdb06
child 554
9d9f26857129
permissions
-rw-r--r--

6868539: javap should use current names for constant pool tags
Reviewed-by: ksrini

jjg@355 1 /*
jjg@355 2 * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
jjg@355 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@355 4 *
jjg@355 5 * This code is free software; you can redistribute it and/or modify it
jjg@355 6 * under the terms of the GNU General Public License version 2 only, as
jjg@355 7 * published by the Free Software Foundation.
jjg@355 8 *
jjg@355 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@355 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@355 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@355 12 * version 2 for more details (a copy is included in the LICENSE file that
jjg@355 13 * accompanied this code).
jjg@355 14 *
jjg@355 15 * You should have received a copy of the GNU General Public License version
jjg@355 16 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@355 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@355 18 *
jjg@355 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
jjg@355 20 * CA 95054 USA or visit www.sun.com if you need additional information or
jjg@355 21 * have any questions.
jjg@355 22 */
jjg@355 23
jjg@355 24 /*
jjg@355 25 * @test
jjg@355 26 * @bug 6868539 6868548
jjg@355 27 * @summary javap should use current names for constant pool entries,
jjg@355 28 * remove spurious ';' from constant pool entries
jjg@355 29 */
jjg@355 30
jjg@355 31 import java.io.*;
jjg@355 32 import java.util.*;
jjg@355 33
jjg@355 34 public class T6868539
jjg@355 35
jjg@355 36 {
jjg@355 37 public static void main(String... args) {
jjg@355 38 new T6868539().run();
jjg@355 39 }
jjg@355 40
jjg@355 41 void run() {
jjg@355 42 verify("T6868539", "Utf8 +java/lang/String"); // 1: Utf8
jjg@355 43 // 2: currently unused
jjg@355 44 verify("T6868539", "Integer +123456"); // 3: Integer
jjg@355 45 verify("T6868539", "Float +123456.0f"); // 4: Float
jjg@355 46 verify("T6868539", "Long +123456l"); // 5: Long
jjg@355 47 verify("T6868539", "Double +123456.0d"); // 6: Double
jjg@355 48 verify("T6868539", "Class +#[0-9]+ +// + T6868539"); // 7: Class
jjg@355 49 verify("T6868539", "String +#[0-9]+ +// + not found"); // 8: String
jjg@355 50 verify("T6868539", "Fieldref +#[0-9]+\\.#[0-9]+ +// +T6868539.errors:I"); // 9: Fieldref
jjg@355 51 verify("T6868539", "Methodref +#[0-9]+\\.#[0-9]+ +// +T6868539.run:\\(\\)V"); // 10: Methodref
jjg@355 52 verify("T6868539", "InterfaceMethodref +#[0-9]+\\.#[0-9]+ +// +java/lang/Runnable\\.run:\\(\\)V");
jjg@355 53 // 11: InterfaceMethodref
jjg@355 54 verify("T6868539", "NameAndType +#[0-9]+:#[0-9]+ +// +run:\\(\\)V"); // 12: NameAndType
jjg@355 55 if (errors > 0)
jjg@355 56 throw new Error(errors + " found.");
jjg@355 57 }
jjg@355 58
jjg@355 59 void verify(String className, String... expects) {
jjg@355 60 String output = javap(className);
jjg@355 61 for (String expect: expects) {
jjg@355 62 if (!output.matches("(?s).*" + expect + ".*"))
jjg@355 63 error(expect + " not found");
jjg@355 64 }
jjg@355 65 }
jjg@355 66
jjg@355 67 void error(String msg) {
jjg@355 68 System.err.println(msg);
jjg@355 69 errors++;
jjg@355 70 }
jjg@355 71
jjg@355 72 int errors;
jjg@355 73
jjg@355 74 String javap(String className) {
jjg@355 75 String testClasses = System.getProperty("test.classes", ".");
jjg@355 76 StringWriter sw = new StringWriter();
jjg@355 77 PrintWriter out = new PrintWriter(sw);
jjg@355 78 String[] args = { "-v", "-classpath", testClasses, className };
jjg@355 79 int rc = com.sun.tools.javap.Main.run(args, out);
jjg@355 80 if (rc != 0)
jjg@355 81 throw new Error("javap failed. rc=" + rc);
jjg@355 82 out.close();
jjg@355 83 String output = sw.toString();
jjg@355 84 System.out.println("class " + className);
jjg@355 85 System.out.println(output);
jjg@355 86 return output;
jjg@355 87 }
jjg@355 88
jjg@355 89 int i = 123456;
jjg@355 90 float f = 123456.f;
jjg@355 91 double d = 123456.;
jjg@355 92 long l = 123456L;
jjg@355 93
jjg@355 94 void m(Runnable r) { r.run(); }
jjg@355 95 }
jjg@355 96

mercurial