changeset 21614:2f92172fa320

Truffle and NFI implementations are now accessed via JVMCI services instead of being hard coded in the VM (JBS:GRAAL-51)
author Doug Simon <doug.simon@oracle.com>
date Sun, 31 May 2015 13:42:47 +0200
parents 60154926b513
children 838f005f9aec
files graal/com.oracle.graal.api.runtime/src/com/oracle/graal/api/runtime/Graal.java graal/com.oracle.graal.api.runtime/src/com/oracle/graal/api/runtime/GraalRuntimeAccess.java graal/com.oracle.graal.api.runtime/src/com/oracle/graal/api/runtime/GraalRuntimeFactory.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntimeAccess.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntimeFactory.java graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntimeAccess.java graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/nfi/HotSpotNativeFunctionInterfaceAccess.java graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Services.java graal/com.oracle.nfi/src/com/oracle/nfi/NativeFunctionInterfaceRuntime.java graal/com.oracle.nfi/src/com/oracle/nfi/api/NativeFunctionInterface.java graal/com.oracle.nfi/src/com/oracle/nfi/api/NativeFunctionInterfaceAccess.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/Truffle.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleRuntimeAccess.java make/defs.make mx/suite.py src/share/vm/jvmci/jvmciRuntime.cpp src/share/vm/prims/nativeLookup.cpp
diffstat 18 files changed, 298 insertions(+), 142 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.api.runtime/src/com/oracle/graal/api/runtime/Graal.java	Sun May 31 12:32:15 2015 +0200
+++ b/graal/com.oracle.graal.api.runtime/src/com/oracle/graal/api/runtime/Graal.java	Sun May 31 13:42:47 2015 +0200
@@ -36,12 +36,9 @@
     private static final GraalRuntime runtime = initializeRuntime();
 
     private static GraalRuntime initializeRuntime() {
-        GraalRuntime rt = null;
-        for (GraalRuntimeFactory factory : Services.load(GraalRuntimeFactory.class)) {
-            assert rt == null : String.format("Multiple %s implementations found: %s, %s", GraalRuntime.class.getName(), rt.getClass().getName(), factory.getRuntime().getClass().getName());
-            rt = factory.getRuntime();
-        }
-        if (rt != null) {
+        GraalRuntimeAccess access = Services.loadSingle(GraalRuntimeAccess.class, false);
+        if (access != null) {
+            GraalRuntime rt = access.getRuntime();
             // The constant is patched in-situ by the build system
             System.setProperty("graal.version", "@@graal.version@@".trim());
             assert !System.getProperty("graal.version").startsWith("@@") && !System.getProperty("graal.version").endsWith("@@") : "Graal version string constant was not patched by build system";
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.api.runtime/src/com/oracle/graal/api/runtime/GraalRuntimeAccess.java	Sun May 31 13:42:47 2015 +0200
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.api.runtime;
+
+import com.oracle.jvmci.service.*;
+
+/**
+ * A {@linkplain Service JVMCI service} that provides access to a {@link GraalRuntime}
+ * implementation.
+ */
+public interface GraalRuntimeAccess extends Service {
+
+    /**
+     * Gets the {@link GraalRuntime} implementation available via this access object.
+     */
+    GraalRuntime getRuntime();
+}
--- a/graal/com.oracle.graal.api.runtime/src/com/oracle/graal/api/runtime/GraalRuntimeFactory.java	Sun May 31 12:32:15 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.graal.api.runtime;
-
-import com.oracle.jvmci.service.*;
-
-public interface GraalRuntimeFactory extends Service {
-
-    GraalRuntime getRuntime();
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntimeAccess.java	Sun May 31 13:42:47 2015 +0200
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.hotspot;
+
+import com.oracle.graal.api.runtime.*;
+import com.oracle.jvmci.service.*;
+
+@ServiceProvider(GraalRuntimeAccess.class)
+public class HotSpotGraalRuntimeAccess implements GraalRuntimeAccess {
+
+    @Override
+    public GraalRuntime getRuntime() {
+        return HotSpotGraalRuntime.runtime();
+    }
+}
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntimeFactory.java	Sun May 31 12:32:15 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.graal.hotspot;
-
-import com.oracle.graal.api.runtime.*;
-import com.oracle.jvmci.service.*;
-
-@ServiceProvider(GraalRuntimeFactory.class)
-public class HotSpotGraalRuntimeFactory implements GraalRuntimeFactory {
-
-    @Override
-    public GraalRuntime getRuntime() {
-        return HotSpotGraalRuntime.runtime();
-    }
-}
--- a/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java	Sun May 31 12:32:15 2015 +0200
+++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java	Sun May 31 13:42:47 2015 +0200
@@ -354,9 +354,6 @@
         return null;
     }
 
-    /**
-     * Called from the VM.
-     */
     public static NativeFunctionInterface createNativeFunctionInterface() {
         HotSpotVMConfig config = HotSpotGraalRuntime.runtime().getConfig();
         Backend backend = HotSpotGraalRuntime.runtime().getHostBackend();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntimeAccess.java	Sun May 31 13:42:47 2015 +0200
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.truffle.hotspot;
+
+import com.oracle.jvmci.service.*;
+import com.oracle.truffle.api.*;
+
+@ServiceProvider(TruffleRuntimeAccess.class)
+public class HotSpotTruffleRuntimeAccess implements TruffleRuntimeAccess {
+    public TruffleRuntime getRuntime() {
+        return HotSpotTruffleRuntime.makeInstance();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/nfi/HotSpotNativeFunctionInterfaceAccess.java	Sun May 31 13:42:47 2015 +0200
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.truffle.hotspot.nfi;
+
+import com.oracle.graal.truffle.hotspot.*;
+import com.oracle.jvmci.service.*;
+import com.oracle.nfi.api.*;
+
+@ServiceProvider(NativeFunctionInterfaceAccess.class)
+public class HotSpotNativeFunctionInterfaceAccess implements NativeFunctionInterfaceAccess {
+    private final NativeFunctionInterface instance = HotSpotTruffleRuntime.createNativeFunctionInterface();
+
+    public NativeFunctionInterface getNativeFunctionInterface() {
+        return instance;
+    }
+}
--- a/graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Services.java	Sun May 31 12:32:15 2015 +0200
+++ b/graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Services.java	Sun May 31 13:42:47 2015 +0200
@@ -29,9 +29,10 @@
 import sun.reflect.*;
 
 /**
- * A mechanism on top of the standard {@link ServiceLoader} that enables a runtime to efficiently
- * load services marked by {@link Service}. This may be important for services loaded early in the
- * runtime initialization process.
+ * A mechanism on top of the standard {@link ServiceLoader} that enables JVMCI enabled runtime to
+ * efficiently load services marked by {@link Service}. This is important to avoid the performance
+ * overhead of the standard service loader mechanism for services loaded in the runtime
+ * initialization process.
  */
 public class Services {
 
@@ -54,6 +55,7 @@
     @SuppressWarnings("unchecked")
     @CallerSensitive
     public static <S> Iterable<S> load(Class<S> service) {
+        // TODO(ds): add SecurityManager checks
         if (Service.class.isAssignableFrom(service)) {
             try {
                 return (Iterable<S>) cache.get(service);
@@ -67,5 +69,50 @@
         return ServiceLoader.load(service, cl);
     }
 
+    /**
+     * Gets the implementation for a given service for which at most one implementation must be
+     * available.
+     *
+     * @param service the service whose implementation is being requested
+     * @param required specifies if an {@link InternalError} should be thrown if no implementation
+     *            of {@code service} is available
+     */
+    @SuppressWarnings("unchecked")
+    @CallerSensitive
+    public static <S> S loadSingle(Class<S> service, boolean required) {
+        // TODO(ds): add SecurityManager checks
+        Iterable<S> impls = null;
+        if (Service.class.isAssignableFrom(service)) {
+            try {
+                impls = (Iterable<S>) cache.get(service);
+            } catch (UnsatisfiedLinkError e) {
+                // Fall back to standard ServiceLoader
+            }
+        }
+
+        if (impls == null) {
+            // Need to use the ClassLoader of the caller
+            ClassLoader cl = Reflection.getCallerClass().getClassLoader();
+            impls = ServiceLoader.load(service, cl);
+        }
+        S singleImpl = null;
+        for (S impl : impls) {
+            if (singleImpl != null) {
+                throw new InternalError(String.format("Multiple %s implementations found: %s, %s", service.getName(), singleImpl.getClass().getName(), impl.getClass().getName()));
+            }
+            singleImpl = impl;
+        }
+        if (singleImpl == null && required) {
+            String javaHome = System.getProperty("java.home");
+            String vmName = System.getProperty("java.vm.name");
+            Formatter errorMessage = new Formatter();
+            errorMessage.format("The VM does not expose required service %s.%n", service.getName());
+            errorMessage.format("Currently used Java home directory is %s.%n", javaHome);
+            errorMessage.format("Currently used VM configuration is: %s", vmName);
+            throw new UnsupportedOperationException(errorMessage.toString());
+        }
+        return singleImpl;
+    }
+
     private static native <S> S[] getServiceImpls(Class<?> service);
 }
--- a/graal/com.oracle.nfi/src/com/oracle/nfi/NativeFunctionInterfaceRuntime.java	Sun May 31 12:32:15 2015 +0200
+++ b/graal/com.oracle.nfi/src/com/oracle/nfi/NativeFunctionInterfaceRuntime.java	Sun May 31 13:42:47 2015 +0200
@@ -22,6 +22,7 @@
  */
 package com.oracle.nfi;
 
+import com.oracle.jvmci.service.*;
 import com.oracle.nfi.api.*;
 
 /**
@@ -31,14 +32,6 @@
     private static final NativeFunctionInterface INSTANCE;
 
     /**
-     * Creates a new {@link NativeFunctionInterface}.
-     *
-     * @throws UnsatisfiedLinkError if not running on a VM that provides a
-     *             {@link NativeFunctionInterface}
-     */
-    private static native NativeFunctionInterface createInterface();
-
-    /**
      * Gets the {@link NativeFunctionInterface} (if any) provided by the VM.
      *
      * @return null if the VM does not provide a {@link NativeFunctionInterface}
@@ -48,11 +41,11 @@
     }
 
     static {
-        NativeFunctionInterface instance;
-        try {
-            instance = createInterface();
-        } catch (UnsatisfiedLinkError e) {
-            instance = null;
+
+        NativeFunctionInterface instance = null;
+        NativeFunctionInterfaceAccess access = Services.loadSingle(NativeFunctionInterfaceAccess.class, false);
+        if (access != null) {
+            instance = access.getNativeFunctionInterface();
         }
         INSTANCE = instance;
     }
--- a/graal/com.oracle.nfi/src/com/oracle/nfi/api/NativeFunctionInterface.java	Sun May 31 12:32:15 2015 +0200
+++ b/graal/com.oracle.nfi/src/com/oracle/nfi/api/NativeFunctionInterface.java	Sun May 31 13:42:47 2015 +0200
@@ -22,12 +22,14 @@
  */
 package com.oracle.nfi.api;
 
+import com.oracle.jvmci.service.*;
+
 /**
  * Interface to get a {@linkplain NativeFunctionHandle handle} or {@linkplain NativeFunctionPointer
  * pointer} to a native function or a {@linkplain NativeLibraryHandle handle} to an open native
  * library.
  */
-public interface NativeFunctionInterface {
+public interface NativeFunctionInterface extends Service {
 
     /**
      * Resolves and returns a handle to an open native library. This method will open the library
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.nfi/src/com/oracle/nfi/api/NativeFunctionInterfaceAccess.java	Sun May 31 13:42:47 2015 +0200
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.nfi.api;
+
+import com.oracle.jvmci.service.*;
+
+/**
+ * A {@linkplain Service JVMCI service} that provides access to a {@link NativeFunctionInterface}
+ * implementation.
+ */
+public interface NativeFunctionInterfaceAccess extends Service {
+
+    /**
+     * Gets the {@link NativeFunctionInterface} implementation available via this access object.
+     */
+    NativeFunctionInterface getNativeFunctionInterface();
+}
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/Truffle.java	Sun May 31 12:32:15 2015 +0200
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/Truffle.java	Sun May 31 13:42:47 2015 +0200
@@ -26,6 +26,7 @@
 
 import java.security.*;
 
+import com.oracle.jvmci.service.*;
 import com.oracle.truffle.api.impl.*;
 
 /**
@@ -36,14 +37,8 @@
     private static final TruffleRuntime RUNTIME = initRuntime();
 
     /**
-     * Creates a new {@link TruffleRuntime} instance if the runtime has a specialized
-     * implementation.
-     *
-     * @throws UnsatisfiedLinkError if the runtime does not have a specialized implementation of
-     *             {@link TruffleRuntime}
+     * Gets the singleton {@link TruffleRuntime} object.
      */
-    private static native TruffleRuntime createRuntime();
-
     public static TruffleRuntime getRuntime() {
         return RUNTIME;
     }
@@ -57,14 +52,14 @@
             return new DefaultTruffleRuntime();
         }
 
-        try {
-            return AccessController.doPrivileged(new PrivilegedAction<TruffleRuntime>() {
-                public TruffleRuntime run() {
-                    return createRuntime();
+        return AccessController.doPrivileged(new PrivilegedAction<TruffleRuntime>() {
+            public TruffleRuntime run() {
+                TruffleRuntimeAccess access = Services.loadSingle(TruffleRuntimeAccess.class, false);
+                if (access != null) {
+                    return access.getRuntime();
                 }
-            });
-        } catch (UnsatisfiedLinkError e) {
-            return new DefaultTruffleRuntime();
-        }
+                return new DefaultTruffleRuntime();
+            }
+        });
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleRuntimeAccess.java	Sun May 31 13:42:47 2015 +0200
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.truffle.api;
+
+import com.oracle.jvmci.service.*;
+
+/**
+ * A {@linkplain Service JVMCI service} that provides access to a {@link TruffleRuntime}
+ * implementation.
+ */
+public interface TruffleRuntimeAccess extends Service {
+
+    /**
+     * Gets the {@link TruffleRuntime} implementation available via this access object.
+     */
+    TruffleRuntime getRuntime();
+}
--- a/make/defs.make	Sun May 31 12:32:15 2015 +0200
+++ b/make/defs.make	Sun May 31 13:42:47 2015 +0200
@@ -369,7 +369,7 @@
 EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_SERVICES_DIR)/com.oracle.jvmci.hotspot.HotSpotVMEventListener
 EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_SERVICES_DIR)/com.oracle.jvmci.debug.DebugInitializationPropertyProvider
 
-EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_SERVICES_DIR)/com.oracle.graal.api.runtime.GraalRuntimeFactory
+EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_SERVICES_DIR)/com.oracle.graal.api.runtime.GraalRuntimeAccess
 EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_SERVICES_DIR)/com.oracle.graal.compiler.match.MatchStatementSet
 EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_SERVICES_DIR)/com.oracle.graal.hotspot.HotSpotBackendFactory
 EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_SERVICES_DIR)/com.oracle.graal.nodes.spi.ReplacementsProvider
@@ -377,6 +377,9 @@
 EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_SERVICES_DIR)/com.oracle.graal.truffle.hotspot.nfi.RawNativeCallNodeFactory
 EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_SERVICES_DIR)/com.oracle.graal.truffle.OptimizedCallTargetInstrumentationFactory
 
+EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_SERVICES_DIR)/com.oracle.truffle.api.TruffleRuntimeAccess
+EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_SERVICES_DIR)/com.oracle.nfi.api.NativeFunctionInterfaceAccess
+
 EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_OPTIONS_DIR)/com.oracle.jvmci.hotspot.HotSpotConstantReflectionProvider
 EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_OPTIONS_DIR)/com.oracle.jvmci.hotspot.HotSpotJVMCIRuntime
 EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_OPTIONS_DIR)/com.oracle.jvmci.hotspot.HotSpotResolvedJavaFieldImpl
