RFR: 8303431: [JVMCI] libgraal annotation API [v4]
Doug Simon
dnsimon at openjdk.org
Wed Mar 8 19:59:02 UTC 2023
> 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 incrementally with one additional commit since the last revision:
switched to use of lists and maps instead of arrays
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/12810/files
- new: https://git.openjdk.org/jdk/pull/12810/files/3dd5ef9c..948d3aa3
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=12810&range=03
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=12810&range=02-03
Stats: 1241 lines in 15 files changed: 292 ins; 718 del; 231 mod
Patch: https://git.openjdk.org/jdk/pull/12810.diff
Fetch: git fetch https://git.openjdk.org/jdk pull/12810/head:pull/12810
PR: https://git.openjdk.org/jdk/pull/12810
More information about the core-libs-dev
mailing list