Path: blob/master/test/langtools/tools/javap/T6824493.java
41144 views
/*1* Copyright (c) 2009, 2016, 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*/2223import java.io.*;24import java.util.*;2526/*27* @test28* @bug 682449329* @summary experimental support for additional info for instructions30* @modules jdk.jdeps/com.sun.tools.javap31* @compile -g T6824493.java32* @run main T682449333*/34public class T6824493 {35public static void main(String... args) {36new T6824493().run();37}3839void run() {40// for each of the options, we run javap and check for some41// marker strings in the output that generally indicate the42// presence of the expected output, without being as specific43// as a full golden file test.44test("-XDdetails:source",45"for (int i = 0; i < 10; i++) {",46"System.out.println(s + i);");4748test("-XDdetails:tryBlocks",49"try[0]",50"end try[0]",51"catch[0]");5253test("-XDdetails:stackMaps",54"StackMap locals: this java/lang/String int",55"StackMap stack: java/lang/Throwable");5657test("-XDdetails:localVariables",58"start local 3 // java.util.List list",59"end local 3 // java.util.List list");6061test("-XDdetails:localVariableTypes",62"start generic local 3 // java.util.List<java.lang.String> list",63"end generic local 3 // java.util.List<java.lang.String> list");6465if (errors > 0)66throw new Error(errors + " errors found");67}6869void test(String option, String... expect) {70String[] args = {71"-c",72"-classpath",73testSrc + File.pathSeparator + testClasses,74option,75"Test"76};77StringWriter sw = new StringWriter();78PrintWriter pw = new PrintWriter(sw);79int rc = com.sun.tools.javap.Main.run(args, pw);80if (rc != 0) {81error("unexpected return code from javap: " + rc);82return;83}8485String out = sw.toString();86System.out.println(out);87for (String e: expect) {88if (!out.contains(e))89error("Not found: " + e);90}91}9293void error(String msg) {94System.err.println("Error: " + msg);95errors++;96}9798private int errors;99private String testSrc = System.getProperty("test.src", ".");100private String testClasses = System.getProperty("test.classes", ".");101}102103class Test {104void m(String s) {105for (int i = 0; i < 10; i++) {106try {107List<String> list = null;108System.out.println(s + i);109} catch (NullPointerException e) {110System.out.println("catch NPE");111} finally {112System.out.println("finally");113}114}115}116}117118119