changeset 9935:2a091d2987bd

added graal.options mechanism for being able to override default option values
author Doug Simon <doug.simon@oracle.com>
date Fri, 07 Jun 2013 15:59:09 +0200
parents 44fcf49b746f
children 0927013db134
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotOptions.java make/Makefile make/build-graal.xml mx/commands.py
diffstat 4 files changed, 66 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotOptions.java	Fri Jun 07 10:52:48 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotOptions.java	Fri Jun 07 15:59:09 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<String, OptionDescriptor> options = new HashMap<>();
 
-    static {
+    /**
+     * Initializes {@link #options} from {@link Options} services.
+     */
+    private static void initializeOptions() {
         ServiceLoader<Options> 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) {
--- a/make/Makefile	Fri Jun 07 10:52:48 2013 +0200
+++ b/make/Makefile	Fri Jun 07 15:59:09 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)
--- a/make/build-graal.xml	Fri Jun 07 10:52:48 2013 +0200
+++ b/make/build-graal.xml	Fri Jun 07 15:59:09 2013 +0200
@@ -28,7 +28,7 @@
   <property name="classes.dir" value="${shared.dir}/graal"/>
   <property name="jar.dir" value="${shared.dir}"/>
   <property name="jar.file" value="${jar.dir}/graal.jar"/>
-  <target depends="jar" name="main"/>
+  <target depends="jar,options" name="main"/>
   <target depends="cleanclasses" name="compile">
     <mkdir dir="${classes.dir}"/>
     <javac debug="on" destdir="${classes.dir}" includeantruntime="false">
@@ -101,6 +101,11 @@
   <target name="cleanclasses">
     <delete dir="${classes.dir}"/>
   </target>
+  <target name="options">
+    <copy todir="${jar.dir}">
+      <filelist dir="${gamma.dir}" files="graal.options"/>
+    </copy>
+  </target>
   <target depends="cleanclasses" name="clean">
     <delete file="${jar.file}"/>
   </target>
--- a/mx/commands.py	Fri Jun 07 10:52:48 2013 +0200
+++ b/mx/commands.py	Fri Jun 07 15:59:09 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')