On Wed, 22 Mar 2023 14:09:07 GMT, Per Minborg <pminb...@openjdk.org> wrote:

>> API changes for the FFM API (third preview)
>> 
>> Specdiff:
>> https://cr.openjdk.org/~pminborg/panama/21/v1/specdiff/overview-summary.html
>> 
>> Javadoc:
>> https://cr.openjdk.org/~pminborg/panama/21/v1/javadoc/java.base/module-summary.html
>
> Per Minborg has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Improve javadocs for Linker::captureStateLayout

src/java.base/share/classes/jdk/internal/foreign/abi/SharedUtils.java line 297:

> 295:         MethodType mtype = mh.type();
> 296:         int[] perms = new int[mtype.parameterCount()];
> 297:         MethodType swappedType = 
> MethodType.methodType(mtype.returnType());

Instead of `MethodType::appendParameterTypes(…)` (which performs an expensive 
lookup of a new cached `MethodType` value per call), this method should instead 
use a `Class<?>[]` for the arguments, which avoids that overhead inside a loop:

        public static MethodHandle swapArguments(MethodHandle mh, int firstArg, 
int secondArg) {
                MethodType mtype = mh.type();
                int[] perms = new int[mtype.parameterCount()];
                Class<?>[] ptypes = new Class<?>[perms.length];
                for (int i = 0 ; i < perms.length ; i++) {
                        int dst = i;
                        if (i == firstArg) dst = secondArg;
                        else if (i == secondArg) dst = firstArg;
                        perms[i] = dst;
                        ptypes[i] = mtype.parameterType(dst);
                }
                // This should use `JavaLangInvokeAccess` to invoke the internal
                // `MethodType.methodType(Class<?> rtype, Class<?>[] ptypes, 
boolean trusted)`
                // method with a `trusted` value of `true`:
                MethodType swappedType = 
MethodType.methodType(mtype.returnType(), ptypes);
                return permuteArguments(mh, swappedType, perms);
        }

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

> 59:     static final MemorySegment VOID_TYPE = 
> MemorySegment.ofAddress(ffi_type_void());
> 60:     static final short STRUCT_TAG = ffi_type_struct();
> 61:     private static final long SIZEOF_CIF = sizeofCif();

Won’t calling `ffi_default_abi()` (and the other `ffi_*()` methods) throw 
`UnsatisfiedLinkError` if `SUPPORTED` is `false`?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/13079#discussion_r1147259998
PR Review Comment: https://git.openjdk.org/jdk/pull/13079#discussion_r1147267292

Reply via email to