--- a/mx/suite.py	Sun May 31 12:32:15 2015 +0200
+++ b/mx/suite.py	Sun May 31 13:42:47 2015 +0200
@@ -203,7 +203,7 @@
     "com.oracle.nfi" : {
       "subDir" : "graal",
       "sourceDirs" : ["src"],
-      "dependencies" : [],
+      "dependencies" : ["com.oracle.jvmci.service"],
       "checkstyle" : "com.oracle.graal.graph",
       "javaCompliance" : "1.7",
     },
@@ -992,7 +992,7 @@
     "com.oracle.truffle.api" : {
       "subDir" : "graal",
       "sourceDirs" : ["src"],
-      "dependencies" : [],
+      "dependencies" : ["com.oracle.jvmci.service"],
       "javaCompliance" : "1.7",
       "workingSets" : "API,Truffle",
     },
@@ -1302,6 +1302,9 @@
         "com.oracle.truffle.interop",
         "com.oracle.truffle.object.basic",
       ],
+      "distDependencies" : [
+        "JVMCI_SERVICE",
+      ],
     },
 
     "GRAAL_TRUFFLE" : {
--- a/src/share/vm/jvmci/jvmciRuntime.cpp	Sun May 31 12:32:15 2015 +0200
+++ b/src/share/vm/jvmci/jvmciRuntime.cpp	Sun May 31 13:42:47 2015 +0200
@@ -644,32 +644,6 @@
   return JNIHandles::make_local(THREAD, JVMCIRuntime::get_service_impls(serviceKlass, THREAD)());
 JVM_END
 
-// private static TruffleRuntime Truffle.createRuntime()
-JVM_ENTRY(jobject, JVM_CreateTruffleRuntime(JNIEnv *env, jclass c))
-  JVMCIRuntime::ensure_jvmci_class_loader_is_initialized();
-  TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime", CHECK_NULL);
-  KlassHandle klass = JVMCIRuntime::resolve_or_fail(name, CHECK_NULL);
-
-  TempNewSymbol makeInstance = SymbolTable::new_symbol("makeInstance", CHECK_NULL);
-  TempNewSymbol sig = SymbolTable::new_symbol("()Lcom/oracle/truffle/api/TruffleRuntime;", CHECK_NULL);
-  JavaValue result(T_OBJECT);
-  JavaCalls::call_static(&result, klass, makeInstance, sig, CHECK_NULL);
-  return JNIHandles::make_local(THREAD, (oop) result.get_jobject());
-JVM_END
-
-// private static NativeFunctionInterfaceRuntime.createInterface()
-JVM_ENTRY(jobject, JVM_CreateNativeFunctionInterface(JNIEnv *env, jclass c))
-  JVMCIRuntime::ensure_jvmci_class_loader_is_initialized();
-  TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime", CHECK_NULL);
-  KlassHandle klass = JVMCIRuntime::resolve_or_fail(name, CHECK_NULL);
-
-  TempNewSymbol makeInstance = SymbolTable::new_symbol("createNativeFunctionInterface", CHECK_NULL);
-  TempNewSymbol sig = SymbolTable::new_symbol("()Lcom/oracle/nfi/api/NativeFunctionInterface;", CHECK_NULL);
-  JavaValue result(T_OBJECT);
-  JavaCalls::call_static(&result, klass, makeInstance, sig, CHECK_NULL);
-  return JNIHandles::make_local(THREAD, (oop) result.get_jobject());
-JVM_END
-
 Handle JVMCIRuntime::callInitializer(const char* className, const char* methodName, const char* returnType) {
   guarantee(!_HotSpotJVMCIRuntime_initialized, "cannot reinitialize HotSpotJVMCIRuntime");
   Thread* THREAD = Thread::current();
--- a/src/share/vm/prims/nativeLookup.cpp	Sun May 31 12:32:15 2015 +0200
+++ b/src/share/vm/prims/nativeLookup.cpp	Sun May 31 13:42:47 2015 +0200
@@ -132,11 +132,6 @@
   jobject  JNICALL JVM_GetJVMCIRuntime(JNIEnv *env, jclass c);
   jobject  JNICALL JVM_GetJVMCIRuntime(JNIEnv *env, jclass c);
   jobject  JNICALL JVM_GetJVMCIServiceImpls(JNIEnv *env, jclass c, jclass serviceClass);
-  jobject  JNICALL JVM_CreateTruffleRuntime(JNIEnv *env, jclass c);
-  jobject  JNICALL JVM_CreateNativeFunctionInterface(JNIEnv *env, jclass c);
-#ifdef COMPILERJVMCI
-  void     JNICALL JVM_PrintAndResetJVMCICompRate(JNIEnv *env, jclass c);
-#endif
 #endif
 }
 
@@ -152,8 +147,6 @@
   { CC"Java_com_oracle_jvmci_service_JVMCIClassLoaderFactory_init",            NULL, FN_PTR(JVM_InitJVMCIClassLoader)               },
   { CC"Java_com_oracle_jvmci_runtime_JVMCI_initializeRuntime",                 NULL, FN_PTR(JVM_GetJVMCIRuntime)                    },
   { CC"Java_com_oracle_jvmci_service_Services_getServiceImpls",                NULL, FN_PTR(JVM_GetJVMCIServiceImpls)               },
-  { CC"Java_com_oracle_truffle_api_Truffle_createRuntime",                     NULL, FN_PTR(JVM_CreateTruffleRuntime)               },
-  { CC"Java_com_oracle_nfi_NativeFunctionInterfaceRuntime_createInterface",    NULL, FN_PTR(JVM_CreateNativeFunctionInterface)      },
   { CC"Java_com_oracle_jvmci_hotspot_CompilerToVMImpl_init",                   NULL, FN_PTR(JVM_InitializeJVMCINatives)             },
 #endif
 };