Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javap/T6868539.java
32285 views
/*1* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 6868539 6868548 803536426* @summary javap should use current names for constant pool entries,27* remove spurious ';' from constant pool entries28*/2930import java.io.*;31import java.util.*;3233public class T68685393435{36public static void main(String... args) {37new T6868539().run();38}3940void run() {41String output = javap("T6868539");42verify(output, "Utf8 +java/lang/String"); // 1: Utf843// 2: currently unused44verify(output, "Integer +123456"); // 3: Integer45verify(output, "Float +123456.0f"); // 4: Float46verify(output, "Long +123456l"); // 5: Long47verify(output, "Double +123456.0d"); // 6: Double48verify(output, "Class +#[0-9]+ +// +T6868539"); // 7: Class49verify(output, "String +#[0-9]+ +// +not found"); // 8: String50verify(output, "Fieldref +#[0-9]+\\.#[0-9]+ +// +T6868539.errors:I"); // 9: Fieldref51verify(output, "Methodref +#[0-9]+\\.#[0-9]+ +// +T6868539.run:\\(\\)V"); // 10: Methodref52verify(output, "InterfaceMethodref +#[0-9]+\\.#[0-9]+ +// +java/lang/Runnable\\.run:\\(\\)V");53// 11: InterfaceMethodref54verify(output, "NameAndType +#[0-9]+:#[0-9]+ +// +run:\\(\\)V"); // 12: NameAndType55if (errors > 0)56throw new Error(errors + " found.");57}5859void verify(String output, String... expects) {60for (String expect: expects) {61if (!output.matches("(?s).*" + expect + ".*"))62error(expect + " not found");63}64}6566void error(String msg) {67System.err.println(msg);68errors++;69}7071int errors;7273String javap(String className) {74String testClasses = System.getProperty("test.classes", ".");75StringWriter sw = new StringWriter();76PrintWriter out = new PrintWriter(sw);77String[] args = { "-v", "-classpath", testClasses, className };78int rc = com.sun.tools.javap.Main.run(args, out);79if (rc != 0)80throw new Error("javap failed. rc=" + rc);81out.close();82String output = sw.toString();83System.out.println("class " + className);84System.out.println(output);85return output;86}8788int i = 123456;89float f = 123456.f;90double d = 123456.;91long l = 123456L;9293void m(Runnable r) { r.run(); }94}95969798