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