Skip to content

Commit 8864bd5

Browse files
committed
[GR-69454] Implement annotation parsing in Graal
PullRequest: graal/22070
2 parents 0295446 + ce822e5 commit 8864bd5

File tree

111 files changed

+5163
-1725
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+5163
-1725
lines changed

common.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@
5555
"graalvm-ee-25-ea": {"name": "graalvm-jdk", "version": "25.0.0", "ea": "36", "platformspecific": true },
5656

5757
"oraclejdk-latest": {"name": "jpg-jdk", "version": "25", "build_id": "jdk-25+37", "platformspecific": true, "extrabundles": ["static-libs"]},
58-
"labsjdk-ce-latest": {"name": "labsjdk", "version": "ce-25+37-jvmci-b04", "platformspecific": true },
59-
"labsjdk-ce-latestDebug": {"name": "labsjdk", "version": "ce-25+37-jvmci-b04-debug", "platformspecific": true },
60-
"labsjdk-ce-latest-llvm": {"name": "labsjdk", "version": "ce-25+37-jvmci-b04-sulong", "platformspecific": true },
61-
"labsjdk-ee-latest": {"name": "labsjdk", "version": "ee-25+37-jvmci-b04", "platformspecific": true },
62-
"labsjdk-ee-latestDebug": {"name": "labsjdk", "version": "ee-25+37-jvmci-b04-debug", "platformspecific": true },
63-
"labsjdk-ee-latest-llvm": {"name": "labsjdk", "version": "ee-25+37-jvmci-b04-sulong", "platformspecific": true }
58+
"labsjdk-ce-latest": {"name": "labsjdk", "version": "ce-25+37-jvmci-b05", "platformspecific": true },
59+
"labsjdk-ce-latestDebug": {"name": "labsjdk", "version": "ce-25+37-jvmci-b05-debug", "platformspecific": true },
60+
"labsjdk-ce-latest-llvm": {"name": "labsjdk", "version": "ce-25+37-jvmci-b05-sulong", "platformspecific": true },
61+
"labsjdk-ee-latest": {"name": "labsjdk", "version": "ee-25+37-jvmci-b05", "platformspecific": true },
62+
"labsjdk-ee-latestDebug": {"name": "labsjdk", "version": "ee-25+37-jvmci-b05-debug", "platformspecific": true },
63+
"labsjdk-ee-latest-llvm": {"name": "labsjdk", "version": "ee-25+37-jvmci-b05-sulong", "platformspecific": true }
6464
},
6565

6666
"eclipse": {

compiler/mx.compiler/mx_compiler.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,11 +821,21 @@ class GraalUnittestConfig(mx_unittest.MxUnittestConfig):
821821
def __init__(self):
822822
super(GraalUnittestConfig, self).__init__('graal')
823823

824+
def _replace_graal_test_deps(self, cp):
825+
"""
826+
Updates the classpath `cp` to replace the path for GRAAL_TEST_COMPILETIME's jar
827+
with the path for GRAAL_TEST_RUNTIME's jar. This is used by tests (such as
828+
TestAnnotationsOnTypes) in jdk.graal.compiler.annotation.test to ensure annotation
829+
parsing handles an annotation use where the annotation type has evolved since the
830+
source code of the use was compiled.
831+
"""
832+
return cp.replace(mx.distribution("GRAAL_TEST_COMPILETIME").path, mx.distribution("GRAAL_TEST_RUNTIME").path)
833+
824834
def apply(self, config):
825835
vmArgs, mainClass, mainClassArgs = config
826836
cpIndex, cp = mx.find_classpath_arg(vmArgs)
827837
if cp:
828-
cp = _remove_redundant_entries(cp)
838+
cp = self._replace_graal_test_deps(_remove_redundant_entries(cp))
829839

830840
vmArgs[cpIndex] = cp
831841
# JVMCI is dynamically exported to Graal when JVMCI is initialized. This is too late

compiler/mx.compiler/suite.py

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,12 @@
139139
],
140140
"requiresConcealed" : {
141141
"java.base" : [
142-
"jdk.internal.misc"
142+
"jdk.internal.misc",
143+
"sun.reflect.generics.parser",
143144
],
144145
"jdk.internal.vm.ci" : [
145146
"jdk.vm.ci.meta",
147+
"jdk.vm.ci.meta.annotation",
146148
"jdk.vm.ci.code",
147149
"jdk.vm.ci.code.site",
148150
"jdk.vm.ci.code.stack",
@@ -190,6 +192,10 @@
190192
"jdk.graal.compiler.jtt",
191193
"jdk.graal.compiler.truffle.test",
192194
],
195+
# Direct reference to jdk.vm.ci.meta.annotation and
196+
# jdk.vm.ci.meta.ResolvedJavaRecordComponent causes
197+
# spotbugs analysis to fail with "missing class" error.
198+
"spotbugs": "false",
193199
},
194200

