Mercurial > hg > truffle
annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java @ 13113:e2933e3d4fb0
print stack traces when doing CompileTheWorld
author | twisti |
---|---|
date | Thu, 21 Nov 2013 16:52:14 -0800 |
parents | f87c68d79f07 |
children | bae0869c829a |
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 | |
71 /** | |
72 * Create a compile-the-world instance with default values from | |
73 * {@link GraalOptions#CompileTheWorld}, {@link GraalOptions#CompileTheWorldStartAt} and | |
74 * {@link GraalOptions#CompileTheWorldStopAt}. | |
75 */ | |
76 public CompileTheWorld() { | |
9864
063a712fe8d8
converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
9289
diff
changeset
|
77 this(CompileTheWorld.getValue(), CompileTheWorldStartAt.getValue(), CompileTheWorldStopAt.getValue()); |
9108 | 78 } |
79 | |
80 /** | |
81 * Create a compile-the-world instance. | |
82 * | |
83 * @param files {@link File#pathSeparator} separated list of Zip/Jar files to compile | |
84 * @param startAt index of the class file to start compilation at | |
85 * @param stopAt index of the class file to stop compilation at | |
86 */ | |
87 public CompileTheWorld(String files, int startAt, int stopAt) { | |
88 this.files = files; | |
89 this.startAt = startAt; | |
90 this.stopAt = stopAt; | |
91 | |
13113 | 92 // 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
|
93 ExitVMOnException.setValue(false); |
13113 | 94 |
95 // ...but we want to see exceptions. | |
96 PrintBailout.setValue(true); | |
97 PrintStackTraceOnException.setValue(true); | |
9108 | 98 } |
99 | |
100 /** | |
101 * Compile all methods in all classes in the Zip/Jar files in | |
102 * {@link GraalOptions#CompileTheWorld}. If the GraalOptions.CompileTheWorld contains the magic | |
103 * token {@link CompileTheWorld#SUN_BOOT_CLASS_PATH} passed up from HotSpot we take the files | |
104 * from the boot class path. | |
105 * | |
106 * @throws Throwable | |
107 */ | |
108 public void compile() throws Throwable { | |
109 if (SUN_BOOT_CLASS_PATH.equals(files)) { | |
110 final String[] entries = System.getProperty(SUN_BOOT_CLASS_PATH).split(File.pathSeparator); | |
111 String bcpFiles = ""; | |
112 for (int i = 0; i < entries.length; i++) { | |
113 final String entry = entries[i]; | |
114 | |
115 // We stop at rt.jar, unless it is the first boot class path entry. | |
116 if (entry.endsWith("rt.jar") && (i > 0)) { | |
117 break; | |
118 } | |
119 if (i > 0) { | |
120 bcpFiles += File.pathSeparator; | |
121 } | |
122 bcpFiles += entry; | |
123 } | |
124 compile(bcpFiles); | |
125 } else { | |
126 compile(files); | |
127 } | |
128 } | |
129 | |
130 /** | |
131 * Compile all methods in all classes in the Zip/Jar files passed. | |
132 * | |
133 * @param fileList {@link File#pathSeparator} separated list of Zip/Jar files to compile | |
134 * @throws Throwable | |
135 */ | |
136 private void compile(String fileList) throws Throwable { | |
137 final String[] entries = fileList.split(File.pathSeparator); | |
138 | |
139 for (int i = 0; i < entries.length; i++) { | |
140 final String entry = entries[i]; | |
141 | |
142 // For now we only compile all methods in all classes in zip/jar files. | |
143 if (!entry.endsWith(".zip") && !entry.endsWith(".jar")) { | |
144 TTY.println("CompileTheWorld : Skipped classes in " + entry); | |
145 TTY.println(); | |
146 continue; | |
147 } | |
148 | |
149 TTY.println("CompileTheWorld : Compiling all classes in " + entry); | |
150 TTY.println(); | |
151 | |
152 URL url = new URL("jar", "", "file:" + entry + "!/"); | |
153 ClassLoader loader = new URLClassLoader(new URL[]{url}); | |
154 | |
155 JarFile jarFile = new JarFile(entry); | |
156 Enumeration<JarEntry> e = jarFile.entries(); | |
157 | |
158 while (e.hasMoreElements()) { | |
159 JarEntry je = e.nextElement(); | |
160 if (je.isDirectory() || !je.getName().endsWith(".class")) { | |
161 continue; | |
162 } | |
163 | |
164 // Are we done? | |
165 if (classFileCounter >= stopAt) { | |
166 break; | |
167 } | |
168 | |
169 String className = je.getName().substring(0, je.getName().length() - ".class".length()); | |
170 classFileCounter++; | |
171 | |
172 try { | |
173 // 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
|
174 Class<?> javaClass = Class.forName(className.replace('/', '.'), true, loader); |
9108 | 175 |
176 // Pre-load all classes in the constant pool. | |
177 try { | |
178 HotSpotResolvedObjectType objectType = (HotSpotResolvedObjectType) HotSpotResolvedObjectType.fromClass(javaClass); | |
179 ConstantPool constantPool = objectType.constantPool(); | |
180 for (int cpi = 1; cpi < constantPool.length(); cpi++) { | |
181 constantPool.loadReferencedType(cpi, Bytecodes.LDC); | |
182 } | |
183 } catch (Throwable t) { | |
184 // If something went wrong during pre-loading we just ignore it. | |
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
|
185 TTY.println("Preloading failed for (%d) %s", classFileCounter, className); |
9108 | 186 } |
187 | |
188 // 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
|
189 HotSpotMetaAccessProvider metaAccess = runtime.getHostProviders().getMetaAccess(); |
9108 | 190 if (classFileCounter >= startAt) { |
191 TTY.println("CompileTheWorld (%d) : %s", classFileCounter, className); | |
192 | |
193 // Enqueue each constructor/method in the class for compilation. | |
194 for (Constructor<?> constructor : javaClass.getDeclaredConstructors()) { | |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
10672
diff
changeset
|
195 HotSpotResolvedJavaMethod javaMethod = (HotSpotResolvedJavaMethod) metaAccess.lookupJavaConstructor(constructor); |
9108 | 196 if (canBeCompiled(javaMethod, constructor.getModifiers())) { |
197 compileMethod(javaMethod); | |
198 } | |
199 } | |
200 for (Method method : javaClass.getDeclaredMethods()) { | |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
10672
diff
changeset
|
201 HotSpotResolvedJavaMethod javaMethod = (HotSpotResolvedJavaMethod) metaAccess.lookupJavaMethod(method); |
9108 | 202 if (canBeCompiled(javaMethod, method.getModifiers())) { |
203 compileMethod(javaMethod); | |
204 } | |
205 } | |
206 } | |
207 } catch (Throwable t) { | |
208 TTY.println("CompileTheWorld (%d) : Skipping %s", classFileCounter, className); | |
209 } | |
210 } | |
211 jarFile.close(); | |
212 } | |
213 | |
214 TTY.println(); | |
215 TTY.println("CompileTheWorld : Done (%d classes, %d methods, %d ms)", classFileCounter, compiledMethodsCounter, compileTime); | |
216 } | |
217 | |
218 /** | |
219 * Helper method to schedule a method for compilation and gather some statistics. | |
220 */ | |
221 private void compileMethod(HotSpotResolvedJavaMethod method) { | |
222 try { | |
223 long start = System.currentTimeMillis(); | |
10672
e7d07c9bb779
Removed priority compilation queue.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
10543
diff
changeset
|
224 vmToCompiler.compileMethod(method, StructuredGraph.INVOCATION_ENTRY_BCI, true); |
9108 | 225 compileTime += (System.currentTimeMillis() - start); |
226 compiledMethodsCounter++; | |
227 method.reprofile(); // makes the method also not-entrant | |
228 } catch (Throwable t) { | |
229 // Catch everything and print a message | |
230 TTY.println("CompileTheWorld (%d) : Error compiling method: %s", classFileCounter, MetaUtil.format("%H.%n(%p):%r", method)); | |
231 t.printStackTrace(TTY.cachedOut); | |
232 } | |
233 } | |
234 | |
235 /** | |
236 * Helper method for CompileTheWorld to determine if a method should be compiled (Cf. | |
237 * CompilationPolicy::can_be_compiled). | |
238 * | |
239 * @return true if it can be compiled, false otherwise | |
240 */ | |
241 private static boolean canBeCompiled(HotSpotResolvedJavaMethod javaMethod, int modifiers) { | |
242 if (Modifier.isAbstract(modifiers) || Modifier.isNative(modifiers)) { | |
243 return false; | |
244 } | |
245 // This number is from HotSpot: | |
246 final int hugeMethodLimit = 8000; | |
247 if (javaMethod.getCodeSize() > hugeMethodLimit) { | |
248 return false; | |
249 } | |
250 // Skip @Snippets for now | |
251 if (javaMethod.getAnnotation(Snippet.class) != null) { | |
252 return false; | |
253 } | |
254 return true; | |
255 } | |
256 | |
257 } |