diff graal/com.oracle.truffle.api/src/com/oracle/truffle/api/Truffle.java @ 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 afa70d3e8159
children ffe693cc427f
line wrap: on
line diff
--- 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();
+            }
+        });
     }
 }