package org.graalvm.compiler.hotspot.test;
import static java.util.Collections.singletonList;
import static org.graalvm.compiler.core.CompilationWrapper.ExceptionAction.Print;
import static org.graalvm.compiler.core.GraalCompilerOptions.CompilationBailoutAction;
import static org.graalvm.compiler.core.GraalCompilerOptions.CompilationFailureAction;
import static org.graalvm.compiler.core.test.ReflectionOptionDescriptors.extractEntries;
import static org.graalvm.compiler.debug.MemUseTrackerKey.getCurrentThreadAllocatedBytes;
import static org.graalvm.compiler.hotspot.test.CompileTheWorld.Options.DESCRIPTORS;
import static org.graalvm.compiler.serviceprovider.GraalServices.Java8OrEarlier;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import jdk.internal.vm.compiler.collections.EconomicMap;
import jdk.internal.vm.compiler.collections.UnmodifiableEconomicMap;
import org.graalvm.compiler.api.replacements.Snippet;
import org.graalvm.compiler.bytecode.Bytecodes;
import org.graalvm.compiler.core.CompilerThreadFactory;
import org.graalvm.compiler.core.test.ReflectionOptionDescriptors;
import org.graalvm.compiler.debug.DebugOptions;
import org.graalvm.compiler.debug.GraalError;
import org.graalvm.compiler.debug.MethodFilter;
import org.graalvm.compiler.debug.TTY;
import org.graalvm.compiler.hotspot.CompilationTask;
import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
import org.graalvm.compiler.hotspot.HotSpotGraalCompiler;
import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
import org.graalvm.compiler.options.OptionDescriptors;
import org.graalvm.compiler.options.OptionKey;
import org.graalvm.compiler.options.OptionValues;
import org.graalvm.compiler.options.OptionsParser;
import org.graalvm.compiler.serviceprovider.GraalServices;
import jdk.vm.ci.hotspot.HotSpotCodeCacheProvider;
import jdk.vm.ci.hotspot.HotSpotCompilationRequest;
import jdk.vm.ci.hotspot.HotSpotInstalledCode;
import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
import jdk.vm.ci.meta.ConstantPool;
import jdk.vm.ci.meta.MetaAccessProvider;
import jdk.vm.ci.runtime.JVMCI;
import jdk.vm.ci.runtime.JVMCICompiler;
public final class CompileTheWorld {
public static final String SUN_BOOT_CLASS_PATH = "sun.boot.class.path";
public static final String JRT_CLASS_PATH_ENTRY = "<jrt>";
public static EconomicMap<OptionKey<?>, Object> parseOptions(String options) {
if (options != null) {
EconomicMap<String, String> optionSettings = EconomicMap.create();
for (String optionSetting : options.split("\\s+|#")) {
OptionsParser.parseOptionSettingTo(optionSetting, optionSettings);
}
EconomicMap<OptionKey<?>, Object> values = OptionValues.newOptionMap();
ServiceLoader<OptionDescriptors> loader = ServiceLoader.load(OptionDescriptors.class, OptionDescriptors.class.getClassLoader());
OptionsParser.parseOptions(optionSettings, values, loader);
return values;
}
return EconomicMap.create();
}
private final HotSpotJVMCIRuntime jvmciRuntime;
private final HotSpotGraalCompiler compiler;
private final String inputClassPath;
private final int startAt;
private final int stopAt;
private final MethodFilter[] methodFilters;
private final MethodFilter[] excludeMethodFilters;
private int classFileCounter = 0;
private AtomicLong compiledMethodsCounter = new AtomicLong();
private AtomicLong compileTime = new AtomicLong();
private AtomicLong memoryUsed = new AtomicLong();
private boolean verbose;
private boolean running;
private ThreadPoolExecutor threadPool;
private OptionValues currentOptions;
private final UnmodifiableEconomicMap<OptionKey<?>, Object> compilationOptions;
public CompileTheWorld(HotSpotJVMCIRuntime jvmciRuntime, HotSpotGraalCompiler compiler, String files, int startAt, int stopAt, String methodFilters, String excludeMethodFilters,
boolean verbose, OptionValues initialOptions, EconomicMap<OptionKey<?>, Object> compilationOptions) {
this.jvmciRuntime = jvmciRuntime;
this.compiler = compiler;
this.inputClassPath = files;
this.startAt = startAt;
this.stopAt = stopAt;
this.methodFilters = methodFilters == null || methodFilters.isEmpty() ? null : MethodFilter.parse(methodFilters);
this.excludeMethodFilters = excludeMethodFilters == null || excludeMethodFilters.isEmpty() ? null : MethodFilter.parse(excludeMethodFilters);
this.verbose = verbose;
this.currentOptions = initialOptions;
EconomicMap<OptionKey<?>, Object> compilationOptionsCopy = EconomicMap.create(initialOptions.getMap());
compilationOptionsCopy.putAll(compilationOptions);
CompilationBailoutAction.putIfAbsent(compilationOptionsCopy, Print);
CompilationFailureAction.putIfAbsent(compilationOptionsCopy, Print);
DebugOptions.MetricsThreadFilter.putIfAbsent(compilationOptionsCopy, "^CompileTheWorld");
this.compilationOptions = compilationOptionsCopy;
}
public CompileTheWorld(HotSpotJVMCIRuntime jvmciRuntime, HotSpotGraalCompiler compiler, OptionValues options) {
this(jvmciRuntime, compiler, Options.Classpath.getValue(options),
Options.StartAt.getValue(options),
Options.StopAt.getValue(options),
Options.MethodFilter.getValue(options),
Options.ExcludeMethodFilter.getValue(options),
Options.Verbose.getValue(options),
options,
parseOptions(Options.Config.getValue(options)));
}
public void compile() throws Throwable {
if (SUN_BOOT_CLASS_PATH.equals(inputClassPath)) {
String bcpEntry = null;
if (Java8OrEarlier) {
final String[] entries = System.getProperty(SUN_BOOT_CLASS_PATH).split(File.pathSeparator);
for (int i = 0; i < entries.length && bcpEntry == null; i++) {
String entry = entries[i];
File entryFile = new File(entry);
if (entryFile.getName().endsWith("rt.jar") && entryFile.isFile()) {
bcpEntry = entry;
}
}
if (bcpEntry == null) {
throw new GraalError("Could not find rt.jar on boot class path %s", System.getProperty(SUN_BOOT_CLASS_PATH));
}
} else {
bcpEntry = JRT_CLASS_PATH_ENTRY;
}
compile(bcpEntry);
} else {
compile(inputClassPath);
}
}
public void println() {
println("");
}
public void println(String format, Object... args) {
println(String.format(format, args));
}
public void println(String s) {
println(verbose, s);
}
public static void println(boolean cond, String s) {
if (cond) {
TTY.println(s);
}
}
public void printStackTrace(Throwable t) {
if (verbose) {
t.printStackTrace(TTY.out);
}
}
@SuppressWarnings("unused")
private static void dummy() {
}
abstract static class ClassPathEntry implements Closeable {
final String name;
ClassPathEntry(String name) {
this.name = name;
}
public abstract ClassLoader createClassLoader() throws IOException;
public abstract List<String> getClassNames() throws IOException;
@Override
public String toString() {
return name;
}
@Override
public void close() throws IOException {
}
}
static class DirClassPathEntry extends ClassPathEntry {
private final File dir;
DirClassPathEntry(String name) {
super(name);
dir = new File(name);
assert dir.isDirectory();
}
@Override
public ClassLoader createClassLoader() throws IOException {
URL url = dir.toURI().toURL();
return new URLClassLoader(new URL[]{url});
}
@Override
public List<String> getClassNames() throws IOException {
List<String> classNames = new ArrayList<>();
String root = dir.getPath();
SimpleFileVisitor<Path> visitor = new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (attrs.isRegularFile()) {
File path = file.toFile();
if (path.getName().endsWith(".class")) {
String pathString = path.getPath();
assert pathString.startsWith(root);
String classFile = pathString.substring(root.length() + 1);
String className = classFile.replace(File.separatorChar, '.');
classNames.add(className.replace('/', '.').substring(0, className.length() - ".class".length()));
}
}
return super.visitFile(file, attrs);
}
};
Files.walkFileTree(dir.toPath(), visitor);
return classNames;
}
}
static class JarClassPathEntry extends ClassPathEntry {
private final JarFile jarFile;
JarClassPathEntry(String name) throws IOException {
super(name);
jarFile = new JarFile(name);
}
@Override
public ClassLoader createClassLoader() throws IOException {
URL url = new URL("jar", "", "file:" + name + "!/");
return new URLClassLoader(new URL[]{url});
}
static Pattern MultiReleaseJarVersionedClassRE = Pattern.compile("META-INF/versions/[1-9][0-9]*/(.+)");
@Override
public List<String> getClassNames() throws IOException {
Enumeration<JarEntry> e = jarFile.entries();
List<String> classNames = new ArrayList<>(jarFile.size());
while (e.hasMoreElements()) {
JarEntry je = e.nextElement();
if (je.isDirectory() || !je.getName().endsWith(".class")) {
continue;
}
String className = je.getName().substring(0, je.getName().length() - ".class".length());
if (className.equals("module-info")) {
continue;
}
if (className.startsWith("META-INF/versions/")) {
Matcher m = MultiReleaseJarVersionedClassRE.matcher(className);
if (m.matches()) {
className = m.group(1);
} else {
continue;
}
}
classNames.add(className.replace('/', '.'));
}
return classNames;
}
@Override
public void close() throws IOException {
jarFile.close();
}
}
static class JRTClassPathEntry extends ClassPathEntry {
private final String limitModules;
JRTClassPathEntry(String name, String limitModules) {
super(name);
this.limitModules = limitModules;
}
@Override
public ClassLoader createClassLoader() throws IOException {
URL url = URI.create("jrt:/").toURL();
return new URLClassLoader(new URL[]{url});
}
@Override
public List<String> getClassNames() throws IOException {
Set<String> negative = new HashSet<>();
Set<String> positive = new HashSet<>();
if (limitModules != null && !limitModules.isEmpty()) {
for (String s : limitModules.split(",")) {
if (s.startsWith("~")) {
negative.add(s.substring(1));
} else {
positive.add(s);
}
}
}
List<String> classNames = new ArrayList<>();
FileSystem fs = FileSystems.newFileSystem(URI.create("jrt:/"), Collections.emptyMap());
Path top = fs.getPath("/modules/");
Files.find(top, Integer.MAX_VALUE,
(path, attrs) -> attrs.isRegularFile()).forEach(p -> {
int nameCount = p.getNameCount();
if (nameCount > 2) {
String base = p.getName(nameCount - 1).toString();
if (base.endsWith(".class") && !base.equals("module-info.class")) {
String module = p.getName(1).toString();
if (positive.isEmpty() || positive.contains(module)) {
if (negative.isEmpty() || !negative.contains(module)) {
String className = p.subpath(2, nameCount).toString().replace('/', '.');
className = className.replace('/', '.').substring(0, className.length() - ".class".length());
classNames.add(className);
}
}
}
}
});
return classNames;
}
}
private boolean isClassIncluded(String className) {
if (methodFilters != null && !MethodFilter.matchesClassName(methodFilters, className)) {
return false;
}
if (excludeMethodFilters != null && MethodFilter.matchesClassName(excludeMethodFilters, className)) {
return false;
}
return true;
}
@SuppressWarnings("try")
private void compile(String classPath) throws IOException {
final String[] entries = classPath.split(File.pathSeparator);
long start = System.currentTimeMillis();
Map<Thread, StackTraceElement[]> initialThreads = Thread.getAllStackTraces();
try {
HotSpotResolvedJavaMethod dummyMethod = (HotSpotResolvedJavaMethod) JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess().lookupJavaMethod(
CompileTheWorld.class.getDeclaredMethod("dummy"));
int entryBCI = JVMCICompiler.INVOCATION_ENTRY_BCI;
boolean useProfilingInfo = false;
boolean installAsDefault = false;
CompilationTask task = new CompilationTask(jvmciRuntime, compiler, new HotSpotCompilationRequest(dummyMethod, entryBCI, 0L), useProfilingInfo, installAsDefault, currentOptions);
task.runCompilation();
} catch (NoSuchMethodException | SecurityException e1) {
printStackTrace(e1);
}
int threadCount = 1;
if (Options.MultiThreaded.getValue(currentOptions)) {
threadCount = Options.Threads.getValue(currentOptions);
if (threadCount == 0) {
threadCount = Runtime.getRuntime().availableProcessors();
}
} else {
running = true;
}
OptionValues savedOptions = currentOptions;
currentOptions = new OptionValues(compilationOptions);
threadPool = new ThreadPoolExecutor(threadCount, threadCount, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new CompilerThreadFactory("CompileTheWorld"));
try {
for (int i = 0; i < entries.length; i++) {
final String entry = entries[i];
ClassPathEntry cpe;
if (entry.endsWith(".zip") || entry.endsWith(".jar")) {
cpe = new JarClassPathEntry(entry);
} else if (entry.equals(JRT_CLASS_PATH_ENTRY)) {
cpe = new JRTClassPathEntry(entry, Options.LimitModules.getValue(currentOptions));
} else {
if (!new File(entry).isDirectory()) {
println("CompileTheWorld : Skipped classes in " + entry);
println();
continue;
}
cpe = new DirClassPathEntry(entry);
}
if (methodFilters == null || methodFilters.length == 0) {
println("CompileTheWorld : Compiling all classes in " + entry);
} else {
String include = Arrays.asList(methodFilters).stream().map(MethodFilter::toString).collect(Collectors.joining(", "));
println("CompileTheWorld : Compiling all methods in " + entry + " matching one of the following filters: " + include);
}
if (excludeMethodFilters != null && excludeMethodFilters.length > 0) {
String exclude = Arrays.asList(excludeMethodFilters).stream().map(MethodFilter::toString).collect(Collectors.joining(", "));
println("CompileTheWorld : Excluding all methods matching one of the following filters: " + exclude);
}
println();
ClassLoader loader = cpe.createClassLoader();
for (String className : cpe.getClassNames()) {
if (classFileCounter >= stopAt) {
break;
}
classFileCounter++;
if (className.startsWith("jdk.management.") ||
className.startsWith("jdk.internal.cmm.*") ||
className.startsWith("sun.tools.jconsole.")) {
continue;
}
if (!isClassIncluded(className)) {
continue;
}
try {
Class<?> javaClass = Class.forName(className, true, loader);
MetaAccessProvider metaAccess = JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess();
try {
HotSpotResolvedObjectType objectType = (HotSpotResolvedObjectType) metaAccess.lookupJavaType(javaClass);
ConstantPool constantPool = objectType.getConstantPool();
for (int cpi = 1; cpi < constantPool.length(); cpi++) {
constantPool.loadReferencedType(cpi, Bytecodes.LDC);
}
} catch (Throwable t) {
if (isClassIncluded(className)) {
println("Preloading failed for (%d) %s: %s", classFileCounter, className, t);
}
continue;
}
if (classFileCounter >= startAt) {
println("CompileTheWorld (%d) : %s", classFileCounter, className);
for (Constructor<?> constructor : javaClass.getDeclaredConstructors()) {
HotSpotResolvedJavaMethod javaMethod = (HotSpotResolvedJavaMethod) metaAccess.lookupJavaMethod(constructor);
if (canBeCompiled(javaMethod, constructor.getModifiers())) {
compileMethod(javaMethod);
}
}
for (Method method : javaClass.getDeclaredMethods()) {
HotSpotResolvedJavaMethod javaMethod = (HotSpotResolvedJavaMethod) metaAccess.lookupJavaMethod(method);
if (canBeCompiled(javaMethod, method.getModifiers())) {
compileMethod(javaMethod);
}
}
HotSpotResolvedJavaMethod clinit = (HotSpotResolvedJavaMethod) metaAccess.lookupJavaType(javaClass).getClassInitializer();
if (clinit != null && canBeCompiled(clinit, clinit.getModifiers())) {
compileMethod(clinit);
}
}
} catch (Throwable t) {
if (isClassIncluded(className)) {
println("CompileTheWorld (%d) : Skipping %s %s", classFileCounter, className, t.toString());
printStackTrace(t);
}
}
}
cpe.close();
}
} finally {
currentOptions = savedOptions;
}
if (!running) {
startThreads();
}
int wakeups = 0;
while (threadPool.getCompletedTaskCount() != threadPool.getTaskCount()) {
if (wakeups % 15 == 0) {
TTY.println("CompileTheWorld : Waiting for " + (threadPool.getTaskCount() - threadPool.getCompletedTaskCount()) + " compiles");
}
try {
threadPool.awaitTermination(1, TimeUnit.SECONDS);
wakeups++;
} catch (InterruptedException e) {
}
}
threadPool = null;
long elapsedTime = System.currentTimeMillis() - start;
println();
if (Options.MultiThreaded.getValue(currentOptions)) {
TTY.println("CompileTheWorld : Done (%d classes, %d methods, %d ms elapsed, %d ms compile time, %d bytes of memory used)", classFileCounter, compiledMethodsCounter.get(), elapsedTime,
compileTime.get(), memoryUsed.get());
} else {
TTY.println("CompileTheWorld : Done (%d classes, %d methods, %d ms, %d bytes of memory used)", classFileCounter, compiledMethodsCounter.get(), compileTime.get(), memoryUsed.get());
}
Map<Thread, StackTraceElement[]> suspiciousThreads = new HashMap<>();
for (Map.Entry<Thread, StackTraceElement[]> e : Thread.getAllStackTraces().entrySet()) {
Thread thread = e.getKey();
if (thread != Thread.currentThread() && !initialThreads.containsKey(thread) && !thread.isDaemon() && thread.isAlive()) {
suspiciousThreads.put(thread, e.getValue());
}
}
if (!suspiciousThreads.isEmpty()) {
TTY.println("--- Non-daemon threads started during CTW ---");
for (Map.Entry<Thread, StackTraceElement[]> e : suspiciousThreads.entrySet()) {
Thread thread = e.getKey();
if (thread.isAlive()) {
TTY.println(thread.toString() + " " + thread.getState());
for (StackTraceElement ste : e.getValue()) {
TTY.println("\tat " + ste);
}
}
}
TTY.println("---------------------------------------------");
}
}
private synchronized void startThreads() {
running = true;
notifyAll();
}
private synchronized void waitToRun() {
while (!running) {
try {
wait();
} catch (InterruptedException e) {
}
}
}
@SuppressWarnings("try")
private void compileMethod(HotSpotResolvedJavaMethod method) throws InterruptedException, ExecutionException {
if (methodFilters != null && !MethodFilter.matches(methodFilters, method)) {
return;
}
if (excludeMethodFilters != null && MethodFilter.matches(excludeMethodFilters, method)) {
return;
}
Future<?> task = threadPool.submit(new Runnable() {
@Override
public void run() {
waitToRun();
OptionValues savedOptions = currentOptions;
currentOptions = new OptionValues(compilationOptions);
try {
compileMethod(method, classFileCounter);
} finally {
currentOptions = savedOptions;
}
}
});
if (threadPool.getCorePoolSize() == 1) {
task.get();
}
}
private void compileMethod(HotSpotResolvedJavaMethod method, int counter) {
try {
long start = System.currentTimeMillis();
long allocatedAtStart = getCurrentThreadAllocatedBytes();
int entryBCI = JVMCICompiler.INVOCATION_ENTRY_BCI;
HotSpotCompilationRequest request = new HotSpotCompilationRequest(method, entryBCI, 0L);
boolean useProfilingInfo = false;
boolean installAsDefault = false;
CompilationTask task = new CompilationTask(jvmciRuntime, compiler, request, useProfilingInfo, installAsDefault, currentOptions);
task.runCompilation();
HotSpotInstalledCode installedCode = task.getInstalledCode();
if (installedCode != null) {
installedCode.invalidate();
}
memoryUsed.getAndAdd(getCurrentThreadAllocatedBytes() - allocatedAtStart);
compileTime.getAndAdd(System.currentTimeMillis() - start);
compiledMethodsCounter.incrementAndGet();
} catch (Throwable t) {
println("CompileTheWorld (%d) : Error compiling method: %s", counter, method.format("%H.%n(%p):%r"));
printStackTrace(t);
}
}
private boolean canBeCompiled(HotSpotResolvedJavaMethod javaMethod, int modifiers) {
if (Modifier.isAbstract(modifiers) || Modifier.isNative(modifiers)) {
return false;
}
GraalHotSpotVMConfig c = compiler.getGraalRuntime().getVMConfig();
if (c.dontCompileHugeMethods && javaMethod.getCodeSize() > c.hugeMethodLimit) {
println(verbose || methodFilters != null,
String.format("CompileTheWorld (%d) : Skipping huge method %s (use -XX:-DontCompileHugeMethods or -XX:HugeMethodLimit=%d to include it)", classFileCounter,
javaMethod.format("%H.%n(%p):%r"),
javaMethod.getCodeSize()));
return false;
}
if (!javaMethod.canBeInlined()) {
return false;
}
for (Annotation annotation : javaMethod.getAnnotations()) {
if (annotation.annotationType().equals(Snippet.class)) {
return false;
}
}
return true;
}
static class Options {
public static final OptionKey<Boolean> Help = new OptionKey<>(false);
public static final OptionKey<String> Classpath = new OptionKey<>(CompileTheWorld.SUN_BOOT_CLASS_PATH);
public static final OptionKey<Boolean> Verbose = new OptionKey<>(true);
public static final OptionKey<String> LimitModules = new OptionKey<>("~jdk.internal.vm.compiler");
public static final OptionKey<Integer> Iterations = new OptionKey<>(1);
public static final OptionKey<String> MethodFilter = new OptionKey<>(null);
public static final OptionKey<String> ExcludeMethodFilter = new OptionKey<>(null);
public static final OptionKey<Integer> StartAt = new OptionKey<>(1);
public static final OptionKey<Integer> StopAt = new OptionKey<>(Integer.MAX_VALUE);
public static final OptionKey<String> Config = new OptionKey<>(null);
public static final OptionKey<Boolean> MultiThreaded = new OptionKey<>(false);
public static final OptionKey<Integer> Threads = new OptionKey<>(0);
static final ReflectionOptionDescriptors DESCRIPTORS = new ReflectionOptionDescriptors(Options.class,
"Help", "List options and their help messages and then exit.",
"Classpath", "Class path denoting methods to compile. Default is to compile boot classes.",
"Verbose", "Verbose operation.",
"LimitModules", "Comma separated list of module names to which compilation should be limited. " +
"Module names can be prefixed with \"~\" to exclude the named module.",
"Iterations", "The number of iterations to perform.",
"MethodFilter", "Only compile methods matching this filter.",
"ExcludeMethodFilter", "Exclude methods matching this filter from compilation.",
"StartAt", "First class to consider for compilation.",
"StopAt", "Last class to consider for compilation.",
"Config", "Option value overrides to use during compile the world. For example, " +
"to disable inlining and partial escape analysis specify 'PartialEscapeAnalysis=false Inline=false'. " +
"The format for each option is the same as on the command line just without the '-Dgraal.' prefix.",
"MultiThreaded", "Run using multiple threads for compilation.",
"Threads", "Number of threads to use for multithreaded execution. Defaults to Runtime.getRuntime().availableProcessors().");
}
public static OptionValues loadOptions(OptionValues initialValues) {
EconomicMap<OptionKey<?>, Object> values = OptionValues.newOptionMap();
List<OptionDescriptors> loader = singletonList(DESCRIPTORS);
OptionsParser.parseOptions(extractEntries(System.getProperties(), "CompileTheWorld.", true), values, loader);
OptionValues options = new OptionValues(initialValues, values);
if (Options.Help.getValue(options)) {
options.printHelp(loader, System.out, "CompileTheWorld.");
System.exit(0);
}
return options;
}
public static void main(String[] args) throws Throwable {
HotSpotJVMCIRuntime jvmciRuntime = HotSpotJVMCIRuntime.runtime();
HotSpotGraalCompiler compiler = (HotSpotGraalCompiler) jvmciRuntime.getCompiler();
HotSpotGraalRuntimeProvider graalRuntime = compiler.getGraalRuntime();
HotSpotCodeCacheProvider codeCache = graalRuntime.getHostProviders().getCodeCache();
OptionValues options = loadOptions(graalRuntime.getOptions());
int iterations = Options.Iterations.getValue(options);
for (int i = 0; i < iterations; i++) {
codeCache.resetCompilationStatistics();
TTY.println("CompileTheWorld : iteration " + i);
CompileTheWorld ctw = new CompileTheWorld(jvmciRuntime, compiler, options);
ctw.compile();
}
System.exit(0);
}
}