Mon, 17 Oct 2011 12:57:36 +0100
7093325: Redundant entry in bytecode exception table
Summary: Inlining of finalizers does not update gaps list accordingly
Reviewed-by: jjg
1 /*
2 * Copyright (c) 2008, 2011, 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 */
24 /*
25 * @test
26 * @bug 6508981
27 * @summary cleanup file separator handling in JavacFileManager
28 * (This test is specifically to test the new impl of inferBinaryName)
29 * @build p.A
30 * @run main TestInferBinaryName
31 */
33 import java.io.*;
34 import java.util.*;
35 import javax.tools.*;
37 import com.sun.tools.javac.file.JavacFileManager;
38 import com.sun.tools.javac.util.Context;
39 import com.sun.tools.javac.util.Options;
41 import static javax.tools.JavaFileObject.Kind.*;
42 import static javax.tools.StandardLocation.*;
45 /**
46 * Verify the various implementations of inferBinaryName, but configuring
47 * different instances of a file manager, getting a file object, and checking
48 * the impl of inferBinaryName for that file object.
49 */
50 public class TestInferBinaryName {
51 static final boolean IGNORE_SYMBOL_FILE = false;
52 static final boolean USE_SYMBOL_FILE = true;
53 static final boolean DONT_USE_ZIP_FILE_INDEX = false;
54 static final boolean USE_ZIP_FILE_INDEX = true;
56 public static void main(String... args) throws Exception {
57 new TestInferBinaryName().run();
58 }
60 void run() throws Exception {
61 //System.err.println(System.getProperties());
62 testDirectory();
63 testSymbolArchive();
64 testZipArchive();
65 testZipFileIndexArchive();
66 testZipFileIndexArchive2();
67 if (errors > 0)
68 throw new Exception(errors + " error found");
69 }
71 void testDirectory() throws IOException {
72 String testClassName = "p.A";
73 JavaFileManager fm =
74 getFileManager("test.classes", USE_SYMBOL_FILE, USE_ZIP_FILE_INDEX);
75 test("testDirectory",
76 fm, testClassName, "com.sun.tools.javac.file.RegularFileObject");
77 }
79 void testSymbolArchive() throws IOException {
80 String testClassName = "java.lang.String";
81 JavaFileManager fm =
82 getFileManager("sun.boot.class.path", USE_SYMBOL_FILE, DONT_USE_ZIP_FILE_INDEX);
83 test("testSymbolArchive",
84 fm, testClassName, "com.sun.tools.javac.file.SymbolArchive$SymbolFileObject");
85 }
87 void testZipArchive() throws IOException {
88 String testClassName = "java.lang.String";
89 JavaFileManager fm =
90 getFileManager("sun.boot.class.path", IGNORE_SYMBOL_FILE, DONT_USE_ZIP_FILE_INDEX);
91 test("testZipArchive",
92 fm, testClassName, "com.sun.tools.javac.file.ZipArchive$ZipFileObject");
93 }
95 void testZipFileIndexArchive() throws IOException {
96 String testClassName = "java.lang.String";
97 JavaFileManager fm =
98 getFileManager("sun.boot.class.path", USE_SYMBOL_FILE, USE_ZIP_FILE_INDEX);
99 test("testZipFileIndexArchive",
100 fm, testClassName, "com.sun.tools.javac.file.ZipFileIndexArchive$ZipFileIndexFileObject");
101 }
103 void testZipFileIndexArchive2() throws IOException {
104 String testClassName = "java.lang.String";
105 JavaFileManager fm =
106 getFileManager("sun.boot.class.path", IGNORE_SYMBOL_FILE, USE_ZIP_FILE_INDEX);
107 test("testZipFileIndexArchive2",
108 fm, testClassName, "com.sun.tools.javac.file.ZipFileIndexArchive$ZipFileIndexFileObject");
109 }
111 /**
112 * @param testName for debugging
113 * @param fm suitably configured file manager
114 * @param testClassName the classname to test
115 * @param implClassName the expected classname of the JavaFileObject impl,
116 * used for checking that we are checking the expected impl of
117 * inferBinaryName
118 */
119 void test(String testName,
120 JavaFileManager fm, String testClassName, String implClassName) throws IOException {
121 JavaFileObject fo = fm.getJavaFileForInput(CLASS_PATH, testClassName, CLASS);
122 if (fo == null) {
123 System.err.println("Can't find " + testClassName);
124 errors++;
125 return;
126 }
128 String cn = fo.getClass().getName();
129 String bn = fm.inferBinaryName(CLASS_PATH, fo);
130 System.err.println(testName + " " + cn + " " + bn);
131 check(cn, implClassName);
132 check(bn, testClassName);
133 System.err.println("OK");
134 }
136 JavaFileManager getFileManager(String classpathProperty,
137 boolean symFileKind,
138 boolean zipFileIndexKind)
139 throws IOException {
140 Context ctx = new Context();
141 Options options = Options.instance(ctx);
142 options.put("useOptimizedZip",
143 Boolean.toString(zipFileIndexKind == USE_ZIP_FILE_INDEX));
145 if (symFileKind == IGNORE_SYMBOL_FILE)
146 options.put("ignore.symbol.file", "true");
147 JavacFileManager fm = new JavacFileManager(ctx, false, null);
148 List<File> path = getPath(System.getProperty(classpathProperty));
149 fm.setLocation(CLASS_PATH, path);
150 return fm;
151 }
153 List<File> getPath(String s) {
154 List<File> path = new ArrayList<File>();
155 for (String f: s.split(File.pathSeparator)) {
156 if (f.length() > 0)
157 path.add(new File(f));
158 }
159 //System.err.println("path: " + path);
160 return path;
161 }
163 void check(String found, String expect) {
164 if (!found.equals(expect)) {
165 System.err.println("Expected: " + expect);
166 System.err.println(" Found: " + found);
167 errors++;
168 }
169 }
171 private int errors;
172 }
174 class A { }