Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8364729

Improve JVMCI annotation handling

XMLWordPrintable

      The current design of jdk.vm.ci.meta.AnnotationData and jdk.vm.ci.meta.Annotated can be improved to have better naming and to support more use cases.

      In terms of improving naming:

      * AnnotationData -> AnnotationValue (avoids confusion with java.lang.Class.AnnotationData)
      * The 2 versions of Annotated#getAnnotationData should be renamed to getAnnotationValue (for retrieving a single annotation value) and getAnnotationValues (for retrieving multiple annotation values).

      The other improvements are largely for the purpose of allowing Native Image to move away from use of JDK core reflection to only relying on JVMCI:

      * The getAnnotationValues method above will have a single varargs value which, when it has a length of 0 will return all annotations declared on an element. This allows for Native Image to access all annotations for an element for the purposing of encoding them into a native image for reflection access at runtime.
      * Avoid triggering class initialization for enum classes used in an annotation. This is an important use case for Native Image where arbitrary class initialization must be avoided at build time.
      * Errors in parsing annotations at Native Image build time that result in a TypeNotPresentException and AnnotationTypeMismatchException need to be preserved when copying annotations into a native image. As such, the existing jdk.vm.ci.meta.ErrorData type needs to be replaced with separate types for the 2 aforementioned exception types.
      * Currently, JVMCI annotation does not have support for the equivalent of:
         - Method.annotationDefault
         - [Method|Constructor].parameterAnnotations
         - [Method|Constructor].getAnnotationReturnType()
         - Executable.getAnnotatedReceiverType()
         - Class.getAnnotatedSuperclass()
         - Class.getAnnotatedInterfaces()
         - [RecordComponent|Field].getAnnotatedType()
      * JVMCI is a lower level API than the core JDK annotation API. It should restrict itself only to what's necessary to support core JDK annotation API. As such, it will only support declared annotations and ignore inherited annotations.

      A follow-up issue will update ResolvedJava[Type|Field|Method] to no longer implement java.lang.reflect.AnnotatedElement.

            dnsimon Douglas Simon
            dnsimon Douglas Simon
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: