Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javap/T6824493.java
32285 views
/*1* Copyright (c) 2009, 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* @compile -g T6824493.java31* @run main T682449332*/33public class T6824493 {34public static void main(String... args) {35new T6824493().run();36}3738void run() {39// for each of the options, we run javap and check for some40// marker strings in the output that generally indicate the41// presence of the expected output, without being as specific42// as a full golden file test.43test("-XDdetails:source",44"for (int i = 0; i < 10; i++) {",45"System.out.println(s + i);");4647test("-XDdetails:tryBlocks",48"try[0]",49"end try[0]",50"catch[0]");5152test("-XDdetails:stackMaps",53"StackMap locals: this java/lang/String int",54"StackMap stack: java/lang/Throwable");5556test("-XDdetails:localVariables",57"start local 3 // java.util.List list",58"end local 3 // java.util.List list");5960test("-XDdetails:localVariableTypes",61"start generic local 3 // java.util.List<java.lang.String> list",62"end generic local 3 // java.util.List<java.lang.String> list");6364if (errors > 0)65throw new Error(errors + " errors found");66}6768void test(String option, String... expect) {69String[] args = {70"-c",71"-classpath",72testSrc + File.pathSeparator + testClasses,73option,74"Test"75};76StringWriter sw = new StringWriter();77PrintWriter pw = new PrintWriter(sw);78int rc = com.sun.tools.javap.Main.run(args, pw);79if (rc != 0) {80error("unexpected return code from javap: " + rc);81return;82}8384String out = sw.toString();85System.out.println(out);86for (String e: expect) {87if (!out.contains(e))88error("Not found: " + e);89}90}9192void error(String msg) {93System.err.println("Error: " + msg);94errors++;95}9697private int errors;98private String testSrc = System.getProperty("test.src", ".");99private String testClasses = System.getProperty("test.classes", ".");100}101102class Test {103void m(String s) {104for (int i = 0; i < 10; i++) {105try {106List<String> list = null;107System.out.println(s + i);108} catch (NullPointerException e) {109System.out.println("catch NPE");110} finally {111System.out.println("finally");112}113}114}115}116117118