From f0459d583e37f01158048552494d5d36370fe888 Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Wed, 5 Oct 2022 11:33:23 -0700 Subject: [PATCH 1/4] Replace GuardedAnnotationAccess with AnnotationAccess --- .../oracle/graal/pointsto/flow/MethodTypeFlowBuilder.java | 4 ++-- .../graal/reachability/DirectMethodProcessingHandler.java | 4 ++-- .../reachability/SimpleInMemoryMethodSummaryProvider.java | 4 ++-- .../svm/core/graal/amd64/SubstrateAMD64Backend.java | 4 ++-- .../src/com/oracle/svm/core/graal/llvm/LLVMGenerator.java | 4 ++-- .../src/com/oracle/svm/core/c/libc/LibCBase.java | 6 +++--- .../src/com/oracle/svm/core/config/ObjectLayout.java | 4 ++-- .../oracle/svm/core/graal/code/StubCallingConvention.java | 6 +++--- .../core/graal/word/SubstrateWordOperationPlugins.java | 4 ++-- .../oracle/svm/core/graal/word/SubstrateWordTypes.java | 4 ++-- .../src/com/oracle/svm/hosted/FeatureImpl.java | 4 ++-- .../src/com/oracle/svm/hosted/NativeImageGenerator.java | 4 ++-- .../src/com/oracle/svm/hosted/SVMHost.java | 8 ++++---- .../cenum/CEnumCallWrapperSubstitutionProcessor.java | 6 +++--- .../hosted/classinitialization/TypeInitializerGraph.java | 4 ++-- .../hosted/code/NativeMethodSubstitutionProcessor.java | 8 ++++---- .../svm/hosted/heap/PodFactorySubstitutionMethod.java | 4 ++-- .../oracle/svm/hosted/jni/JNIFunctionTablesFeature.java | 4 ++-- .../oracle/svm/hosted/phases/ImplicitAssertionsPhase.java | 4 ++-- .../svm/hosted/phases/InlineBeforeAnalysisPolicyImpl.java | 6 +++--- .../oracle/svm/hosted/reflect/ReflectionDataBuilder.java | 4 ++-- .../com/oracle/svm/hosted/reflect/ReflectionFeature.java | 4 ++-- .../svm/hosted/reflect/ReflectionMetadataEncoderImpl.java | 4 ++-- .../com/oracle/svm/hosted/substitute/AnnotatedMethod.java | 4 ++-- .../substitute/AnnotationSubstitutionProcessor.java | 8 ++++---- .../src/com/oracle/svm/truffle/TruffleFeature.java | 6 +++--- 26 files changed, 63 insertions(+), 63 deletions(-) diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodTypeFlowBuilder.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodTypeFlowBuilder.java index 45eacc7748d0..11e28920c6cb 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodTypeFlowBuilder.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodTypeFlowBuilder.java @@ -134,7 +134,6 @@ import com.oracle.graal.pointsto.results.StaticAnalysisResultsBuilder; import com.oracle.graal.pointsto.typestate.TypeState; import com.oracle.graal.pointsto.util.AnalysisError; -import com.oracle.svm.util.GuardedAnnotationAccess; import jdk.vm.ci.code.BytecodeFrame; import jdk.vm.ci.code.BytecodePosition; @@ -142,6 +141,7 @@ import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.VMConstant; +import org.graalvm.nativeimage.AnnotationAccess; public class MethodTypeFlowBuilder { @@ -335,7 +335,7 @@ private static void registerForeignCall(PointsToAnalysis bb, ForeignCallDescript protected void apply() { // assert method.getAnnotation(Fold.class) == null : method; - if (GuardedAnnotationAccess.isAnnotationPresent(method, NodeIntrinsic.class)) { + if (AnnotationAccess.isAnnotationPresent(method, NodeIntrinsic.class)) { graph.getDebug().log("apply MethodTypeFlow on node intrinsic %s", method); AnalysisType returnType = (AnalysisType) method.getSignature().getReturnType(method.getDeclaringClass()); if (returnType.getJavaKind() == JavaKind.Object) { diff --git a/substratevm/src/com.oracle.graal.reachability/src/com/oracle/graal/reachability/DirectMethodProcessingHandler.java b/substratevm/src/com.oracle.graal.reachability/src/com/oracle/graal/reachability/DirectMethodProcessingHandler.java index e55a707ec90f..f8ac9238975b 100644 --- a/substratevm/src/com.oracle.graal.reachability/src/com/oracle/graal/reachability/DirectMethodProcessingHandler.java +++ b/substratevm/src/com.oracle.graal.reachability/src/com/oracle/graal/reachability/DirectMethodProcessingHandler.java @@ -25,7 +25,6 @@ package com.oracle.graal.reachability; import com.oracle.graal.pointsto.meta.AnalysisMethod; -import com.oracle.svm.util.GuardedAnnotationAccess; import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.ResolvedJavaMethod; import jdk.vm.ci.meta.ResolvedJavaType; @@ -49,6 +48,7 @@ import org.graalvm.compiler.replacements.nodes.BinaryMathIntrinsicNode; import org.graalvm.compiler.replacements.nodes.MacroInvokable; import org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode; +import org.graalvm.nativeimage.AnnotationAccess; import java.lang.reflect.Modifier; import java.util.Optional; @@ -128,7 +128,7 @@ private static void analyzeStructuredGraph(ReachabilityAnalysisEngine bb, Reacha Invoke node = (Invoke) n; CallTargetNode.InvokeKind kind = node.getInvokeKind(); ReachabilityAnalysisMethod targetMethod = (ReachabilityAnalysisMethod) node.getTargetMethod(); - if (targetMethod == null || GuardedAnnotationAccess.isAnnotationPresent(targetMethod, Node.NodeIntrinsic.class)) { + if (targetMethod == null || AnnotationAccess.isAnnotationPresent(targetMethod, Node.NodeIntrinsic.class)) { continue; } if (method != null) { diff --git a/substratevm/src/com.oracle.graal.reachability/src/com/oracle/graal/reachability/SimpleInMemoryMethodSummaryProvider.java b/substratevm/src/com.oracle.graal.reachability/src/com/oracle/graal/reachability/SimpleInMemoryMethodSummaryProvider.java index d94089b8414f..9fa4fdbbae1d 100644 --- a/substratevm/src/com.oracle.graal.reachability/src/com/oracle/graal/reachability/SimpleInMemoryMethodSummaryProvider.java +++ b/substratevm/src/com.oracle.graal.reachability/src/com/oracle/graal/reachability/SimpleInMemoryMethodSummaryProvider.java @@ -27,7 +27,6 @@ import com.oracle.graal.pointsto.meta.AnalysisField; import com.oracle.graal.pointsto.meta.AnalysisMethod; import com.oracle.graal.pointsto.meta.AnalysisType; -import com.oracle.svm.util.GuardedAnnotationAccess; import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.ResolvedJavaMethod; import jdk.vm.ci.meta.ResolvedJavaType; @@ -52,6 +51,7 @@ import org.graalvm.compiler.replacements.nodes.BinaryMathIntrinsicNode; import org.graalvm.compiler.replacements.nodes.MacroInvokable; import org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode; +import org.graalvm.nativeimage.AnnotationAccess; import java.lang.reflect.Modifier; import java.util.Optional; @@ -139,7 +139,7 @@ private static MethodSummary createSummaryFromGraph(ReachabilityAnalysisEngine b Invoke node = (Invoke) n; CallTargetNode.InvokeKind kind = node.getInvokeKind(); ReachabilityAnalysisMethod targetMethod = (ReachabilityAnalysisMethod) node.getTargetMethod(); - if (targetMethod == null || GuardedAnnotationAccess.isAnnotationPresent(targetMethod, Node.NodeIntrinsic.class)) { + if (targetMethod == null || AnnotationAccess.isAnnotationPresent(targetMethod, Node.NodeIntrinsic.class)) { continue; } if (method != null) { diff --git a/substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64Backend.java b/substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64Backend.java index 30cce51b2420..cd6b4e7554de 100644 --- a/substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64Backend.java +++ b/substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64Backend.java @@ -124,6 +124,7 @@ import org.graalvm.compiler.phases.common.AddressLoweringPhase; import org.graalvm.compiler.phases.util.Providers; import org.graalvm.compiler.replacements.amd64.AMD64IntrinsicStubs; +import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.ImageSingletons; import com.oracle.svm.core.CPUFeatureAccess; @@ -170,7 +171,6 @@ import com.oracle.svm.core.snippets.SubstrateForeignCallTarget; import com.oracle.svm.core.thread.VMThreads.StatusSupport; import com.oracle.svm.core.util.VMError; -import com.oracle.svm.util.GuardedAnnotationAccess; import jdk.vm.ci.amd64.AMD64; import jdk.vm.ci.amd64.AMD64Kind; @@ -1010,7 +1010,7 @@ public Variable emitReadReturnAddress() { @Override public ForeignCallLinkage lookupGraalStub(ValueNode valueNode, ForeignCallDescriptor foreignCallDescriptor) { ResolvedJavaMethod method = valueNode.graph().method(); - if (method != null && GuardedAnnotationAccess.getAnnotation(method, SubstrateForeignCallTarget.class) != null) { + if (method != null && AnnotationAccess.getAnnotation(method, SubstrateForeignCallTarget.class) != null) { // Emit assembly for snippet stubs return null; } diff --git a/substratevm/src/com.oracle.svm.core.graal.llvm/src/com/oracle/svm/core/graal/llvm/LLVMGenerator.java b/substratevm/src/com.oracle.svm.core.graal.llvm/src/com/oracle/svm/core/graal/llvm/LLVMGenerator.java index 68f855f01da4..5f08c0cc3ead 100644 --- a/substratevm/src/com.oracle.svm.core.graal.llvm/src/com/oracle/svm/core/graal/llvm/LLVMGenerator.java +++ b/substratevm/src/com.oracle.svm.core.graal.llvm/src/com/oracle/svm/core/graal/llvm/LLVMGenerator.java @@ -81,6 +81,7 @@ import org.graalvm.compiler.nodes.type.NarrowOopStamp; import org.graalvm.compiler.phases.util.Providers; import org.graalvm.compiler.serviceprovider.JavaVersionUtil; +import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.c.constant.CEnum; import org.graalvm.nativeimage.c.function.CEntryPoint; @@ -124,7 +125,6 @@ import com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef; import com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef; import com.oracle.svm.shadowed.org.bytedeco.llvm.global.LLVM; -import com.oracle.svm.util.GuardedAnnotationAccess; import com.oracle.svm.util.ReflectionUtil; import jdk.vm.ci.code.CallingConvention; @@ -499,7 +499,7 @@ private LLVMTypeRef prependArgumentTypes(LLVMTypeRef functionType, int prefixTyp } private static boolean isCEnumType(ResolvedJavaType type) { - return type.isEnum() && GuardedAnnotationAccess.isAnnotationPresent(type, CEnum.class); + return type.isEnum() && AnnotationAccess.isAnnotationPresent(type, CEnum.class); } /* Constants */ diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/libc/LibCBase.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/libc/LibCBase.java index 3e3791e382a9..c8ca9fdba816 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/libc/LibCBase.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/libc/LibCBase.java @@ -30,22 +30,22 @@ import java.util.List; import org.graalvm.compiler.api.replacements.Fold; +import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; -import com.oracle.svm.util.GuardedAnnotationAccess; public interface LibCBase { @Platforms(Platform.HOSTED_ONLY.class) static boolean containsLibCAnnotation(AnnotatedElement element) { - return GuardedAnnotationAccess.getAnnotation(element, LibCSpecific.class) != null; + return AnnotationAccess.getAnnotation(element, LibCSpecific.class) != null; } @Platforms(Platform.HOSTED_ONLY.class) static boolean isProvidedInCurrentLibc(AnnotatedElement element) { LibCBase currentLibC = ImageSingletons.lookup(LibCBase.class); - LibCSpecific targetLibC = GuardedAnnotationAccess.getAnnotation(element, LibCSpecific.class); + LibCSpecific targetLibC = AnnotationAccess.getAnnotation(element, LibCSpecific.class); return targetLibC != null && Arrays.asList(targetLibC.value()).contains(currentLibC.getClass()); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/config/ObjectLayout.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/config/ObjectLayout.java index 73cd0f7db9c8..82a7770618c1 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/config/ObjectLayout.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/config/ObjectLayout.java @@ -26,8 +26,8 @@ import org.graalvm.compiler.api.replacements.Fold; import org.graalvm.compiler.core.common.NumUtil; +import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.c.constant.CEnum; -import com.oracle.svm.util.GuardedAnnotationAccess; import org.graalvm.word.WordBase; import com.oracle.svm.core.SubstrateTargetDescription; @@ -182,7 +182,7 @@ public static JavaKind getCallSignatureKind(boolean isEntryPoint, ResolvedJavaTy if (metaAccess.lookupJavaType(WordBase.class).isAssignableFrom(type)) { return target.wordJavaKind; } - if (isEntryPoint && GuardedAnnotationAccess.isAnnotationPresent(type, CEnum.class)) { + if (isEntryPoint && AnnotationAccess.isAnnotationPresent(type, CEnum.class)) { return JavaKind.Int; } return type.getJavaKind(); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/code/StubCallingConvention.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/code/StubCallingConvention.java index 0f33f8e1d0bd..89a8fc41e18b 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/code/StubCallingConvention.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/code/StubCallingConvention.java @@ -29,13 +29,13 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; import com.oracle.svm.core.CalleeSavedRegisters; import com.oracle.svm.core.snippets.SubstrateForeignCallTarget; import com.oracle.svm.core.util.UserError; -import com.oracle.svm.util.GuardedAnnotationAccess; import jdk.vm.ci.meta.ResolvedJavaMethod; @@ -54,11 +54,11 @@ class Utils { public static boolean hasStubCallingConvention(ResolvedJavaMethod method) { boolean result = false; if (CalleeSavedRegisters.supportedByPlatform()) { - SubstrateForeignCallTarget foreignCallTargetAnnotation = GuardedAnnotationAccess.getAnnotation(method, SubstrateForeignCallTarget.class); + SubstrateForeignCallTarget foreignCallTargetAnnotation = AnnotationAccess.getAnnotation(method, SubstrateForeignCallTarget.class); if (foreignCallTargetAnnotation != null && foreignCallTargetAnnotation.stubCallingConvention()) { result = true; } else { - result = GuardedAnnotationAccess.isAnnotationPresent(method, StubCallingConvention.class); + result = AnnotationAccess.isAnnotationPresent(method, StubCallingConvention.class); } } if (result && !method.isStatic()) { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/word/SubstrateWordOperationPlugins.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/word/SubstrateWordOperationPlugins.java index 929bfa235dca..bbda2a6f331a 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/word/SubstrateWordOperationPlugins.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/word/SubstrateWordOperationPlugins.java @@ -38,7 +38,7 @@ import org.graalvm.compiler.nodes.memory.address.AddressNode; import org.graalvm.compiler.word.WordOperationPlugin; import org.graalvm.compiler.word.WordTypes; -import com.oracle.svm.util.GuardedAnnotationAccess; +import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.word.LocationIdentity; import jdk.vm.ci.meta.JavaKind; @@ -58,7 +58,7 @@ public boolean handleInvoke(GraphBuilderContext b, ResolvedJavaMethod method, Va } } - SubstrateOperation operation = GuardedAnnotationAccess.getAnnotation(method, SubstrateOperation.class); + SubstrateOperation operation = AnnotationAccess.getAnnotation(method, SubstrateOperation.class); if (operation == null) { processWordOperation(b, args, wordTypes.getWordOperation(method, b.getMethod().getDeclaringClass())); return true; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/word/SubstrateWordTypes.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/word/SubstrateWordTypes.java index 7cd26258ab58..d0e81f45d679 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/word/SubstrateWordTypes.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/word/SubstrateWordTypes.java @@ -25,8 +25,8 @@ package com.oracle.svm.core.graal.word; import org.graalvm.compiler.word.WordTypes; +import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.c.function.InvokeCFunctionPointer; -import com.oracle.svm.util.GuardedAnnotationAccess; import com.oracle.svm.core.util.UserError; @@ -42,7 +42,7 @@ public SubstrateWordTypes(MetaAccessProvider metaAccess, JavaKind wordKind) { @Override public boolean isWordOperation(ResolvedJavaMethod targetMethod) { - if (GuardedAnnotationAccess.isAnnotationPresent(targetMethod, InvokeCFunctionPointer.class)) { + if (AnnotationAccess.isAnnotationPresent(targetMethod, InvokeCFunctionPointer.class)) { return false; // handled by CInterfaceInvocationPlugin } return super.isWordOperation(targetMethod); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/FeatureImpl.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/FeatureImpl.java index 47acd21e7020..c319c20bde20 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/FeatureImpl.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/FeatureImpl.java @@ -50,6 +50,7 @@ import org.graalvm.collections.Pair; import org.graalvm.compiler.debug.DebugContext; import org.graalvm.compiler.phases.util.Providers; +import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.hosted.Feature.DuringAnalysisAccess; import org.graalvm.nativeimage.hosted.FieldValueTransformer; @@ -87,7 +88,6 @@ import com.oracle.svm.hosted.meta.HostedMethod; import com.oracle.svm.hosted.meta.HostedUniverse; import com.oracle.svm.hosted.option.HostedOptionProvider; -import com.oracle.svm.util.GuardedAnnotationAccess; import com.oracle.svm.util.ReflectionUtil; import com.oracle.svm.util.UnsafePartitionKind; @@ -391,7 +391,7 @@ public void registerAsUnsafeAccessed(Field field, UnsafePartitionKind partitionK } public boolean registerAsUnsafeAccessed(AnalysisField aField, UnsafePartitionKind partitionKind) { - assert !GuardedAnnotationAccess.isAnnotationPresent(aField, Delete.class); + assert !AnnotationAccess.isAnnotationPresent(aField, Delete.class); return bb.registerAsUnsafeAccessed(aField, partitionKind); } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java index 27df21f53e59..e9635b69924c 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java @@ -108,6 +108,7 @@ import org.graalvm.compiler.replacements.TargetGraphBuilderPlugins; import org.graalvm.compiler.word.WordOperationPlugin; import org.graalvm.compiler.word.WordTypes; +import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.ImageInfo; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platform; @@ -301,7 +302,6 @@ import com.oracle.svm.hosted.substitute.UnsafeAutomaticSubstitutionProcessor; import com.oracle.svm.util.AnnotationExtracter; import com.oracle.svm.util.ClassUtil; -import com.oracle.svm.util.GuardedAnnotationAccess; import com.oracle.svm.util.ImageBuildStatistics; import com.oracle.svm.util.ReflectionUtil; import com.oracle.svm.util.ReflectionUtil.ReflectionUtilError; @@ -1182,7 +1182,7 @@ protected void register(Type declaringClass, InvocationPlugin plugin, boolean al @Override public void notifyNoPlugin(ResolvedJavaMethod targetMethod, OptionValues options) { if (Options.WarnMissingIntrinsic.getValue(options)) { - for (Class annotationType : GuardedAnnotationAccess.getAnnotationTypes(targetMethod)) { + for (Class annotationType : AnnotationAccess.getAnnotationTypes(targetMethod)) { if (ClassUtil.getUnqualifiedName(annotationType).contains("IntrinsicCandidate")) { String method = String.format("%s.%s%s", targetMethod.getDeclaringClass().toJavaName().replace('.', '/'), targetMethod.getName(), targetMethod.getSignature().toMethodDescriptor()); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java index 8fb8c3b8627c..b3f922f6a65e 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java @@ -68,6 +68,7 @@ import org.graalvm.compiler.phases.common.BoxNodeIdentityPhase; import org.graalvm.compiler.phases.common.CanonicalizerPhase; import org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase; +import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.function.RelocatedPointer; @@ -122,7 +123,6 @@ import com.oracle.svm.hosted.phases.ImplicitAssertionsPhase; import com.oracle.svm.hosted.phases.InlineBeforeAnalysisPolicyImpl; import com.oracle.svm.hosted.substitute.UnsafeAutomaticSubstitutionProcessor; -import com.oracle.svm.util.GuardedAnnotationAccess; import com.oracle.svm.util.ReflectionUtil; import jdk.vm.ci.meta.DeoptimizationReason; @@ -682,7 +682,7 @@ public boolean isAnalysisTrivialMethod(AnalysisMethod method) { @Override public boolean hasNeverInlineDirective(ResolvedJavaMethod method) { - if (GuardedAnnotationAccess.isAnnotationPresent(method, NeverInline.class)) { + if (AnnotationAccess.isAnnotationPresent(method, NeverInline.class)) { return true; } @@ -739,7 +739,7 @@ public boolean platformSupported(AnnotatedElement element) { } } - Platforms platformsAnnotation = GuardedAnnotationAccess.getAnnotation(element, Platforms.class); + Platforms platformsAnnotation = AnnotationAccess.getAnnotation(element, Platforms.class); if (platform == null || platformsAnnotation == null) { return true; } @@ -758,7 +758,7 @@ public void registerNeverInlineTrivialHandler(BiPredicate new CEnumCallWrapperMethod(nativeLibraries, v)); } else { return method; diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/TypeInitializerGraph.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/TypeInitializerGraph.java index 22cdd6a6949b..1e969974099c 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/TypeInitializerGraph.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/TypeInitializerGraph.java @@ -44,9 +44,9 @@ import com.oracle.svm.hosted.phases.SubstrateClassInitializationPlugin; import com.oracle.svm.hosted.substitute.SubstitutionMethod; import com.oracle.svm.hosted.substitute.SubstitutionType; -import com.oracle.svm.util.GuardedAnnotationAccess; import jdk.vm.ci.meta.ResolvedJavaType; +import org.graalvm.nativeimage.AnnotationAccess; /** * Keeps a type-hierarchy dependency graph for {@link AnalysisType}s from {@code universe}. Each @@ -250,7 +250,7 @@ private void addInitializer(AnalysisType t) { boolean isSubstituted = false; if (rt instanceof SubstitutionType) { SubstitutionType substitutionType = (SubstitutionType) rt; - isSubstituted = GuardedAnnotationAccess.isAnnotationPresent(substitutionType, Substitute.class) || GuardedAnnotationAccess.isAnnotationPresent(substitutionType, Delete.class); + isSubstituted = AnnotationAccess.isAnnotationPresent(substitutionType, Substitute.class) || AnnotationAccess.isAnnotationPresent(substitutionType, Delete.class); } types.put(t, isSubstituted ? Safety.UNSAFE : initialTypeInitializerSafety(t)); dependencies.put(t, new HashSet<>()); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/NativeMethodSubstitutionProcessor.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/NativeMethodSubstitutionProcessor.java index 3553651b5d34..cc6773d60988 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/NativeMethodSubstitutionProcessor.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/NativeMethodSubstitutionProcessor.java @@ -28,6 +28,7 @@ import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin; import org.graalvm.compiler.nodes.spi.Replacements; import org.graalvm.compiler.word.Word.Operation; +import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.c.constant.CConstant; import org.graalvm.nativeimage.c.function.CFunction; @@ -35,7 +36,6 @@ import com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor; import com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod; import com.oracle.svm.core.option.HostedOptionValues; -import com.oracle.svm.util.GuardedAnnotationAccess; import jdk.vm.ci.meta.ResolvedJavaMethod; @@ -64,9 +64,9 @@ public ResolvedJavaMethod lookup(ResolvedJavaMethod method) { assert !(method instanceof WrappedJavaMethod) : "Must not see AnalysisMethod or HostedMethod here"; return method; } - assert !GuardedAnnotationAccess.isAnnotationPresent(method, CFunction.class) : "CFunction must have been handled by another SubstitutionProcessor"; - if (GuardedAnnotationAccess.isAnnotationPresent(method, NodeIntrinsic.class) || GuardedAnnotationAccess.isAnnotationPresent(method, Operation.class) || - GuardedAnnotationAccess.isAnnotationPresent(method, CConstant.class)) { + assert !AnnotationAccess.isAnnotationPresent(method, CFunction.class) : "CFunction must have been handled by another SubstitutionProcessor"; + if (AnnotationAccess.isAnnotationPresent(method, NodeIntrinsic.class) || AnnotationAccess.isAnnotationPresent(method, Operation.class) || + AnnotationAccess.isAnnotationPresent(method, CConstant.class)) { return method; } boolean isHandledByPlugin = replacements.getGraphBuilderPlugins().getInvocationPlugins().lookupInvocation(method, HostedOptionValues.singleton()) != null; diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/heap/PodFactorySubstitutionMethod.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/heap/PodFactorySubstitutionMethod.java index a422107e04b3..485a703ebabe 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/heap/PodFactorySubstitutionMethod.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/heap/PodFactorySubstitutionMethod.java @@ -62,19 +62,19 @@ import com.oracle.svm.hosted.meta.HostedMethod; import com.oracle.svm.hosted.nodes.DeoptProxyNode; import com.oracle.svm.hosted.phases.HostedGraphKit; -import com.oracle.svm.util.GuardedAnnotationAccess; import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.ResolvedJavaField; import jdk.vm.ci.meta.ResolvedJavaMethod; import jdk.vm.ci.meta.ResolvedJavaType; +import org.graalvm.nativeimage.AnnotationAccess; final class PodFactorySubstitutionProcessor extends SubstitutionProcessor { private final ConcurrentMap substitutions = new ConcurrentHashMap<>(); @Override public ResolvedJavaMethod lookup(ResolvedJavaMethod method) { - if (method.isSynthetic() && GuardedAnnotationAccess.isAnnotationPresent(method.getDeclaringClass(), PodFactory.class) && !method.isConstructor()) { + if (method.isSynthetic() && AnnotationAccess.isAnnotationPresent(method.getDeclaringClass(), PodFactory.class) && !method.isConstructor()) { assert !(method instanceof CustomSubstitutionMethod); return substitutions.computeIfAbsent(method, PodFactorySubstitutionMethod::new); } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIFunctionTablesFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIFunctionTablesFeature.java index e6ed37ba4183..d17d11864172 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIFunctionTablesFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIFunctionTablesFeature.java @@ -30,6 +30,7 @@ import java.util.List; import java.util.stream.Stream; +import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.c.function.CEntryPoint; import org.graalvm.nativeimage.c.function.CFunctionPointer; @@ -62,7 +63,6 @@ import com.oracle.svm.hosted.jni.JNIPrimitiveArrayOperationMethod.Operation; import com.oracle.svm.hosted.meta.HostedMethod; import com.oracle.svm.hosted.meta.HostedType; -import com.oracle.svm.util.GuardedAnnotationAccess; import jdk.vm.ci.meta.ConstantPool; import jdk.vm.ci.meta.JavaKind; @@ -125,7 +125,7 @@ public void beforeAnalysis(BeforeAnalysisAccess arg) { Stream unimplementedMethods = Stream.of((AnalysisMethod) getSingleMethod(metaAccess, UnimplementedWithJNIEnvArgument.class), (AnalysisMethod) getSingleMethod(metaAccess, UnimplementedWithJavaVMArgument.class)); Stream.concat(analysisMethods, unimplementedMethods).forEach(method -> { - CEntryPoint annotation = GuardedAnnotationAccess.getAnnotation(method, CEntryPoint.class); + CEntryPoint annotation = AnnotationAccess.getAnnotation(method, CEntryPoint.class); assert annotation != null : "only entry points allowed in class"; CEntryPointCallStubSupport.singleton().registerStubForMethod(method, () -> { CEntryPointData data = CEntryPointData.create(method); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/ImplicitAssertionsPhase.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/ImplicitAssertionsPhase.java index 27d8ad73d407..fad3bbb9cbf0 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/ImplicitAssertionsPhase.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/ImplicitAssertionsPhase.java @@ -48,13 +48,13 @@ import org.graalvm.compiler.nodes.java.NewInstanceNode; import org.graalvm.compiler.nodes.spi.CoreProviders; import org.graalvm.compiler.phases.BasePhase; -import com.oracle.svm.util.GuardedAnnotationAccess; import com.oracle.svm.core.code.FactoryMethodMarker; import com.oracle.svm.core.snippets.ImplicitExceptions; import com.oracle.svm.util.ReflectionUtil; import jdk.vm.ci.meta.ResolvedJavaMethod; +import org.graalvm.nativeimage.AnnotationAccess; /** * Code that must be allocation free cannot throw new {@link AssertionError}. Therefore we convert @@ -73,7 +73,7 @@ public class ImplicitAssertionsPhase extends BasePhase { @Override protected void run(StructuredGraph graph, CoreProviders context) { - if (GuardedAnnotationAccess.isAnnotationPresent(graph.method().getDeclaringClass(), FactoryMethodMarker.class)) { + if (AnnotationAccess.isAnnotationPresent(graph.method().getDeclaringClass(), FactoryMethodMarker.class)) { /* * Factory methods, which includes methods in ImplicitExceptions, are the methods that * actually perform the allocations at run time. diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/InlineBeforeAnalysisPolicyImpl.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/InlineBeforeAnalysisPolicyImpl.java index 8aeac3de0623..7e9ae670188c 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/InlineBeforeAnalysisPolicyImpl.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/InlineBeforeAnalysisPolicyImpl.java @@ -50,7 +50,6 @@ import org.graalvm.compiler.nodes.virtual.VirtualArrayNode; import org.graalvm.compiler.nodes.virtual.VirtualObjectNode; import org.graalvm.compiler.options.Option; -import com.oracle.svm.util.GuardedAnnotationAccess; import com.oracle.graal.pointsto.meta.AnalysisMetaAccess; import com.oracle.graal.pointsto.meta.AnalysisMethod; @@ -62,6 +61,7 @@ import com.oracle.svm.hosted.SVMHost; import jdk.vm.ci.meta.ResolvedJavaMethod; +import org.graalvm.nativeimage.AnnotationAccess; /** * The defaults for node limits are very conservative. Only small methods should be inlined. The @@ -139,14 +139,14 @@ protected boolean shouldInlineInvoke(GraphBuilderContext b, ResolvedJavaMethod m if (hostVM.neverInlineTrivial(caller, callee)) { return false; } - if (GuardedAnnotationAccess.isAnnotationPresent(callee, Fold.class) || GuardedAnnotationAccess.isAnnotationPresent(callee, NodeIntrinsic.class)) { + if (AnnotationAccess.isAnnotationPresent(callee, Fold.class) || AnnotationAccess.isAnnotationPresent(callee, NodeIntrinsic.class)) { /* * We should never see a call to such a method. But if we do, do not inline them * otherwise we miss the opportunity later to report it as an error. */ return false; } - if (GuardedAnnotationAccess.isAnnotationPresent(callee, RestrictHeapAccess.class)) { + if (AnnotationAccess.isAnnotationPresent(callee, RestrictHeapAccess.class)) { /* * This is conservative. We do not know the caller's heap restriction state yet because * that can only be computed after static analysis (it relies on the call graph produced diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionDataBuilder.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionDataBuilder.java index 5e31995f4ed3..2f8feb67e905 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionDataBuilder.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionDataBuilder.java @@ -50,6 +50,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; +import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.hosted.Feature.DuringAnalysisAccess; import org.graalvm.nativeimage.hosted.RuntimeProxyCreation; @@ -79,7 +80,6 @@ import com.oracle.svm.hosted.annotation.SubstrateAnnotationExtracter; import com.oracle.svm.hosted.annotation.TypeAnnotationValue; import com.oracle.svm.hosted.substitute.SubstitutionReflectivityFilter; -import com.oracle.svm.util.GuardedAnnotationAccess; import com.oracle.svm.util.ReflectionUtil; import jdk.vm.ci.meta.JavaType; @@ -476,7 +476,7 @@ private void registerTypesForField(DuringAnalysisAccessImpl access, AnalysisFiel * registered as unsafe-accessible, whether they have been explicitly registered or their * Field object is reachable in the image heap. */ - if (!analysisField.isUnsafeAccessed() && !GuardedAnnotationAccess.isAnnotationPresent(analysisField, InjectAccessors.class)) { + if (!analysisField.isUnsafeAccessed() && !AnnotationAccess.isAnnotationPresent(analysisField, InjectAccessors.class)) { analysisField.registerAsAccessed(); analysisField.registerAsUnsafeAccessed(); } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionFeature.java index 900515be20d0..db2d524b348f 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionFeature.java @@ -39,6 +39,7 @@ import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins; import org.graalvm.compiler.phases.util.Providers; import org.graalvm.compiler.serviceprovider.JavaVersionUtil; +import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.c.function.CFunctionPointer; import org.graalvm.nativeimage.hosted.RuntimeReflection; @@ -80,7 +81,6 @@ import com.oracle.svm.hosted.snippets.ReflectionPlugins; import com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor; import com.oracle.svm.util.AnnotationExtracter; -import com.oracle.svm.util.GuardedAnnotationAccess; import com.oracle.svm.util.ModuleSupport; import com.oracle.svm.util.ReflectionUtil; @@ -321,7 +321,7 @@ public int getFieldOffset(Field field, boolean checkUnsafeAccessed) { @Override public String getDeletionReason(Field reflectionField) { ResolvedJavaField field = hMetaAccess.lookupJavaField(reflectionField); - Delete annotation = GuardedAnnotationAccess.getAnnotation(field, Delete.class); + Delete annotation = AnnotationAccess.getAnnotation(field, Delete.class); return annotation != null ? annotation.value() : null; } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionMetadataEncoderImpl.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionMetadataEncoderImpl.java index a7a4220124b9..57cedd2e61e5 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionMetadataEncoderImpl.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionMetadataEncoderImpl.java @@ -63,6 +63,7 @@ import org.graalvm.compiler.core.common.util.TypeConversion; import org.graalvm.compiler.core.common.util.UnsafeArrayTypeWriter; import org.graalvm.compiler.serviceprovider.JavaVersionUtil; +import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.impl.RuntimeReflectionSupport; @@ -93,7 +94,6 @@ import com.oracle.svm.hosted.meta.HostedMethod; import com.oracle.svm.hosted.meta.HostedType; import com.oracle.svm.hosted.substitute.DeletedElementException; -import com.oracle.svm.util.GuardedAnnotationAccess; import com.oracle.svm.util.ReflectionUtil; import jdk.internal.reflect.Reflection; @@ -330,7 +330,7 @@ public void addReflectionFieldMetadata(MetaAccessProvider metaAccess, HostedFiel boolean trustedFinal = isTrustedFinal(reflectField); String signature = getSignature(reflectField); int offset = hostedField.wrapped.isUnsafeAccessed() ? hostedField.getOffset() : SharedField.LOC_UNINITIALIZED; - Delete deleteAnnotation = GuardedAnnotationAccess.getAnnotation(hostedField, Delete.class); + Delete deleteAnnotation = AnnotationAccess.getAnnotation(hostedField, Delete.class); String deletedReason = (deleteAnnotation != null) ? deleteAnnotation.value() : null; /* Fill encoders with the necessary values. */ diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotatedMethod.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotatedMethod.java index 2caae728a58b..1a27cd71a0ce 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotatedMethod.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotatedMethod.java @@ -40,7 +40,6 @@ import com.oracle.svm.core.annotate.AnnotateOriginal; import com.oracle.svm.core.util.VMError; import com.oracle.svm.util.AnnotationWrapper; -import com.oracle.svm.util.GuardedAnnotationAccess; import jdk.vm.ci.meta.Constant; import jdk.vm.ci.meta.ConstantPool; @@ -52,6 +51,7 @@ import jdk.vm.ci.meta.ResolvedJavaType; import jdk.vm.ci.meta.Signature; import jdk.vm.ci.meta.SpeculationLog; +import org.graalvm.nativeimage.AnnotationAccess; public class AnnotatedMethod implements ResolvedJavaMethod, GraphProvider, OriginalMethodProvider, AnnotationWrapper { @@ -225,7 +225,7 @@ public LineNumberTable getLineNumberTable() { @Override public String toString() { - return "AnnotatedMethod"; + return "AnnotatedMethod"; } @Override diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotationSubstitutionProcessor.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotationSubstitutionProcessor.java index fb28a3c04240..333fae9f166f 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotationSubstitutionProcessor.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotationSubstitutionProcessor.java @@ -44,6 +44,7 @@ import java.util.function.BooleanSupplier; import java.util.function.Predicate; +import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; @@ -75,7 +76,6 @@ import com.oracle.svm.hosted.annotation.AnnotationSubstitutionType; import com.oracle.svm.hosted.annotation.CustomSubstitutionMethod; import com.oracle.svm.hosted.classinitialization.ClassInitializationSupport; -import com.oracle.svm.util.GuardedAnnotationAccess; import com.oracle.svm.util.ReflectionUtil; import com.oracle.svm.util.ReflectionUtil.ReflectionUtilError; @@ -219,7 +219,7 @@ public boolean isDeleted(ResolvedJavaField field) { } ResolvedJavaField substitutionField = fieldSubstitutions.get(field); if (substitutionField != null) { - return GuardedAnnotationAccess.isAnnotationPresent(substitutionField, Delete.class); + return AnnotationAccess.isAnnotationPresent(substitutionField, Delete.class); } return false; } @@ -324,7 +324,7 @@ public void processComputedValueFields(BigBang bb) { targetFieldDeclaringType.registerAsReachable(); AnalysisField targetField = bb.getMetaAccess().lookupJavaField(cvField.getTargetField()); targetField.registerAsAccessed(); - assert !GuardedAnnotationAccess.isAnnotationPresent(targetField, Delete.class); + assert !AnnotationAccess.isAnnotationPresent(targetField, Delete.class); targetField.registerAsUnsafeAccessed(); break; } @@ -1084,7 +1084,7 @@ private Class[] interceptParameterTypes(Class[] types) { protected T lookupAnnotation(AnnotatedElement element, Class annotationClass) { assert element instanceof Class || element instanceof Executable || element instanceof Field : element.getClass(); - return GuardedAnnotationAccess.getAnnotation(element, annotationClass); + return AnnotationAccess.getAnnotation(element, annotationClass); } protected static String deleteErrorMessage(AnnotatedElement element, Delete deleteAnnotation, boolean hosted) { diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleFeature.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleFeature.java index fc0b00184042..59d86f4cac34 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleFeature.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleFeature.java @@ -125,6 +125,7 @@ import org.graalvm.compiler.truffle.compiler.phases.TruffleHostInliningPhase; import org.graalvm.compiler.truffle.compiler.substitutions.KnownTruffleTypes; import org.graalvm.compiler.truffle.runtime.TruffleCallBoundary; +import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.hosted.Feature; @@ -160,7 +161,6 @@ import com.oracle.svm.truffle.api.SubstrateThreadLocalHandshakeSnippets; import com.oracle.svm.truffle.api.SubstrateTruffleCompiler; import com.oracle.svm.truffle.api.SubstrateTruffleRuntime; -import com.oracle.svm.util.GuardedAnnotationAccess; import com.oracle.truffle.api.CompilerAsserts; import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; @@ -762,12 +762,12 @@ private void warnAllMethods(MetaAccessProvider metaAccess, Class clazz) { * all methods in the warning list, just enough to trigger the warnings. Accessors are * generally allowed too. */ - if (GuardedAnnotationAccess.getAnnotationTypes(m).length == 0 && !m.getName().startsWith("get") && !m.getName().startsWith("set")) { + if (AnnotationAccess.getAnnotationTypes(m).length == 0 && !m.getName().startsWith("get") && !m.getName().startsWith("set")) { warnMethods.add(metaAccess.lookupJavaMethod(m)); } } for (Executable m : clazz.getDeclaredConstructors()) { - if (GuardedAnnotationAccess.getAnnotationTypes(m).length == 0) { + if (AnnotationAccess.getAnnotationTypes(m).length == 0) { warnMethods.add(metaAccess.lookupJavaMethod(m)); } } From 8a4c3963eb2ca36b83422e5fd17feb7361d92a69 Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Wed, 5 Oct 2022 11:36:40 -0700 Subject: [PATCH 2/4] Replace DirectAnnotationAccess with AnnotationAccess --- .../com/oracle/svm/core/c/function/CEntryPointErrors.java | 4 ++-- .../oracle/svm/core/graal/meta/SubstrateReplacements.java | 4 ++-- .../graal/phases/SubstrateSafepointInsertionPhase.java | 4 ++-- .../src/com/oracle/svm/core/hub/DynamicHub.java | 4 ++-- .../com/oracle/svm/core/jdk/LambdaFormHiddenMethod.java | 4 ++-- .../src/com/oracle/svm/core/jdk/StackTraceUtils.java | 8 ++++---- .../src/com/oracle/svm/core/snippets/SnippetRuntime.java | 6 +++--- .../svm/hosted/snippets/SubstrateGraphBuilderPlugins.java | 4 ++-- .../src/com/oracle/svm/truffle/TruffleBaseFeature.java | 4 ++-- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/function/CEntryPointErrors.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/function/CEntryPointErrors.java index 466234ce3012..772924d5353d 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/function/CEntryPointErrors.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/function/CEntryPointErrors.java @@ -31,7 +31,7 @@ import java.lang.reflect.Field; import java.util.Arrays; -import com.oracle.svm.util.DirectAnnotationAccess; +import org.graalvm.nativeimage.AnnotationAccess; import com.oracle.svm.core.util.VMError; @@ -146,7 +146,7 @@ public static String getDescription(int code) { continue; } int value = field.getInt(null); - String description = DirectAnnotationAccess.getAnnotation(field, CEntryPointErrors.Description.class).value(); + String description = AnnotationAccess.getAnnotation(field, CEntryPointErrors.Description.class).value(); maxValue = Math.max(value, maxValue); if (maxValue >= array.length) { array = Arrays.copyOf(array, 2 * maxValue); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/meta/SubstrateReplacements.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/meta/SubstrateReplacements.java index 55d2a4600bee..270fde34b191 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/meta/SubstrateReplacements.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/meta/SubstrateReplacements.java @@ -78,10 +78,10 @@ import org.graalvm.compiler.replacements.PEGraphDecoder; import org.graalvm.compiler.replacements.ReplacementsImpl; import org.graalvm.compiler.word.WordTypes; +import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.hosted.Feature; -import com.oracle.svm.util.DirectAnnotationAccess; import com.oracle.svm.core.SubstrateTargetDescription; import com.oracle.svm.core.config.ConfigurationValues; @@ -260,7 +260,7 @@ public IntrinsicContext getIntrinsic() { @Platforms(Platform.HOSTED_ONLY.class) @Override public void registerSnippet(ResolvedJavaMethod method, ResolvedJavaMethod original, Object receiver, boolean trackNodeSourcePosition, OptionValues options) { - assert DirectAnnotationAccess.isAnnotationPresent(method, Snippet.class) : "Snippet must be annotated with @" + Snippet.class.getSimpleName() + " " + method; + assert AnnotationAccess.isAnnotationPresent(method, Snippet.class) : "Snippet must be annotated with @" + Snippet.class.getSimpleName() + " " + method; assert method.hasBytecodes() : "Snippet must not be abstract or native"; assert builder.graphs.get(method) == null : "snippet registered twice: " + method.getName(); assert builder.registered.add(method) : "snippet registered twice: " + method.getName(); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/phases/SubstrateSafepointInsertionPhase.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/phases/SubstrateSafepointInsertionPhase.java index 682f15968f00..bac4b90d47ba 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/phases/SubstrateSafepointInsertionPhase.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/phases/SubstrateSafepointInsertionPhase.java @@ -29,9 +29,9 @@ import org.graalvm.compiler.nodes.StructuredGraph; import org.graalvm.compiler.phases.common.LoopSafepointInsertionPhase; import org.graalvm.compiler.phases.tiers.MidTierContext; +import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.c.function.CFunction; import org.graalvm.nativeimage.c.function.InvokeCFunctionPointer; -import com.oracle.svm.util.DirectAnnotationAccess; import com.oracle.svm.core.Uninterruptible; import com.oracle.svm.core.graal.code.SubstrateBackend; @@ -47,7 +47,7 @@ public static boolean needSafepointCheck(SharedMethod method) { /* Uninterruptible methods must not have a safepoint inserted. */ return false; } - if (DirectAnnotationAccess.isAnnotationPresent(method, CFunction.class) || DirectAnnotationAccess.isAnnotationPresent(method, InvokeCFunctionPointer.class)) { + if (AnnotationAccess.isAnnotationPresent(method, CFunction.class) || AnnotationAccess.isAnnotationPresent(method, InvokeCFunctionPointer.class)) { /* * Methods transferring from Java to C have an implicit safepoint check as part of the * transition from C back to Java. So no explicit end-of-method safepoint check needs to diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java index 3bd52448ed79..be91c6459968 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java @@ -57,6 +57,7 @@ import org.graalvm.compiler.core.common.NumUtil; import org.graalvm.compiler.core.common.SuppressFBWarnings; import org.graalvm.compiler.serviceprovider.GraalUnsafeAccess; +import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; @@ -86,7 +87,6 @@ import com.oracle.svm.core.reflect.Target_jdk_internal_reflect_ConstantPool; import com.oracle.svm.core.util.LazyFinalReference; import com.oracle.svm.core.util.VMError; -import com.oracle.svm.util.DirectAnnotationAccess; import com.oracle.svm.util.ReflectionUtil; import com.oracle.svm.util.ReflectionUtil.ReflectionUtilError; @@ -872,7 +872,7 @@ public T[] getAnnotationsByType(Class annotationClass) */ T[] result = getDeclaredAnnotationsByType(annotationClass); - if (result.length == 0 && DirectAnnotationAccess.isAnnotationPresent(annotationClass, Inherited.class)) { + if (result.length == 0 && AnnotationAccess.isAnnotationPresent(annotationClass, Inherited.class)) { DynamicHub superClass = (DynamicHub) this.getSuperclass(); if (superClass != null) { /* Determine if the annotation is associated with the superclass. */ diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/LambdaFormHiddenMethod.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/LambdaFormHiddenMethod.java index 8e06c72885fc..d0cda88a2976 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/LambdaFormHiddenMethod.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/LambdaFormHiddenMethod.java @@ -30,7 +30,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import com.oracle.svm.util.DirectAnnotationAccess; +import org.graalvm.nativeimage.AnnotationAccess; /** * Annotation for types whose methods are synthetic methods for lambda invocations, and ignored for @@ -46,7 +46,7 @@ class Holder { /** Instance of the annotation, useful when the annotation is manually injected. */ - public static final LambdaFormHiddenMethod INSTANCE = DirectAnnotationAccess.getAnnotation(Holder.class, LambdaFormHiddenMethod.class); + public static final LambdaFormHiddenMethod INSTANCE = AnnotationAccess.getAnnotation(Holder.class, LambdaFormHiddenMethod.class); /** * Array that contains only the instance of the annotation, useful when the annotation is diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/StackTraceUtils.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/StackTraceUtils.java index 3d7f0b1fd480..3302cc6017db 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/StackTraceUtils.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/StackTraceUtils.java @@ -32,13 +32,14 @@ import java.util.ArrayList; import com.oracle.svm.core.hub.DynamicHub; +import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.IsolateThread; import org.graalvm.nativeimage.c.function.CodePointer; import org.graalvm.word.Pointer; +import com.oracle.svm.core.NeverInline; import com.oracle.svm.core.SubstrateOptions; import com.oracle.svm.core.SubstrateUtil; -import com.oracle.svm.core.NeverInline; import com.oracle.svm.core.code.FrameInfoQueryResult; import com.oracle.svm.core.heap.VMOperationInfos; import com.oracle.svm.core.snippets.KnownIntrinsics; @@ -52,7 +53,6 @@ import com.oracle.svm.core.thread.Target_jdk_internal_vm_Continuation; import com.oracle.svm.core.thread.VMOperation; import com.oracle.svm.core.thread.VirtualThreads; -import com.oracle.svm.util.DirectAnnotationAccess; import jdk.vm.ci.meta.MetaAccessProvider; import jdk.vm.ci.meta.ResolvedJavaMethod; @@ -185,11 +185,11 @@ public static boolean shouldShowFrame(MetaAccessProvider metaAccess, ResolvedJav } ResolvedJavaType clazz = method.getDeclaringClass(); - if (DirectAnnotationAccess.isAnnotationPresent(clazz, InternalVMMethod.class)) { + if (AnnotationAccess.isAnnotationPresent(clazz, InternalVMMethod.class)) { return false; } - if (!showLambdaFrames && DirectAnnotationAccess.isAnnotationPresent(clazz, LambdaFormHiddenMethod.class)) { + if (!showLambdaFrames && AnnotationAccess.isAnnotationPresent(clazz, LambdaFormHiddenMethod.class)) { return false; } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/snippets/SnippetRuntime.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/snippets/SnippetRuntime.java index 4601368a37b0..f12e8ea9da49 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/snippets/SnippetRuntime.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/snippets/SnippetRuntime.java @@ -31,7 +31,7 @@ import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor; import org.graalvm.compiler.replacements.nodes.BinaryMathIntrinsicNode.BinaryOperation; import org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation; -import com.oracle.svm.util.DirectAnnotationAccess; +import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.word.LocationIdentity; import com.oracle.svm.core.Uninterruptible; @@ -74,7 +74,7 @@ public static SubstrateForeignCallDescriptor findForeignCall(Class declaringC private static SubstrateForeignCallDescriptor findForeignCall(String descriptorName, Class declaringClass, String methodName, boolean isReexecutable, LocationIdentity... additionalKilledLocations) { Method method = findMethod(declaringClass, methodName); - SubstrateForeignCallTarget foreignCallTargetAnnotation = DirectAnnotationAccess.getAnnotation(method, SubstrateForeignCallTarget.class); + SubstrateForeignCallTarget foreignCallTargetAnnotation = AnnotationAccess.getAnnotation(method, SubstrateForeignCallTarget.class); VMError.guarantee(foreignCallTargetAnnotation != null, "Add missing @SubstrateForeignCallTarget to " + declaringClass.getName() + "." + methodName); boolean isUninterruptible = Uninterruptible.Utils.isUninterruptible(method); @@ -85,7 +85,7 @@ private static SubstrateForeignCallDescriptor findForeignCall(String descriptorN private static SubstrateForeignCallDescriptor findForeignJdkCall(String descriptorName, Class declaringClass, String methodName, boolean isReexecutable, boolean isUninterruptible, boolean isFullyUninterruptible, LocationIdentity... additionalKilledLocations) { Method method = findMethod(declaringClass, methodName); - SubstrateForeignCallTarget foreignCallTargetAnnotation = DirectAnnotationAccess.getAnnotation(method, SubstrateForeignCallTarget.class); + SubstrateForeignCallTarget foreignCallTargetAnnotation = AnnotationAccess.getAnnotation(method, SubstrateForeignCallTarget.class); VMError.guarantee(foreignCallTargetAnnotation == null, declaringClass.getName() + "." + methodName + " must not be annotated with @SubstrateForeignCallTarget."); return findForeignCall(descriptorName, method, isReexecutable, isUninterruptible, isFullyUninterruptible, additionalKilledLocations); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/SubstrateGraphBuilderPlugins.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/SubstrateGraphBuilderPlugins.java index e69fd3acd3a0..5fbe274f9e60 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/SubstrateGraphBuilderPlugins.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/SubstrateGraphBuilderPlugins.java @@ -88,6 +88,7 @@ import org.graalvm.compiler.replacements.nodes.MacroNode.MacroParams; import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.compiler.word.WordCastNode; +import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.ImageInfo; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platform; @@ -150,7 +151,6 @@ import com.oracle.svm.hosted.nodes.DeoptProxyNode; import com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor; import com.oracle.svm.util.ClassUtil; -import com.oracle.svm.util.DirectAnnotationAccess; import jdk.vm.ci.code.Architecture; import jdk.vm.ci.meta.DeoptimizationAction; @@ -857,7 +857,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } private static void checkNeverInline(GraphBuilderContext b) { - if (!DirectAnnotationAccess.isAnnotationPresent(b.getMethod(), NeverInline.class)) { + if (!AnnotationAccess.isAnnotationPresent(b.getMethod(), NeverInline.class)) { throw VMError.shouldNotReachHere("Accessing the stack pointer or instruction pointer of the caller frame is only safe and deterministic if the method is not inlined. " + "Therefore, the method " + b.getMethod().format("%H.%n(%p)") + " must be annoated with @" + NeverInline.class.getSimpleName()); } diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleBaseFeature.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleBaseFeature.java index 7776018635fc..1936fbbb30d4 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleBaseFeature.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleBaseFeature.java @@ -59,6 +59,7 @@ import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins; import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration; import org.graalvm.compiler.phases.util.Providers; +import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.hosted.FieldValueTransformer; import org.graalvm.nativeimage.hosted.RuntimeClassInitialization; @@ -96,7 +97,6 @@ import com.oracle.svm.hosted.heap.PodSupport; import com.oracle.svm.hosted.snippets.SubstrateGraphBuilderPlugins; import com.oracle.svm.truffle.api.SubstrateTruffleRuntime; -import com.oracle.svm.util.DirectAnnotationAccess; import com.oracle.svm.util.ReflectionUtil; import com.oracle.truffle.api.CompilerAsserts; import com.oracle.truffle.api.CompilerDirectives; @@ -519,7 +519,7 @@ public void accept(DuringAnalysisAccess t, Class u) { * Never replaceable classes do not count as candidates. They are checked to never be * used for replacing. */ - if (DirectAnnotationAccess.getAnnotation(u, DenyReplace.class) != null) { + if (AnnotationAccess.getAnnotation(u, DenyReplace.class) != null) { return; } From c9b86486f5ee9612835547c1738f9fe0a81b23af Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Tue, 4 Oct 2022 15:52:54 -0700 Subject: [PATCH 3/4] Remove GuardedAnnotationAccess and DirectAnnotationAccess --- sdk/mx.sdk/suite.py | 2 +- .../graalvm/nativeimage/AnnotationAccess.java | 8 +- ...sSupport.java => AnnotationExtracter.java} | 10 +- .../.checkstyle_checks.xml | 4 +- .../oracle/svm/hosted/ImageClassLoader.java | 19 +-- .../hosted/NativeImageClassLoaderSupport.java | 2 +- .../svm/hosted/NativeImageGenerator.java | 5 +- ...eCodeAnnotationAccessSupportSingleton.java | 57 ------- .../SubstrateAnnotationExtracter.java | 45 +++-- .../svm/hosted/reflect/ReflectionFeature.java | 2 +- .../.checkstyle_checks.xml | 4 +- .../oracle/svm/util/AnnotationExtracter.java | 40 ----- .../oracle/svm/util/AnnotationWrapper.java | 56 +++++-- .../svm/util/DirectAnnotationAccess.java | 60 ------- .../svm/util/GuardedAnnotationAccess.java | 154 ------------------ 15 files changed, 104 insertions(+), 364 deletions(-) rename sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/{ImageBuildtimeCodeAnnotationAccessSupport.java => AnnotationExtracter.java} (85%) delete mode 100644 substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/ImageBuildtimeCodeAnnotationAccessSupportSingleton.java delete mode 100644 substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/AnnotationExtracter.java delete mode 100644 substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/DirectAnnotationAccess.java delete mode 100644 substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/GuardedAnnotationAccess.java diff --git a/sdk/mx.sdk/suite.py b/sdk/mx.sdk/suite.py index 013966a2789b..004bb4606c0d 100644 --- a/sdk/mx.sdk/suite.py +++ b/sdk/mx.sdk/suite.py @@ -437,7 +437,7 @@ "org.graalvm.word", "org.graalvm.polyglot.impl to org.graalvm.truffle, com.oracle.graal.graal_enterprise", "org.graalvm.word.impl to jdk.internal.vm.compiler", - "org.graalvm.nativeimage.impl to org.graalvm.nativeimage.builder,org.graalvm.nativeimage.configure,com.oracle.svm.svm_enterprise", + "org.graalvm.nativeimage.impl to org.graalvm.nativeimage.base,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.configure,com.oracle.svm.svm_enterprise", "org.graalvm.nativeimage.impl.clinit to org.graalvm.nativeimage.builder", ], "uses" : [ diff --git a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/AnnotationAccess.java b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/AnnotationAccess.java index 43e3a6d34422..2e275c6bc986 100644 --- a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/AnnotationAccess.java +++ b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/AnnotationAccess.java @@ -44,7 +44,7 @@ import java.lang.reflect.AnnotatedElement; import java.util.Arrays; -import org.graalvm.nativeimage.impl.ImageBuildtimeCodeAnnotationAccessSupport; +import org.graalvm.nativeimage.impl.AnnotationExtracter; /** * This class provides methods to query annotation information on {@link AnnotatedElement}s while @@ -79,7 +79,7 @@ public final class AnnotationAccess { */ public static boolean isAnnotationPresent(AnnotatedElement element, Class annotationClass) { if (ImageInfo.inImageBuildtimeCode()) { - return ImageSingletons.lookup(ImageBuildtimeCodeAnnotationAccessSupport.class).isAnnotationPresent(element, annotationClass); + return ImageSingletons.lookup(AnnotationExtracter.class).hasAnnotation(element, annotationClass); } else { return element.isAnnotationPresent(annotationClass); } @@ -93,7 +93,7 @@ public static boolean isAnnotationPresent(AnnotatedElement element, Class T getAnnotation(AnnotatedElement element, Class annotationType) { if (ImageInfo.inImageBuildtimeCode()) { - return (T) ImageSingletons.lookup(ImageBuildtimeCodeAnnotationAccessSupport.class).getAnnotation(element, annotationType); + return ImageSingletons.lookup(AnnotationExtracter.class).extractAnnotation(element, annotationType, false); } else { return element.getAnnotation(annotationType); } @@ -107,7 +107,7 @@ public static T getAnnotation(AnnotatedElement element, C @SuppressWarnings("unchecked") public static Class[] getAnnotationTypes(AnnotatedElement element) { if (ImageInfo.inImageBuildtimeCode()) { - return ImageSingletons.lookup(ImageBuildtimeCodeAnnotationAccessSupport.class).getAnnotationTypes(element); + return ImageSingletons.lookup(AnnotationExtracter.class).getAnnotationTypes(element); } else { return Arrays.stream(element.getAnnotations()).map(Annotation::annotationType).toArray(Class[]::new); } diff --git a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/ImageBuildtimeCodeAnnotationAccessSupport.java b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/AnnotationExtracter.java similarity index 85% rename from sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/ImageBuildtimeCodeAnnotationAccessSupport.java rename to sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/AnnotationExtracter.java index 6a5cca760324..5f7b193d843e 100644 --- a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/ImageBuildtimeCodeAnnotationAccessSupport.java +++ b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/AnnotationExtracter.java @@ -43,12 +43,14 @@ import java.lang.annotation.Annotation; import java.lang.reflect.AnnotatedElement; -public interface ImageBuildtimeCodeAnnotationAccessSupport { - // needed as Annotation Access-specific ImageSingletons key +import org.graalvm.nativeimage.Platform; +import org.graalvm.nativeimage.Platforms; - boolean isAnnotationPresent(AnnotatedElement element, Class annotationClass); +@Platforms(Platform.HOSTED_ONLY.class) +public interface AnnotationExtracter { + boolean hasAnnotation(AnnotatedElement element, Class annotationType); - Annotation getAnnotation(AnnotatedElement element, Class annotationType); + T extractAnnotation(AnnotatedElement element, Class annotationType, boolean declaredOnly); Class[] getAnnotationTypes(AnnotatedElement element); } diff --git a/substratevm/src/com.oracle.svm.core/.checkstyle_checks.xml b/substratevm/src/com.oracle.svm.core/.checkstyle_checks.xml index 75cc4e32ceb2..293f176e4b72 100644 --- a/substratevm/src/com.oracle.svm.core/.checkstyle_checks.xml +++ b/substratevm/src/com.oracle.svm.core/.checkstyle_checks.xml @@ -6,7 +6,7 @@ @@ -14,7 +14,7 @@ - + diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ImageClassLoader.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ImageClassLoader.java index 76d8bef6bee7..a64ca74c6d26 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ImageClassLoader.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ImageClassLoader.java @@ -51,7 +51,6 @@ import com.oracle.svm.core.SubstrateOptions; import com.oracle.svm.core.TypeResult; -import com.oracle.svm.util.GuardedAnnotationAccess; import com.oracle.svm.util.ReflectionUtil; public final class ImageClassLoader { @@ -143,7 +142,7 @@ private void findSystemElements(Class systemClass) { private boolean isInPlatform(AnnotatedElement element) { try { - Platforms platformAnnotation = GuardedAnnotationAccess.getAnnotation(classLoaderSupport.annotationExtracter, element, Platforms.class); + Platforms platformAnnotation = classLoaderSupport.annotationExtracter.extractAnnotation(element, Platforms.class, false); return NativeImageGenerator.includedIn(platform, platformAnnotation); } catch (Throwable t) { handleClassLoadingError(t); @@ -176,7 +175,7 @@ void handleClass(Class clazz) { do { Platforms platformsAnnotation; try { - platformsAnnotation = GuardedAnnotationAccess.getAnnotation(classLoaderSupport.annotationExtracter, cur, Platforms.class); + platformsAnnotation = classLoaderSupport.annotationExtracter.extractAnnotation(cur, Platforms.class, false); } catch (Throwable t) { handleClassLoadingError(t); return; @@ -374,7 +373,7 @@ public List> findAnnotatedClasses(Class annotatio private void addAnnotatedClasses(EconomicSet> classes, Class annotationClass, ArrayList> result) { for (Class systemClass : classes) { - if (GuardedAnnotationAccess.isAnnotationPresent(classLoaderSupport.annotationExtracter, systemClass, annotationClass)) { + if (classLoaderSupport.annotationExtracter.hasAnnotation(systemClass, annotationClass)) { result.add(systemClass); } } @@ -383,7 +382,7 @@ private void addAnnotatedClasses(EconomicSet> classes, Class findAnnotatedMethods(Class annotationClass) { ArrayList result = new ArrayList<>(); for (Method method : systemMethods) { - if (GuardedAnnotationAccess.isAnnotationPresent(classLoaderSupport.annotationExtracter, method, annotationClass)) { + if (classLoaderSupport.annotationExtracter.hasAnnotation(method, annotationClass)) { result.add(method); } } @@ -395,7 +394,7 @@ public List findAnnotatedMethods(Class[] annotatio for (Method method : systemMethods) { boolean match = true; for (Class annotationClass : annotationClasses) { - if (!GuardedAnnotationAccess.isAnnotationPresent(classLoaderSupport.annotationExtracter, method, annotationClass)) { + if (!classLoaderSupport.annotationExtracter.hasAnnotation(method, annotationClass)) { match = false; break; } @@ -410,7 +409,7 @@ public List findAnnotatedMethods(Class[] annotatio public List findAnnotatedFields(Class annotationClass) { ArrayList result = new ArrayList<>(); for (Field field : systemFields) { - if (GuardedAnnotationAccess.isAnnotationPresent(classLoaderSupport.annotationExtracter, field, annotationClass)) { + if (classLoaderSupport.annotationExtracter.hasAnnotation(field, annotationClass)) { result.add(field); } } @@ -432,13 +431,13 @@ public List> allAnnotations() { public List findAnnotations(Class annotationClass) { List result = new ArrayList<>(); for (Class clazz : findAnnotatedClasses(annotationClass, false)) { - result.add(GuardedAnnotationAccess.getAnnotation(classLoaderSupport.annotationExtracter, clazz, annotationClass)); + result.add(classLoaderSupport.annotationExtracter.extractAnnotation(clazz, annotationClass, false)); } for (Method method : findAnnotatedMethods(annotationClass)) { - result.add(GuardedAnnotationAccess.getAnnotation(classLoaderSupport.annotationExtracter, method, annotationClass)); + result.add(classLoaderSupport.annotationExtracter.extractAnnotation(method, annotationClass, false)); } for (Field field : findAnnotatedFields(annotationClass)) { - result.add(GuardedAnnotationAccess.getAnnotation(classLoaderSupport.annotationExtracter, field, annotationClass)); + result.add(classLoaderSupport.annotationExtracter.extractAnnotation(field, annotationClass, false)); } return result; } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoaderSupport.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoaderSupport.java index 4bc39863de60..7c2b80dcd6fb 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoaderSupport.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoaderSupport.java @@ -76,6 +76,7 @@ import org.graalvm.collections.Pair; import org.graalvm.compiler.options.OptionKey; import org.graalvm.compiler.options.OptionValues; +import org.graalvm.nativeimage.impl.AnnotationExtracter; import com.oracle.svm.core.SubstrateOptions; import com.oracle.svm.core.option.LocatableMultiOptionValue; @@ -87,7 +88,6 @@ import com.oracle.svm.core.util.VMError; import com.oracle.svm.hosted.annotation.SubstrateAnnotationExtracter; import com.oracle.svm.hosted.option.HostedOptionParser; -import com.oracle.svm.util.AnnotationExtracter; import com.oracle.svm.util.ModuleSupport; import com.oracle.svm.util.ReflectionUtil; diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java index e9635b69924c..2cedf7f378ea 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java @@ -125,8 +125,8 @@ import org.graalvm.nativeimage.c.struct.RawStructure; import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.hosted.Feature.OnAnalysisExitAccess; +import org.graalvm.nativeimage.impl.AnnotationExtracter; import org.graalvm.nativeimage.impl.CConstantValueSupport; -import org.graalvm.nativeimage.impl.ImageBuildtimeCodeAnnotationAccessSupport; import org.graalvm.nativeimage.impl.RuntimeClassInitializationSupport; import org.graalvm.nativeimage.impl.SizeOfSupport; import org.graalvm.nativeimage.impl.clinit.ClassInitializationTracking; @@ -251,7 +251,6 @@ import com.oracle.svm.hosted.analysis.SVMAnalysisMetaAccess; import com.oracle.svm.hosted.analysis.SubstrateUnsupportedFeatures; import com.oracle.svm.hosted.annotation.AnnotationSupport; -import com.oracle.svm.hosted.annotation.ImageBuildtimeCodeAnnotationAccessSupportSingleton; import com.oracle.svm.hosted.c.CAnnotationProcessorCache; import com.oracle.svm.hosted.c.CConstantValueSupportImpl; import com.oracle.svm.hosted.c.NativeLibraries; @@ -300,7 +299,6 @@ import com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor; import com.oracle.svm.hosted.substitute.DeletedFieldsPlugin; import com.oracle.svm.hosted.substitute.UnsafeAutomaticSubstitutionProcessor; -import com.oracle.svm.util.AnnotationExtracter; import com.oracle.svm.util.ClassUtil; import com.oracle.svm.util.ImageBuildStatistics; import com.oracle.svm.util.ReflectionUtil; @@ -527,7 +525,6 @@ public void run(Map entryPoints, ImageSingletons.add(TimerCollection.class, timerCollection); ImageSingletons.add(ImageBuildStatistics.TimerCollectionPrinter.class, timerCollection); ImageSingletons.add(AnnotationExtracter.class, loader.classLoaderSupport.annotationExtracter); - ImageSingletons.add(ImageBuildtimeCodeAnnotationAccessSupport.class, new ImageBuildtimeCodeAnnotationAccessSupportSingleton()); ImageSingletons.add(BuildArtifacts.class, (type, artifact) -> buildArtifacts.computeIfAbsent(type, t -> new ArrayList<>()).add(artifact)); ImageSingletons.add(HostedOptionValues.class, new HostedOptionValues(optionProvider.getHostedValues())); ImageSingletons.add(RuntimeOptionValues.class, new RuntimeOptionValues(optionProvider.getRuntimeValues(), allOptionNames)); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/ImageBuildtimeCodeAnnotationAccessSupportSingleton.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/ImageBuildtimeCodeAnnotationAccessSupportSingleton.java deleted file mode 100644 index 4f906cc2bf75..000000000000 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/ImageBuildtimeCodeAnnotationAccessSupportSingleton.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.svm.hosted.annotation; - -import java.lang.annotation.Annotation; -import java.lang.reflect.AnnotatedElement; - -import org.graalvm.nativeimage.ImageInfo; -import org.graalvm.nativeimage.impl.ImageBuildtimeCodeAnnotationAccessSupport; - -import com.oracle.svm.util.GuardedAnnotationAccess; - -public final class ImageBuildtimeCodeAnnotationAccessSupportSingleton implements ImageBuildtimeCodeAnnotationAccessSupport { - - @Override - public boolean isAnnotationPresent(AnnotatedElement element, Class annotationClass) { - assert ImageInfo.inImageBuildtimeCode() : "This method should only be called from within image buildtime code"; - - return GuardedAnnotationAccess.isAnnotationPresent(element, annotationClass); - } - - @Override - public Annotation getAnnotation(AnnotatedElement element, Class annotationType) { - assert ImageInfo.inImageBuildtimeCode() : "This method should only be called from within image buildtime code"; - - return GuardedAnnotationAccess.getAnnotation(element, annotationType); - } - - @Override - public Class[] getAnnotationTypes(AnnotatedElement element) { - assert ImageInfo.inImageBuildtimeCode() : "This method should only be called from within image buildtime code"; - - return GuardedAnnotationAccess.getAnnotationTypes(element); - } -} diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/SubstrateAnnotationExtracter.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/SubstrateAnnotationExtracter.java index e050c7daf944..3ea9886c80e0 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/SubstrateAnnotationExtracter.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/SubstrateAnnotationExtracter.java @@ -41,11 +41,11 @@ import java.util.concurrent.ConcurrentHashMap; import org.graalvm.compiler.debug.GraalError; +import org.graalvm.nativeimage.AnnotationAccess; +import org.graalvm.nativeimage.impl.AnnotationExtracter; import com.oracle.svm.hosted.annotation.AnnotationMetadata.AnnotationExtractionError; -import com.oracle.svm.util.AnnotationExtracter; import com.oracle.svm.util.AnnotationWrapper; -import com.oracle.svm.util.GuardedAnnotationAccess; import com.oracle.svm.util.ReflectionUtil; import jdk.internal.reflect.ConstantPool; @@ -71,8 +71,8 @@ * subclass of {@link AnnotationMemberValue}. The actual annotation can then be created using the * {@link AnnotationMemberValue#get(Class)} method. * - * The {@link SubstrateAnnotationExtracter} is tightly coupled with {@link GuardedAnnotationAccess}, - * which provides implementations of {@link AnnotatedElement#isAnnotationPresent(Class)} and + * The {@link SubstrateAnnotationExtracter} is tightly coupled with {@link AnnotationAccess}, which + * provides implementations of {@link AnnotatedElement#isAnnotationPresent(Class)} and * {@link AnnotatedElement#getAnnotation(Class)}. {@link AnnotatedElement#getAnnotations()} should * in principle not be used during Native Image generation. */ @@ -163,22 +163,43 @@ public class SubstrateAnnotationExtracter implements AnnotationExtracter { @SuppressWarnings("unchecked") @Override public T extractAnnotation(AnnotatedElement element, Class annotationType, boolean declaredOnly) { - for (AnnotationValue annotation : getAnnotationData(element, declaredOnly)) { - if (annotation.type != null && annotation.type.equals(annotationType)) { - return (T) resolvedAnnotationsCache.computeIfAbsent(annotation, value -> (Annotation) value.get(annotationType)); + try { + for (AnnotationValue annotation : getAnnotationData(element, declaredOnly)) { + if (annotation.type != null && annotation.type.equals(annotationType)) { + return (T) resolvedAnnotationsCache.computeIfAbsent(annotation, value -> (Annotation) value.get(annotationType)); + } } + return null; + } catch (LinkageError e) { + /* + * Returning null essentially means that the element doesn't declare the annotationType, + * but we cannot know that since the annotation parsing failed. However, this allows us + * to defend against crashing the image builder if the user code references types + * missing from the classpath. + */ + return null; } - return null; + } @Override public boolean hasAnnotation(AnnotatedElement element, Class annotationType) { - for (AnnotationValue annotation : getAnnotationData(element, false)) { - if (annotation.type != null && annotation.type.equals(annotationType)) { - return true; + try { + for (AnnotationValue annotation : getAnnotationData(element, false)) { + if (annotation.type != null && annotation.type.equals(annotationType)) { + return true; + } } + return false; + } catch (LinkageError e) { + /* + * Returning false essentially means that the element doesn't declare the + * annotationType, but we cannot know that since the annotation parsing failed. However, + * this allows us to defend against crashing the image builder if the user code + * references types missing from the classpath. + */ + return false; } - return false; } @SuppressWarnings("unchecked") diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionFeature.java index db2d524b348f..ccf89f1faafb 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionFeature.java @@ -43,6 +43,7 @@ import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.c.function.CFunctionPointer; import org.graalvm.nativeimage.hosted.RuntimeReflection; +import org.graalvm.nativeimage.impl.AnnotationExtracter; import org.graalvm.nativeimage.impl.RuntimeReflectionSupport; import com.oracle.graal.pointsto.meta.AnalysisMethod; @@ -80,7 +81,6 @@ import com.oracle.svm.hosted.meta.HostedMetaAccess; import com.oracle.svm.hosted.snippets.ReflectionPlugins; import com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor; -import com.oracle.svm.util.AnnotationExtracter; import com.oracle.svm.util.ModuleSupport; import com.oracle.svm.util.ReflectionUtil; diff --git a/substratevm/src/com.oracle.svm.test/.checkstyle_checks.xml b/substratevm/src/com.oracle.svm.test/.checkstyle_checks.xml index d054b5424d01..1ded401b7505 100644 --- a/substratevm/src/com.oracle.svm.test/.checkstyle_checks.xml +++ b/substratevm/src/com.oracle.svm.test/.checkstyle_checks.xml @@ -6,7 +6,7 @@ @@ -14,7 +14,7 @@ - + diff --git a/substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/AnnotationExtracter.java b/substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/AnnotationExtracter.java deleted file mode 100644 index b3365e4d3c21..000000000000 --- a/substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/AnnotationExtracter.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.svm.util; - -import java.lang.annotation.Annotation; -import java.lang.reflect.AnnotatedElement; - -import org.graalvm.nativeimage.Platform; -import org.graalvm.nativeimage.Platforms; - -@Platforms(Platform.HOSTED_ONLY.class) -public interface AnnotationExtracter { - boolean hasAnnotation(AnnotatedElement element, Class annotationType); - - Class[] getAnnotationTypes(AnnotatedElement element); - - T extractAnnotation(AnnotatedElement element, Class annotationType, boolean declaredOnly); -} diff --git a/substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/AnnotationWrapper.java b/substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/AnnotationWrapper.java index 06b3a7c607cd..8807a6025f0b 100644 --- a/substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/AnnotationWrapper.java +++ b/substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/AnnotationWrapper.java @@ -31,6 +31,13 @@ import java.util.Collections; import java.util.List; +import org.graalvm.nativeimage.AnnotationAccess; +import org.graalvm.nativeimage.ImageInfo; +import org.graalvm.nativeimage.ImageSingletons; +import org.graalvm.nativeimage.impl.AnnotationExtracter; + +// Checkstyle: allow direct annotation access + public interface AnnotationWrapper extends AnnotatedElement { AnnotatedElement getAnnotationRoot(); @@ -63,12 +70,12 @@ default boolean isAnnotationPresent(Class annotationClass) } } if (getAnnotationRoot() != null) { - if (GuardedAnnotationAccess.isAnnotationPresent(getAnnotationRoot(), annotationClass)) { + if (AnnotationAccess.isAnnotationPresent(getAnnotationRoot(), annotationClass)) { return true; } } if (getSecondaryAnnotationRoot() != null) { - return GuardedAnnotationAccess.isAnnotationPresent(getSecondaryAnnotationRoot(), annotationClass); + return AnnotationAccess.isAnnotationPresent(getSecondaryAnnotationRoot(), annotationClass); } return false; } @@ -90,18 +97,14 @@ private static Annotation[] getAnnotations(AnnotationWrapper element, boolean de annotations.addAll(Arrays.asList(element.getInjectedAnnotations())); } if (element.getAnnotationRoot() != null) { - Annotation[] rootAnnotations = declaredOnly ? GuardedAnnotationAccess.getDeclaredAnnotations(element.getAnnotationRoot()) - : GuardedAnnotationAccess.getAnnotations(element.getAnnotationRoot()); - for (Annotation rootAnnotation : rootAnnotations) { + for (Annotation rootAnnotation : getRootAnnotations(element.getAnnotationRoot(), declaredOnly)) { if (!ignoredAnnotations.contains(rootAnnotation.annotationType())) { annotations.add(rootAnnotation); } } } if (element.getSecondaryAnnotationRoot() != null) { - Annotation[] secondaryRootAnnotations = declaredOnly ? GuardedAnnotationAccess.getDeclaredAnnotations(element.getSecondaryAnnotationRoot()) - : GuardedAnnotationAccess.getAnnotations(element.getSecondaryAnnotationRoot()); - for (Annotation secondaryRootAnnotation : secondaryRootAnnotations) { + for (Annotation secondaryRootAnnotation : getRootAnnotations(element.getSecondaryAnnotationRoot(), declaredOnly)) { if (!ignoredAnnotations.contains(secondaryRootAnnotation.annotationType())) { annotations.add(secondaryRootAnnotation); } @@ -110,6 +113,25 @@ private static Annotation[] getAnnotations(AnnotationWrapper element, boolean de return annotations.toArray(new Annotation[0]); } + private static Annotation[] getRootAnnotations(AnnotatedElement annotationRoot, boolean declaredOnly) { + try { + if (declaredOnly) { + return annotationRoot.getDeclaredAnnotations(); + } else { + return annotationRoot.getAnnotations(); + } + } catch (LinkageError e) { + /* + * Returning an empty array essentially means that the element doesn't declare any + * annotations, but we know that it is not true since the reason the annotation parsing + * failed is because some annotation referenced a missing class. However, this allows us + * to defend against crashing the image builder if the user code references types + * missing from the classpath. + */ + return new Annotation[0]; + } + } + @Override default T getAnnotation(Class annotationClass) { return getAnnotation(this, annotationClass, false); @@ -136,16 +158,26 @@ private static T getAnnotation(AnnotationWrapper element, } } if (element.getAnnotationRoot() != null) { - T rootAnnotation = declaredOnly ? GuardedAnnotationAccess.getDeclaredAnnotation(element.getAnnotationRoot(), annotationClass) - : GuardedAnnotationAccess.getAnnotation(element.getAnnotationRoot(), annotationClass); + T rootAnnotation = getRootAnnotation(element.getAnnotationRoot(), annotationClass, declaredOnly); if (rootAnnotation != null) { return rootAnnotation; } } if (element.getSecondaryAnnotationRoot() != null) { - return declaredOnly ? GuardedAnnotationAccess.getDeclaredAnnotation(element.getSecondaryAnnotationRoot(), annotationClass) - : GuardedAnnotationAccess.getAnnotation(element.getSecondaryAnnotationRoot(), annotationClass); + return getRootAnnotation(element.getSecondaryAnnotationRoot(), annotationClass, declaredOnly); } return null; } + + private static T getRootAnnotation(AnnotatedElement annotationRoot, Class annotationClass, boolean declaredOnly) { + if (ImageInfo.inImageBuildtimeCode()) { + return ImageSingletons.lookup(AnnotationExtracter.class).extractAnnotation(annotationRoot, annotationClass, declaredOnly); + } else { + if (declaredOnly) { + return annotationRoot.getDeclaredAnnotation(annotationClass); + } else { + return annotationRoot.getAnnotation(annotationClass); + } + } + } } diff --git a/substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/DirectAnnotationAccess.java b/substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/DirectAnnotationAccess.java deleted file mode 100644 index a2b6acd31fa6..000000000000 --- a/substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/DirectAnnotationAccess.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.svm.util; - -import java.lang.annotation.Annotation; -import java.lang.reflect.AnnotatedElement; - -/** - * Wrapper class for annotation access. The purpose of this class is to encapsulate the - * AnnotatedElement.getAnnotation() to avoid the use of the "Checkstyle: allow direct annotation - * access " and "Checkstyle: disallow direct annotation access" comments for situations where the - * annotation access doesn't need to guarded, i.e., in runtime code or code that accesses annotation - * on non-user types. See {@link GuardedAnnotationAccess} for details on these checkstyle rules. - */ -public class DirectAnnotationAccess { - - // Checkstyle: allow direct annotation access - public static boolean isAnnotationPresent(AnnotatedElement element, Class annotationClass) { - return element.getAnnotation(annotationClass) != null; - } - - public static T getAnnotation(AnnotatedElement element, Class annotationType) { - return element.getAnnotation(annotationType); - } - - public static T getDeclaredAnnotation(AnnotatedElement element, Class annotationType) { - return element.getDeclaredAnnotation(annotationType); - } - - public static Annotation[] getAnnotations(AnnotatedElement element) { - return element.getAnnotations(); - } - - public static Annotation[] getDeclaredAnnotations(AnnotatedElement element) { - return element.getDeclaredAnnotations(); - } - // Checkstyle: disallow direct annotation access -} diff --git a/substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/GuardedAnnotationAccess.java b/substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/GuardedAnnotationAccess.java deleted file mode 100644 index 2e66ad8cb92b..000000000000 --- a/substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/GuardedAnnotationAccess.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.svm.util; - -import java.lang.annotation.Annotation; -import java.lang.reflect.AnnotatedElement; -import java.util.Arrays; - -import org.graalvm.nativeimage.ImageInfo; -import org.graalvm.nativeimage.ImageSingletons; - -/** - * Wrapper class for annotation access that defends against - * https://bugs.openjdk.java.net/browse/JDK-7183985: when an annotation declares a Class array - * parameter and one of the referenced classes is not present on the classpath parsing the - * annotations will result in an ArrayStoreException instead of caching of a - * TypeNotPresentExceptionProxy. This is a problem in JDK8 but was fixed in JDK11+. This wrapper - * class also defends against incomplete class path issues. If the element for which annotations are - * queried is a JMVCI value, i.e., a HotSpotResolvedJavaField, or HotSpotResolvedJavaMethod, the - * annotations are read via HotSpotJDKReflection using the - * getFieldAnnotation()/getMethodAnnotation() methods which first construct the field/method object - * via CompilerToVM.asReflectionField()/CompilerToVM.asReflectionExecutable() which eagerly try to - * resolve the types referenced in the element signature. If a field declared type or a method - * return type is missing then JVMCI throws a NoClassDefFoundError. - */ -public final class GuardedAnnotationAccess { - - public static boolean isAnnotationPresent(AnnotatedElement element, Class annotationClass) { - if (ImageInfo.inImageBuildtimeCode()) { - return isAnnotationPresent(ImageSingletons.lookup(AnnotationExtracter.class), element, annotationClass); - } else { - return DirectAnnotationAccess.isAnnotationPresent(element, annotationClass); - } - } - - public static boolean isAnnotationPresent(AnnotationExtracter extracter, AnnotatedElement element, Class annotationClass) { - try { - return extracter.hasAnnotation(element, annotationClass); - } catch (ArrayStoreException | LinkageError e) { - /* - * Returning null essentially means that the element doesn't declare the annotationType, - * but we cannot know that since the annotation parsing failed. However, this allows us - * to defend against crashing the image builder if the above JDK bug is encountered in - * user code or if the user code references types missing from the classpath. - */ - return false; - } - } - - public static T getAnnotation(AnnotatedElement element, Class annotationType) { - if (ImageInfo.inImageBuildtimeCode()) { - return getAnnotation(ImageSingletons.lookup(AnnotationExtracter.class), element, annotationType); - } else { - return DirectAnnotationAccess.getAnnotation(element, annotationType); - } - } - - public static T getAnnotation(AnnotationExtracter extracter, AnnotatedElement element, Class annotationType) { - try { - return extracter.extractAnnotation(element, annotationType, false); - } catch (ArrayStoreException | LinkageError e) { - /* - * Returning null essentially means that the element doesn't declare the annotationType, - * but we cannot know that since the annotation parsing failed. However, this allows us - * to defend against crashing the image builder if the above JDK bug is encountered in - * user code or if the user code references types missing from the classpath. - */ - return null; - } - } - - public static Annotation[] getAnnotations(AnnotatedElement element) { - try { - return DirectAnnotationAccess.getAnnotations(element); - } catch (ArrayStoreException | LinkageError e) { - /* - * Returning an empty array essentially means that the element doesn't declare any - * annotations, but we know that it is not true since the reason the annotation parsing - * failed is because some annotation referenced a missing class. However, this allows us - * to defend against crashing the image builder if the above JDK bug is encountered in - * user code or if the user code references types missing from the classpath. - */ - return new Annotation[0]; - } - } - - @SuppressWarnings("unchecked") - public static Class[] getAnnotationTypes(AnnotatedElement element) { - if (ImageInfo.inImageBuildtimeCode()) { - return ImageSingletons.lookup(AnnotationExtracter.class).getAnnotationTypes(element); - } else { - return Arrays.stream(DirectAnnotationAccess.getAnnotations(element)).map(Annotation::annotationType).toArray(Class[]::new); - } - } - - public static T getDeclaredAnnotation(AnnotatedElement element, Class annotationType) { - if (ImageInfo.inImageBuildtimeCode()) { - return getDeclaredAnnotation(ImageSingletons.lookup(AnnotationExtracter.class), element, annotationType); - } else { - return DirectAnnotationAccess.getDeclaredAnnotation(element, annotationType); - } - } - - public static T getDeclaredAnnotation(AnnotationExtracter extracter, AnnotatedElement element, Class annotationType) { - try { - return extracter.extractAnnotation(element, annotationType, true); - } catch (ArrayStoreException | LinkageError e) { - /* - * Returning null essentially means that the element doesn't declare the annotationType, - * but we cannot know that since the annotation parsing failed. However, this allows us - * to defend against crashing the image builder if the above JDK bug is encountered in - * user code or if the user code references types missing from the classpath. - */ - return null; - } - } - - public static Annotation[] getDeclaredAnnotations(AnnotatedElement element) { - try { - return DirectAnnotationAccess.getDeclaredAnnotations(element); - } catch (ArrayStoreException | LinkageError e) { - /* - * Returning an empty array essentially means that the element doesn't declare any - * annotations, but we know that it is not true since the reason the annotation parsing - * failed is because some annotation referenced a missing class. However, this allows us - * to defend against crashing the image builder if the above JDK bug is encountered in - * user code or if the user code references types missing from the classpath. - */ - return new Annotation[0]; - } - } -} From 8c7d58f4b92c4480180b7a234478d9010821e635 Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Thu, 6 Oct 2022 09:02:18 -0700 Subject: [PATCH 4/4] Rename Extracter to Extractor --- .../graalvm/nativeimage/AnnotationAccess.java | 8 ++++---- ...Extracter.java => AnnotationExtractor.java} | 2 +- .../oracle/svm/hosted/ImageClassLoader.java | 18 +++++++++--------- .../hosted/NativeImageClassLoaderSupport.java | 8 ++++---- .../svm/hosted/NativeImageGenerator.java | 4 ++-- ....java => SubstrateAnnotationExtractor.java} | 8 ++++---- .../hosted/reflect/ReflectionDataBuilder.java | 18 +++++++++--------- .../svm/hosted/reflect/ReflectionFeature.java | 6 +++--- .../com/oracle/svm/util/AnnotationWrapper.java | 4 ++-- 9 files changed, 38 insertions(+), 38 deletions(-) rename sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/{AnnotationExtracter.java => AnnotationExtractor.java} (98%) rename substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/{SubstrateAnnotationExtracter.java => SubstrateAnnotationExtractor.java} (99%) diff --git a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/AnnotationAccess.java b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/AnnotationAccess.java index 2e275c6bc986..272e1f2cf94a 100644 --- a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/AnnotationAccess.java +++ b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/AnnotationAccess.java @@ -44,7 +44,7 @@ import java.lang.reflect.AnnotatedElement; import java.util.Arrays; -import org.graalvm.nativeimage.impl.AnnotationExtracter; +import org.graalvm.nativeimage.impl.AnnotationExtractor; /** * This class provides methods to query annotation information on {@link AnnotatedElement}s while @@ -79,7 +79,7 @@ public final class AnnotationAccess { */ public static boolean isAnnotationPresent(AnnotatedElement element, Class annotationClass) { if (ImageInfo.inImageBuildtimeCode()) { - return ImageSingletons.lookup(AnnotationExtracter.class).hasAnnotation(element, annotationClass); + return ImageSingletons.lookup(AnnotationExtractor.class).hasAnnotation(element, annotationClass); } else { return element.isAnnotationPresent(annotationClass); } @@ -93,7 +93,7 @@ public static boolean isAnnotationPresent(AnnotatedElement element, Class T getAnnotation(AnnotatedElement element, Class annotationType) { if (ImageInfo.inImageBuildtimeCode()) { - return ImageSingletons.lookup(AnnotationExtracter.class).extractAnnotation(element, annotationType, false); + return ImageSingletons.lookup(AnnotationExtractor.class).extractAnnotation(element, annotationType, false); } else { return element.getAnnotation(annotationType); } @@ -107,7 +107,7 @@ public static T getAnnotation(AnnotatedElement element, C @SuppressWarnings("unchecked") public static Class[] getAnnotationTypes(AnnotatedElement element) { if (ImageInfo.inImageBuildtimeCode()) { - return ImageSingletons.lookup(AnnotationExtracter.class).getAnnotationTypes(element); + return ImageSingletons.lookup(AnnotationExtractor.class).getAnnotationTypes(element); } else { return Arrays.stream(element.getAnnotations()).map(Annotation::annotationType).toArray(Class[]::new); } diff --git a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/AnnotationExtracter.java b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/AnnotationExtractor.java similarity index 98% rename from sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/AnnotationExtracter.java rename to sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/AnnotationExtractor.java index 5f7b193d843e..2186d03e3fe2 100644 --- a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/AnnotationExtracter.java +++ b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/AnnotationExtractor.java @@ -47,7 +47,7 @@ import org.graalvm.nativeimage.Platforms; @Platforms(Platform.HOSTED_ONLY.class) -public interface AnnotationExtracter { +public interface AnnotationExtractor { boolean hasAnnotation(AnnotatedElement element, Class annotationType); T extractAnnotation(AnnotatedElement element, Class annotationType, boolean declaredOnly); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ImageClassLoader.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ImageClassLoader.java index a64ca74c6d26..13491a00239b 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ImageClassLoader.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ImageClassLoader.java @@ -142,7 +142,7 @@ private void findSystemElements(Class systemClass) { private boolean isInPlatform(AnnotatedElement element) { try { - Platforms platformAnnotation = classLoaderSupport.annotationExtracter.extractAnnotation(element, Platforms.class, false); + Platforms platformAnnotation = classLoaderSupport.annotationExtractor.extractAnnotation(element, Platforms.class, false); return NativeImageGenerator.includedIn(platform, platformAnnotation); } catch (Throwable t) { handleClassLoadingError(t); @@ -175,7 +175,7 @@ void handleClass(Class clazz) { do { Platforms platformsAnnotation; try { - platformsAnnotation = classLoaderSupport.annotationExtracter.extractAnnotation(cur, Platforms.class, false); + platformsAnnotation = classLoaderSupport.annotationExtractor.extractAnnotation(cur, Platforms.class, false); } catch (Throwable t) { handleClassLoadingError(t); return; @@ -373,7 +373,7 @@ public List> findAnnotatedClasses(Class annotatio private void addAnnotatedClasses(EconomicSet> classes, Class annotationClass, ArrayList> result) { for (Class systemClass : classes) { - if (classLoaderSupport.annotationExtracter.hasAnnotation(systemClass, annotationClass)) { + if (classLoaderSupport.annotationExtractor.hasAnnotation(systemClass, annotationClass)) { result.add(systemClass); } } @@ -382,7 +382,7 @@ private void addAnnotatedClasses(EconomicSet> classes, Class findAnnotatedMethods(Class annotationClass) { ArrayList result = new ArrayList<>(); for (Method method : systemMethods) { - if (classLoaderSupport.annotationExtracter.hasAnnotation(method, annotationClass)) { + if (classLoaderSupport.annotationExtractor.hasAnnotation(method, annotationClass)) { result.add(method); } } @@ -394,7 +394,7 @@ public List findAnnotatedMethods(Class[] annotatio for (Method method : systemMethods) { boolean match = true; for (Class annotationClass : annotationClasses) { - if (!classLoaderSupport.annotationExtracter.hasAnnotation(method, annotationClass)) { + if (!classLoaderSupport.annotationExtractor.hasAnnotation(method, annotationClass)) { match = false; break; } @@ -409,7 +409,7 @@ public List findAnnotatedMethods(Class[] annotatio public List findAnnotatedFields(Class annotationClass) { ArrayList result = new ArrayList<>(); for (Field field : systemFields) { - if (classLoaderSupport.annotationExtracter.hasAnnotation(field, annotationClass)) { + if (classLoaderSupport.annotationExtractor.hasAnnotation(field, annotationClass)) { result.add(field); } } @@ -431,13 +431,13 @@ public List> allAnnotations() { public List findAnnotations(Class annotationClass) { List result = new ArrayList<>(); for (Class clazz : findAnnotatedClasses(annotationClass, false)) { - result.add(classLoaderSupport.annotationExtracter.extractAnnotation(clazz, annotationClass, false)); + result.add(classLoaderSupport.annotationExtractor.extractAnnotation(clazz, annotationClass, false)); } for (Method method : findAnnotatedMethods(annotationClass)) { - result.add(classLoaderSupport.annotationExtracter.extractAnnotation(method, annotationClass, false)); + result.add(classLoaderSupport.annotationExtractor.extractAnnotation(method, annotationClass, false)); } for (Field field : findAnnotatedFields(annotationClass)) { - result.add(classLoaderSupport.annotationExtracter.extractAnnotation(field, annotationClass, false)); + result.add(classLoaderSupport.annotationExtractor.extractAnnotation(field, annotationClass, false)); } return result; } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoaderSupport.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoaderSupport.java index 7c2b80dcd6fb..88b460db41eb 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoaderSupport.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoaderSupport.java @@ -76,7 +76,7 @@ import org.graalvm.collections.Pair; import org.graalvm.compiler.options.OptionKey; import org.graalvm.compiler.options.OptionValues; -import org.graalvm.nativeimage.impl.AnnotationExtracter; +import org.graalvm.nativeimage.impl.AnnotationExtractor; import com.oracle.svm.core.SubstrateOptions; import com.oracle.svm.core.option.LocatableMultiOptionValue; @@ -86,7 +86,7 @@ import com.oracle.svm.core.util.InterruptImageBuilding; import com.oracle.svm.core.util.UserError; import com.oracle.svm.core.util.VMError; -import com.oracle.svm.hosted.annotation.SubstrateAnnotationExtracter; +import com.oracle.svm.hosted.annotation.SubstrateAnnotationExtractor; import com.oracle.svm.hosted.option.HostedOptionParser; import com.oracle.svm.util.ModuleSupport; import com.oracle.svm.util.ReflectionUtil; @@ -111,7 +111,7 @@ public class NativeImageClassLoaderSupport { public final ModuleLayer moduleLayerForImageBuild; public final ModuleFinder modulepathModuleFinder; - public final AnnotationExtracter annotationExtracter; + public final AnnotationExtractor annotationExtractor; static final class ClassPathClassLoader extends URLClassLoader { ClassPathClassLoader(URL[] urls, ClassLoader parent) { @@ -163,7 +163,7 @@ protected NativeImageClassLoaderSupport(ClassLoader defaultSystemClassLoader, St modulepathModuleFinder = ModuleFinder.of(modulepath().toArray(Path[]::new)); - annotationExtracter = new SubstrateAnnotationExtracter(); + annotationExtractor = new SubstrateAnnotationExtractor(); } List classpath() { diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java index 2cedf7f378ea..cc70704c23a9 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java @@ -125,7 +125,7 @@ import org.graalvm.nativeimage.c.struct.RawStructure; import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.hosted.Feature.OnAnalysisExitAccess; -import org.graalvm.nativeimage.impl.AnnotationExtracter; +import org.graalvm.nativeimage.impl.AnnotationExtractor; import org.graalvm.nativeimage.impl.CConstantValueSupport; import org.graalvm.nativeimage.impl.RuntimeClassInitializationSupport; import org.graalvm.nativeimage.impl.SizeOfSupport; @@ -524,7 +524,7 @@ public void run(Map entryPoints, ImageSingletons.add(ProgressReporter.class, reporter); ImageSingletons.add(TimerCollection.class, timerCollection); ImageSingletons.add(ImageBuildStatistics.TimerCollectionPrinter.class, timerCollection); - ImageSingletons.add(AnnotationExtracter.class, loader.classLoaderSupport.annotationExtracter); + ImageSingletons.add(AnnotationExtractor.class, loader.classLoaderSupport.annotationExtractor); ImageSingletons.add(BuildArtifacts.class, (type, artifact) -> buildArtifacts.computeIfAbsent(type, t -> new ArrayList<>()).add(artifact)); ImageSingletons.add(HostedOptionValues.class, new HostedOptionValues(optionProvider.getHostedValues())); ImageSingletons.add(RuntimeOptionValues.class, new RuntimeOptionValues(optionProvider.getRuntimeValues(), allOptionNames)); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/SubstrateAnnotationExtracter.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/SubstrateAnnotationExtractor.java similarity index 99% rename from substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/SubstrateAnnotationExtracter.java rename to substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/SubstrateAnnotationExtractor.java index 3ea9886c80e0..0f5e08a114b2 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/SubstrateAnnotationExtracter.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/SubstrateAnnotationExtractor.java @@ -42,7 +42,7 @@ import org.graalvm.compiler.debug.GraalError; import org.graalvm.nativeimage.AnnotationAccess; -import org.graalvm.nativeimage.impl.AnnotationExtracter; +import org.graalvm.nativeimage.impl.AnnotationExtractor; import com.oracle.svm.hosted.annotation.AnnotationMetadata.AnnotationExtractionError; import com.oracle.svm.util.AnnotationWrapper; @@ -63,7 +63,7 @@ * through the JDK's {@link AnnotationParser} initializes the class of every annotation on the * queried element. * - * When queried, the extracter looks for the root of the provided element, which can be a + * When queried, the extractor looks for the root of the provided element, which can be a * {@link Field}, {@link Method}, {@link Constructor} or {@link Class} object, as well as a record * component on JDK 17. It then looks into the byte arrays representing annotations in the root * object and outputs wrapper classes containing all the information necessary to reconstruct the @@ -71,12 +71,12 @@ * subclass of {@link AnnotationMemberValue}. The actual annotation can then be created using the * {@link AnnotationMemberValue#get(Class)} method. * - * The {@link SubstrateAnnotationExtracter} is tightly coupled with {@link AnnotationAccess}, which + * The {@link SubstrateAnnotationExtractor} is tightly coupled with {@link AnnotationAccess}, which * provides implementations of {@link AnnotatedElement#isAnnotationPresent(Class)} and * {@link AnnotatedElement#getAnnotation(Class)}. {@link AnnotatedElement#getAnnotations()} should * in principle not be used during Native Image generation. */ -public class SubstrateAnnotationExtracter implements AnnotationExtracter { +public class SubstrateAnnotationExtractor implements AnnotationExtractor { private final Map, AnnotationValue[]> annotationCache = new ConcurrentHashMap<>(); private final Map declaredAnnotationCache = new ConcurrentHashMap<>(); private final Map parameterAnnotationCache = new ConcurrentHashMap<>(); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionDataBuilder.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionDataBuilder.java index 2f8feb67e905..a96ca48c8e31 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionDataBuilder.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionDataBuilder.java @@ -77,7 +77,7 @@ import com.oracle.svm.hosted.annotation.AnnotationMemberValue; import com.oracle.svm.hosted.annotation.AnnotationSubstitutionType; import com.oracle.svm.hosted.annotation.AnnotationValue; -import com.oracle.svm.hosted.annotation.SubstrateAnnotationExtracter; +import com.oracle.svm.hosted.annotation.SubstrateAnnotationExtractor; import com.oracle.svm.hosted.annotation.TypeAnnotationValue; import com.oracle.svm.hosted.substitute.SubstitutionReflectivityFilter; import com.oracle.svm.util.ReflectionUtil; @@ -121,10 +121,10 @@ public class ReflectionDataBuilder extends ConditionalConfigurationRegistry impl private final Map filteredParameterAnnotations = new ConcurrentHashMap<>(); private final Map filteredTypeAnnotations = new ConcurrentHashMap<>(); - private final SubstrateAnnotationExtracter annotationExtracter; + private final SubstrateAnnotationExtractor annotationExtractor; - ReflectionDataBuilder(SubstrateAnnotationExtracter annotationExtracter) { - this.annotationExtracter = annotationExtracter; + ReflectionDataBuilder(SubstrateAnnotationExtractor annotationExtractor) { + this.annotationExtractor = annotationExtractor; } @Override @@ -596,7 +596,7 @@ private void registerTypesForAnnotations(DuringAnalysisAccessImpl access, Annota if (annotatedElement != null) { filteredAnnotations.computeIfAbsent(annotatedElement, element -> { List includedAnnotations = new ArrayList<>(); - for (AnnotationValue annotation : annotationExtracter.getDeclaredAnnotationData(element)) { + for (AnnotationValue annotation : annotationExtractor.getDeclaredAnnotationData(element)) { if (includeAnnotation(access, annotation)) { includedAnnotations.add(annotation); registerTypes(access, annotation.getTypes()); @@ -610,7 +610,7 @@ private void registerTypesForAnnotations(DuringAnalysisAccessImpl access, Annota private void registerTypesForParameterAnnotations(DuringAnalysisAccessImpl access, AnalysisMethod executable) { if (executable != null) { filteredParameterAnnotations.computeIfAbsent(executable, element -> { - AnnotationValue[][] parameterAnnotations = annotationExtracter.getParameterAnnotationData(element); + AnnotationValue[][] parameterAnnotations = annotationExtractor.getParameterAnnotationData(element); AnnotationValue[][] includedParameterAnnotations = new AnnotationValue[parameterAnnotations.length][]; for (int i = 0; i < includedParameterAnnotations.length; ++i) { AnnotationValue[] annotations = parameterAnnotations[i]; @@ -632,7 +632,7 @@ private void registerTypesForTypeAnnotations(DuringAnalysisAccessImpl access, An if (annotatedElement != null) { filteredTypeAnnotations.computeIfAbsent(annotatedElement, element -> { List includedTypeAnnotations = new ArrayList<>(); - for (TypeAnnotationValue typeAnnotation : annotationExtracter.getTypeAnnotationData(element)) { + for (TypeAnnotationValue typeAnnotation : annotationExtractor.getTypeAnnotationData(element)) { if (includeAnnotation(access, typeAnnotation.getAnnotationData())) { includedTypeAnnotations.add(typeAnnotation); registerTypes(access, typeAnnotation.getAnnotationData().getTypes()); @@ -644,7 +644,7 @@ private void registerTypesForTypeAnnotations(DuringAnalysisAccessImpl access, An } private void registerTypesForAnnotationDefault(DuringAnalysisAccessImpl access, AnalysisMethod method) { - AnnotationMemberValue annotationDefault = annotationExtracter.getAnnotationDefaultData(method); + AnnotationMemberValue annotationDefault = annotationExtractor.getAnnotationDefaultData(method); if (annotationDefault != null) { registerTypes(access, annotationDefault.getTypes()); } @@ -902,7 +902,7 @@ public TypeAnnotationValue[] getTypeAnnotationData(AnnotatedElement element) { } public AnnotationMemberValue getAnnotationDefaultData(AnnotatedElement element) { - return annotationExtracter.getAnnotationDefaultData(element); + return annotationExtractor.getAnnotationDefaultData(element); } @Override diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionFeature.java index ccf89f1faafb..5cb0c7717053 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionFeature.java @@ -43,7 +43,7 @@ import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.c.function.CFunctionPointer; import org.graalvm.nativeimage.hosted.RuntimeReflection; -import org.graalvm.nativeimage.impl.AnnotationExtracter; +import org.graalvm.nativeimage.impl.AnnotationExtractor; import org.graalvm.nativeimage.impl.RuntimeReflectionSupport; import com.oracle.graal.pointsto.meta.AnalysisMethod; @@ -74,7 +74,7 @@ import com.oracle.svm.hosted.FeatureImpl.DuringSetupAccessImpl; import com.oracle.svm.hosted.ImageClassLoader; import com.oracle.svm.hosted.analysis.Inflation; -import com.oracle.svm.hosted.annotation.SubstrateAnnotationExtracter; +import com.oracle.svm.hosted.annotation.SubstrateAnnotationExtractor; import com.oracle.svm.hosted.code.FactoryMethodSupport; import com.oracle.svm.hosted.config.ConfigurationParserUtils; import com.oracle.svm.hosted.meta.HostedField; @@ -249,7 +249,7 @@ public void afterRegistration(AfterRegistrationAccess access) { ImageSingletons.add(ReflectionSubstitutionSupport.class, this); - reflectionData = new ReflectionDataBuilder((SubstrateAnnotationExtracter) ImageSingletons.lookup(AnnotationExtracter.class)); + reflectionData = new ReflectionDataBuilder((SubstrateAnnotationExtractor) ImageSingletons.lookup(AnnotationExtractor.class)); ImageSingletons.add(RuntimeReflectionSupport.class, reflectionData); ImageSingletons.add(ReflectionHostedSupport.class, reflectionData); } diff --git a/substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/AnnotationWrapper.java b/substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/AnnotationWrapper.java index 8807a6025f0b..ced77941831f 100644 --- a/substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/AnnotationWrapper.java +++ b/substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/AnnotationWrapper.java @@ -34,7 +34,7 @@ import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.ImageInfo; import org.graalvm.nativeimage.ImageSingletons; -import org.graalvm.nativeimage.impl.AnnotationExtracter; +import org.graalvm.nativeimage.impl.AnnotationExtractor; // Checkstyle: allow direct annotation access @@ -171,7 +171,7 @@ private static T getAnnotation(AnnotationWrapper element, private static T getRootAnnotation(AnnotatedElement annotationRoot, Class annotationClass, boolean declaredOnly) { if (ImageInfo.inImageBuildtimeCode()) { - return ImageSingletons.lookup(AnnotationExtracter.class).extractAnnotation(annotationRoot, annotationClass, declaredOnly); + return ImageSingletons.lookup(AnnotationExtractor.class).extractAnnotation(annotationRoot, annotationClass, declaredOnly); } else { if (declaredOnly) { return annotationRoot.getDeclaredAnnotation(annotationClass);