Skip to content

Commit bc9b0e5

Browse files
committed
[GR-70940] Replace AnnotatedElement usages with Annotated-based access in SVM
PullRequest: graal/22429
2 parents 3a869e2 + e96bf46 commit bc9b0e5

File tree

135 files changed

+1487
-1061
lines changed

Some content is hidden

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

135 files changed

+1487
-1061
lines changed

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/core/test/CheckGraalInvariants.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,6 @@ public boolean shouldVerifyFoldableMethods() {
215215
return true;
216216
}
217217

218-
/**
219-
* Determines if {@link VerifyAnnotatedElementUsage} is to be checked.
220-
*/
221-
public boolean shouldVerifyAnnotatedElementUsages() {
222-
return true;
223-
}
224-
225218
public void verifyCurrentTimeMillis(MetaAccessProvider meta, MethodCallTargetNode t, ResolvedJavaType declaringClass) {
226219
final ResolvedJavaType services = meta.lookupJavaType(GraalServices.class);
227220
if (!declaringClass.equals(services)) {
@@ -385,6 +378,7 @@ public static void runTest(InvariantsTool tool) {
385378
verifiers.add(new VerifyLoopInfo());
386379
verifiers.add(new VerifyGuardsStageUsages());
387380
verifiers.add(new VerifyAArch64RegisterUsages());
381+
verifiers.add(new VerifyAnnotatedElementUsage());
388382
VerifyAssertionUsage assertionUsages = null;
389383
boolean checkAssertions = tool.checkAssertions();
390384

@@ -403,9 +397,6 @@ public static void runTest(InvariantsTool tool) {
403397
if (tool.shouldVerifyFoldableMethods()) {
404398
verifiers.add(foldableMethodsVerifier);
405399
}
406-
if (tool.shouldVerifyAnnotatedElementUsages()) {
407-
verifiers.add(new VerifyAnnotatedElementUsage());
408-
}
409400

410401
verifiers.add(new VerifyCurrentTimeMillisUsage(tool));
411402

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/annotation/AnnotationValueParser.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public static Object parseMemberValue(ResolvedJavaType memberType,
151151
result = new ElementTypeMismatch(memberType.toJavaName());
152152
} else if (tag != '[' &&
153153
!(result instanceof ErrorElement) &&
154-
!matchesMemberType(result, memberType)) {
154+
!AnnotationValueType.matchesElementType(result, memberType)) {
155155
if (result instanceof AnnotationValue) {
156156
result = new ElementTypeMismatch(result.toString());
157157
} else {
@@ -161,22 +161,6 @@ public static Object parseMemberValue(ResolvedJavaType memberType,
161161
return result;
162162
}
163163

164-
private static boolean matchesMemberType(Object result, ResolvedJavaType memberType) {
165-
if (result instanceof AnnotationValue av) {
166-
return memberType.equals(av.getAnnotationType());
167-
}
168-
if (result instanceof ResolvedJavaType) {
169-
return memberType.getName().equals("Ljava/lang/Class;");
170-
}
171-
if (result instanceof EnumElement ee) {
172-
return ee.enumType.equals(memberType);
173-
}
174-
if (memberType.isPrimitive()) {
175-
return result.getClass() == memberType.getJavaKind().toBoxedJavaClass();
176-
}
177-
return memberType.toJavaName().equals(result.getClass().getName());
178-
}
179-
180164
private static Object parsePrimitiveConst(char tag,
181165
ByteBuffer buf, ConstantPool constPool) {
182166
int constIndex = buf.getShort() & 0xFFFF;

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/annotation/AnnotationValueType.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,29 @@ private AnnotationValueType(ResolvedJavaType annotationClass) {
7777
}
7878
}
7979

80+
/**
81+
* Determines if the type of {@code elementValue} matches {@code elementType}.
82+
*
83+
* @param elementValue a value of a type returned by {@link AnnotationValue#get}
84+
* @param elementType an annotation element type (i.e. the return type of an annotation
85+
* interface method)
86+
*/
87+
public static boolean matchesElementType(Object elementValue, ResolvedJavaType elementType) {
88+
if (elementValue instanceof AnnotationValue av) {
89+
return elementType.equals(av.getAnnotationType());
90+
}
91+
if (elementValue instanceof ResolvedJavaType) {
92+
return elementType.getName().equals("Ljava/lang/Class;");
93+
}
94+
if (elementValue instanceof EnumElement ee) {
95+
return ee.enumType.equals(elementType);
96+
}
97+
if (elementType.isPrimitive()) {
98+
return elementValue.getClass() == elementType.getJavaKind().toBoxedJavaClass();
99+
}
100+
return elementType.toJavaName().equals(elementValue.getClass().getName());
101+
}
102+
80103
/**
81104
* Gets the element types for the annotation represented by this object.
82105
*

substratevm/mx.substratevm/suite.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,13 @@
228228
"compiler:GRAAL",
229229
],
230230
"requiresConcealed" : {
231-
"java.base" : ["jdk.internal.module"],
231+
"java.base" : [
232+
"jdk.internal.module",
233+
"sun.reflect.annotation"
234+
],
232235
"jdk.internal.vm.ci": [
233236
"jdk.vm.ci.meta",
237+
"jdk.vm.ci.meta.annotation",
234238
"jdk.vm.ci.code",
235239
"jdk.vm.ci.runtime"
236240
]
@@ -242,6 +246,10 @@
242246
"checkstyle": "com.oracle.svm.core",
243247
"workingSets": "SVM",
244248
"jacoco" : "include",
249+
250+
# Direct reference to jdk.vm.ci.meta.annotation.Annotated
251+
# causes spotbugs analysis to fail with "missing class" error.
252+
"spotbugs": "false",
245253
},
246254

247255
"com.oracle.svm.common": {
@@ -378,6 +386,7 @@
378386
],
379387
"jdk.internal.vm.ci": [
380388
"jdk.vm.ci.meta",
389+
"jdk.vm.ci.meta.annotation",
381390
"jdk.vm.ci.code",
382391
"jdk.vm.ci.aarch64",
383392
"jdk.vm.ci.amd64",
@@ -1373,6 +1382,7 @@
13731382
"jdk.internal.vm.ci": [
13741383
"jdk.vm.ci.aarch64",
13751384
"jdk.vm.ci.meta",
1385+
"jdk.vm.ci.meta.annotation",
13761386
"jdk.vm.ci.code",
13771387
"jdk.vm.ci.code.stack"
13781388
]
@@ -1583,6 +1593,7 @@
15831593
"requiresConcealed": {
15841594
"jdk.internal.vm.ci": [
15851595
"jdk.vm.ci.meta",
1596+
"jdk.vm.ci.meta.annotation",
15861597
"jdk.vm.ci.code",
15871598
"jdk.vm.ci.common",
15881599
]
@@ -1632,6 +1643,7 @@
16321643
"requiresConcealed" : {
16331644
"jdk.internal.vm.ci" : [
16341645
"jdk.vm.ci.meta",
1646+
"jdk.vm.ci.meta.annotation",
16351647
"jdk.vm.ci.code",
16361648
],
16371649
"java.base" : [

substratevm/src/com.oracle.graal.pointsto.standalone/src/com/oracle/graal/pointsto/standalone/StandaloneAnnotationExtractor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626

2727
package com.oracle.graal.pointsto.standalone;
2828

29-
import org.graalvm.nativeimage.impl.AnnotationExtractor;
30-
3129
import java.lang.annotation.Annotation;
3230
import java.lang.reflect.AnnotatedElement;
3331
import java.util.Arrays;
3432

33+
import org.graalvm.nativeimage.impl.AnnotationExtractor;
34+
3535
public class StandaloneAnnotationExtractor implements AnnotationExtractor {
3636
// Checkstyle: allow direct annotation access
3737
@Override

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/PointsToAnalysis.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
import java.util.function.Consumer;
4343
import java.util.stream.StreamSupport;
4444

45-
import org.graalvm.nativeimage.AnnotationAccess;
46-
4745
import com.oracle.graal.pointsto.api.HostVM;
4846
import com.oracle.graal.pointsto.api.PointstoOptions;
4947
import com.oracle.graal.pointsto.constraints.UnsupportedFeatures;
@@ -77,6 +75,7 @@
7775
import com.oracle.graal.pointsto.util.Timer.StopTimer;
7876
import com.oracle.graal.pointsto.util.TimerCollection;
7977
import com.oracle.svm.common.meta.MultiMethod;
78+
import com.oracle.svm.util.AnnotationUtil;
8079
import com.oracle.svm.util.ClassUtil;
8180

8281
import jdk.graal.compiler.api.replacements.Fold;
@@ -166,7 +165,7 @@ public PointsToAnalysis(OptionValues options, AnalysisUniverse universe, HostVM
166165
* this type cannot be extended outside the observable universe.</li>
167166
* <li>In <b>closed type world</b> all types are considered closed.</li>
168167
* </ul>
169-
*
168+
*
170169
* This method is conservative, it returns false in cases where we are not sure, and further
171170
* refining when a type is closed will improve analysis. For example GR-59311 will also define
172171
* when a sealed type can be treated as a closed type.
@@ -394,7 +393,7 @@ public AnalysisMethod addRootMethod(AnalysisMethod aMethod, boolean invokeSpecia
394393
assert !universe.sealed() : "Cannot register root methods after analysis universe is sealed.";
395394
validateRootMethodRegistration(aMethod, invokeSpecial);
396395
AnalysisError.guarantee(aMethod.isOriginalMethod());
397-
AnalysisError.guarantee(!AnnotationAccess.isAnnotationPresent(aMethod, Fold.class), "@Fold annotated method cannot be a root method.");
396+
AnalysisError.guarantee(!AnnotationUtil.isAnnotationPresent(aMethod, Fold.class), "@Fold annotated method cannot be a root method.");
398397
boolean isStatic = aMethod.isStatic();
399398
int paramCount = aMethod.getSignature().getParameterCount(!isStatic);
400399
PointsToAnalysisMethod originalPTAMethod = assertPointsToAnalysisMethod(aMethod);

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodTypeFlowBuilder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
import java.util.Map;
3535
import java.util.Optional;
3636

37-
import org.graalvm.nativeimage.AnnotationAccess;
38-
3937
import com.oracle.graal.pointsto.AbstractAnalysisEngine;
4038
import com.oracle.graal.pointsto.ObjectScanner.EmbeddedRootScan;
4139
import com.oracle.graal.pointsto.PointsToAnalysis;
@@ -62,6 +60,7 @@
6260
import com.oracle.graal.pointsto.typestate.TypeState;
6361
import com.oracle.graal.pointsto.util.AnalysisError;
6462
import com.oracle.svm.common.meta.MultiMethod;
63+
import com.oracle.svm.util.AnnotationUtil;
6564

6665
import jdk.graal.compiler.core.common.SuppressFBWarnings;
6766
import jdk.graal.compiler.core.common.spi.ForeignCallDescriptor;
@@ -509,7 +508,7 @@ private static void registerForeignCall(AbstractAnalysisEngine bb, ForeignCallsP
509508
}
510509

511510
private boolean handleNodeIntrinsic() {
512-
if (AnnotationAccess.isAnnotationPresent(method, NodeIntrinsic.class)) {
511+
if (AnnotationUtil.isAnnotationPresent(method, NodeIntrinsic.class)) {
513512
graph.getDebug().log("apply MethodTypeFlow on node intrinsic %s", method);
514513
AnalysisType returnType = method.getSignature().getReturnType();
515514
if (bb.isSupportedJavaKind(returnType.getJavaKind())) {

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/WrappedJavaField.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,18 @@
2424
*/
2525
package com.oracle.graal.pointsto.infrastructure;
2626

27+
import com.oracle.svm.util.AnnotatedWrapper;
28+
2729
import jdk.vm.ci.meta.ResolvedJavaField;
30+
import jdk.vm.ci.meta.annotation.Annotated;
2831

29-
public interface WrappedJavaField extends ResolvedJavaField, WrappedElement {
32+
public interface WrappedJavaField extends ResolvedJavaField, WrappedElement, AnnotatedWrapper {
3033

3134
@Override
3235
ResolvedJavaField getWrapped();
36+
37+
@Override
38+
default Annotated getWrappedAnnotated() {
39+
return getWrapped();
40+
}
3341
}

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/WrappedJavaMethod.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,18 @@
2424
*/
2525
package com.oracle.graal.pointsto.infrastructure;
2626

27+
import com.oracle.svm.util.AnnotatedWrapper;
28+
2729
import jdk.vm.ci.meta.ResolvedJavaMethod;
30+
import jdk.vm.ci.meta.annotation.Annotated;
2831

29-
public interface WrappedJavaMethod extends WrappedElement, ResolvedJavaMethod {
32+
public interface WrappedJavaMethod extends WrappedElement, AnnotatedWrapper, ResolvedJavaMethod {
3033

3134
@Override
3235
ResolvedJavaMethod getWrapped();
36+
37+
@Override
38+
default Annotated getWrappedAnnotated() {
39+
return getWrapped();
40+
}
3341
}

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/WrappedJavaType.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,18 @@
2424
*/
2525
package com.oracle.graal.pointsto.infrastructure;
2626

27+
import com.oracle.svm.util.AnnotatedWrapper;
28+
2729
import jdk.vm.ci.meta.ResolvedJavaType;
30+
import jdk.vm.ci.meta.annotation.Annotated;
2831

29-
public interface WrappedJavaType extends WrappedElement, ResolvedJavaType {
32+
public interface WrappedJavaType extends WrappedElement, AnnotatedWrapper, ResolvedJavaType {
3033

3134
@Override
3235
ResolvedJavaType getWrapped();
36+
37+
@Override
38+
default Annotated getWrappedAnnotated() {
39+
return getWrapped();
40+
}
3341
}

0 commit comments

Comments
 (0)