RFR: 8304265: Implementation of Foreign Function and Memory API (Third Preview) [v8]
ExE Boss
duke at openjdk.org
Fri Apr 7 07:34:54 UTC 2023
On Tue, 28 Mar 2023 10:00:28 GMT, Per Minborg <pminborg at openjdk.org> wrote:
>> 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);
>> }
>
> Thanks for this enhancement proposal. I hope you do not mind me asking if you could file a separate issue about this where you describe the above? We can then merge that proposal independent of this PR.
I don’t (yet) have a **JBS** account, so it’s painful to file issues because the **Java Bug Report** website[^1] doesn’t support neither **Markdown** nor **Jira** formatting (and also the `JI‑*` to `JDK‑*` issue transfer waiting time).
[^1]: https://bugreport.java.com/bugreport/
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13079#discussion_r1160504428
More information about the build-dev
mailing list