Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/mx.sdk/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import java.lang.reflect.AnnotatedElement;
import java.util.Arrays;

import org.graalvm.nativeimage.impl.ImageBuildtimeCodeAnnotationAccessSupport;
import org.graalvm.nativeimage.impl.AnnotationExtractor;

/**
* This class provides methods to query annotation information on {@link AnnotatedElement}s while
Expand Down Expand Up @@ -79,7 +79,7 @@ public final class AnnotationAccess {
*/
public static boolean isAnnotationPresent(AnnotatedElement element, Class<? extends Annotation> annotationClass) {
if (ImageInfo.inImageBuildtimeCode()) {
return ImageSingletons.lookup(ImageBuildtimeCodeAnnotationAccessSupport.class).isAnnotationPresent(element, annotationClass);
return ImageSingletons.lookup(AnnotationExtractor.class).hasAnnotation(element, annotationClass);
} else {
return element.isAnnotationPresent(annotationClass);
}
Expand All @@ -93,7 +93,7 @@ public static boolean isAnnotationPresent(AnnotatedElement element, Class<? exte
@SuppressWarnings("unchecked")
public static <T extends Annotation> T getAnnotation(AnnotatedElement element, Class<T> annotationType) {
if (ImageInfo.inImageBuildtimeCode()) {
return (T) ImageSingletons.lookup(ImageBuildtimeCodeAnnotationAccessSupport.class).getAnnotation(element, annotationType);
return ImageSingletons.lookup(AnnotationExtractor.class).extractAnnotation(element, annotationType, false);
} else {
return element.getAnnotation(annotationType);
}
Expand All @@ -107,7 +107,7 @@ public static <T extends Annotation> T getAnnotation(AnnotatedElement element, C
@SuppressWarnings("unchecked")
public static Class<? extends Annotation>[] getAnnotationTypes(AnnotatedElement element) {
if (ImageInfo.inImageBuildtimeCode()) {
return ImageSingletons.lookup(ImageBuildtimeCodeAnnotationAccessSupport.class).getAnnotationTypes(element);
return ImageSingletons.lookup(AnnotationExtractor.class).getAnnotationTypes(element);
} else {
return Arrays.stream(element.getAnnotations()).map(Annotation::annotationType).toArray(Class[]::new);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends Annotation> annotationClass);
@Platforms(Platform.HOSTED_ONLY.class)
public interface AnnotationExtractor {
boolean hasAnnotation(AnnotatedElement element, Class<? extends Annotation> annotationType);

Annotation getAnnotation(AnnotatedElement element, Class<? extends Annotation> annotationType);
<T extends Annotation> T extractAnnotation(AnnotatedElement element, Class<T> annotationType, boolean declaredOnly);

Class<? extends Annotation>[] getAnnotationTypes(AnnotatedElement element);
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,14 @@
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;
import jdk.vm.ci.meta.Constant;
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 {

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions substratevm/src/com.oracle.svm.core/.checkstyle_checks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<module name="TreeWalker">

<!-- Disallows direct calls to "AnnotatedElement.get(Declared)Annotation(s)". This check can yield false positives,
i.e., it will match any ".get(Declared)Annotation(s)" calls that are not preceded by "GuardedAnnotationAccess"
i.e., it will match any ".get(Declared)Annotation(s)" calls that are not preceded by "AnnotationAccess"
since checkstyle relies only on pattern matching and it cannot determine the type of the call's receiver object.
-->
<module name="RegexpSinglelineJava">
<property name="id" value="annotationAccess"/>
<metadata name="net.sf.eclipsecs.core.comment" value="Disallow calls to AnnotatedElement.get(Declared)Annotation(s)."/>
<property name="severity" value="error"/>
<property name="format" value="(?&lt;!AnnotationAccess)\.(getAnnotation|getAnnotations|getDeclaredAnnotation|getDeclaredAnnotations|isAnnotationPresent)\b"/>
<property name="message" value="Direct calls to java.lang.reflect.AnnotatedElement.get(Declared)Annotation(s) are restricted. Use either com.oracle.svm.util.GuardedAnnotationAccess or com.oracle.svm.util.DirectAnnotationAccess methods. (Use &quot;// Checkstyle: allow direct annotation access... // Checkstyle: disallow direct annotation access&quot; to disable this check.)"/>
<property name="message" value="Direct calls to java.lang.reflect.AnnotatedElement.get(Declared)Annotation(s) are restricted. Use org.graalvm.nativeimage.AnnotationAccess methods. (Use &quot;// Checkstyle: allow direct annotation access... // Checkstyle: disallow direct annotation access&quot; to disable this check.)"/>
<property name="ignoreComments" value="true"/>
</module>
<module name="SuppressionCommentFilter">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Loading