8199862: Examine ProxyBuilder::referencedTypes startup cost
Reviewed-by: mchung
This commit is contained in:
parent
74827c6a87
commit
c71bc3581a
src/java.base/share/classes/java/lang/reflect
@ -253,6 +253,11 @@ public final class Constructor<T> extends Executable {
|
||||
return parameterTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
Class<?>[] getSharedExceptionTypes() {
|
||||
return exceptionTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -226,6 +226,10 @@ public abstract class Executable extends AccessibleObject
|
||||
// to the untrusted code...
|
||||
abstract Class<?>[] getSharedParameterTypes();
|
||||
|
||||
// returns shared array of exception types - must never give it out
|
||||
// to the untrusted code...
|
||||
abstract Class<?>[] getSharedExceptionTypes();
|
||||
|
||||
/**
|
||||
* Returns an array of {@code Class} objects that represent the formal
|
||||
* parameter types, in declaration order, of the executable
|
||||
|
@ -301,6 +301,11 @@ public final class Method extends Executable {
|
||||
return parameterTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
Class<?>[] getSharedExceptionTypes() {
|
||||
return exceptionTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -708,24 +708,32 @@ public class Proxy implements java.io.Serializable {
|
||||
*/
|
||||
private static Set<Class<?>> referencedTypes(ClassLoader loader,
|
||||
List<Class<?>> interfaces) {
|
||||
return interfaces.stream()
|
||||
.flatMap(intf -> Stream.of(intf.getMethods())
|
||||
.filter(m -> !Modifier.isStatic(m.getModifiers()))
|
||||
.flatMap(ProxyBuilder::methodRefTypes)
|
||||
.map(ProxyBuilder::getElementType)
|
||||
.filter(t -> !t.isPrimitive()))
|
||||
.collect(Collectors.toSet());
|
||||
var types = new HashSet<Class<?>>();
|
||||
for (var intf : interfaces) {
|
||||
for (Method m : intf.getMethods()) {
|
||||
if (!Modifier.isStatic(m.getModifiers())) {
|
||||
addElementType(types, m.getReturnType());
|
||||
addElementTypes(types, m.getSharedParameterTypes());
|
||||
addElementTypes(types, m.getSharedExceptionTypes());
|
||||
}
|
||||
}
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
/*
|
||||
* Extracts all types referenced on a method signature including
|
||||
* its return type, parameter types, and exception types.
|
||||
*/
|
||||
private static Stream<Class<?>> methodRefTypes(Method m) {
|
||||
return Stream.of(new Class<?>[] { m.getReturnType() },
|
||||
m.getParameterTypes(),
|
||||
m.getExceptionTypes())
|
||||
.flatMap(Stream::of);
|
||||
private static void addElementTypes(HashSet<Class<?>> types,
|
||||
Class<?> ... classes) {
|
||||
for (var cls : classes) {
|
||||
addElementType(types, cls);
|
||||
}
|
||||
}
|
||||
|
||||
private static void addElementType(HashSet<Class<?>> types,
|
||||
Class<?> cls) {
|
||||
var type = getElementType(cls);
|
||||
if (!type.isPrimitive()) {
|
||||
types.add(type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user