changeset 21894:91b861398ad6

removed dependency from NFI to JVMCI
author Doug Simon <doug.simon@oracle.com>
date Wed, 10 Jun 2015 16:10:26 +0200
parents db885c930362
children 763db13bd6f4
files graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/nfi/HotSpotNativeFunctionInterfaceAccess.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 mx/suite.py
diffstat 5 files changed, 25 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/nfi/HotSpotNativeFunctionInterfaceAccess.java	Wed Jun 10 12:07:31 2015 +0200
+++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/nfi/HotSpotNativeFunctionInterfaceAccess.java	Wed Jun 10 16:10:26 2015 +0200
@@ -27,7 +27,7 @@
 import com.oracle.nfi.api.*;
 
 @ServiceProvider(NativeFunctionInterfaceAccess.class)
-public class HotSpotNativeFunctionInterfaceAccess implements NativeFunctionInterfaceAccess {
+public class HotSpotNativeFunctionInterfaceAccess implements NativeFunctionInterfaceAccess, Service {
     private final NativeFunctionInterface instance = HotSpotTruffleRuntime.createNativeFunctionInterface();
 
     public NativeFunctionInterface getNativeFunctionInterface() {
--- a/graal/com.oracle.nfi/src/com/oracle/nfi/NativeFunctionInterfaceRuntime.java	Wed Jun 10 12:07:31 2015 +0200
+++ b/graal/com.oracle.nfi/src/com/oracle/nfi/NativeFunctionInterfaceRuntime.java	Wed Jun 10 16:10:26 2015 +0200
@@ -22,7 +22,8 @@
  */
 package com.oracle.nfi;
 
-import com.oracle.jvmci.service.*;
+import java.lang.reflect.*;
+
 import com.oracle.nfi.api.*;
 
 /**
@@ -43,7 +44,24 @@
     static {
 
         NativeFunctionInterface instance = null;
-        NativeFunctionInterfaceAccess access = Services.loadSingle(NativeFunctionInterfaceAccess.class, false);
+
+        NativeFunctionInterfaceAccess access = null;
+        Class<?> servicesClass = null;
+        try {
+            servicesClass = Class.forName("com.oracle.jvmci.service.Services");
+        } catch (ClassNotFoundException e) {
+            // JVMCI is unavailable
+        }
+        if (servicesClass != null) {
+            try {
+                Method m = servicesClass.getDeclaredMethod("loadSingle", Class.class, boolean.class);
+                access = (NativeFunctionInterfaceAccess) m.invoke(null, NativeFunctionInterfaceAccess.class, false);
+            } catch (Throwable e) {
+                // Fail fast for other errors
+                throw (InternalError) new InternalError().initCause(e);
+            }
+        }
+        // TODO: try standard ServiceLoader?
         if (access != null) {
             instance = access.getNativeFunctionInterface();
         }
--- a/graal/com.oracle.nfi/src/com/oracle/nfi/api/NativeFunctionInterface.java	Wed Jun 10 12:07:31 2015 +0200
+++ b/graal/com.oracle.nfi/src/com/oracle/nfi/api/NativeFunctionInterface.java	Wed Jun 10 16:10:26 2015 +0200
@@ -22,14 +22,12 @@
  */
 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 extends Service {
+public interface NativeFunctionInterface {
 
     /**
      * Resolves and returns a handle to an open native library. This method will open the library
--- a/graal/com.oracle.nfi/src/com/oracle/nfi/api/NativeFunctionInterfaceAccess.java	Wed Jun 10 12:07:31 2015 +0200
+++ b/graal/com.oracle.nfi/src/com/oracle/nfi/api/NativeFunctionInterfaceAccess.java	Wed Jun 10 16:10:26 2015 +0200
@@ -22,13 +22,10 @@
  */
 package com.oracle.nfi.api;
 
-import com.oracle.jvmci.service.*;
-
 /**
- * A {@linkplain Service JVMCI service} that provides access to a {@link NativeFunctionInterface}
- * implementation.
+ * A service that provides access to a {@link NativeFunctionInterface} implementation.
  */
-public interface NativeFunctionInterfaceAccess extends Service {
+public interface NativeFunctionInterfaceAccess {
 
     /**
      * Gets the {@link NativeFunctionInterface} implementation available via this access object.
--- a/mx/suite.py	Wed Jun 10 12:07:31 2015 +0200
+++ b/mx/suite.py	Wed Jun 10 16:10:26 2015 +0200
@@ -398,7 +398,6 @@
     "com.oracle.nfi" : {
       "subDir" : "graal",
       "sourceDirs" : ["src"],
-      "dependencies" : ["com.oracle.jvmci.service"],
       "checkstyle" : "com.oracle.graal.graph",
       "javaCompliance" : "1.7",
     },
@@ -1359,6 +1358,7 @@
       ],
       "exclude" : ["FINDBUGS"],
       "distDependencies" : [
+        "JVMCI_SERVICE",
         "JVMCI_HOTSPOT",
         "TRUFFLE",
       ],
@@ -1375,9 +1375,6 @@
         "com.oracle.truffle.object.basic",
         "com.oracle.truffle.tools"
       ],
-      "distDependencies" : [
-        "JVMCI_SERVICE",
-      ],
     },
 
     "GRAAL_TRUFFLE" : {