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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9108
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
1 /*
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
4 *
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
7 * published by the Free Software Foundation.
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
8 *
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
13 * accompanied this code).
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
14 *
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
18 *
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
21 * questions.
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
22 */
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
23 package com.oracle.graal.hotspot;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
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
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
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
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
32 import java.util.jar.*;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
33
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
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
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
36 import com.oracle.graal.debug.*;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
37 import com.oracle.graal.hotspot.bridge.*;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
38 import com.oracle.graal.hotspot.meta.*;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
39 import com.oracle.graal.nodes.*;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
40 import com.oracle.graal.phases.*;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
41 import com.oracle.graal.replacements.*;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
42
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
43 /**
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
44 * This class implements compile-the-world functionality in Graal.
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
45 */
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
46 public final class CompileTheWorld {
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
47
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
48 /**
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
49 * This is our magic token to trigger reading files from the boot class path.
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
50 */
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
51 public static final String SUN_BOOT_CLASS_PATH = "sun.boot.class.path";
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
52
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
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
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
56
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
57 /** List of Zip/Jar files to compile (see {@link GraalOptions#CompileTheWorld}. */
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
58 private final String files;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
59
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
60 /** Class index to start compilation at (see {@link GraalOptions#CompileTheWorldStartAt}. */
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
61 private final int startAt;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
62
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
63 /** Class index to stop compilation at (see {@link GraalOptions#CompileTheWorldStopAt}. */
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
64 private final int stopAt;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
65
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
66 // Counters
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
67 private int classFileCounter = 0;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
68 private int compiledMethodsCounter = 0;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
69 private long compileTime = 0;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
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
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
73 /**
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
74 * Create a compile-the-world instance with default values from
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
75 * {@link GraalOptions#CompileTheWorld}, {@link GraalOptions#CompileTheWorldStartAt} and
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
76 * {@link GraalOptions#CompileTheWorldStopAt}.
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
77 */
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
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
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
80 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
81
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
82 /**
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
83 * Create a compile-the-world instance.
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
84 *
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
85 * @param files {@link File#pathSeparator} separated list of Zip/Jar files to compile
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
86 * @param startAt index of the class file to start compilation at
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
87 * @param stopAt index of the class file to stop compilation at
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
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
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
90 this.files = files;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
91 this.startAt = startAt;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
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
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
94
13113
e2933e3d4fb0 print stack traces when doing CompileTheWorld
twisti
parents: 12456
diff changeset
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
e2933e3d4fb0 print stack traces when doing CompileTheWorld
twisti
parents: 12456
diff changeset
97
e2933e3d4fb0 print stack traces when doing CompileTheWorld
twisti
parents: 12456
diff changeset
98 // ...but we want to see exceptions.
e2933e3d4fb0 print stack traces when doing CompileTheWorld
twisti
parents: 12456
diff changeset
99 PrintBailout.setValue(true);
e2933e3d4fb0 print stack traces when doing CompileTheWorld
twisti
parents: 12456
diff changeset
100 PrintStackTraceOnException.setValue(true);
9108
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
101 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
102
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
103 /**
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
104 * Compile all methods in all classes in the Zip/Jar files in
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
105 * {@link GraalOptions#CompileTheWorld}. If the GraalOptions.CompileTheWorld contains the magic
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
106 * token {@link CompileTheWorld#SUN_BOOT_CLASS_PATH} passed up from HotSpot we take the files
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
107 * from the boot class path.
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
108 *
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
109 * @throws Throwable
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
110 */
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
111 public void compile() throws Throwable {
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
112 if (SUN_BOOT_CLASS_PATH.equals(files)) {
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
113 final String[] entries = System.getProperty(SUN_BOOT_CLASS_PATH).split(File.pathSeparator);
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
114 String bcpFiles = "";
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
115 for (int i = 0; i < entries.length; i++) {
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
116 final String entry = entries[i];
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
117
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
118 // We stop at rt.jar, unless it is the first boot class path entry.
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
119 if (entry.endsWith("rt.jar") && (i > 0)) {
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
120 break;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
121 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
122 if (i > 0) {
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
123 bcpFiles += File.pathSeparator;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
124 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
125 bcpFiles += entry;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
126 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
127 compile(bcpFiles);
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
128 } else {
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
129 compile(files);
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
130 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
131 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
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
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
147 /**
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
148 * Compile all methods in all classes in the Zip/Jar files passed.
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
149 *
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
150 * @param fileList {@link File#pathSeparator} separated list of Zip/Jar files to compile
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
151 * @throws Throwable
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
152 */
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
153 private void compile(String fileList) throws Throwable {
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
154 final String[] entries = fileList.split(File.pathSeparator);
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
155
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
156 for (int i = 0; i < entries.length; i++) {
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
157 final String entry = entries[i];
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
158
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
159 // For now we only compile all methods in all classes in zip/jar files.
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
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
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
163 continue;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
164 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
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
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
168
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
169 URL url = new URL("jar", "", "file:" + entry + "!/");
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
170 ClassLoader loader = new URLClassLoader(new URL[]{url});
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
171
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
172 JarFile jarFile = new JarFile(entry);
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
173 Enumeration<JarEntry> e = jarFile.entries();
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
174
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
175 while (e.hasMoreElements()) {
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
176 JarEntry je = e.nextElement();
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
177 if (je.isDirectory() || !je.getName().endsWith(".class")) {
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
178 continue;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
179 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
180
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
181 // Are we done?
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
182 if (classFileCounter >= stopAt) {
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
183 break;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
184 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
185
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
186 String className = je.getName().substring(0, je.getName().length() - ".class".length());
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
187 classFileCounter++;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
188
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
189 try {
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
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
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
192
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
193 // Pre-load all classes in the constant pool.
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
194 try {
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
195 HotSpotResolvedObjectType objectType = (HotSpotResolvedObjectType) HotSpotResolvedObjectType.fromClass(javaClass);
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
196 ConstantPool constantPool = objectType.constantPool();
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
197 for (int cpi = 1; cpi < constantPool.length(); cpi++) {
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
198 constantPool.loadReferencedType(cpi, Bytecodes.LDC);
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
199 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
200 } catch (Throwable t) {
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
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
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
203 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
204
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
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
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
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
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
209
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
210 // Enqueue each constructor/method in the class for compilation.
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
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
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
213 if (canBeCompiled(javaMethod, constructor.getModifiers())) {
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
214 compileMethod(javaMethod);
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
215 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
216 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
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
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
219 if (canBeCompiled(javaMethod, method.getModifiers())) {
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
220 compileMethod(javaMethod);
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
221 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
222 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
223 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
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
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
226 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
227 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
228 jarFile.close();
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
229 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
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
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
233 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
234
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
235 /**
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
236 * Helper method to schedule a method for compilation and gather some statistics.
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
237 */
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
238 private void compileMethod(HotSpotResolvedJavaMethod method) {
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
239 try {
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
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
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
242 compileTime += (System.currentTimeMillis() - start);
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
243 compiledMethodsCounter++;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
244 method.reprofile(); // makes the method also not-entrant
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
245 } catch (Throwable t) {
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
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
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
248 t.printStackTrace(TTY.cachedOut);
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
249 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
250 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
251
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
252 /**
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
253 * Helper method for CompileTheWorld to determine if a method should be compiled (Cf.
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
254 * CompilationPolicy::can_be_compiled).
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
255 *
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
256 * @return true if it can be compiled, false otherwise
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
257 */
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
258 private static boolean canBeCompiled(HotSpotResolvedJavaMethod javaMethod, int modifiers) {
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
259 if (Modifier.isAbstract(modifiers) || Modifier.isNative(modifiers)) {
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
260 return false;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
261 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
262 // This number is from HotSpot:
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
263 final int hugeMethodLimit = 8000;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
264 if (javaMethod.getCodeSize() > hugeMethodLimit) {
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
265 return false;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
266 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
267 // Skip @Snippets for now
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
268 if (javaMethod.getAnnotation(Snippet.class) != null) {
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
269 return false;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
270 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
271 return true;
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
272 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
273
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents:
diff changeset
274 }