8235274: Enhance typing of methods
Reviewed-by: jrose, psandoz, skoivu
This commit is contained in:
parent
4df99aa7ae
commit
2309ac529c
@ -116,7 +116,8 @@ class MethodType
|
|||||||
|
|
||||||
// The remaining fields are caches of various sorts:
|
// The remaining fields are caches of various sorts:
|
||||||
private @Stable MethodTypeForm form; // erased form, plus cached data about primitives
|
private @Stable MethodTypeForm form; // erased form, plus cached data about primitives
|
||||||
private @Stable MethodType wrapAlt; // alternative wrapped/unwrapped version
|
private @Stable Object wrapAlt; // alternative wrapped/unwrapped version and
|
||||||
|
// private communication for readObject and readResolve
|
||||||
private @Stable Invokers invokers; // cache of handy higher-order adapters
|
private @Stable Invokers invokers; // cache of handy higher-order adapters
|
||||||
private @Stable String methodDescriptor; // cache for toMethodDescriptorString
|
private @Stable String methodDescriptor; // cache for toMethodDescriptorString
|
||||||
|
|
||||||
@ -711,7 +712,7 @@ class MethodType
|
|||||||
|
|
||||||
private static MethodType wrapWithPrims(MethodType pt) {
|
private static MethodType wrapWithPrims(MethodType pt) {
|
||||||
assert(pt.hasPrimitives());
|
assert(pt.hasPrimitives());
|
||||||
MethodType wt = pt.wrapAlt;
|
MethodType wt = (MethodType)pt.wrapAlt;
|
||||||
if (wt == null) {
|
if (wt == null) {
|
||||||
// fill in lazily
|
// fill in lazily
|
||||||
wt = MethodTypeForm.canonicalize(pt, MethodTypeForm.WRAP, MethodTypeForm.WRAP);
|
wt = MethodTypeForm.canonicalize(pt, MethodTypeForm.WRAP, MethodTypeForm.WRAP);
|
||||||
@ -723,7 +724,7 @@ class MethodType
|
|||||||
|
|
||||||
private static MethodType unwrapWithNoPrims(MethodType wt) {
|
private static MethodType unwrapWithNoPrims(MethodType wt) {
|
||||||
assert(!wt.hasPrimitives());
|
assert(!wt.hasPrimitives());
|
||||||
MethodType uwt = wt.wrapAlt;
|
MethodType uwt = (MethodType)wt.wrapAlt;
|
||||||
if (uwt == null) {
|
if (uwt == null) {
|
||||||
// fill in lazily
|
// fill in lazily
|
||||||
uwt = MethodTypeForm.canonicalize(wt, MethodTypeForm.UNWRAP, MethodTypeForm.UNWRAP);
|
uwt = MethodTypeForm.canonicalize(wt, MethodTypeForm.UNWRAP, MethodTypeForm.UNWRAP);
|
||||||
@ -1248,27 +1249,18 @@ s.writeObject(this.parameterArray());
|
|||||||
*/
|
*/
|
||||||
@java.io.Serial
|
@java.io.Serial
|
||||||
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException {
|
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException {
|
||||||
// Assign temporary defaults in case this object escapes
|
// Assign defaults in case this object escapes
|
||||||
MethodType_init(void.class, NO_PTYPES);
|
UNSAFE.putReference(this, OffsetHolder.rtypeOffset, void.class);
|
||||||
|
UNSAFE.putReference(this, OffsetHolder.ptypesOffset, NO_PTYPES);
|
||||||
|
|
||||||
s.defaultReadObject(); // requires serialPersistentFields to be an empty array
|
s.defaultReadObject(); // requires serialPersistentFields to be an empty array
|
||||||
|
|
||||||
Class<?> returnType = (Class<?>) s.readObject();
|
Class<?> returnType = (Class<?>) s.readObject();
|
||||||
Class<?>[] parameterArray = (Class<?>[]) s.readObject();
|
Class<?>[] parameterArray = (Class<?>[]) s.readObject();
|
||||||
parameterArray = parameterArray.clone(); // make sure it is unshared
|
|
||||||
|
|
||||||
// Assign deserialized values
|
// Verify all operands, and make sure ptypes is unshared
|
||||||
MethodType_init(returnType, parameterArray);
|
// Cache the new MethodType for readResolve
|
||||||
}
|
wrapAlt = new MethodType[]{MethodType.methodType(returnType, parameterArray)};
|
||||||
|
|
||||||
// Initialization of state for deserialization only
|
|
||||||
private void MethodType_init(Class<?> rtype, Class<?>[] ptypes) {
|
|
||||||
// In order to communicate these values to readResolve, we must
|
|
||||||
// store them into the implementation-specific final fields.
|
|
||||||
checkRtype(rtype);
|
|
||||||
checkPtypes(ptypes);
|
|
||||||
UNSAFE.putReference(this, OffsetHolder.rtypeOffset, rtype);
|
|
||||||
UNSAFE.putReference(this, OffsetHolder.ptypesOffset, ptypes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Support for resetting final fields while deserializing. Implement Holder
|
// Support for resetting final fields while deserializing. Implement Holder
|
||||||
@ -1291,12 +1283,10 @@ s.writeObject(this.parameterArray());
|
|||||||
// Do not use a trusted path for deserialization:
|
// Do not use a trusted path for deserialization:
|
||||||
// return makeImpl(rtype, ptypes, true);
|
// return makeImpl(rtype, ptypes, true);
|
||||||
// Verify all operands, and make sure ptypes is unshared:
|
// Verify all operands, and make sure ptypes is unshared:
|
||||||
try {
|
// Return a new validated MethodType for the rtype and ptypes passed from readObject.
|
||||||
return methodType(rtype, ptypes);
|
MethodType mt = ((MethodType[])wrapAlt)[0];
|
||||||
} finally {
|
wrapAlt = null;
|
||||||
// Re-assign defaults in case this object escapes
|
return mt;
|
||||||
MethodType_init(void.class, NO_PTYPES);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user