author | dlong |
Fri, 22 Nov 2019 19:23:30 -0800 | |
changeset 59237 | 2601fc0874be |
parent 55509 | d58442b8abc1 |
permissions | -rw-r--r-- |
42650 | 1 |
/* |
55094
80dd2b549354
8224931: disable JAOTC invokedynamic support until 8223533 is fixed
dlong
parents:
54084
diff
changeset
|
2 |
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
42650 | 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 |
||
51436 | 24 |
|
25 |
||
42650 | 26 |
package jdk.tools.jaotc; |
27 |
||
28 |
import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC; |
|
29 |
import static org.graalvm.compiler.core.common.GraalOptions.ImmutableCode; |
|
30 |
import static org.graalvm.compiler.hotspot.meta.HotSpotAOTProfilingPlugin.Options.TieredAOT; |
|
31 |
||
53071 | 32 |
import java.io.IOException; |
42650 | 33 |
import java.io.PrintWriter; |
34 |
import java.text.MessageFormat; |
|
53071 | 35 |
import java.util.ArrayList; |
36 |
import java.util.Collections; |
|
42650 | 37 |
import java.util.List; |
43405
1fab8e6866d7
8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents:
42650
diff
changeset
|
38 |
import java.util.ListIterator; |
42650 | 39 |
import java.util.Set; |
53071 | 40 |
import java.util.StringTokenizer; |
41 |
import java.util.stream.Stream; |
|
42 |
import java.nio.file.Files; |
|
43 |
import java.nio.file.Paths; |
|
42650 | 44 |
|
46640 | 45 |
import org.graalvm.compiler.api.replacements.SnippetReflectionProvider; |
42650 | 46 |
import org.graalvm.compiler.api.runtime.GraalJVMCICompiler; |
46640 | 47 |
import org.graalvm.compiler.debug.DebugContext; |
48 |
import org.graalvm.compiler.debug.DebugContext.Activation; |
|
46344 | 49 |
import org.graalvm.compiler.hotspot.CompilerConfigurationFactory; |
43405
1fab8e6866d7
8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents:
42650
diff
changeset
|
50 |
import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig; |
46344 | 51 |
import org.graalvm.compiler.hotspot.HotSpotGraalCompilerFactory; |
52 |
import org.graalvm.compiler.hotspot.HotSpotGraalOptionValues; |
|
51206
14b870bda24f
8207069: [AOT] we should check that VM uses the same GC as one used for AOT library generation.
kvn
parents:
49873
diff
changeset
|
53 |
import org.graalvm.compiler.hotspot.HotSpotGraalRuntime; |
59237
2601fc0874be
8234432: AOT tests failing with 'used 'epsilon gc' is different from current 'g1 gc'' after CMS removal
dlong
parents:
55509
diff
changeset
|
54 |
import org.graalvm.compiler.hotspot.HotSpotGraalRuntime.HotSpotGC; |
42650 | 55 |
import org.graalvm.compiler.hotspot.HotSpotHostBackend; |
47668 | 56 |
import org.graalvm.compiler.hotspot.meta.HotSpotInvokeDynamicPlugin; |
43405
1fab8e6866d7
8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents:
42650
diff
changeset
|
57 |
import org.graalvm.compiler.java.GraphBuilderPhase; |
1fab8e6866d7
8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents:
42650
diff
changeset
|
58 |
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration; |
55094
80dd2b549354
8224931: disable JAOTC invokedynamic support until 8223533 is fixed
dlong
parents:
54084
diff
changeset
|
59 |
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext; |
46344 | 60 |
import org.graalvm.compiler.options.OptionValues; |
43405
1fab8e6866d7
8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents:
42650
diff
changeset
|
61 |
import org.graalvm.compiler.phases.BasePhase; |
1fab8e6866d7
8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents:
42650
diff
changeset
|
62 |
import org.graalvm.compiler.phases.PhaseSuite; |
1fab8e6866d7
8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents:
42650
diff
changeset
|
63 |
import org.graalvm.compiler.phases.tiers.HighTierContext; |
46640 | 64 |
import org.graalvm.compiler.printer.GraalDebugHandlersFactory; |
42650 | 65 |
import org.graalvm.compiler.runtime.RuntimeProvider; |
66 |
||
51436 | 67 |
import jdk.tools.jaotc.Options.Option; |
68 |
import jdk.tools.jaotc.binformat.BinaryContainer; |
|
42650 | 69 |
import jdk.vm.ci.meta.MetaAccessProvider; |
70 |
import jdk.vm.ci.meta.ResolvedJavaMethod; |
|
71 |
import jdk.vm.ci.runtime.JVMCI; |
|
72 |
||
46949 | 73 |
public final class Main { |
42650 | 74 |
|
46949 | 75 |
final Options options = new Options(); |
76 |
private PrintWriter log; |
|
77 |
LogPrinter printer; |
|
78 |
GraalFilters filters; |
|
42650 | 79 |
|
80 |
private static final int EXIT_OK = 0; // No errors. |
|
81 |
private static final int EXIT_CMDERR = 2; // Bad command-line arguments and/or switches. |
|
82 |
private static final int EXIT_ABNORMAL = 4; // Terminated abnormally. |
|
83 |
||
84 |
private static final String PROGNAME = "jaotc"; |
|
85 |
||
86 |
private static final String JVM_VERSION = System.getProperty("java.runtime.version"); |
|
87 |
||
88 |
public static void main(String[] args) throws Exception { |
|
89 |
Main t = new Main(); |
|
53071 | 90 |
final int exitCode = t.run(parse(args)); |
42650 | 91 |
System.exit(exitCode); |
92 |
} |
|
93 |
||
53071 | 94 |
/** |
95 |
* Expands '@file' in command line arguments by replacing '@file' with the content of 'file' |
|
96 |
* parsed by StringTokenizer. '@' character can be quoted as '@@'. |
|
97 |
*/ |
|
98 |
private static String[] parse(String[] args) throws IOException { |
|
99 |
List<String> result = new ArrayList<>(); |
|
100 |
for (String arg : args) { |
|
101 |
if (arg.length() > 1 && arg.charAt(0) == '@') { |
|
102 |
String v = arg.substring(1); |
|
103 |
if (v.charAt(0) == '@') { |
|
104 |
result.add(v); |
|
105 |
} else { |
|
106 |
try (Stream<String> file = Files.lines(Paths.get(v))) { |
|
107 |
file.map(StringTokenizer::new).map(Collections::list).flatMap(l -> l.stream().map(o -> (String) o)).forEachOrdered(result::add); |
|
108 |
} |
|
109 |
} |
|
110 |
} else { |
|
111 |
result.add(arg); |
|
112 |
} |
|
113 |
} |
|
114 |
return result.toArray(String[]::new); |
|
115 |
} |
|
116 |
||
42650 | 117 |
private int run(String[] args) { |
46949 | 118 |
log = new PrintWriter(System.out); |
119 |
printer = new LogPrinter(this, log); |
|
42650 | 120 |
|
121 |
try { |
|
46949 | 122 |
Options.handleOptions(this, args); |
42650 | 123 |
if (options.help) { |
124 |
showHelp(); |
|
125 |
return EXIT_OK; |
|
126 |
} |
|
127 |
if (options.version) { |
|
128 |
showVersion(); |
|
129 |
return EXIT_OK; |
|
130 |
} |
|
131 |
||
46949 | 132 |
printer.printlnInfo("Compiling " + options.outputName + "..."); |
42650 | 133 |
final long start = System.currentTimeMillis(); |
43464
f38fde4a6b52
8169588: [AOT] jaotc --classpath option is confusing
rbackman
parents:
43405
diff
changeset
|
134 |
if (!run()) { |
46344 | 135 |
return EXIT_ABNORMAL; |
43464
f38fde4a6b52
8169588: [AOT] jaotc --classpath option is confusing
rbackman
parents:
43405
diff
changeset
|
136 |
} |
42650 | 137 |
final long end = System.currentTimeMillis(); |
46949 | 138 |
printer.printlnInfo("Total time: " + (end - start) + " ms"); |
42650 | 139 |
|
140 |
return EXIT_OK; |
|
46949 | 141 |
} catch (Options.BadArgs e) { |
142 |
printer.reportError(e.key, e.args); |
|
42650 | 143 |
if (e.showUsage) { |
144 |
showUsage(); |
|
145 |
} |
|
146 |
return EXIT_CMDERR; |
|
147 |
} catch (Exception e) { |
|
148 |
e.printStackTrace(); |
|
149 |
return EXIT_ABNORMAL; |
|
150 |
} finally { |
|
151 |
log.flush(); |
|
152 |
} |
|
153 |
} |
|
154 |
||
155 |
@SuppressWarnings("try") |
|
43464
f38fde4a6b52
8169588: [AOT] jaotc --classpath option is confusing
rbackman
parents:
43405
diff
changeset
|
156 |
private boolean run() throws Exception { |
46949 | 157 |
LogPrinter.openLog(); |
42650 | 158 |
|
159 |
try { |
|
160 |
||
46949 | 161 |
final Linker linker = new Linker(this); |
162 |
final String objectFileName = linker.objFile(); |
|
163 |
final Collector collector = new Collector(this); |
|
164 |
Set<Class<?>> classesToCompile; |
|
42650 | 165 |
|
166 |
try (Timer t = new Timer(this, "")) { |
|
46949 | 167 |
classesToCompile = collector.collectClassesToCompile(); |
168 |
printer.printInfo(classesToCompile.size() + " classes found"); |
|
42650 | 169 |
} |
170 |
||
54084 | 171 |
OptionValues graalOptions = HotSpotGraalOptionValues.defaultOptions(); |
46344 | 172 |
// Setting -Dgraal.TieredAOT overrides --compile-for-tiered |
173 |
if (!TieredAOT.hasBeenSet(graalOptions)) { |
|
174 |
graalOptions = new OptionValues(graalOptions, TieredAOT, options.tiered); |
|
175 |
} |
|
46557 | 176 |
graalOptions = new OptionValues(graalOptions, GeneratePIC, true, ImmutableCode, true); |
49873 | 177 |
GraalJVMCICompiler graalCompiler = HotSpotGraalCompilerFactory.createCompiler("JAOTC", JVMCI.getRuntime(), graalOptions, CompilerConfigurationFactory.selectFactory(null, graalOptions)); |
51206
14b870bda24f
8207069: [AOT] we should check that VM uses the same GC as one used for AOT library generation.
kvn
parents:
49873
diff
changeset
|
178 |
HotSpotGraalRuntime runtime = (HotSpotGraalRuntime) graalCompiler.getGraalRuntime(); |
42650 | 179 |
HotSpotHostBackend backend = (HotSpotHostBackend) runtime.getCapability(RuntimeProvider.class).getHostBackend(); |
180 |
MetaAccessProvider metaAccess = backend.getProviders().getMetaAccess(); |
|
46949 | 181 |
filters = new GraalFilters(metaAccess); |
42650 | 182 |
|
183 |
List<AOTCompiledClass> classes; |
|
184 |
||
185 |
try (Timer t = new Timer(this, "")) { |
|
46949 | 186 |
classes = collector.collectMethodsToCompile(classesToCompile, metaAccess); |
42650 | 187 |
} |
188 |
||
189 |
// Free memory! |
|
190 |
try (Timer t = options.verbose ? new Timer(this, "Freeing memory") : null) { |
|
46949 | 191 |
printer.printMemoryUsage(); |
42650 | 192 |
classesToCompile = null; |
193 |
System.gc(); |
|
194 |
} |
|
195 |
||
47668 | 196 |
AOTDynamicTypeStore dynoStore = new AOTDynamicTypeStore(); |
197 |
AOTCompiledClass.setDynamicTypeStore(dynoStore); |
|
198 |
||
55509 | 199 |
// AOTBackend aotBackend = new AOTBackend(this, graalOptions, backend, new |
200 |
// HotSpotInvokeDynamicPlugin(dynoStore)); |
|
55094
80dd2b549354
8224931: disable JAOTC invokedynamic support until 8223533 is fixed
dlong
parents:
54084
diff
changeset
|
201 |
// Temporary workaround until JDK-8223533 is fixed. |
80dd2b549354
8224931: disable JAOTC invokedynamic support until 8223533 is fixed
dlong
parents:
54084
diff
changeset
|
202 |
// Disable invokedynamic support. |
80dd2b549354
8224931: disable JAOTC invokedynamic support until 8223533 is fixed
dlong
parents:
54084
diff
changeset
|
203 |
var indyPlugin = new HotSpotInvokeDynamicPlugin(dynoStore) { |
80dd2b549354
8224931: disable JAOTC invokedynamic support until 8223533 is fixed
dlong
parents:
54084
diff
changeset
|
204 |
@Override |
80dd2b549354
8224931: disable JAOTC invokedynamic support until 8223533 is fixed
dlong
parents:
54084
diff
changeset
|
205 |
public boolean supportsDynamicInvoke(GraphBuilderContext builder, int index, int opcode) { |
80dd2b549354
8224931: disable JAOTC invokedynamic support until 8223533 is fixed
dlong
parents:
54084
diff
changeset
|
206 |
return false; |
80dd2b549354
8224931: disable JAOTC invokedynamic support until 8223533 is fixed
dlong
parents:
54084
diff
changeset
|
207 |
} |
80dd2b549354
8224931: disable JAOTC invokedynamic support until 8223533 is fixed
dlong
parents:
54084
diff
changeset
|
208 |
}; |
80dd2b549354
8224931: disable JAOTC invokedynamic support until 8223533 is fixed
dlong
parents:
54084
diff
changeset
|
209 |
AOTBackend aotBackend = new AOTBackend(this, graalOptions, backend, indyPlugin); |
46640 | 210 |
SnippetReflectionProvider snippetReflection = aotBackend.getProviders().getSnippetReflection(); |
46344 | 211 |
AOTCompiler compiler = new AOTCompiler(this, graalOptions, aotBackend, options.threads); |
42650 | 212 |
classes = compiler.compileClasses(classes); |
213 |
||
43405
1fab8e6866d7
8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents:
42650
diff
changeset
|
214 |
GraalHotSpotVMConfig graalHotSpotVMConfig = runtime.getVMConfig(); |
1fab8e6866d7
8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents:
42650
diff
changeset
|
215 |
PhaseSuite<HighTierContext> graphBuilderSuite = aotBackend.getGraphBuilderSuite(); |
1fab8e6866d7
8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents:
42650
diff
changeset
|
216 |
ListIterator<BasePhase<? super HighTierContext>> iterator = graphBuilderSuite.findPhase(GraphBuilderPhase.class); |
1fab8e6866d7
8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents:
42650
diff
changeset
|
217 |
GraphBuilderConfiguration graphBuilderConfig = ((GraphBuilderPhase) iterator.previous()).getGraphBuilderConfig(); |
1fab8e6866d7
8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents:
42650
diff
changeset
|
218 |
|
42650 | 219 |
// Free memory! |
220 |
try (Timer t = options.verbose ? new Timer(this, "Freeing memory") : null) { |
|
46949 | 221 |
printer.printMemoryUsage(); |
42650 | 222 |
aotBackend = null; |
223 |
compiler = null; |
|
224 |
System.gc(); |
|
225 |
} |
|
226 |
||
59237
2601fc0874be
8234432: AOT tests failing with 'used 'epsilon gc' is different from current 'g1 gc'' after CMS removal
dlong
parents:
55509
diff
changeset
|
227 |
HotSpotGC graal_gc = runtime.getGarbageCollector(); |
2601fc0874be
8234432: AOT tests failing with 'used 'epsilon gc' is different from current 'g1 gc'' after CMS removal
dlong
parents:
55509
diff
changeset
|
228 |
int def = graal_gc.ordinal() + 1; |
2601fc0874be
8234432: AOT tests failing with 'used 'epsilon gc' is different from current 'g1 gc'' after CMS removal
dlong
parents:
55509
diff
changeset
|
229 |
String name = "CollectedHeap::" + graal_gc.name(); |
2601fc0874be
8234432: AOT tests failing with 'used 'epsilon gc' is different from current 'g1 gc'' after CMS removal
dlong
parents:
55509
diff
changeset
|
230 |
int gc = graalHotSpotVMConfig.getConstant(name, Integer.class, def); |
2601fc0874be
8234432: AOT tests failing with 'used 'epsilon gc' is different from current 'g1 gc'' after CMS removal
dlong
parents:
55509
diff
changeset
|
231 |
|
51206
14b870bda24f
8207069: [AOT] we should check that VM uses the same GC as one used for AOT library generation.
kvn
parents:
49873
diff
changeset
|
232 |
BinaryContainer binaryContainer = new BinaryContainer(graalOptions, graalHotSpotVMConfig, graphBuilderConfig, gc, JVM_VERSION); |
42650 | 233 |
DataBuilder dataBuilder = new DataBuilder(this, backend, classes, binaryContainer); |
46640 | 234 |
|
235 |
try (DebugContext debug = DebugContext.create(graalOptions, new GraalDebugHandlersFactory(snippetReflection)); Activation a = debug.activate()) { |
|
236 |
dataBuilder.prepareData(debug); |
|
237 |
} |
|
42650 | 238 |
|
239 |
// Print information about section sizes |
|
46949 | 240 |
printer.containersInfo(binaryContainer); |
42650 | 241 |
|
242 |
// Free memory! |
|
243 |
try (Timer t = options.verbose ? new Timer(this, "Freeing memory") : null) { |
|
46949 | 244 |
printer.printMemoryUsage(); |
42650 | 245 |
backend = null; |
246 |
for (AOTCompiledClass aotCompClass : classes) { |
|
247 |
aotCompClass.clear(); |
|
248 |
} |
|
249 |
classes.clear(); |
|
250 |
classes = null; |
|
251 |
dataBuilder = null; |
|
252 |
binaryContainer.freeMemory(); |
|
253 |
System.gc(); |
|
254 |
} |
|
255 |
||
256 |
try (Timer t = new Timer(this, "Creating binary: " + objectFileName)) { |
|
46949 | 257 |
binaryContainer.createBinary(objectFileName); |
42650 | 258 |
} |
259 |
||
260 |
// Free memory! |
|
261 |
try (Timer t = options.verbose ? new Timer(this, "Freeing memory") : null) { |
|
46949 | 262 |
printer.printMemoryUsage(); |
42650 | 263 |
binaryContainer = null; |
264 |
System.gc(); |
|
265 |
} |
|
266 |
||
46949 | 267 |
try (Timer t = new Timer(this, "Creating shared library: " + linker.libFile())) { |
268 |
linker.link(); |
|
42650 | 269 |
} |
270 |
||
46949 | 271 |
printer.printVerbose("Final memory "); |
272 |
printer.printMemoryUsage(); |
|
273 |
printer.printlnVerbose(""); |
|
42650 | 274 |
|
275 |
} finally { |
|
46949 | 276 |
LogPrinter.closeLog(); |
42650 | 277 |
} |
43464
f38fde4a6b52
8169588: [AOT] jaotc --classpath option is confusing
rbackman
parents:
43405
diff
changeset
|
278 |
return true; |
42650 | 279 |
} |
280 |
||
46949 | 281 |
void handleError(ResolvedJavaMethod resolvedMethod, Throwable e, String message) { |
282 |
String methodName = JavaMethodInfo.uniqueMethodName(resolvedMethod); |
|
42650 | 283 |
|
46949 | 284 |
if (options.debug) { |
285 |
printer.printError("Failed compilation: " + methodName + ": " + e); |
|
42650 | 286 |
} |
46949 | 287 |
|
288 |
// Ignore some exceptions when meta-compiling Graal. |
|
289 |
if (GraalFilters.shouldIgnoreException(e)) { |
|
42650 | 290 |
return; |
291 |
} |
|
292 |
||
46949 | 293 |
LogPrinter.writeLog("Failed compilation of method " + methodName + message); |
42650 | 294 |
|
46949 | 295 |
if (!options.debug) { |
296 |
printer.printError("Failed compilation: " + methodName + ": " + e); |
|
42650 | 297 |
} |
298 |
||
46949 | 299 |
if (options.verbose) { |
300 |
e.printStackTrace(log); |
|
301 |
} |
|
42650 | 302 |
|
46949 | 303 |
if (options.exitOnError) { |
304 |
System.exit(1); |
|
42650 | 305 |
} |
306 |
} |
|
307 |
||
46949 | 308 |
void warning(String key, Object... args) { |
42650 | 309 |
log.println("Warning: " + MessageFormat.format(key, args)); |
310 |
log.flush(); |
|
311 |
} |
|
312 |
||
313 |
private void showUsage() { |
|
43479 | 314 |
log.println("Usage: " + PROGNAME + " <options> list"); |
42650 | 315 |
log.println("use --help for a list of possible options"); |
46949 | 316 |
log.flush(); |
42650 | 317 |
} |
318 |
||
319 |
private void showHelp() { |
|
43479 | 320 |
log.println("Usage: " + PROGNAME + " <options> list"); |
42650 | 321 |
log.println(); |
43479 | 322 |
log.println(" list A : separated list of class names, modules, jar files"); |
323 |
log.println(" or directories which contain class files."); |
|
42650 | 324 |
log.println(); |
43479 | 325 |
log.println("where options include:"); |
46949 | 326 |
for (Option o : Options.recognizedOptions) { |
42650 | 327 |
String name = o.aliases[0].substring(1); // there must always be at least one name |
328 |
name = name.charAt(0) == '-' ? name.substring(1) : name; |
|
329 |
if (o.isHidden() || name.equals("h")) { |
|
330 |
continue; |
|
331 |
} |
|
332 |
log.println(o.help); |
|
333 |
} |
|
46949 | 334 |
log.flush(); |
42650 | 335 |
} |
336 |
||
337 |
private void showVersion() { |
|
338 |
log.println(PROGNAME + " " + JVM_VERSION); |
|
339 |
} |
|
340 |
} |