1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javap/T6824493.java Tue May 19 11:50:54 2009 -0700 1.3 @@ -0,0 +1,116 @@ 1.4 +/* 1.5 + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + */ 1.26 + 1.27 +import java.io.*; 1.28 +import java.util.*; 1.29 + 1.30 +/* 1.31 + * @test 1.32 + * @bug 6824493 1.33 + * @summary experimental support for additional info for instructions 1.34 + * @compile -g T6824493.java 1.35 + * @run main T6824493 1.36 + */ 1.37 +public class T6824493 { 1.38 + public static void main(String... args) { 1.39 + new T6824493().run(); 1.40 + } 1.41 + 1.42 + void run() { 1.43 + // for each of the options, we run javap and check for some 1.44 + // marker strings in the output that generally indicate the 1.45 + // presence of the expected output, without being as specific 1.46 + // as a full golden file test. 1.47 + test("-XDdetails:source", 1.48 + "for (int i = 0; i < 10; i++) {", 1.49 + "System.out.println(s + i);"); 1.50 + 1.51 + test("-XDdetails:tryBlocks", 1.52 + "try[0]", 1.53 + "end try[0]", 1.54 + "catch[0]"); 1.55 + 1.56 + test("-XDdetails:stackMaps", 1.57 + "StackMap locals: this java/lang/String int", 1.58 + "StackMap stack: java/lang/Throwable"); 1.59 + 1.60 + test("-XDdetails:localVariables", 1.61 + "start local 3 // java.util.List list", 1.62 + "end local 3 // java.util.List list"); 1.63 + 1.64 + test("-XDdetails:localVariableTypes", 1.65 + "start generic local 3 // java.util.List<java.lang.String> list", 1.66 + "end generic local 3 // java.util.List<java.lang.String> list"); 1.67 + 1.68 + if (errors > 0) 1.69 + throw new Error(errors + " errors found"); 1.70 + } 1.71 + 1.72 + void test(String option, String... expect) { 1.73 + String[] args = { 1.74 + "-c", 1.75 + "-classpath", 1.76 + testSrc + File.pathSeparator + testClasses, 1.77 + option, 1.78 + "Test" 1.79 + }; 1.80 + StringWriter sw = new StringWriter(); 1.81 + PrintWriter pw = new PrintWriter(sw); 1.82 + int rc = com.sun.tools.javap.Main.run(args, pw); 1.83 + if (rc != 0) { 1.84 + error("unexpected return code from javap: " + rc); 1.85 + return; 1.86 + } 1.87 + 1.88 + String out = sw.toString(); 1.89 + System.out.println(out); 1.90 + for (String e: expect) { 1.91 + if (!out.contains(e)) 1.92 + error("Not found: " + e); 1.93 + } 1.94 + } 1.95 + 1.96 + void error(String msg) { 1.97 + System.err.println("Error: " + msg); 1.98 + errors++; 1.99 + } 1.100 + 1.101 + private int errors; 1.102 + private String testSrc = System.getProperty("test.src", "."); 1.103 + private String testClasses = System.getProperty("test.classes", "."); 1.104 +} 1.105 + 1.106 +class Test { 1.107 + void m(String s) { 1.108 + for (int i = 0; i < 10; i++) { 1.109 + try { 1.110 + List<String> list = null; 1.111 + System.out.println(s + i); 1.112 + } catch (NullPointerException e) { 1.113 + System.out.println("catch NPE"); 1.114 + } finally { 1.115 + System.out.println("finally"); 1.116 + } 1.117 + } 1.118 + } 1.119 +}