From: <cap...@us...> - 2008-02-24 16:34:35
|
Revision: 13982 http://jikesrvm.svn.sourceforge.net/jikesrvm/?rev=13982&view=rev Author: captain5050 Date: 2008-02-24 08:34:27 -0800 (Sun, 24 Feb 2008) Log Message: ----------- Avoid holding singleton arrays of VM_Annotations, create them when needed. Modified Paths: -------------- rvmroot/trunk/rvm/src/org/jikesrvm/classloader/VM_AnnotatedElement.java Modified: rvmroot/trunk/rvm/src/org/jikesrvm/classloader/VM_AnnotatedElement.java =================================================================== --- rvmroot/trunk/rvm/src/org/jikesrvm/classloader/VM_AnnotatedElement.java 2008-02-24 13:43:33 UTC (rev 13981) +++ rvmroot/trunk/rvm/src/org/jikesrvm/classloader/VM_AnnotatedElement.java 2008-02-24 16:34:27 UTC (rev 13982) @@ -27,10 +27,14 @@ /** * Annotations from the class file that are described as runtime * visible. These annotations are available to the reflection API. + * This is either null, a VM_Annotation if a single annotation is + * present, or an array of VM_Annotation if there is >1 */ - protected final VM_Annotation[] declaredAnnotationDatas; + protected final Object declaredAnnotationDatas; /** Cached array of declared annotations. */ private Annotation[] declaredAnnotations; + /** Empty annotation array */ + private static final Annotation[] emptyAnnotationArray = new Annotation[0]; /** * Constructor used by all annotated elements @@ -38,7 +42,14 @@ * @param annotations array of runtime visible annotations */ protected VM_AnnotatedElement(VM_Annotation[] annotations) { - this.declaredAnnotationDatas = annotations; + if (annotations == null) { + declaredAnnotationDatas = null; + declaredAnnotations = emptyAnnotationArray; + } else if (annotations.length == 1) { + this.declaredAnnotationDatas = annotations[0]; + } else { + this.declaredAnnotationDatas = annotations; + } } /** @@ -101,9 +112,13 @@ * Copy array of annotations so can be safely returned to user. */ private Annotation[] cloneAnnotations(final Annotation[] internal) { - final Annotation[] annotations = new Annotation[internal.length]; - System.arraycopy(internal, 0, annotations, 0, internal.length); - return annotations; + if (internal.length == 0) { + return emptyAnnotationArray; + } else { + final Annotation[] annotations = new Annotation[internal.length]; + System.arraycopy(internal, 0, annotations, 0, internal.length); + return annotations; + } } /** @@ -112,10 +127,15 @@ * @param annotations the annotations. * @return the annotation instances. */ - final Annotation[] toAnnotations(final VM_Annotation[] annotations) { - if (null == annotations) { - return new Annotation[0]; - } else { + final Annotation[] toAnnotations(final Object datas) { + if (null == datas) { + return emptyAnnotationArray; + } else if (datas instanceof VM_Annotation) { + final Annotation[] copy = new Annotation[1]; + copy[0] = ((VM_Annotation)datas).getValue(); + return copy; + } else { + VM_Annotation[] annotations = (VM_Annotation[])datas; final Annotation[] copy = new Annotation[annotations.length]; for (int i = 0; i < copy.length; i++) { copy[i] = annotations[i].getValue(); @@ -158,15 +178,21 @@ */ @Uninterruptible final boolean isAnnotationDeclared(final VM_TypeReference annotationTypeRef) { - if (null != declaredAnnotationDatas) { - for (VM_Annotation annotation : declaredAnnotationDatas) { + if (declaredAnnotationDatas == null) { + return false; + } else if (declaredAnnotationDatas instanceof VM_Annotation) { + VM_Annotation annotation = (VM_Annotation)declaredAnnotationDatas; + return annotation.getType() == annotationTypeRef.getName() && + annotation.getClassLoader() == annotationTypeRef.getClassLoader(); + } else { + for (VM_Annotation annotation : (VM_Annotation[])declaredAnnotationDatas) { if (annotation.getType() == annotationTypeRef.getName() && - annotation.getClassLoader() == annotationTypeRef.getClassLoader()) { + annotation.getClassLoader() == annotationTypeRef.getClassLoader()) { return true; } } + return false; } - return false; } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |