-
Enhancement
-
Resolution: Fixed
-
P4
-
None
-
b22
In the current implementation MethodHandle.viewAsType eagerly rebinds when creating a view of a method type as an alternative type:
MethodHandle viewAsType(MethodType newType, boolean strict) {
MethodHandle mh = rebind();
return this.copyWith(newType, mh.form);
}
This prevents exposing uncrackable DMHs, ie, ones where calling Lookup.revealDirect(mh) would not produce a correct MethodHandleInfo.
If we restructure this so that crackability is a property on the DMH, we can avoid the rebinds:
http://cr.openjdk.java.net/~redestad/scratch/constructor_withType.03/
This improves overhead slightly when calling MH.asType with a "viewable" type (one where all parameters in the new type can be assigned without transforms to parameters in the old; and return in the old can be assigned without transforms in the new).
Since the Hidden Classes JEP this means a small startup gain for capturing lambdas. Might also benefit VarHandle bootstrap costs.
MethodHandle viewAsType(MethodType newType, boolean strict) {
MethodHandle mh = rebind();
return this.copyWith(newType, mh.form);
}
This prevents exposing uncrackable DMHs, ie, ones where calling Lookup.revealDirect(mh) would not produce a correct MethodHandleInfo.
If we restructure this so that crackability is a property on the DMH, we can avoid the rebinds:
http://cr.openjdk.java.net/~redestad/scratch/constructor_withType.03/
This improves overhead slightly when calling MH.asType with a "viewable" type (one where all parameters in the new type can be assigned without transforms to parameters in the old; and return in the old can be assigned without transforms in the new).
Since the Hidden Classes JEP this means a small startup gain for capturing lambdas. Might also benefit VarHandle bootstrap costs.