195201
"jdk.graal.compiler.processor" : {
@@ -204,11 +210,37 @@
204210
"javaCompliance" : "21+",
205211
},
206212

213+
# Definition of classes that jdk.graal.compiler.test compiles against.
214+
# An alternative version of these classes is provided by jdk.graal.compiler.test.runtime.
215+
"jdk.graal.compiler.test.compiletime" : {
216+
"subDir" : "src",
217+
"sourceDirs" : ["src"],
218+
"checkstyle" : "jdk.graal.compiler",
219+
"javaCompliance" : "24+",
220+
"forceJavac": True,
221+
"jacoco" : "exclude",
222+
"testProject" : True,
223+
},
224+
225+
# Alternative definition of classes in jdk.graal.compiler.test.compiletime
226+
# that jdk.graal.compiler.test runs against. See _replace_graal_test_deps
227+
# in mx_compiler.py.
228+
"jdk.graal.compiler.test.runtime" : {
229+
"subDir" : "src",
230+
"sourceDirs" : ["src"],
231+
"checkstyle" : "jdk.graal.compiler",
232+
"javaCompliance" : "24+",
233+
"forceJavac": True,
234+
"jacoco" : "exclude",
235+
"testProject" : True,
236+
},
237+
207238
"jdk.graal.compiler.test" : {
208239
"subDir" : "src",
209240
"sourceDirs" : ["src"],
210241
"dependencies" : [
211242
"jdk.graal.compiler",
243+
"GRAAL_TEST_COMPILETIME",
212244
"mx:JUNIT",
213245
"JAVA_ALLOCATION_INSTRUMENTER",
214246
"truffle:TRUFFLE_SL_TEST",
@@ -228,8 +260,10 @@
228260
"java.base" : [
229261
"jdk.internal.module",
230262
"jdk.internal.misc",
263+
"jdk.internal.reflect",
231264
"jdk.internal.util",
232265
"jdk.internal.vm.annotation",
266+
"sun.reflect.annotation",
233267
"sun.security.util.math",
234268
"sun.security.util.math.intpoly",
235269
],
@@ -238,6 +272,7 @@
238272
],
239273
"jdk.internal.vm.ci" : [
240274
"jdk.vm.ci.meta",
275+
"jdk.vm.ci.meta.annotation",
241276
"jdk.vm.ci.code",
242277
"jdk.vm.ci.code.site",
243278
"jdk.vm.ci.code.stack",
@@ -408,6 +443,7 @@
408443
"jdk.internal.vm.ci" : [
409444
"jdk.vm.ci.code",
410445
"jdk.vm.ci.meta",
446+
"jdk.vm.ci.meta.annotation",
411447
"jdk.vm.ci.runtime",
412448
"jdk.vm.ci.services",
413449
"jdk.vm.ci.hotspot",
@@ -420,7 +456,7 @@
420456
],
421457

422458
# Direct reference to jdk.vm.ci.hotspot.CompilerThreadCanCallJavaScope
423-
# causing spotbugs analysis to fail with "missing class" error.
459+
# causes spotbugs analysis to fail with "missing class" error.
424460
"spotbugs": "false",
425461
},
426462

@@ -449,13 +485,34 @@
449485

450486
# ------------- Distributions -------------
451487

488+
# Compile time dependency for GRAAL_TEST
489+
"GRAAL_TEST_COMPILETIME": {
490+
"subDir": "src",
491+
"dependencies": [
492+
"jdk.graal.compiler.test.compiletime",
493+
],
494+
"testDistribution": True,
495+
"maven": False,
496+
},
497+
498+
# Run time dependency for GRAAL_TEST
499+
"GRAAL_TEST_RUNTIME": {
500+
"subDir": "src",
501+
"dependencies": [
502+
"jdk.graal.compiler.test.runtime",
503+
],
504+
"testDistribution": True,
505+
"maven": False,
506+
},
507+
452508
"GRAAL_TEST" : {
453509
"subDir" : "src",
454510
"dependencies" : [
455511
"jdk.graal.compiler.test",
456512
],
457513
"distDependencies" : [
458514
"GRAAL",
515+
"GRAAL_TEST_COMPILETIME",
459516
"truffle:TRUFFLE_SL_TEST",
460517
"truffle:TRUFFLE_TEST",
461518
"truffle:TRUFFLE_COMPILER",

compiler/src/jdk.graal.compiler.libgraal/src/jdk/graal/compiler/libgraal/truffle/LibGraalTruffleHostEnvironment.java

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@
2727
import java.lang.invoke.MethodHandle;
2828
import java.lang.invoke.MethodHandles;
2929
import java.lang.invoke.MethodType;
30-
import java.util.List;
30+
import java.util.Map;
3131

3232
import com.oracle.truffle.compiler.HostMethodInfo;
3333
import com.oracle.truffle.compiler.TruffleCompilable;
3434
import com.oracle.truffle.compiler.TruffleCompilerRuntime;
3535

36+
import jdk.graal.compiler.annotation.AnnotationValue;
37+
import jdk.graal.compiler.annotation.AnnotationValueSupport;
3638
import jdk.graal.compiler.core.common.util.MethodKey;
3739
import jdk.graal.compiler.hotspot.CompilationContext;
3840
import jdk.graal.compiler.hotspot.HotSpotGraalServices;
@@ -41,9 +43,9 @@
4143
import jdk.graal.compiler.truffle.host.TruffleHostEnvironment;
4244
import jdk.graal.compiler.truffle.host.TruffleKnownHostTypes;
4345
import jdk.graal.compiler.truffle.hotspot.HotSpotTruffleCompilerImpl;
44-
import jdk.vm.ci.meta.AnnotationData;
4546
import jdk.vm.ci.meta.MetaAccessProvider;
4647
import jdk.vm.ci.meta.ResolvedJavaMethod;
48+
import jdk.vm.ci.meta.ResolvedJavaType;
4749

4850
final class LibGraalTruffleHostEnvironment extends TruffleHostEnvironment {
4951

@@ -100,27 +102,12 @@ protected Object createKey(ResolvedJavaMethod method) {
100102
@Override
101103
protected HostMethodInfo computeValue(ResolvedJavaMethod method) {
102104
TruffleKnownHostTypes hostTypes = types();
103-
List<AnnotationData> annotationDataList = method.getAnnotationData(hostTypes.TruffleBoundary, hostTypes.BytecodeInterpreterSwitch,
104-
hostTypes.BytecodeInterpreterSwitchBoundary, hostTypes.InliningCutoff);
105-
boolean isTruffleBoundary = false;
106-
boolean isBytecodeInterpreterSwitch = false;
107-
boolean isBytecodeInterpreterSwitchBoundary = false;
108-
boolean isInliningCutoff = false;
109-
boolean isInliningRoot = false;
110-
for (AnnotationData annotationData : annotationDataList) {
111-
String annotationTypeFqn = annotationData.getAnnotationType().getName();
112-
if (hostTypes.TruffleBoundary.getName().equals(annotationTypeFqn)) {
113-
isTruffleBoundary = true;
114-
} else if (hostTypes.BytecodeInterpreterSwitch.getName().equals(annotationTypeFqn)) {
115-
isBytecodeInterpreterSwitch = true;
116-
} else if (hostTypes.BytecodeInterpreterSwitchBoundary.getName().equals(annotationTypeFqn)) {
117-
isBytecodeInterpreterSwitchBoundary = true;
118-
} else if (hostTypes.InliningCutoff.getName().equals(annotationTypeFqn)) {
119-
isInliningCutoff = true;
120-
} else if (hostTypes.InliningRoot != null && hostTypes.InliningRoot.getName().equals(annotationTypeFqn)) {
121-
isInliningRoot = true;
122-
}
123-
}
105+
Map<ResolvedJavaType, AnnotationValue> annotations = AnnotationValueSupport.getDeclaredAnnotationValues(method);
106+
boolean isTruffleBoundary = annotations.containsKey(hostTypes.TruffleBoundary);
107+
boolean isBytecodeInterpreterSwitch = annotations.containsKey(hostTypes.BytecodeInterpreterSwitch);
108+
boolean isBytecodeInterpreterSwitchBoundary = annotations.containsKey(hostTypes.BytecodeInterpreterSwitchBoundary);
109+
boolean isInliningCutoff = annotations.containsKey(hostTypes.InliningCutoff);
110+
boolean isInliningRoot = annotations.containsKey(hostTypes.InliningRoot);
124111
return new HostMethodInfo(isTruffleBoundary, isBytecodeInterpreterSwitch, isBytecodeInterpreterSwitchBoundary, isInliningCutoff, isInliningRoot);
125112
}
126113

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package jdk.graal.compiler.annotation.test;
26+
27+
import java.lang.annotation.Retention;
28+
import java.lang.annotation.RetentionPolicy;
29+
30+
/**
31+
* An annotation type that has an alternative version in the {@code jdk.graal.compiler.test.runtime}
32+
* project. The alternate version defines an {@code addedElement} element. This is used in
33+
* {@code jdk.graal.compiler.annotation.test.AnnotationTestInput#addedMember} to ensure annotation
34+
* parsing handles parsing an annotation use where the annotation type has evolved since the source
35+
* code of the use was compiled.
36+
*/
37+
@Retention(RetentionPolicy.RUNTIME)
38+
public @interface MemberAdded {
39+
String value();
40+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package jdk.graal.compiler.annotation.test;
26+
27+
import java.lang.annotation.Retention;
28+
import java.lang.annotation.RetentionPolicy;
29+
30+
/**
31+
* An annotation type that has an alternative version in the {@code jdk.graal.compiler.test.runtime}
32+
* project. The alternate version does not define {@link #deleted()}. This is used in
33+
* {@code jdk.graal.compiler.annotation.test.AnnotationTestInput#missingMember} to ensure annotation
34+
* parsing handles parsing an annotation use where the annotation type has evolved since the source
35+
* code of the use was compiled.
36+
*/
37+
@Retention(RetentionPolicy.RUNTIME)
38+
public @interface MemberDeleted {
39+
String value();
40+
41+
int retained();
42+
43+
int deleted();
44+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package jdk.graal.compiler.annotation.test;
26+
27+
import java.lang.annotation.Retention;
28+
import java.lang.annotation.RetentionPolicy;
29+
30+
/**
31+
* An annotation type that has an alternative version in the {@code jdk.graal.compiler.test.runtime}
32+
* project. The alternate version defines {@link #any()} with type String. This is used in
33+
* {@code jdk.graal.compiler.annotation.test.AnnotationTestInput#changeTypeOfMember} to ensure
34+
* annotation parsing handles parsing an annotation use where the annotation type has evolved since
35+
* the source code of the use was compiled.
36+
*/
37+
@Retention(RetentionPolicy.RUNTIME)
38+
public @interface MemberTypeChanged {
39+
String value();
40+
41+
int retained();
42+
43+
// Type is String at run time
44+
int any();
45+
}

0 commit comments

Comments
 (0)