changeset 22806:a1f3697dd144

Option for specifying different compiler configurations for user and system compilations.
author Roland Schatz <roland.schatz@oracle.com>
date Tue, 13 Oct 2015 10:38:14 +0200
parents b058d6325c2e
children b62242b9ddd7
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalCompilerFactory.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntimeAccess.java
diffstat 2 files changed, 29 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalCompilerFactory.java	Mon Oct 12 20:05:18 2015 -0700
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalCompilerFactory.java	Tue Oct 13 10:38:14 2015 +0200
@@ -24,7 +24,6 @@
 
 import static jdk.vm.ci.inittimer.InitTimer.timer;
 import jdk.vm.ci.code.Architecture;
-import jdk.vm.ci.compiler.Compiler;
 import jdk.vm.ci.compiler.CompilerFactory;
 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
 import jdk.vm.ci.inittimer.InitTimer;
@@ -69,7 +68,7 @@
 
     @SuppressWarnings("try")
     @Override
-    public Compiler createCompiler(JVMCIRuntime runtime) {
+    public HotSpotGraalCompiler createCompiler(JVMCIRuntime runtime) {
         HotSpotJVMCIRuntime jvmciRuntime = (HotSpotJVMCIRuntime) runtime;
         try (InitTimer t = timer("HotSpotGraalRuntime.<init>")) {
             Lazy.registerBackends();
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntimeAccess.java	Mon Oct 12 20:05:18 2015 -0700
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntimeAccess.java	Tue Oct 13 10:38:14 2015 +0200
@@ -22,9 +22,14 @@
  */
 package com.oracle.graal.hotspot;
 
+import jdk.vm.ci.common.JVMCIError;
+import jdk.vm.ci.compiler.CompilerFactory;
 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntimeProvider;
+import jdk.vm.ci.options.Option;
+import jdk.vm.ci.options.OptionValue;
 import jdk.vm.ci.service.ServiceProvider;
+import jdk.vm.ci.service.Services;
 
 import com.oracle.graal.api.runtime.GraalRuntime;
 import com.oracle.graal.api.runtime.GraalRuntimeAccess;
@@ -32,10 +37,31 @@
 @ServiceProvider(GraalRuntimeAccess.class)
 public class HotSpotGraalRuntimeAccess implements GraalRuntimeAccess {
 
+    static class Options {
+        @Option(help = "") public static final OptionValue<String> UserCompiler = new OptionValue<>(null);
+    }
+
     @Override
     public GraalRuntime getRuntime() {
-        HotSpotJVMCIRuntimeProvider jvmciRuntime = HotSpotJVMCIRuntime.runtime();
-        HotSpotGraalCompiler compiler = (HotSpotGraalCompiler) jvmciRuntime.getCompiler();
+        HotSpotGraalCompiler compiler = getCompiler(Options.UserCompiler.getValue());
         return compiler.getGraalRuntime();
     }
+
+    private static HotSpotGraalCompiler getCompiler(String config) {
+        HotSpotJVMCIRuntimeProvider jvmciRuntime = HotSpotJVMCIRuntime.runtime();
+        if (config == null) {
+            // default: fall back to the JVMCI system compiler
+            return (HotSpotGraalCompiler) jvmciRuntime.getCompiler();
+        } else {
+            for (CompilerFactory factory : Services.load(CompilerFactory.class)) {
+                if (factory instanceof HotSpotGraalCompilerFactory) {
+                    HotSpotGraalCompilerFactory graalFactory = (HotSpotGraalCompilerFactory) factory;
+                    if (config.equals(factory.getCompilerName())) {
+                        return graalFactory.createCompiler(jvmciRuntime);
+                    }
+                }
+            }
+            throw new JVMCIError("Graal compiler configuration '" + config + "' not found");
+        }
+    }
 }