mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8246095: Tweaks to memory access API
Add more user friendly API points to the foreign memory acesss API Reviewed-by: chegar, psandoz
This commit is contained in:
parent
eec7750e55
commit
f1e1cb7055
25 changed files with 1634 additions and 185 deletions
|
@ -5539,6 +5539,40 @@ System.out.println((int) f0.invokeExact("x", "y")); // 2
|
|||
throw newIllegalArgumentException("target and filter types do not match", targetType, filterType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the return value of a target method handle with a filter function. The filter function is
|
||||
* applied to the return value of the original handle; if the filter specifies more than one parameters,
|
||||
* then any remaining parameter is appended to the adapter handle. In other words, the adaptation works
|
||||
* as follows:
|
||||
* <blockquote><pre>{@code
|
||||
* T target(A...)
|
||||
* V filter(B... , T)
|
||||
* V adapter(A... a, B... b) {
|
||||
* T t = target(a...);
|
||||
* return filter(b..., t);
|
||||
* }</pre></blockquote>
|
||||
* <p>
|
||||
* If the filter handle is a unary function, then this method behaves like {@link #filterReturnValue(MethodHandle, MethodHandle)}.
|
||||
*
|
||||
* @param target the target method handle
|
||||
* @param filter the filter method handle
|
||||
* @return the adapter method handle
|
||||
*/
|
||||
/* package */ static MethodHandle collectReturnValue(MethodHandle target, MethodHandle filter) {
|
||||
MethodType targetType = target.type();
|
||||
MethodType filterType = filter.type();
|
||||
BoundMethodHandle result = target.rebind();
|
||||
LambdaForm lform = result.editor().collectReturnValueForm(filterType.basicType());
|
||||
MethodType newType = targetType.changeReturnType(filterType.returnType());
|
||||
if (filterType.parameterList().size() > 1) {
|
||||
for (int i = 0 ; i < filterType.parameterList().size() - 1 ; i++) {
|
||||
newType = newType.appendParameterTypes(filterType.parameterType(i));
|
||||
}
|
||||
}
|
||||
result = result.copyWithExtendL(newType, lform, filter);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapts a target method handle by pre-processing
|
||||
* some of its arguments, and then calling the target with
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue