# HG changeset patch # User Doug Simon # Date 1370618881 -7200 # Node ID 63bae87147dfe815d9bbdb95e94f933981a940fe # Parent 4f5e5bb0318457f009021be970b1f0a0fe9ebdf9# Parent 78a1232be4184532139abbb9bca213e9abe6c23e Merge. diff -r 78a1232be418 -r 63bae87147df graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Fri Jun 07 16:10:07 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Fri Jun 07 17:28:01 2013 +0200 @@ -31,6 +31,7 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.api.runtime.*; import com.oracle.graal.compiler.target.*; +import com.oracle.graal.graph.*; import com.oracle.graal.hotspot.bridge.*; import com.oracle.graal.hotspot.logging.*; import com.oracle.graal.hotspot.meta.*; @@ -87,9 +88,11 @@ runtime.compilerToVm = toVM; } + private static final String DEFAULT_GRAAL_RUNTIME = "basic"; + // @formatter:off @Option(help = "The runtime configuration to use") - private static final OptionValue GraalRuntime = new OptionValue<>("basic"); + private static final OptionValue GraalRuntime = new OptionValue<>(DEFAULT_GRAAL_RUNTIME); // @formatter:on protected static HotSpotGraalRuntimeFactory findFactory(String architecture) { @@ -98,6 +101,11 @@ return factory; } } + if (!DEFAULT_GRAAL_RUNTIME.equals(GraalRuntime.getValue())) { + // Fail fast if a non-default value for GraalRuntime was specified + // and the corresponding factory is not available + throw new GraalInternalError("Specified runtime \"%s\" not available for the %s architecture", GraalRuntime.getValue(), architecture); + } return null; } diff -r 78a1232be418 -r 63bae87147df graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotOptions.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotOptions.java Fri Jun 07 16:10:07 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotOptions.java Fri Jun 07 17:28:01 2013 +0200 @@ -23,16 +23,28 @@ package com.oracle.graal.hotspot; +import static java.nio.file.Files.*; + +import java.io.*; +import java.nio.charset.*; +import java.nio.file.*; import java.util.*; import com.oracle.graal.hotspot.logging.*; import com.oracle.graal.options.*; +/** + * Called from {@code graalCompiler.cpp} to parse any Graal specific options. Such options are + * (currently) distinguished by a {@code "-G:"} prefix. + */ public class HotSpotOptions { private static final Map options = new HashMap<>(); - static { + /** + * Initializes {@link #options} from {@link Options} services. + */ + private static void initializeOptions() { ServiceLoader sl = ServiceLoader.loadInstalled(Options.class); for (Options opts : sl) { for (OptionDescriptor desc : opts) { @@ -45,6 +57,38 @@ } } + /** + * Loads default option value overrides from a {@code graal.options} file if it exists. Each + * line in this file starts with {@code "#"} and is ignored or must have the format of a Graal + * command line option without the leading {@code "-G:"} prefix. These option value are set + * prior to processing of any Graal options present on the command line. + */ + private static void loadOptionOverrides() throws InternalError { + String javaHome = System.getProperty("java.home"); + Path graalDotOptions = Paths.get(javaHome, "lib", "graal.options"); + if (!exists(graalDotOptions)) { + graalDotOptions = Paths.get(javaHome, "jre", "lib", "graal.options"); + } + if (exists(graalDotOptions)) { + try { + for (String line : Files.readAllLines(graalDotOptions, Charset.defaultCharset())) { + if (!line.startsWith("#")) { + if (!setOption(line)) { + throw new InternalError("Invalid option \"" + line + "\" specified in " + graalDotOptions); + } + } + } + } catch (IOException e) { + throw (InternalError) new InternalError().initCause(e); + } + } + } + + static { + initializeOptions(); + loadOptionOverrides(); + } + // Called from VM code public static boolean setOption(String option) { if (option.length() == 0) { diff -r 78a1232be418 -r 63bae87147df graal/com.oracle.graal.options/src/com/oracle/graal/options/OptionProcessor.java --- a/graal/com.oracle.graal.options/src/com/oracle/graal/options/OptionProcessor.java Fri Jun 07 16:10:07 2013 +0200 +++ b/graal/com.oracle.graal.options/src/com/oracle/graal/options/OptionProcessor.java Fri Jun 07 17:28:01 2013 +0200 @@ -159,7 +159,7 @@ String help = option.help; String location = pkg + "." + option.declaringClass + "." + option.field.getSimpleName(); String comma = i == info.options.size() - 1 ? "" : ","; - out.printf(" new %s(\"%s\", %s.class, \"%s\", \"%s\", %s)%s%n", OptionDescriptor.class.getSimpleName(), name, type, help, location, optionValue, comma); + out.printf(" new %s(\"%s\", %s.class, \"%s\", \"%s\", %s)%s\n", OptionDescriptor.class.getSimpleName(), name, type, help, location, optionValue, comma); i++; } out.println(" );"); diff -r 78a1232be418 -r 63bae87147df make/Makefile --- a/make/Makefile Fri Jun 07 16:10:07 2013 +0200 +++ b/make/Makefile Fri Jun 07 17:28:01 2013 +0200 @@ -516,6 +516,10 @@ $(EXPORT_JRE_LIB_DIR)/%.jar: $(SHARED_DIR)/%.jar $(install-file) +# Shared options files +$(EXPORT_JRE_LIB_DIR)/%.options: $(SHARED_DIR)/%.options + $(install-file) + # Include files (jvmti.h, jvmticmlr.h, jni.h, $(JDK_INCLUDE_SUBDIR)/jni_md.h, jmm.h, jfr.h) $(EXPORT_INCLUDE_DIR)/%: $(GEN_DIR)/jvmtifiles/% $(install-file) diff -r 78a1232be418 -r 63bae87147df make/build-graal.xml --- a/make/build-graal.xml Fri Jun 07 16:10:07 2013 +0200 +++ b/make/build-graal.xml Fri Jun 07 17:28:01 2013 +0200 @@ -28,7 +28,7 @@ - + @@ -101,6 +101,11 @@ + + + + + diff -r 78a1232be418 -r 63bae87147df mx/commands.py --- a/mx/commands.py Fri Jun 07 16:10:07 2013 +0200 +++ b/mx/commands.py Fri Jun 07 17:28:01 2013 +0200 @@ -343,6 +343,7 @@ def _installGraalJarInJdks(graalDist): graalJar = graalDist.path + graalOptions = join(_graal_home, 'graal.options') jdks = join(_graal_home, 'jdk' + str(mx.java().version)) if exists(jdks): for e in os.listdir(jdks): @@ -353,6 +354,9 @@ shutil.copyfile(graalJar, tmp) os.close(fd) shutil.move(tmp, join(jreLibDir, 'graal.jar')) + + if exists(graalOptions): + shutil.copy(graalOptions, join(jreLibDir, 'graal.options')) # run a command in the windows SDK Debug Shell def _runInDebugShell(cmd, workingDir, logFile=None, findInOutput=None, respondTo={}): @@ -458,7 +462,7 @@ out.element('property', {'name' : 'jar.dir', 'value' : '${shared.dir}'}) out.element('property', {'name' : 'jar.file', 'value' : '${jar.dir}/graal.jar'}) - out.element('target', {'name' : 'main', 'depends' : 'jar'}) + out.element('target', {'name' : 'main', 'depends' : 'jar,options'}) serviceMap = {}; def addService(service, provider): @@ -513,6 +517,12 @@ out.element('delete', {'dir' : '${classes.dir}'}) out.close('target') + out.open('target', {'name' : 'options'}) + out.open('copy', {'todir' : '${jar.dir}'}) + out.element('filelist', {'dir' : '${gamma.dir}', 'files' : 'graal.options'}) + out.close('copy') + out.close('target') + out.open('target', {'name' : 'clean', 'depends' : 'cleanclasses'}) out.element('delete', {'file' : '${jar.file}'}) out.close('target')