43 import java.text.MessageFormat; |
43 import java.text.MessageFormat; |
44 import java.util.ArrayList; |
44 import java.util.ArrayList; |
45 import java.util.Date; |
45 import java.util.Date; |
46 import java.util.LinkedList; |
46 import java.util.LinkedList; |
47 import java.util.List; |
47 import java.util.List; |
|
48 import java.util.ListIterator; |
48 import java.util.Set; |
49 import java.util.Set; |
49 import java.util.stream.Stream; |
50 import java.util.stream.Stream; |
50 |
51 |
51 import jdk.tools.jaotc.binformat.BinaryContainer; |
52 import jdk.tools.jaotc.binformat.BinaryContainer; |
52 import jdk.tools.jaotc.binformat.ByteContainer; |
53 import jdk.tools.jaotc.binformat.ByteContainer; |
53 import jdk.tools.jaotc.collect.ClassCollector; |
54 import jdk.tools.jaotc.collect.ClassCollector; |
54 import jdk.tools.jaotc.utils.Timer; |
55 import jdk.tools.jaotc.utils.Timer; |
55 |
56 |
56 import org.graalvm.compiler.api.runtime.GraalJVMCICompiler; |
57 import org.graalvm.compiler.api.runtime.GraalJVMCICompiler; |
|
58 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig; |
57 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider; |
59 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider; |
58 import org.graalvm.compiler.hotspot.HotSpotHostBackend; |
60 import org.graalvm.compiler.hotspot.HotSpotHostBackend; |
|
61 import org.graalvm.compiler.java.GraphBuilderPhase; |
|
62 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration; |
|
63 import org.graalvm.compiler.phases.BasePhase; |
|
64 import org.graalvm.compiler.phases.PhaseSuite; |
|
65 import org.graalvm.compiler.phases.tiers.HighTierContext; |
59 import org.graalvm.compiler.runtime.RuntimeProvider; |
66 import org.graalvm.compiler.runtime.RuntimeProvider; |
60 |
67 |
61 import jdk.vm.ci.meta.MetaAccessProvider; |
68 import jdk.vm.ci.meta.MetaAccessProvider; |
62 import jdk.vm.ci.meta.ResolvedJavaMethod; |
69 import jdk.vm.ci.meta.ResolvedJavaMethod; |
63 import jdk.vm.ci.meta.ResolvedJavaType; |
70 import jdk.vm.ci.meta.ResolvedJavaType; |
142 }, new Option(" --compile-commands <file> Name of file with compile commands", true, "--compile-commands") { |
149 }, new Option(" --compile-commands <file> Name of file with compile commands", true, "--compile-commands") { |
143 @Override |
150 @Override |
144 void process(Main task, String opt, String arg) { |
151 void process(Main task, String opt, String arg) { |
145 task.options.methodList = arg; |
152 task.options.methodList = arg; |
146 } |
153 } |
147 }, new Option(" --compile-for-tiered Generated profiling code for tiered compilation", false, "--compile-for-tiered") { |
154 }, new Option(" --compile-for-tiered Generate profiling code for tiered compilation", false, "--compile-for-tiered") { |
148 @Override |
155 @Override |
149 void process(Main task, String opt, String arg) { |
156 void process(Main task, String opt, String arg) { |
150 TieredAOT.setValue(true); |
157 TieredAOT.setValue(true); |
|
158 } |
|
159 }, new Option(" --compile-with-assertions Compile assertions", false, "--compile-with-assertions") { |
|
160 @Override |
|
161 void process(Main task, String opt, String arg) { |
|
162 task.options.compileWithAssertions = true; |
151 } |
163 } |
152 }, new Option(" --classpath <path> Specify where to find user class files", true, "--classpath", "--class-path") { |
164 }, new Option(" --classpath <path> Specify where to find user class files", true, "--classpath", "--class-path") { |
153 @Override |
165 @Override |
154 void process(Main task, String opt, String arg) { |
166 void process(Main task, String opt, String arg) { |
155 task.options.classpath = arg; |
167 task.options.classpath = arg; |
223 /** |
235 /** |
224 * We don't see scaling beyond 16 threads. |
236 * We don't see scaling beyond 16 threads. |
225 */ |
237 */ |
226 private static final int COMPILER_THREADS = 16; |
238 private static final int COMPILER_THREADS = 16; |
227 |
239 |
228 int threads = Integer.min(COMPILER_THREADS, Runtime.getRuntime().availableProcessors()); |
240 public int threads = Integer.min(COMPILER_THREADS, Runtime.getRuntime().availableProcessors()); |
229 |
241 |
230 public boolean ignoreClassLoadingErrors; |
242 public boolean ignoreClassLoadingErrors; |
231 public boolean exitOnError; |
243 public boolean exitOnError; |
232 boolean info; |
244 public boolean info; |
233 boolean verbose; |
245 public boolean verbose; |
234 boolean debug; |
246 public boolean debug; |
235 boolean help; |
247 public boolean help; |
236 boolean version; |
248 public boolean version; |
|
249 public boolean compileWithAssertions; |
237 } |
250 } |
238 |
251 |
239 /* package */final Options options = new Options(); |
252 /* package */final Options options = new Options(); |
240 |
253 |
241 /** |
254 /** |
354 |
367 |
355 AOTBackend aotBackend = new AOTBackend(this, backend, filters); |
368 AOTBackend aotBackend = new AOTBackend(this, backend, filters); |
356 AOTCompiler compiler = new AOTCompiler(this, aotBackend, options.threads); |
369 AOTCompiler compiler = new AOTCompiler(this, aotBackend, options.threads); |
357 classes = compiler.compileClasses(classes); |
370 classes = compiler.compileClasses(classes); |
358 |
371 |
|
372 GraalHotSpotVMConfig graalHotSpotVMConfig = runtime.getVMConfig(); |
|
373 PhaseSuite<HighTierContext> graphBuilderSuite = aotBackend.getGraphBuilderSuite(); |
|
374 ListIterator<BasePhase<? super HighTierContext>> iterator = graphBuilderSuite.findPhase(GraphBuilderPhase.class); |
|
375 GraphBuilderConfiguration graphBuilderConfig = ((GraphBuilderPhase) iterator.previous()).getGraphBuilderConfig(); |
|
376 |
359 // Free memory! |
377 // Free memory! |
360 try (Timer t = options.verbose ? new Timer(this, "Freeing memory") : null) { |
378 try (Timer t = options.verbose ? new Timer(this, "Freeing memory") : null) { |
361 printMemoryUsage(); |
379 printMemoryUsage(); |
362 aotBackend = null; |
380 aotBackend = null; |
363 compiler = null; |
381 compiler = null; |
364 System.gc(); |
382 System.gc(); |
365 } |
383 } |
366 |
384 |
367 BinaryContainer binaryContainer = new BinaryContainer(runtime.getVMConfig(), JVM_VERSION); |
385 BinaryContainer binaryContainer = new BinaryContainer(graalHotSpotVMConfig, graphBuilderConfig, JVM_VERSION); |
368 DataBuilder dataBuilder = new DataBuilder(this, backend, classes, binaryContainer); |
386 DataBuilder dataBuilder = new DataBuilder(this, backend, classes, binaryContainer); |
369 dataBuilder.prepareData(); |
387 dataBuilder.prepareData(); |
370 |
388 |
371 // Print information about section sizes |
389 // Print information about section sizes |
372 printContainerInfo(binaryContainer.getHeaderContainer().getContainer()); |
390 printContainerInfo(binaryContainer.getHeaderContainer().getContainer()); |