Skip to content

Commit 6a085a9

Browse files
committed
replaced uses of AnnotationAccess with AnnotationUtil
1 parent d10978a commit 6a085a9

File tree

112 files changed

+754
-553
lines changed

Some content is hidden

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

112 files changed

+754
-553
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)) {
@@ -382,6 +375,7 @@ public static void runTest(InvariantsTool tool) {
382375
verifiers.add(new VerifyLoopInfo());
383376
verifiers.add(new VerifyGuardsStageUsages());
384377
verifiers.add(new VerifyAArch64RegisterUsages());
378+
verifiers.add(new VerifyAnnotatedElementUsage());
385379
VerifyAssertionUsage assertionUsages = null;
386380
boolean checkAssertions = tool.checkAssertions();
387381

@@ -400,9 +394,6 @@ public static void runTest(InvariantsTool tool) {
400394
if (tool.shouldVerifyFoldableMethods()) {
401395
verifiers.add(foldableMethodsVerifier);
402396
}
403-
if (tool.shouldVerifyAnnotatedElementUsages()) {
404-
verifiers.add(new VerifyAnnotatedElementUsage());
405-
}
406397

407398
verifiers.add(new VerifyCurrentTimeMillisUsage(tool));
408399

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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@
231231
"java.base" : ["jdk.internal.module"],
232232
"jdk.internal.vm.ci": [
233233
"jdk.vm.ci.meta",
234+
"jdk.vm.ci.meta.annotation",
234235
"jdk.vm.ci.code",
235236
"jdk.vm.ci.runtime"
236237
]
@@ -242,6 +243,10 @@
242243
"checkstyle": "com.oracle.svm.core",
243244
"workingSets": "SVM",
244245
"jacoco" : "include",
246+
247+
# Direct reference to jdk.vm.ci.meta.annotation.Annotated
248+
# causes spotbugs analysis to fail with "missing class" error.
249+
"spotbugs": "false",
245250
},
246251

247252
"com.oracle.svm.common": {
@@ -378,6 +383,7 @@
378383
],
379384
"jdk.internal.vm.ci": [
380385
"jdk.vm.ci.meta",
386+
"jdk.vm.ci.meta.annotation",
381387
"jdk.vm.ci.code",
382388
"jdk.vm.ci.aarch64",
383389
"jdk.vm.ci.amd64",
@@ -1373,6 +1379,7 @@
13731379
"jdk.internal.vm.ci": [
13741380
"jdk.vm.ci.aarch64",
13751381
"jdk.vm.ci.meta",
1382+
"jdk.vm.ci.meta.annotation",
13761383
"jdk.vm.ci.code",
13771384
"jdk.vm.ci.code.stack"
13781385
]

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/meta/AnalysisElement.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import com.oracle.graal.pointsto.util.AnalysisFuture;
4949
import com.oracle.graal.pointsto.util.AtomicUtils;
5050
import com.oracle.graal.pointsto.util.ConcurrentLightHashSet;
51+
import com.oracle.svm.util.AnnotationUtil;
5152

5253
import jdk.graal.compiler.debug.GraalError;
5354
import jdk.vm.ci.code.BytecodePosition;
@@ -86,17 +87,17 @@ public AnnotationsInfo getTypeAnnotationInfo() {
8687

8788
@Override
8889
public final boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
89-
return getUniverse().getAnnotationExtractor().hasAnnotation(getWrapped(), annotationClass);
90+
return AnnotationUtil.isAnnotationPresent((Annotated) getWrapped(), annotationClass);
9091
}
9192

9293
@Override
9394
public final <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
94-
return getUniverse().getAnnotationExtractor().extractAnnotation(getWrapped(), annotationClass, false);
95+
return AnnotationUtil.getAnnotation((Annotated) getWrapped(), annotationClass);
9596
}
9697

9798
@Override
9899
public final <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass) {
99-
return getUniverse().getAnnotationExtractor().extractAnnotation(getWrapped(), annotationClass, true);
100+
throw GraalError.shouldNotReachHere("The getDeclaredAnnotation method is not supported");
100101
}
101102

102103
@Override

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisField.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.oracle.graal.pointsto.util.AnalysisFuture;
3737
import com.oracle.graal.pointsto.util.AtomicUtils;
3838
import com.oracle.svm.common.meta.GuaranteeFolded;
39+
import com.oracle.svm.util.AnnotationUtil;
3940
import com.oracle.svm.util.OriginalClassProvider;
4041
import com.oracle.svm.util.OriginalFieldProvider;
4142

@@ -257,7 +258,7 @@ public void injectDeclaredType() {
257258
}
258259

259260
public boolean isGuaranteeFolded() {
260-
return getAnnotation(GuaranteeFolded.class) != null;
261+
return AnnotationUtil.getAnnotation(this, GuaranteeFolded.class) != null;
261262
}
262263

263264
public void checkGuaranteeFolded() {

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/results/TypeFlowSimplifier.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.util.List;
3030

3131
import org.graalvm.collections.EconomicSet;
32-
import org.graalvm.nativeimage.AnnotationAccess;
3332

3433
import com.oracle.graal.pointsto.PointsToAnalysis;
3534
import com.oracle.graal.pointsto.flow.InvokeTypeFlow;
@@ -45,6 +44,7 @@
4544
import com.oracle.graal.pointsto.typestate.TypeState;
4645
import com.oracle.graal.pointsto.util.AnalysisError;
4746
import com.oracle.svm.core.annotate.Delete;
47+
import com.oracle.svm.util.AnnotationUtil;
4848
import com.oracle.svm.util.ImageBuildStatistics;
4949

5050
import jdk.graal.compiler.core.common.type.IntegerStamp;
@@ -376,7 +376,7 @@ private void handleInvoke(Invoke invoke, SimplifierTool tool) {
376376
AnalysisMethod singleCallee = callees.iterator().next();
377377
assert targetMethod.equals(singleCallee) : "Direct invoke target mismatch: " + targetMethod + " != " + singleCallee + ". Called from " + graph.method().format("%H.%n");
378378
}
379-
} else if (AnnotationAccess.isAnnotationPresent(targetMethod, Delete.class)) {
379+
} else if (AnnotationUtil.isAnnotationPresent(targetMethod, Delete.class)) {
380380
/* We de-virtualize invokes to deleted methods since the callee must be unique. */
381381
AnalysisError.guarantee(callees.size() == 1, "@Delete methods should have a single callee.");
382382
AnalysisMethod singleCallee = callees.iterator().next();

substratevm/src/com.oracle.graal.reachability/src/com/oracle/graal/reachability/DirectMethodProcessingHandler.java

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

2727
import java.lang.reflect.Modifier;
2828

29-
import org.graalvm.nativeimage.AnnotationAccess;
30-
3129
import com.oracle.graal.pointsto.AbstractAnalysisEngine;
3230
import com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder;
3331
import com.oracle.graal.pointsto.meta.AnalysisField;
3432
import com.oracle.graal.pointsto.meta.AnalysisType;
33+
import com.oracle.svm.util.AnnotationUtil;
3534

3635
import jdk.graal.compiler.graph.Node;
3736
import jdk.graal.compiler.nodes.CallTargetNode;
@@ -128,7 +127,7 @@ private static void analyzeStructuredGraph(ReachabilityAnalysisEngine bb, Reacha
128127

129128
private static void processInvoke(ReachabilityAnalysisEngine bb, ReachabilityAnalysisMethod method, ReachabilityAnalysisMethod targetMethod, CallTargetNode.InvokeKind kind,
130129
ValueNodeInterface node) {
131-
if (targetMethod == null || AnnotationAccess.isAnnotationPresent(targetMethod, Node.NodeIntrinsic.class)) {
130+
if (targetMethod == null || AnnotationUtil.isAnnotationPresent(targetMethod, Node.NodeIntrinsic.class)) {
132131
return;
133132
}
134133
BytecodePosition reason = AbstractAnalysisEngine.sourcePosition(node.asNode());

0 commit comments

Comments
 (0)