jjg@283: /* ohair@554: * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. jjg@283: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@283: * jjg@283: * This code is free software; you can redistribute it and/or modify it jjg@283: * under the terms of the GNU General Public License version 2 only, as jjg@283: * published by the Free Software Foundation. jjg@283: * jjg@283: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@283: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@283: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@283: * version 2 for more details (a copy is included in the LICENSE file that jjg@283: * accompanied this code). jjg@283: * jjg@283: * You should have received a copy of the GNU General Public License version jjg@283: * 2 along with this work; if not, write to the Free Software Foundation, jjg@283: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@283: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. jjg@283: */ jjg@283: jjg@283: import java.io.*; jjg@283: import java.util.*; jjg@283: jjg@283: /* jjg@283: * @test jjg@283: * @bug 6824493 jjg@283: * @summary experimental support for additional info for instructions jjg@283: * @compile -g T6824493.java jjg@283: * @run main T6824493 jjg@283: */ jjg@283: public class T6824493 { jjg@283: public static void main(String... args) { jjg@283: new T6824493().run(); jjg@283: } jjg@283: jjg@283: void run() { jjg@283: // for each of the options, we run javap and check for some jjg@283: // marker strings in the output that generally indicate the jjg@283: // presence of the expected output, without being as specific jjg@283: // as a full golden file test. jjg@283: test("-XDdetails:source", jjg@283: "for (int i = 0; i < 10; i++) {", jjg@283: "System.out.println(s + i);"); jjg@283: jjg@283: test("-XDdetails:tryBlocks", jjg@283: "try[0]", jjg@283: "end try[0]", jjg@283: "catch[0]"); jjg@283: jjg@283: test("-XDdetails:stackMaps", jjg@283: "StackMap locals: this java/lang/String int", jjg@283: "StackMap stack: java/lang/Throwable"); jjg@283: jjg@283: test("-XDdetails:localVariables", jjg@283: "start local 3 // java.util.List list", jjg@283: "end local 3 // java.util.List list"); jjg@283: jjg@283: test("-XDdetails:localVariableTypes", jjg@283: "start generic local 3 // java.util.List list", jjg@283: "end generic local 3 // java.util.List list"); jjg@283: jjg@283: if (errors > 0) jjg@283: throw new Error(errors + " errors found"); jjg@283: } jjg@283: jjg@283: void test(String option, String... expect) { jjg@283: String[] args = { jjg@283: "-c", jjg@283: "-classpath", jjg@283: testSrc + File.pathSeparator + testClasses, jjg@283: option, jjg@283: "Test" jjg@283: }; jjg@283: StringWriter sw = new StringWriter(); jjg@283: PrintWriter pw = new PrintWriter(sw); jjg@283: int rc = com.sun.tools.javap.Main.run(args, pw); jjg@283: if (rc != 0) { jjg@283: error("unexpected return code from javap: " + rc); jjg@283: return; jjg@283: } jjg@283: jjg@283: String out = sw.toString(); jjg@283: System.out.println(out); jjg@283: for (String e: expect) { jjg@283: if (!out.contains(e)) jjg@283: error("Not found: " + e); jjg@283: } jjg@283: } jjg@283: jjg@283: void error(String msg) { jjg@283: System.err.println("Error: " + msg); jjg@283: errors++; jjg@283: } jjg@283: jjg@283: private int errors; jjg@283: private String testSrc = System.getProperty("test.src", "."); jjg@283: private String testClasses = System.getProperty("test.classes", "."); jjg@283: } jjg@283: jjg@283: class Test { jjg@283: void m(String s) { jjg@283: for (int i = 0; i < 10; i++) { jjg@283: try { jjg@283: List list = null; jjg@283: System.out.println(s + i); jjg@283: } catch (NullPointerException e) { jjg@283: System.out.println("catch NPE"); jjg@283: } finally { jjg@283: System.out.println("finally"); jjg@283: } jjg@283: } jjg@283: } jjg@283: }