mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8315810: Reimplement sun.reflect.ReflectionFactory::newConstructorForSerialization with method handles
Co-authored-by: Chen Liang <liach@openjdk.org> Reviewed-by: rriggs
This commit is contained in:
parent
eb1f67b160
commit
5cea53d372
10 changed files with 141 additions and 41 deletions
|
@ -3525,6 +3525,33 @@ return mh1;
|
|||
return lookup.getDirectConstructorNoSecurityManager(ctor.getDeclaringClass(), ctor);
|
||||
}
|
||||
|
||||
/*
|
||||
* Produces a method handle that is capable of creating instances of the given class
|
||||
* and instantiated by the given constructor. No security manager check.
|
||||
*
|
||||
* This method should only be used by ReflectionFactory::newConstructorForSerialization.
|
||||
*/
|
||||
/* package-private */ MethodHandle serializableConstructor(Class<?> decl, Constructor<?> c) throws IllegalAccessException {
|
||||
MemberName ctor = new MemberName(c);
|
||||
assert(ctor.isConstructor() && constructorInSuperclass(decl, c));
|
||||
checkAccess(REF_newInvokeSpecial, decl, ctor);
|
||||
assert(!MethodHandleNatives.isCallerSensitive(ctor)); // maybeBindCaller not relevant here
|
||||
return DirectMethodHandle.makeAllocator(decl, ctor).setVarargs(ctor);
|
||||
}
|
||||
|
||||
private static boolean constructorInSuperclass(Class<?> decl, Constructor<?> ctor) {
|
||||
if (decl == ctor.getDeclaringClass())
|
||||
return true;
|
||||
|
||||
Class<?> cl = decl;
|
||||
while ((cl = cl.getSuperclass()) != null) {
|
||||
if (cl == ctor.getDeclaringClass()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces a method handle giving read access to a reflected field.
|
||||
* The type of the method handle will have a return type of the field's
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue