Mercurial > hg > truffle
annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java @ 13200:ebdc13d9845d
replaced use of graal.compileTheWorldTest.log system property with a field to control CTW verbosity which is true by default but is set to false by CTW unit test
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Sat, 30 Nov 2013 11:07:41 +0100 |
parents | bae0869c829a |
children | 0e5c4f9fa9a5 |
rev | line source |
---|---|
9108 | 1 /* |
2 * Copyright (c) 2013, 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 package com.oracle.graal.hotspot; | |
24 | |
9289
261a43921c5e
rename: HotSpotGraalRuntime.getInstance() -> graalRuntime()
Doug Simon <doug.simon@oracle.com>
parents:
9108
diff
changeset
|
25 import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; |
9864
063a712fe8d8
converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
9289
diff
changeset
|
26 import static com.oracle.graal.phases.GraalOptions.*; |
9289
261a43921c5e
rename: HotSpotGraalRuntime.getInstance() -> graalRuntime()
Doug Simon <doug.simon@oracle.com>
parents:
9108
diff
changeset
|
27 |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
10672
diff
changeset
|
28 import java.io.*; |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
10672
diff
changeset
|
29 import java.lang.reflect.*; |
9108 | 30 import java.net.*; |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
10672
diff
changeset
|
31 import java.util.*; |
9108 | 32 import java.util.jar.*; |
33 | |
34 import com.oracle.graal.api.meta.*; | |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
10672
diff
changeset
|
35 import com.oracle.graal.bytecode.*; |
9108 | 36 import com.oracle.graal.debug.*; |
37 import com.oracle.graal.hotspot.bridge.*; | |
38 import com.oracle.graal.hotspot.meta.*; | |
39 import com.oracle.graal.nodes.*; | |
40 import com.oracle.graal.phases.*; | |
41 import com.oracle.graal.replacements.*; | |
42 | |
43 /** | |
44 * This class implements compile-the-world functionality in Graal. | |
45 */ | |
46 public final class CompileTheWorld { | |
47 | |
48 /** | |
49 * This is our magic token to trigger reading files from the boot class path. | |
50 */ | |
51 public static final String SUN_BOOT_CLASS_PATH = "sun.boot.class.path"; | |
52 | |
53 // Some runtime instances we need. | |
12431
7080a96be216
rename: graalRuntime -> runtime, getGraalRuntime -> getRuntime
Doug Simon <doug.simon@oracle.com>
parents:
12429
diff
changeset
|
54 private final HotSpotGraalRuntime runtime = runtime(); |
7080a96be216
rename: graalRuntime -> runtime, getGraalRuntime -> getRuntime
Doug Simon <doug.simon@oracle.com>
parents:
12429
diff
changeset
|
55 private final VMToCompilerImpl vmToCompiler = (VMToCompilerImpl) runtime.getVMToCompiler(); |
9108 | 56 |
57 /** List of Zip/Jar files to compile (see {@link GraalOptions#CompileTheWorld}. */ | |
58 private final String files; | |
59 | |
60 /** Class index to start compilation at (see {@link GraalOptions#CompileTheWorldStartAt}. */ | |
61 private final int startAt; | |
62 | |
63 /** Class index to stop compilation at (see {@link GraalOptions#CompileTheWorldStopAt}. */ | |
64 private final int stopAt; | |
65 | |
66 // Counters | |
67 private int classFileCounter = 0; | |
68 private int compiledMethodsCounter = 0; | |
69 private long compileTime = 0; | |
70 | |
13200
ebdc13d9845d
replaced use of graal.compileTheWorldTest.log system property with a field to control CTW verbosity which is true by default but is set to false by CTW unit test
Doug Simon <doug.simon@oracle.com>
parents:
13199
diff
changeset
|
71 private boolean verbose; |
ebdc13d9845d
replaced use of graal.compileTheWorldTest.log system property with a field to control CTW verbosity which is true by default but is set to false by CTW unit test
Doug Simon <doug.simon@oracle.com>
parents:
13199
diff
changeset
|
72 |
9108 | 73 /** |
74 * Create a compile-the-world instance with default values from | |
75 * {@link GraalOptions#CompileTheWorld}, {@link GraalOptions#CompileTheWorldStartAt} and | |
76 * {@link GraalOptions#CompileTheWorldStopAt}. | |
77 */ | |
78 public CompileTheWorld() { | |
13200
ebdc13d9845d
replaced use of graal.compileTheWorldTest.log system property with a field to control CTW verbosity which is true by default but is set to false by CTW unit test
Doug Simon <doug.simon@oracle.com>
parents:
13199
diff
changeset
|
79 this(CompileTheWorld.getValue(), CompileTheWorldStartAt.getValue(), CompileTheWorldStopAt.getValue(), true); |
9108 | 80 } |
81 | |
82 /** | |
83 * Create a compile-the-world instance. | |
84 * | |
85 * @param files {@link File#pathSeparator} separated list of Zip/Jar files to compile | |
86 * @param startAt index of the class file to start compilation at | |
87 * @param stopAt index of the class file to stop compilation at | |
88 */ | |
13200
ebdc13d9845d
replaced use of graal.compileTheWorldTest.log system property with a field to control CTW verbosity which is true by default but is set to false by CTW unit test
Doug Simon <doug.simon@oracle.com>
parents:
13199
diff
changeset
|
89 public CompileTheWorld(String files, int startAt, int stopAt, boolean verbose) { |
9108 | 90 this.files = files; |
91 this.startAt = startAt; | |
92 this.stopAt = stopAt; | |
13200
ebdc13d9845d
replaced use of graal.compileTheWorldTest.log system property with a field to control CTW verbosity which is true by default but is set to false by CTW unit test
Doug Simon <doug.simon@oracle.com>
parents:
13199
diff
changeset
|
93 this.verbose = verbose; |
9108 | 94 |
13113 | 95 // We don't want the VM to exit when a method fails to compile... |
9864
063a712fe8d8
converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
9289
diff
changeset
|
96 ExitVMOnException.setValue(false); |
13113 | 97 |
98 // ...but we want to see exceptions. | |
99 PrintBailout.setValue(true); | |
100 PrintStackTraceOnException.setValue(true); | |
9108 | 101 } |
102 | |
103 /** | |
104 * Compile all methods in all classes in the Zip/Jar files in | |
105 * {@link GraalOptions#CompileTheWorld}. If the GraalOptions.CompileTheWorld contains the magic | |
106 * token {@link CompileTheWorld#SUN_BOOT_CLASS_PATH} passed up from HotSpot we take the files | |
107 * from the boot class path. | |
108 * | |
109 * @throws Throwable | |
110 */ | |
111 public void compile() throws Throwable { | |
112 if (SUN_BOOT_CLASS_PATH.equals(files)) { | |
113 final String[] entries = System.getProperty(SUN_BOOT_CLASS_PATH).split(File.pathSeparator); | |
114 String bcpFiles = ""; | |
115 for (int i = 0; i < entries.length; i++) { | |
116 final String entry = entries[i]; | |
117 | |
118 // We stop at rt.jar, unless it is the first boot class path entry. | |
119 if (entry.endsWith("rt.jar") && (i > 0)) { | |
120 break; | |
121 } | |
122 if (i > 0) { | |
123 bcpFiles += File.pathSeparator; | |
124 } | |
125 bcpFiles += entry; | |
126 } | |
127 compile(bcpFiles); | |
128 } else { | |
129 compile(files); | |
130 } | |
131 } | |
132 | |
13200
ebdc13d9845d
replaced use of graal.compileTheWorldTest.log system property with a field to control CTW verbosity which is true by default but is set to false by CTW unit test
Doug Simon <doug.simon@oracle.com>
parents:
13199
diff
changeset
|
133 public void println() { |
13199
bae0869c829a
put CompileTheWorldTest logging behind the graal.compileTheWorldTest.log system property
Doug Simon <doug.simon@oracle.com>
parents:
13113
diff
changeset
|
134 println(""); |
bae0869c829a
put CompileTheWorldTest logging behind the graal.compileTheWorldTest.log system property
Doug Simon <doug.simon@oracle.com>
parents:
13113
diff
changeset
|
135 } |
bae0869c829a
put CompileTheWorldTest logging behind the graal.compileTheWorldTest.log system property
Doug Simon <doug.simon@oracle.com>
parents:
13113
diff
changeset
|
136 |
13200
ebdc13d9845d
replaced use of graal.compileTheWorldTest.log system property with a field to control CTW verbosity which is true by default but is set to false by CTW unit test
Doug Simon <doug.simon@oracle.com>
parents:
13199
diff
changeset
|
137 public void println(String format, Object... args) { |
13199
bae0869c829a
put CompileTheWorldTest logging behind the graal.compileTheWorldTest.log system property
Doug Simon <doug.simon@oracle.com>
parents:
13113
diff
changeset
|
138 println(String.format(format, args)); |
bae0869c829a
put CompileTheWorldTest logging behind the graal.compileTheWorldTest.log system property
Doug Simon <doug.simon@oracle.com>
parents:
13113
diff
changeset
|
139 } |
bae0869c829a
put CompileTheWorldTest logging behind the graal.compileTheWorldTest.log system property
Doug Simon <doug.simon@oracle.com>
parents:
13113
diff
changeset
|
140 |
13200
ebdc13d9845d
replaced use of graal.compileTheWorldTest.log system property with a field to control CTW verbosity which is true by default but is set to false by CTW unit test
Doug Simon <doug.simon@oracle.com>
parents:
13199
diff
changeset
|
141 public void println(String s) { |
ebdc13d9845d
replaced use of graal.compileTheWorldTest.log system property with a field to control CTW verbosity which is true by default but is set to false by CTW unit test
Doug Simon <doug.simon@oracle.com>
parents:
13199
diff
changeset
|
142 if (verbose) { |
13199
bae0869c829a
put CompileTheWorldTest logging behind the graal.compileTheWorldTest.log system property
Doug Simon <doug.simon@oracle.com>
parents:
13113
diff
changeset
|
143 TTY.println(s); |
bae0869c829a
put CompileTheWorldTest logging behind the graal.compileTheWorldTest.log system property
Doug Simon <doug.simon@oracle.com>
parents:
13113
diff
changeset
|
144 } |
bae0869c829a
put CompileTheWorldTest logging behind the graal.compileTheWorldTest.log system property
Doug Simon <doug.simon@oracle.com>
parents:
13113
diff
changeset
|
145 } |
bae0869c829a
put CompileTheWorldTest logging behind the graal.compileTheWorldTest.log system property
Doug Simon <doug.simon@oracle.com>
parents:
13113
diff
changeset
|
146 |
9108 | 147 /** |
148 * Compile all methods in all classes in the Zip/Jar files passed. | |
149 * | |
150 * @param fileList {@link File#pathSeparator} separated list of Zip/Jar files to compile | |
151 * @throws Throwable | |
152 */ | |
153 private void compile(String fileList) throws Throwable { | |
154 final String[] entries = fileList.split(File.pathSeparator); | |
155 | |
156 for (int i = 0; i < entries.length; i++) { | |
157 final String entry = entries[i]; | |
158 | |
159 // For now we only compile all methods in all classes in zip/jar files. | |
160 if (!entry.endsWith(".zip") && !entry.endsWith(".jar")) { | |
13199
bae0869c829a
put CompileTheWorldTest logging behind the graal.compileTheWorldTest.log system property
Doug Simon <doug.simon@oracle.com>
parents:
13113
diff
changeset
|
161 println("CompileTheWorld : Skipped classes in " + entry); |
bae0869c829a
put CompileTheWorldTest logging behind the graal.compileTheWorldTest.log system property
Doug Simon <doug.simon@oracle.com>
parents:
13113
diff
changeset
|
162 println(); |
9108 | 163 continue; |
164 } | |
165 | |
13199
bae0869c829a
put CompileTheWorldTest logging behind the graal.compileTheWorldTest.log system property
Doug Simon <doug.simon@oracle.com>
parents:
13113
diff
changeset
|
166 println("CompileTheWorld : Compiling all classes in " + entry); |
bae0869c829a
put CompileTheWorldTest logging behind the graal.compileTheWorldTest.log system property
Doug Simon <doug.simon@oracle.com>
parents:
13113
diff
changeset
|
167 println(); |
9108 | 168 |
169 URL url = new URL("jar", "", "file:" + entry + "!/"); | |
170 ClassLoader loader = new URLClassLoader(new URL[]{url}); | |
171 | |
172 JarFile jarFile = new JarFile(entry); | |
173 Enumeration<JarEntry> e = jarFile.entries(); | |
174 | |
175 while (e.hasMoreElements()) { | |
176 JarEntry je = e.nextElement(); | |
177 if (je.isDirectory() || !je.getName().endsWith(".class")) { | |
178 continue; | |
179 } | |
180 | |
181 // Are we done? | |
182 if (classFileCounter >= stopAt) { | |
183 break; | |
184 } | |
185 | |
186 String className = je.getName().substring(0, je.getName().length() - ".class".length()); | |
187 classFileCounter++; | |
188 | |
189 try { | |
190 // Load and initialize class | |
10543
97caf20971ed
CTW: adapt output messages, so that they match with the output of hotspot
Bernhard Urban <bernhard.urban@jku.at>
parents:
10461
diff
changeset
|
191 Class<?> javaClass = Class.forName(className.replace('/', '.'), true, loader); |
9108 | 192 |
193 // Pre-load all classes in the constant pool. | |
194 try { | |
195 HotSpotResolvedObjectType objectType = (HotSpotResolvedObjectType) HotSpotResolvedObjectType.fromClass(javaClass); | |
196 ConstantPool constantPool = objectType.constantPool(); | |
197 for (int cpi = 1; cpi < constantPool.length(); cpi++) { | |
198 constantPool.loadReferencedType(cpi, Bytecodes.LDC); | |
199 } | |
200 } catch (Throwable t) { | |
201 // If something went wrong during pre-loading we just ignore it. | |
13199
bae0869c829a
put CompileTheWorldTest logging behind the graal.compileTheWorldTest.log system property
Doug Simon <doug.simon@oracle.com>
parents:
13113
diff
changeset
|
202 println("Preloading failed for (%d) %s", classFileCounter, className); |
9108 | 203 } |
204 | |
205 // Are we compiling this class? | |
12456
f87c68d79f07
improved support for co-existing, multiple backends (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents:
12431
diff
changeset
|
206 HotSpotMetaAccessProvider metaAccess = runtime.getHostProviders().getMetaAccess(); |
9108 | 207 if (classFileCounter >= startAt) { |
13199
bae0869c829a
put CompileTheWorldTest logging behind the graal.compileTheWorldTest.log system property
Doug Simon <doug.simon@oracle.com>
parents:
13113
diff
changeset
|
208 println("CompileTheWorld (%d) : %s", classFileCounter, className); |
9108 | 209 |
210 // Enqueue each constructor/method in the class for compilation. | |
211 for (Constructor<?> constructor : javaClass.getDeclaredConstructors()) { | |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
10672
diff
changeset
|
212 HotSpotResolvedJavaMethod javaMethod = (HotSpotResolvedJavaMethod) metaAccess.lookupJavaConstructor(constructor); |
9108 | 213 if (canBeCompiled(javaMethod, constructor.getModifiers())) { |
214 compileMethod(javaMethod); | |
215 } | |
216 } | |
217 for (Method method : javaClass.getDeclaredMethods()) { | |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
10672
diff
changeset
|
218 HotSpotResolvedJavaMethod javaMethod = (HotSpotResolvedJavaMethod) metaAccess.lookupJavaMethod(method); |
9108 | 219 if (canBeCompiled(javaMethod, method.getModifiers())) { |
220 compileMethod(javaMethod); | |
221 } | |
222 } | |
223 } | |
224 } catch (Throwable t) { | |
13199
bae0869c829a
put CompileTheWorldTest logging behind the graal.compileTheWorldTest.log system property
Doug Simon <doug.simon@oracle.com>
parents:
13113
diff
changeset
|
225 println("CompileTheWorld (%d) : Skipping %s", classFileCounter, className); |
9108 | 226 } |
227 } | |
228 jarFile.close(); | |
229 } | |
230 | |
13199
bae0869c829a
put CompileTheWorldTest logging behind the graal.compileTheWorldTest.log system property
Doug Simon <doug.simon@oracle.com>
parents:
13113
diff
changeset
|
231 println(); |
bae0869c829a
put CompileTheWorldTest logging behind the graal.compileTheWorldTest.log system property
Doug Simon <doug.simon@oracle.com>
parents:
13113
diff
changeset
|
232 println("CompileTheWorld : Done (%d classes, %d methods, %d ms)", classFileCounter, compiledMethodsCounter, compileTime); |
9108 | 233 } |
234 | |
235 /** | |
236 * Helper method to schedule a method for compilation and gather some statistics. | |
237 */ | |
238 private void compileMethod(HotSpotResolvedJavaMethod method) { | |
239 try { | |
240 long start = System.currentTimeMillis(); | |
10672
e7d07c9bb779
Removed priority compilation queue.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
10543
diff
changeset
|
241 vmToCompiler.compileMethod(method, StructuredGraph.INVOCATION_ENTRY_BCI, true); |
9108 | 242 compileTime += (System.currentTimeMillis() - start); |
243 compiledMethodsCounter++; | |
244 method.reprofile(); // makes the method also not-entrant | |
245 } catch (Throwable t) { | |
246 // Catch everything and print a message | |
13199
bae0869c829a
put CompileTheWorldTest logging behind the graal.compileTheWorldTest.log system property
Doug Simon <doug.simon@oracle.com>
parents:
13113
diff
changeset
|
247 println("CompileTheWorld (%d) : Error compiling method: %s", classFileCounter, MetaUtil.format("%H.%n(%p):%r", method)); |
9108 | 248 t.printStackTrace(TTY.cachedOut); |
249 } | |
250 } | |
251 | |
252 /** | |
253 * Helper method for CompileTheWorld to determine if a method should be compiled (Cf. | |
254 * CompilationPolicy::can_be_compiled). | |
255 * | |
256 * @return true if it can be compiled, false otherwise | |
257 */ | |
258 private static boolean canBeCompiled(HotSpotResolvedJavaMethod javaMethod, int modifiers) { | |
259 if (Modifier.isAbstract(modifiers) || Modifier.isNative(modifiers)) { | |
260 return false; | |
261 } | |
262 // This number is from HotSpot: | |
263 final int hugeMethodLimit = 8000; | |
264 if (javaMethod.getCodeSize() > hugeMethodLimit) { | |
265 return false; | |
266 } | |
267 // Skip @Snippets for now | |
268 if (javaMethod.getAnnotation(Snippet.class) != null) { | |
269 return false; | |
270 } | |
271 return true; | |
272 } | |
273 | |
274 } |