< prev index next >

src/java.base/share/classes/java/lang/reflect/Proxy.java

Print this page
rev 49262 : 8199862: Examine ProxyBuilder::referencedTypes startup cost
Reviewed-by: TBD

*** 706,733 **** * Returns all types referenced by all public non-static method signatures of * the proxy interfaces */ 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()); } ! /* ! * 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); } /** * Returns the module that the generated proxy class belongs to. * --- 706,741 ---- * Returns all types referenced by all public non-static method signatures of * the proxy interfaces */ private static Set<Class<?>> referencedTypes(ClassLoader loader, List<Class<?>> interfaces) { ! 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; } ! 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); ! } } /** * Returns the module that the generated proxy class belongs to. *
< prev index next >