8189266: (ann) Optimize AnnotationInvocationHandler.invoke
Reviewed-by: jfranck, plevart
Contributed-by: christoph.dreis@freenet.de
--- a/src/java.base/share/classes/sun/reflect/annotation/AnnotationInvocationHandler.java Mon Oct 23 10:43:45 2017 +0200
+++ b/src/java.base/share/classes/sun/reflect/annotation/AnnotationInvocationHandler.java Mon Oct 23 11:33:16 2017 +0200
@@ -57,21 +57,22 @@
public Object invoke(Object proxy, Method method, Object[] args) {
String member = method.getName();
- Class<?>[] paramTypes = method.getParameterTypes();
+ int parameterCount = method.getParameterCount();
// Handle Object and Annotation methods
- if (member.equals("equals") && paramTypes.length == 1 &&
- paramTypes[0] == Object.class)
+ if (parameterCount == 1 && member == "equals" &&
+ method.getParameterTypes()[0] == Object.class) {
return equalsImpl(proxy, args[0]);
- if (paramTypes.length != 0)
+ }
+ if (parameterCount != 0) {
throw new AssertionError("Too many parameters for an annotation method");
+ }
- switch(member) {
- case "toString":
+ if (member == "toString") {
return toStringImpl();
- case "hashCode":
+ } else if (member == "hashCode") {
return hashCodeImpl();
- case "annotationType":
+ } else if (member == "annotationType") {
return type;
}