test/tools/javap/T6868539.java

Thu, 04 Apr 2013 19:05:42 -0700

author
katleman
date
Thu, 04 Apr 2013 19:05:42 -0700
changeset 1662
4a48f3173534
parent 798
4868a36f6fd8
child 2288
4267f38a1706
permissions
-rw-r--r--

Added tag jdk8-b84 for changeset cfb65ca92082

jjg@355 1 /*
ohair@798 2 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. 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 *
ohair@554 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 20 * or visit www.oracle.com if you need additional information or have any
ohair@554 21 * 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@683 42 String output = javap("T6868539");
jjg@683 43 verify(output, "Utf8 +java/lang/String"); // 1: Utf8
jjg@355 44 // 2: currently unused
jjg@683 45 verify(output, "Integer +123456"); // 3: Integer
jjg@683 46 verify(output, "Float +123456.0f"); // 4: Float
jjg@683 47 verify(output, "Long +123456l"); // 5: Long
jjg@683 48 verify(output, "Double +123456.0d"); // 6: Double
jjg@683 49 verify(output, "Class +#[0-9]+ +// + T6868539"); // 7: Class
jjg@683 50 verify(output, "String +#[0-9]+ +// + not found"); // 8: String
jjg@683 51 verify(output, "Fieldref +#[0-9]+\\.#[0-9]+ +// +T6868539.errors:I"); // 9: Fieldref
jjg@683 52 verify(output, "Methodref +#[0-9]+\\.#[0-9]+ +// +T6868539.run:\\(\\)V"); // 10: Methodref
jjg@683 53 verify(output, "InterfaceMethodref +#[0-9]+\\.#[0-9]+ +// +java/lang/Runnable\\.run:\\(\\)V");
jjg@355 54 // 11: InterfaceMethodref
jjg@683 55 verify(output, "NameAndType +#[0-9]+:#[0-9]+ +// +run:\\(\\)V"); // 12: NameAndType
jjg@355 56 if (errors > 0)
jjg@355 57 throw new Error(errors + " found.");
jjg@355 58 }
jjg@355 59
jjg@683 60 void verify(String output, String... expects) {
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