RFR: 8304265: Implementation of Foreign Function and Memory API (Third Preview) [v8]

Per Minborg pminborg at openjdk.org
Tue Mar 28 10:03:37 UTC 2023


On Fri, 24 Mar 2023 08:35:06 GMT, ExE Boss <duke at openjdk.org> wrote:

>> 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);
> 	}

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.

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

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



More information about the build-dev mailing list