T6824493.java revision 3294:9adfb22ff08f
1/* 2 * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24import java.io.*; 25import java.util.*; 26 27/* 28 * @test 29 * @bug 6824493 30 * @summary experimental support for additional info for instructions 31 * @modules jdk.jdeps/com.sun.tools.javap 32 * @compile -g T6824493.java 33 * @run main T6824493 34 */ 35public class T6824493 { 36 public static void main(String... args) { 37 new T6824493().run(); 38 } 39 40 void run() { 41 // for each of the options, we run javap and check for some 42 // marker strings in the output that generally indicate the 43 // presence of the expected output, without being as specific 44 // as a full golden file test. 45 test("-XDdetails:source", 46 "for (int i = 0; i < 10; i++) {", 47 "System.out.println(s + i);"); 48 49 test("-XDdetails:tryBlocks", 50 "try[0]", 51 "end try[0]", 52 "catch[0]"); 53 54 test("-XDdetails:stackMaps", 55 "StackMap locals: this java/lang/String int", 56 "StackMap stack: java/lang/Throwable"); 57 58 test("-XDdetails:localVariables", 59 "start local 3 // java.util.List list", 60 "end local 3 // java.util.List list"); 61 62 test("-XDdetails:localVariableTypes", 63 "start generic local 3 // java.util.List<java.lang.String> list", 64 "end generic local 3 // java.util.List<java.lang.String> list"); 65 66 if (errors > 0) 67 throw new Error(errors + " errors found"); 68 } 69 70 void test(String option, String... expect) { 71 String[] args = { 72 "-c", 73 "-classpath", 74 testSrc + File.pathSeparator + testClasses, 75 option, 76 "Test" 77 }; 78 StringWriter sw = new StringWriter(); 79 PrintWriter pw = new PrintWriter(sw); 80 int rc = com.sun.tools.javap.Main.run(args, pw); 81 if (rc != 0) { 82 error("unexpected return code from javap: " + rc); 83 return; 84 } 85 86 String out = sw.toString(); 87 System.out.println(out); 88 for (String e: expect) { 89 if (!out.contains(e)) 90 error("Not found: " + e); 91 } 92 } 93 94 void error(String msg) { 95 System.err.println("Error: " + msg); 96 errors++; 97 } 98 99 private int errors; 100 private String testSrc = System.getProperty("test.src", "."); 101 private String testClasses = System.getProperty("test.classes", "."); 102} 103 104class Test { 105 void m(String s) { 106 for (int i = 0; i < 10; i++) { 107 try { 108 List<String> list = null; 109 System.out.println(s + i); 110 } catch (NullPointerException e) { 111 System.out.println("catch NPE"); 112 } finally { 113 System.out.println("finally"); 114 } 115 } 116 } 117} 118