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