src/share/classes/java/lang/reflect/Method.java
Print this page
rev 10466 : 8054987: (reflect) Add sharing of annotations between instances of Executable
Reviewed-by: duke
*** 77,86 ****
--- 77,89 ----
private byte[] annotationDefault;
private volatile MethodAccessor methodAccessor;
// For sharing of MethodAccessors. This branching structure is
// currently only two levels deep (i.e., one root Method and
// potentially many Method objects pointing to it.)
+ //
+ // If this branching structure would ever contain cycles, deadlocks can
+ // occur in annotation code.
private Method root;
// Generics infrastructure
private String getGenericSignature() {return signature;}
*** 142,160 ****
--- 145,174 ----
// method in the VM. (All of this contortion is only necessary
// because of the "accessibility" bit in AccessibleObject,
// which implicitly requires that new java.lang.reflect
// objects be fabricated for each reflective call on Class
// objects.)
+ if (this.root != null)
+ throw new IllegalArgumentException("Can not copy a non-root Method");
+
Method res = new Method(clazz, name, parameterTypes, returnType,
exceptionTypes, modifiers, slot, signature,
annotations, parameterAnnotations, annotationDefault);
res.root = this;
// Might as well eagerly propagate this if already present
res.methodAccessor = methodAccessor;
return res;
}
+ /**
+ * Used by Excecutable for annotation sharing.
+ */
+ @Override
+ Executable getRoot() {
+ return root;
+ }
+
@Override
boolean hasGenericInformation() {
return (getGenericSignature() != null);
}