# HG changeset patch # User Matthias Grimmer # Date 1391093446 -3600 # Node ID 5fb138b6a92f1c68da055e8607ccb74e7a0cf60c # Parent beb735d1e5c3d0e7154da666b7505f9759cb2544 GNFI fixes diff -r beb735d1e5c3 -r 5fb138b6a92f graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/NativeFunctionHandle.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/NativeFunctionHandle.java Thu Jan 30 15:50:29 2014 +0100 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/NativeFunctionHandle.java Thu Jan 30 15:50:46 2014 +0100 @@ -24,7 +24,6 @@ /** * The function handle of a native foreign function. - * */ public interface NativeFunctionHandle { diff -r beb735d1e5c3 -r 5fb138b6a92f graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/NativeFunctionInterface.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/NativeFunctionInterface.java Thu Jan 30 15:50:29 2014 +0100 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/NativeFunctionInterface.java Thu Jan 30 15:50:46 2014 +0100 @@ -37,7 +37,8 @@ NativeLibraryHandle getLibraryHandle(String libPath); /** - * Resolves the NativeFunctionHandle of a native function that can be called. + * Resolves the NativeFunctionHandle of a native function that can be called. Use a + * {@code NativeFunctionHandle} to invoke the native target function. * * @param libraryHandle the handle to a resolved library * @param functionName the name of the function to be resolved @@ -48,7 +49,8 @@ NativeFunctionHandle getFunctionHandle(NativeLibraryHandle libraryHandle, String functionName, Class returnType, Class[] argumentTypes); /** - * Resolves the NativeFunctionHandle of a native function that can be called. + * Resolves the NativeFunctionHandle of a native function that can be called. Use a + * {@code NativeFunctionHandle} to invoke the native target function. * * @param functionPointer the function pointer * @param returnType the type of the return value @@ -58,7 +60,8 @@ NativeFunctionHandle getFunctionHandle(NativeFunctionPointer functionPointer, Class returnType, Class[] argumentTypes); /** - * Resolves the function pointer NativeFunctionPointer of a native function. + * Resolves the function pointer NativeFunctionPointer of a native function. A + * {@code NativeFunctionPointer} wraps the raw pointer value. * * @param libraryHandles the handles to a various resolved library, the first library containing * the method wins @@ -68,7 +71,8 @@ NativeFunctionPointer getFunctionPointer(NativeLibraryHandle[] libraryHandles, String functionName); /** - * Resolves the NativeFunctionHandle of a native function that can be called. + * Resolves the NativeFunctionHandle of a native function that can be called. Use a + * {@code NativeFunctionHandle} to invoke the native target function. * * @param libraryHandles the handles to a various resolved library, the first library containing * the method wins @@ -80,7 +84,8 @@ NativeFunctionHandle getFunctionHandle(NativeLibraryHandle[] libraryHandles, String functionName, Class returnType, Class[] argumentTypes); /** - * Resolves the NativeFunctionHandle of a native function that can be called. + * Resolves the NativeFunctionHandle of a native function that can be called. Use a + * {@code NativeFunctionHandle} to invoke the native target function. * * @param functionName the name of the function to be resolved * @param returnType the type of the return value @@ -90,7 +95,8 @@ NativeFunctionHandle getFunctionHandle(String functionName, Class returnType, Class[] argumentTypes); /** - * Creates NativeFunctionPointer from raw value. + * Creates NativeFunctionPointer from raw value. A {@code NativeFunctionPointer} + * wraps the raw pointer value. * * @param rawValue Raw pointer value * @return NativeFunctionPointer of the raw pointer diff -r beb735d1e5c3 -r 5fb138b6a92f graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/target/Backend.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/target/Backend.java Thu Jan 30 15:50:29 2014 +0100 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/target/Backend.java Thu Jan 30 15:50:46 2014 +0100 @@ -63,8 +63,6 @@ return providers.getCodeCache().getTarget(); } - public abstract NativeFunctionInterface getNativeFunctionInterface(); - public abstract FrameMap newFrameMap(); public abstract LIRGenerator newLIRGenerator(StructuredGraph graph, FrameMap frameMap, CallingConvention cc, LIR lir); diff -r beb735d1e5c3 -r 5fb138b6a92f graal/com.oracle.graal.ffi.amd64.test/test/com/oracle/graal/ffi/amd64/test/LibCallTest.java --- a/graal/com.oracle.graal.ffi.amd64.test/test/com/oracle/graal/ffi/amd64/test/LibCallTest.java Thu Jan 30 15:50:29 2014 +0100 +++ b/graal/com.oracle.graal.ffi.amd64.test/test/com/oracle/graal/ffi/amd64/test/LibCallTest.java Thu Jan 30 15:50:46 2014 +0100 @@ -30,13 +30,24 @@ import com.oracle.graal.api.code.*; import com.oracle.graal.api.runtime.*; +import com.oracle.graal.compiler.target.*; +import com.oracle.graal.graph.*; import com.oracle.graal.runtime.*; public class LibCallTest { protected static final Unsafe unsafe = getUnsafe(); - public static final RuntimeProvider runtimeProvider = Graal.getRequiredCapability(RuntimeProvider.class); - public static final NativeFunctionInterface ffi = runtimeProvider.getHostBackend().getNativeFunctionInterface(); + public final RuntimeProvider runtimeProvider; + public final NativeFunctionInterface ffi; + + public LibCallTest() { + this.runtimeProvider = Graal.getRequiredCapability(RuntimeProvider.class); + if (runtimeProvider.getHostBackend() instanceof HostBackend) { + ffi = ((HostBackend) runtimeProvider.getHostBackend()).getNativeFunctionInterface(); + } else { + throw GraalInternalError.shouldNotReachHere("Cannot initialize GNFI - backend is not a HostBackend"); + } + } @Test public void test() { diff -r beb735d1e5c3 -r 5fb138b6a92f graal/com.oracle.graal.ffi.amd64.test/test/com/oracle/graal/ffi/amd64/test/MathLibCallTest.java --- a/graal/com.oracle.graal.ffi.amd64.test/test/com/oracle/graal/ffi/amd64/test/MathLibCallTest.java Thu Jan 30 15:50:29 2014 +0100 +++ b/graal/com.oracle.graal.ffi.amd64.test/test/com/oracle/graal/ffi/amd64/test/MathLibCallTest.java Thu Jan 30 15:50:46 2014 +0100 @@ -28,8 +28,8 @@ public class MathLibCallTest extends LibCallTest { - static final Object[] args = new Object[]{Double.doubleToLongBits(3), Double.doubleToLongBits(5.5)}; - static final NativeFunctionHandle handle = ffi.getFunctionHandle("pow", double.class, new Class[]{double.class, double.class}); + private final Object[] args = new Object[]{Double.doubleToLongBits(3), Double.doubleToLongBits(5.5)}; + private final NativeFunctionHandle handle = ffi.getFunctionHandle("pow", double.class, new Class[]{double.class, double.class}); @Test public void powTest() { @@ -47,7 +47,7 @@ } - private static double callPow() { + private double callPow() { return (double) handle.call(args); } } diff -r beb735d1e5c3 -r 5fb138b6a92f graal/com.oracle.graal.ffi.amd64/src/com/oracle/graal/ffi/amd64/util/InstallUtil.java --- a/graal/com.oracle.graal.ffi.amd64/src/com/oracle/graal/ffi/amd64/util/InstallUtil.java Thu Jan 30 15:50:29 2014 +0100 +++ b/graal/com.oracle.graal.ffi.amd64/src/com/oracle/graal/ffi/amd64/util/InstallUtil.java Thu Jan 30 15:50:46 2014 +0100 @@ -67,7 +67,7 @@ PhaseSuite phaseSuite = backend.getSuites().getDefaultGraphBuilderSuite().copy(); CallingConvention cc = getCallingConvention(providers.getCodeCache(), Type.JavaCallee, g.method(), false); CompilationResult compResult = GraalCompiler.compileGraph(g, cc, g.method(), providers, backend, backend.getTarget(), null, phaseSuite, OptimisticOptimizations.ALL, - DefaultProfilingInfo.get(TriState.UNKNOWN), new SpeculationLog(), suites, true, new CompilationResult(), CompilationResultBuilderFactory.Default); + DefaultProfilingInfo.get(TriState.UNKNOWN), null, suites, true, new CompilationResult(), CompilationResultBuilderFactory.Default); InstalledCode installedCode; try (Scope s = Debug.scope("CodeInstall", providers.getCodeCache(), g.method())) { installedCode = providers.getCodeCache().addMethod(g.method(), compResult, null); diff -r beb735d1e5c3 -r 5fb138b6a92f graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java Thu Jan 30 15:50:29 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java Thu Jan 30 15:50:46 2014 +0100 @@ -41,6 +41,7 @@ import com.oracle.graal.compiler.gen.*; import com.oracle.graal.compiler.target.*; import com.oracle.graal.ffi.amd64.*; +import com.oracle.graal.graph.*; import com.oracle.graal.hotspot.*; import com.oracle.graal.hotspot.bridge.*; import com.oracle.graal.hotspot.meta.*; @@ -314,7 +315,7 @@ AMD64NativeFunctionPointer functionLookupPointer = new AMD64NativeFunctionPointer(getRuntime().getConfig().functionLookupAddress, "GNFI_UTIL_FUNCTIONLOOKUP"); AMD64NativeLibraryHandle rtldDefault = new AMD64NativeLibraryHandle(getRuntime().getConfig().rtldDefault); if (!libraryLoadPointer.isValid() || !functionLookupPointer.isValid()) { - throw new AssertionError("Lookup Pointers null"); + throw GraalInternalError.shouldNotReachHere("Lookup Pointers null"); } return new AMD64NativeFunctionInterface(this.getProviders(), this, libraryLoadPointer, functionLookupPointer, rtldDefault); } diff -r beb735d1e5c3 -r 5fb138b6a92f graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java Thu Jan 30 15:50:29 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java Thu Jan 30 15:50:46 2014 +0100 @@ -353,6 +353,8 @@ public void emitCCall(long address, CallingConvention nativeCallingConvention, Value[] args, int numberOfFloatingPointArguments) { Value[] argLocations = new Value[args.length]; frameMap.callsMethod(nativeCallingConvention); + // TODO(mg): in case a native function uses floating point varargs, the ABI requires that + // RAX contains the length of the varargs AllocatableValue numberOfFloatingPointArgumentsRegister = AMD64.rax.asValue(); emitMove(numberOfFloatingPointArgumentsRegister, Constant.forInt(numberOfFloatingPointArguments)); for (int i = 0; i < args.length; i++) { diff -r beb735d1e5c3 -r 5fb138b6a92f graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend.java Thu Jan 30 15:50:29 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend.java Thu Jan 30 15:50:46 2014 +0100 @@ -414,9 +414,4 @@ codeBuffer.emitString0("};"); codeBuffer.emitString(""); } - - @Override - public NativeFunctionInterface getNativeFunctionInterface() { - throw GraalInternalError.unimplemented("No NativeFunctionInterface of HSAIL"); - } } diff -r beb735d1e5c3 -r 5fb138b6a92f graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java Thu Jan 30 15:50:29 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java Thu Jan 30 15:50:46 2014 +0100 @@ -484,10 +484,4 @@ private static native int getAvailableProcessors0(); - - @Override - public NativeFunctionInterface getNativeFunctionInterface() { - throw GraalInternalError.unimplemented("No NativeFunctionInterface of PTX"); - } - } diff -r beb735d1e5c3 -r 5fb138b6a92f graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackend.java Thu Jan 30 15:50:29 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackend.java Thu Jan 30 15:50:46 2014 +0100 @@ -32,6 +32,7 @@ import com.oracle.graal.asm.sparc.*; import com.oracle.graal.asm.sparc.SPARCAssembler.*; import com.oracle.graal.compiler.gen.LIRGenerator; +import com.oracle.graal.graph.*; import com.oracle.graal.hotspot.*; import com.oracle.graal.hotspot.bridge.*; import com.oracle.graal.hotspot.meta.*; diff -r beb735d1e5c3 -r 5fb138b6a92f mx/eclipseinit.timestamp diff -r beb735d1e5c3 -r 5fb138b6a92f src/share/vm/graal/graalCompilerToVM.cpp --- a/src/share/vm/graal/graalCompilerToVM.cpp Thu Jan 30 15:50:29 2014 +0100 +++ b/src/share/vm/graal/graalCompilerToVM.cpp Thu Jan 30 15:50:46 2014 +0100 @@ -554,7 +554,7 @@ //------------------------------------------------------------------------------------------------ set_int("graalCountersThreadOffset", in_bytes(JavaThread::graal_counters_offset())); - set_int("graalCountersSize", (jint) GraalCounterSize);\ + set_int("graalCountersSize", (jint) GraalCounterSize); //------------------------------------------------------------------------------------------------