# HG changeset patch # User Matthias Grimmer # Date 1391588796 -3600 # Node ID e2db5c351ef3624f41168610d93f0d4ecb9e5c5d # Parent e30bae026c936bf937cdb8fcc1cb3453a4dab0c2 GNFI: cache lookup handles diff -r e30bae026c93 -r e2db5c351ef3 graal/com.oracle.graal.ffi.amd64/src/com/oracle/graal/ffi/amd64/AMD64NativeFunctionInterface.java --- a/graal/com.oracle.graal.ffi.amd64/src/com/oracle/graal/ffi/amd64/AMD64NativeFunctionInterface.java Wed Feb 05 09:24:23 2014 +0100 +++ b/graal/com.oracle.graal.ffi.amd64/src/com/oracle/graal/ffi/amd64/AMD64NativeFunctionInterface.java Wed Feb 05 09:26:36 2014 +0100 @@ -45,6 +45,9 @@ protected final AMD64NativeFunctionPointer libraryLoadFunctionPointer; protected final AMD64NativeFunctionPointer functionLookupFunctionPointer; + private AMD64NativeFunctionHandle libraryLookupFunctionHandle; + private AMD64NativeFunctionHandle dllLookupFunctionHandle; + public AMD64NativeFunctionInterface(HotSpotProviders providers, Backend backend, AMD64NativeFunctionPointer libraryLoadFunctionPointer, AMD64NativeFunctionPointer functionLookUpFunctionPointer, AMD64NativeLibraryHandle rtldDefault) { this.rtldDefault = rtldDefault; @@ -56,8 +59,9 @@ @Override public AMD64NativeLibraryHandle getLibraryHandle(String libPath) { - AMD64NativeFunctionHandle libraryLookupFunctionHandle = new AMD64NativeFunctionHandle(providers, backend, libraryLoadFunctionPointer, long.class, - new Class[]{long.class, long.class, int.class}); + if (libraryLookupFunctionHandle == null) { + libraryLookupFunctionHandle = new AMD64NativeFunctionHandle(providers, backend, libraryLoadFunctionPointer, long.class, new Class[]{long.class, long.class, int.class}); + } long allocatedMemory = -1; try { @@ -106,7 +110,9 @@ if (!functionLookupFunctionPointer.isValid()) { throw new IllegalStateException("no dlsym function pointer"); } - AMD64NativeFunctionHandle dllLookupFunctionHandle = new AMD64NativeFunctionHandle(providers, backend, functionLookupFunctionPointer, LOOKUP_FUNCTION_RETURNTYPE, LOOKUP_FUNCTION_SIGNATURE); + if (dllLookupFunctionHandle == null) { + dllLookupFunctionHandle = new AMD64NativeFunctionHandle(providers, backend, functionLookupFunctionPointer, LOOKUP_FUNCTION_RETURNTYPE, LOOKUP_FUNCTION_SIGNATURE); + } long allocatedMemory = copyStringToMemory(functionName); Object[] args = new Object[]{handle, allocatedMemory}; long functionPointer = (long) dllLookupFunctionHandle.call(args);