8174222: LambdaMetafactory: validate inputs and improve documentation

Reviewed-by: mchung
This commit is contained in:
Dan Smith 2021-06-07 23:21:24 +00:00
parent 5e557d8650
commit fc08af58cb
8 changed files with 800 additions and 436 deletions

View file

@ -38,19 +38,19 @@ final class LambdaProxyClassArchive {
}
private static native void addToArchive(Class<?> caller,
String invokedName,
MethodType invokedType,
MethodType samMethodType,
MemberName implMethod,
MethodType instantiatedMethodType,
String interfaceMethodName,
MethodType factoryType,
MethodType interfaceMethodType,
MemberName implementationMember,
MethodType dynamicMethodType,
Class<?> lambdaProxyClass);
private static native Class<?> findFromArchive(Class<?> caller,
String invokedName,
MethodType invokedType,
MethodType samMethodType,
MemberName implMethod,
MethodType instantiatedMethodType);
String interfaceMethodName,
MethodType factoryType,
MethodType interfaceMethodType,
MemberName implementationMember,
MethodType dynamicMethodType);
/**
* Registers the lambdaProxyClass into CDS archive.
@ -62,22 +62,22 @@ final class LambdaProxyClassArchive {
* loaded by a built-in class loader.
*/
static boolean register(Class<?> caller,
String invokedName,
MethodType invokedType,
MethodType samMethodType,
MethodHandle implMethod,
MethodType instantiatedMethodType,
String interfaceMethodName,
MethodType factoryType,
MethodType interfaceMethodType,
MethodHandle implementation,
MethodType dynamicMethodType,
boolean isSerializable,
Class<?>[] markerInterfaces,
MethodType[] additionalBridges,
Class<?>[] altInterfaces,
MethodType[] altMethods,
Class<?> lambdaProxyClass) {
if (!CDS.isDumpingArchive())
throw new IllegalStateException("should only register lambda proxy class at dump time");
if (loadedByBuiltinLoader(caller) &&
!isSerializable && markerInterfaces.length == 0 && additionalBridges.length == 0) {
addToArchive(caller, invokedName, invokedType, samMethodType,
implMethod.internalMemberName(), instantiatedMethodType,
!isSerializable && altInterfaces.length == 0 && altMethods.length == 0) {
addToArchive(caller, interfaceMethodName, factoryType, interfaceMethodType,
implementation.internalMemberName(), dynamicMethodType,
lambdaProxyClass);
return true;
}
@ -93,22 +93,22 @@ final class LambdaProxyClassArchive {
* loaded by a built-in class loader.
*/
static Class<?> find(Class<?> caller,
String invokedName,
MethodType invokedType,
MethodType samMethodType,
MethodHandle implMethod,
MethodType instantiatedMethodType,
String interfaceMethodName,
MethodType factoryType,
MethodType interfaceMethodType,
MethodHandle implementation,
MethodType dynamicMethodType,
boolean isSerializable,
Class<?>[] markerInterfaces,
MethodType[] additionalBridges) {
Class<?>[] altInterfaces,
MethodType[] altMethods) {
if (CDS.isDumpingArchive())
throw new IllegalStateException("cannot load class from CDS archive at dump time");
if (!loadedByBuiltinLoader(caller) ||
!CDS.isSharingEnabled() || isSerializable || markerInterfaces.length > 0 || additionalBridges.length > 0)
!CDS.isSharingEnabled() || isSerializable || altInterfaces.length > 0 || altMethods.length > 0)
return null;
return findFromArchive(caller, invokedName, invokedType, samMethodType,
implMethod.internalMemberName(), instantiatedMethodType);
return findFromArchive(caller, interfaceMethodName, factoryType, interfaceMethodType,
implementation.internalMemberName(), dynamicMethodType);
}
}