Mercurial > hg > truffle
diff graal/com.oracle.nfi/src/com/oracle/nfi/NativeFunctionInterfaceRuntime.java @ 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 | 2f92172fa320 |
children |
line wrap: on
line diff
--- 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(); }