src/share/classes/java/lang/invoke/MethodHandle.java
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File
jdk Cdiff src/share/classes/java/lang/invoke/MethodHandle.java
src/share/classes/java/lang/invoke/MethodHandle.java
Print this page
rev 10273 : 8049555: Move varargsArray from sun.invoke.util package to java.lang.invoke
Reviewed-by: ?
rev 10274 : 8050052: Small cleanups in java.lang.invoke code
Reviewed-by: ?
rev 10275 : 8050053: Improve caching of different invokers
Reviewed-by: vlivanov, ?
Contributed-by: john.r.rose@oracle.com
rev 10276 : 8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
Reviewed-by: vlivanov, ?
Contributed-by: john.r.rose@oracle.com
*** 764,774 ****
/** Override this to change asType behavior. */
/*non-public*/ MethodHandle asTypeUncached(MethodType newType) {
if (!type.isConvertibleTo(newType))
throw new WrongMethodTypeException("cannot convert "+this+" to "+newType);
! return asTypeCache = convertArguments(newType);
}
/**
* Makes an <em>array-spreading</em> method handle, which accepts a trailing array argument
* and spreads its elements as positional arguments.
--- 764,774 ----
/** Override this to change asType behavior. */
/*non-public*/ MethodHandle asTypeUncached(MethodType newType) {
if (!type.isConvertibleTo(newType))
throw new WrongMethodTypeException("cannot convert "+this+" to "+newType);
! return asTypeCache = MethodHandleImpl.makePairwiseConvert(this, newType, 1);
}
/**
* Makes an <em>array-spreading</em> method handle, which accepts a trailing array argument
* and spreads its elements as positional arguments.
*** 977,987 ****
public MethodHandle asCollector(Class<?> arrayType, int arrayLength) {
asCollectorChecks(arrayType, arrayLength);
int collectArgPos = type().parameterCount()-1;
MethodHandle target = this;
if (arrayType != type().parameterType(collectArgPos))
! target = convertArguments(type().changeParameterType(collectArgPos, arrayType));
MethodHandle collector = MethodHandleImpl.varargsArray(arrayType, arrayLength);
return MethodHandles.collectArguments(target, collectArgPos, collector);
}
/**
--- 977,987 ----
public MethodHandle asCollector(Class<?> arrayType, int arrayLength) {
asCollectorChecks(arrayType, arrayLength);
int collectArgPos = type().parameterCount()-1;
MethodHandle target = this;
if (arrayType != type().parameterType(collectArgPos))
! target = MethodHandleImpl.makePairwiseConvert(this, type().changeParameterType(collectArgPos, arrayType), 1);
MethodHandle collector = MethodHandleImpl.varargsArray(arrayType, arrayLength);
return MethodHandles.collectArguments(target, collectArgPos, collector);
}
/**
*** 1250,1267 ****
* @throws ClassCastException if {@code x} cannot be converted
* to the leading parameter type of the target
* @see MethodHandles#insertArguments
*/
public MethodHandle bindTo(Object x) {
! Class<?> ptype;
! @SuppressWarnings("LocalVariableHidesMemberVariable")
! MethodType type = type();
! if (type.parameterCount() == 0 ||
! (ptype = type.parameterType(0)).isPrimitive())
! throw newIllegalArgumentException("no leading reference parameter", x);
! x = ptype.cast(x); // throw CCE if needed
! return bindReceiver(x);
}
/**
* Returns a string representation of the method handle,
* starting with the string {@code "MethodHandle"} and
--- 1250,1261 ----
* @throws ClassCastException if {@code x} cannot be converted
* to the leading parameter type of the target
* @see MethodHandles#insertArguments
*/
public MethodHandle bindTo(Object x) {
! x = type.leadingReferenceParameter().cast(x); // throw CCE if needed
! return bindArgumentL(0, x);
}
/**
* Returns a string representation of the method handle,
* starting with the string {@code "MethodHandle"} and
*** 1296,1305 ****
--- 1290,1303 ----
//// Sub-classes can override these default implementations.
//// All these methods assume arguments are already validated.
// Other transforms to do: convert, explicitCast, permute, drop, filter, fold, GWT, catch
+ BoundMethodHandle bindArgumentL(int pos, Object value) {
+ return rebind().bindArgumentL(pos, value);
+ }
+
/*non-public*/
MethodHandle setVarargs(MemberName member) throws IllegalAccessException {
if (!member.isVarargs()) return this;
Class<?> arrayType = type().lastParameterType();
if (arrayType.isArray()) {
*** 1364,1404 ****
//// Method handle implementation methods.
//// Sub-classes can override these default implementations.
//// All these methods assume arguments are already validated.
- /*non-public*/ MethodHandle convertArguments(MethodType newType) {
- // Override this if it can be improved.
- return MethodHandleImpl.makePairwiseConvert(this, newType, 1);
- }
-
- /*non-public*/
- MethodHandle bindArgument(int pos, BasicType basicType, Object value) {
- // Override this if it can be improved.
- return rebind().bindArgument(pos, basicType, value);
- }
-
- /*non-public*/
- MethodHandle bindReceiver(Object receiver) {
- // Override this if it can be improved.
- return bindArgument(0, L_TYPE, receiver);
- }
-
- /*non-public*/
- MethodHandle dropArguments(MethodType srcType, int pos, int drops) {
- // Override this if it can be improved.
- return rebind().dropArguments(srcType, pos, drops);
- }
-
- /*non-public*/
- MethodHandle permuteArguments(MethodType newType, int[] reorder) {
- // Override this if it can be improved.
- return rebind().permuteArguments(newType, reorder);
- }
-
/*non-public*/
! MethodHandle rebind() {
// Bind 'this' into a new invoker, of the known class BMH.
MethodType type2 = type();
LambdaForm form2 = reinvokerForm(this);
// form2 = lambda (bmh, arg*) { thismh = bmh[0]; invokeBasic(thismh, arg*) }
return BoundMethodHandle.bindSingle(type2, form2, this);
--- 1362,1373 ----
//// Method handle implementation methods.
//// Sub-classes can override these default implementations.
//// All these methods assume arguments are already validated.
/*non-public*/
! BoundMethodHandle rebind() {
// Bind 'this' into a new invoker, of the known class BMH.
MethodType type2 = type();
LambdaForm form2 = reinvokerForm(this);
// form2 = lambda (bmh, arg*) { thismh = bmh[0]; invokeBasic(thismh, arg*) }
return BoundMethodHandle.bindSingle(type2, form2, this);
src/share/classes/java/lang/invoke/MethodHandle.java
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File