< prev index next >

src/java.base/share/classes/jdk/internal/foreign/abi/fallback/LibFallback.java

Print this page

 48                         } catch (UnsatisfiedLinkError ule) {
 49                             return false;
 50                         }
 51                     }
 52                 });
 53     }
 54 
 55     static int defaultABI() { return NativeConstants.DEFAULT_ABI; }
 56 
 57     static MemorySegment uint8Type() { return NativeConstants.UINT8_TYPE; }
 58     static MemorySegment sint8Type() { return NativeConstants.SINT8_TYPE; }
 59     static MemorySegment uint16Type() { return NativeConstants.UINT16_TYPE; }
 60     static MemorySegment sint16Type() { return NativeConstants.SINT16_TYPE; }
 61     static MemorySegment sint32Type() { return NativeConstants.SINT32_TYPE; }
 62     static MemorySegment sint64Type() { return NativeConstants.SINT64_TYPE; }
 63     static MemorySegment floatType() { return NativeConstants.FLOAT_TYPE; }
 64     static MemorySegment doubleType() { return NativeConstants.DOUBLE_TYPE; }
 65     static MemorySegment pointerType() { return NativeConstants.POINTER_TYPE; }
 66     static MemorySegment voidType() { return NativeConstants.VOID_TYPE; }
 67 






 68     static short structTag() { return NativeConstants.STRUCT_TAG; }
 69 
 70     private static final MethodType UPCALL_TARGET_TYPE = MethodType.methodType(void.class, MemorySegment.class, MemorySegment.class);
 71 
 72     /**
 73      * Do a libffi based downcall. This method wraps the {@code ffi_call} function
 74      *
 75      * @param cif a pointer to a {@code ffi_cif} struct
 76      * @param target the address of the target function
 77      * @param retPtr a pointer to a buffer into which the return value shall be written, or {@code null} if the target
 78      *               function does not return a value
 79      * @param argPtrs a pointer to an array of pointers, which each point to an argument value
 80      * @param capturedState a pointer to a buffer into which captured state is written, or {@code null} if no state is
 81      *                      to be captured
 82      * @param capturedStateMask the bit mask indicating which state to capture
 83      *
 84      * @see jdk.internal.foreign.abi.CapturableState
 85      */
 86     static void doDowncall(MemorySegment cif, MemorySegment target, MemorySegment retPtr, MemorySegment argPtrs,
 87                                   MemorySegment capturedState, int capturedStateMask) {

205 
206     private static native int ffi_prep_cif(long cif, int abi, int nargs, long rtype, long atypes);
207     private static native int ffi_prep_cif_var(long cif, int abi, int nfixedargs, int ntotalargs, long rtype, long atypes);
208     private static native int ffi_get_struct_offsets(int abi, long type, long offsets);
209 
210     private static native int ffi_default_abi();
211     private static native short ffi_type_struct();
212 
213     private static native long ffi_type_void();
214     private static native long ffi_type_uint8();
215     private static native long ffi_type_sint8();
216     private static native long ffi_type_uint16();
217     private static native long ffi_type_sint16();
218     private static native long ffi_type_uint32();
219     private static native long ffi_type_sint32();
220     private static native long ffi_type_uint64();
221     private static native long ffi_type_sint64();
222     private static native long ffi_type_float();
223     private static native long ffi_type_double();
224     private static native long ffi_type_pointer();




225 
226     // put these in a separate class to avoid an UnsatisfiedLinkError
227     // when LibFallback is initialized but the library is not present
228     private static final class NativeConstants {
229         private NativeConstants() {}
230 
231         static final int DEFAULT_ABI = ffi_default_abi();
232 
233         static final MemorySegment UINT8_TYPE = MemorySegment.ofAddress(ffi_type_uint8());
234         static final MemorySegment SINT8_TYPE = MemorySegment.ofAddress(ffi_type_sint8());
235         static final MemorySegment UINT16_TYPE = MemorySegment.ofAddress(ffi_type_uint16());
236         static final MemorySegment SINT16_TYPE = MemorySegment.ofAddress(ffi_type_sint16());
237         static final MemorySegment SINT32_TYPE = MemorySegment.ofAddress(ffi_type_sint32());
238         static final MemorySegment SINT64_TYPE = MemorySegment.ofAddress(ffi_type_sint64());
239         static final MemorySegment FLOAT_TYPE = MemorySegment.ofAddress(ffi_type_float());
240         static final MemorySegment DOUBLE_TYPE = MemorySegment.ofAddress(ffi_type_double());
241         static final MemorySegment POINTER_TYPE = MemorySegment.ofAddress(ffi_type_pointer());





242 
243         static final MemorySegment VOID_TYPE = MemorySegment.ofAddress(ffi_type_void());
244         static final short STRUCT_TAG = ffi_type_struct();
245         static final long SIZEOF_CIF = sizeofCif();
246     }
247 }

 48                         } catch (UnsatisfiedLinkError ule) {
 49                             return false;
 50                         }
 51                     }
 52                 });
 53     }
 54 
 55     static int defaultABI() { return NativeConstants.DEFAULT_ABI; }
 56 
 57     static MemorySegment uint8Type() { return NativeConstants.UINT8_TYPE; }
 58     static MemorySegment sint8Type() { return NativeConstants.SINT8_TYPE; }
 59     static MemorySegment uint16Type() { return NativeConstants.UINT16_TYPE; }
 60     static MemorySegment sint16Type() { return NativeConstants.SINT16_TYPE; }
 61     static MemorySegment sint32Type() { return NativeConstants.SINT32_TYPE; }
 62     static MemorySegment sint64Type() { return NativeConstants.SINT64_TYPE; }
 63     static MemorySegment floatType() { return NativeConstants.FLOAT_TYPE; }
 64     static MemorySegment doubleType() { return NativeConstants.DOUBLE_TYPE; }
 65     static MemorySegment pointerType() { return NativeConstants.POINTER_TYPE; }
 66     static MemorySegment voidType() { return NativeConstants.VOID_TYPE; }
 67 
 68     // platform-dependent types
 69     static int shortSize() { return NativeConstants.SIZEOF_SHORT; }
 70     static int intSize() { return NativeConstants.SIZEOF_INT; }
 71     static int longSize() {return NativeConstants.SIZEOF_LONG; }
 72     static int wcharSize() {return NativeConstants.SIZEOF_WCHAR; }
 73 
 74     static short structTag() { return NativeConstants.STRUCT_TAG; }
 75 
 76     private static final MethodType UPCALL_TARGET_TYPE = MethodType.methodType(void.class, MemorySegment.class, MemorySegment.class);
 77 
 78     /**
 79      * Do a libffi based downcall. This method wraps the {@code ffi_call} function
 80      *
 81      * @param cif a pointer to a {@code ffi_cif} struct
 82      * @param target the address of the target function
 83      * @param retPtr a pointer to a buffer into which the return value shall be written, or {@code null} if the target
 84      *               function does not return a value
 85      * @param argPtrs a pointer to an array of pointers, which each point to an argument value
 86      * @param capturedState a pointer to a buffer into which captured state is written, or {@code null} if no state is
 87      *                      to be captured
 88      * @param capturedStateMask the bit mask indicating which state to capture
 89      *
 90      * @see jdk.internal.foreign.abi.CapturableState
 91      */
 92     static void doDowncall(MemorySegment cif, MemorySegment target, MemorySegment retPtr, MemorySegment argPtrs,
 93                                   MemorySegment capturedState, int capturedStateMask) {

211 
212     private static native int ffi_prep_cif(long cif, int abi, int nargs, long rtype, long atypes);
213     private static native int ffi_prep_cif_var(long cif, int abi, int nfixedargs, int ntotalargs, long rtype, long atypes);
214     private static native int ffi_get_struct_offsets(int abi, long type, long offsets);
215 
216     private static native int ffi_default_abi();
217     private static native short ffi_type_struct();
218 
219     private static native long ffi_type_void();
220     private static native long ffi_type_uint8();
221     private static native long ffi_type_sint8();
222     private static native long ffi_type_uint16();
223     private static native long ffi_type_sint16();
224     private static native long ffi_type_uint32();
225     private static native long ffi_type_sint32();
226     private static native long ffi_type_uint64();
227     private static native long ffi_type_sint64();
228     private static native long ffi_type_float();
229     private static native long ffi_type_double();
230     private static native long ffi_type_pointer();
231     private static native int ffi_sizeof_short();
232     private static native int ffi_sizeof_int();
233     private static native int ffi_sizeof_long();
234     private static native int ffi_sizeof_wchar();
235 
236     // put these in a separate class to avoid an UnsatisfiedLinkError
237     // when LibFallback is initialized but the library is not present
238     private static final class NativeConstants {
239         private NativeConstants() {}
240 
241         static final int DEFAULT_ABI = ffi_default_abi();
242 
243         static final MemorySegment UINT8_TYPE = MemorySegment.ofAddress(ffi_type_uint8());
244         static final MemorySegment SINT8_TYPE = MemorySegment.ofAddress(ffi_type_sint8());
245         static final MemorySegment UINT16_TYPE = MemorySegment.ofAddress(ffi_type_uint16());
246         static final MemorySegment SINT16_TYPE = MemorySegment.ofAddress(ffi_type_sint16());
247         static final MemorySegment SINT32_TYPE = MemorySegment.ofAddress(ffi_type_sint32());
248         static final MemorySegment SINT64_TYPE = MemorySegment.ofAddress(ffi_type_sint64());
249         static final MemorySegment FLOAT_TYPE = MemorySegment.ofAddress(ffi_type_float());
250         static final MemorySegment DOUBLE_TYPE = MemorySegment.ofAddress(ffi_type_double());
251         static final MemorySegment POINTER_TYPE = MemorySegment.ofAddress(ffi_type_pointer());
252         static final int SIZEOF_SHORT = ffi_sizeof_short();
253         static final int SIZEOF_INT = ffi_sizeof_int();
254         static final int SIZEOF_LONG = ffi_sizeof_long();
255         static final int SIZEOF_WCHAR = ffi_sizeof_wchar();
256 
257 
258         static final MemorySegment VOID_TYPE = MemorySegment.ofAddress(ffi_type_void());
259         static final short STRUCT_TAG = ffi_type_struct();
260         static final long SIZEOF_CIF = sizeofCif();
261     }
262 }
< prev index next >