On Wed, 8 Mar 2023 22:59:23 GMT, Doug Simon <dnsi...@openjdk.org> wrote:
>> This PR extends JVMCI with new API (`jdk.vm.ci.meta.Annotated`) for >> accessing annotations. The main differences from >> `java.lang.reflect.AnnotatedElement` are: >> * Each `Annotated` method explicitly specifies the annotation type(s) for >> which it wants annotation data. That is, there is no direct equivalent of >> `AnnotatedElement.getAnnotations()`. >> * Annotation data is returned in a map-like object (of type >> `jdk.vm.ci.meta.AnnotationData`) instead of in an `Annotation` object. This >> works better for libgraal as it avoids the need for annotation types to be >> loaded and included in libgraal. >> >> To demonstrate the new API, here's an example in terms >> `java.lang.reflect.AnnotatedElement` (which `ResolvedJavaType` implements): >> >> ResolvedJavaMethod method = ...; >> ExplodeLoop a = method.getAnnotation(ExplodeLoop.class); >> return switch (a.kind()) { >> case FULL_UNROLL -> LoopExplosionKind.FULL_UNROLL; >> case FULL_UNROLL_UNTIL_RETURN -> >> LoopExplosionKind.FULL_UNROLL_UNTIL_RETURN; >> ... >> } >> >> >> The same code using the new API: >> >> >> ResolvedJavaMethod method = ...; >> ResolvedJavaType explodeLoopType = ...; >> AnnotationData a = method.getAnnotationDataFor(explodeLoopType); >> return switch (a.getEnum("kind").getName()) { >> case "FULL_UNROLL" -> LoopExplosionKind.FULL_UNROLL; >> case "FULL_UNROLL_UNTIL_RETURN" -> >> LoopExplosionKind.FULL_UNROLL_UNTIL_RETURN; >> ... >> } >> >> >> The implementation relies on new methods in `jdk.internal.vm.VMSupport` for >> parsing annotations and serializing/deserializing to/from a byte array. This >> allows the annotation data to be passed from the HotSpot heap to the >> libgraal heap. > > Doug Simon has updated the pull request with a new target base due to a merge > or a rebase. The pull request now contains seven commits: > > - Merge remote-tracking branch 'openjdk-jdk/master' into JDK-8303431 > - switched to use of lists and maps instead of arrays > - fixed whitespace > - added support for inherited annotations > - Merge branch 'master' into JDK-8303431 > - made AnnotationDataDecoder package-private > - add annotation API to JVMCI The JVMCI changes look ok to me. src/hotspot/share/jvmci/jvmciCompilerToVM.cpp line 2699: > 2697: typeArrayOop ba = typeArrayOop(res); > 2698: int ba_len = ba->length(); > 2699: if (ba_len <= 256) { Is this really necessary? Resource allocation is very cheap. src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Annotated.java line 40: > 38: * annotations of this element. > 39: * > 40: * If this element is a class, then {@link Inherited} annotations are > included in set of in the set ------------- Marked as reviewed by never (Reviewer). PR: https://git.openjdk.org/jdk/pull/12810