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
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,6 @@ public boolean shouldVerifyFoldableMethods() {
return true;
}

/**
* Determines if {@link VerifyAnnotatedElementUsage} is to be checked.
*/
public boolean shouldVerifyAnnotatedElementUsages() {
return true;
}

public void verifyCurrentTimeMillis(MetaAccessProvider meta, MethodCallTargetNode t, ResolvedJavaType declaringClass) {
final ResolvedJavaType services = meta.lookupJavaType(GraalServices.class);
if (!declaringClass.equals(services)) {
Expand Down Expand Up @@ -385,6 +378,7 @@ public static void runTest(InvariantsTool tool) {
verifiers.add(new VerifyLoopInfo());
verifiers.add(new VerifyGuardsStageUsages());
verifiers.add(new VerifyAArch64RegisterUsages());
verifiers.add(new VerifyAnnotatedElementUsage());
VerifyAssertionUsage assertionUsages = null;
boolean checkAssertions = tool.checkAssertions();

Expand All @@ -403,9 +397,6 @@ public static void runTest(InvariantsTool tool) {
if (tool.shouldVerifyFoldableMethods()) {
verifiers.add(foldableMethodsVerifier);
}
if (tool.shouldVerifyAnnotatedElementUsages()) {
verifiers.add(new VerifyAnnotatedElementUsage());
}

verifiers.add(new VerifyCurrentTimeMillisUsage(tool));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public static Object parseMemberValue(ResolvedJavaType memberType,
result = new ElementTypeMismatch(memberType.toJavaName());
} else if (tag != '[' &&
!(result instanceof ErrorElement) &&
!matchesMemberType(result, memberType)) {
!AnnotationValueType.matchesElementType(result, memberType)) {
if (result instanceof AnnotationValue) {
result = new ElementTypeMismatch(result.toString());
} else {
Expand All @@ -161,22 +161,6 @@ public static Object parseMemberValue(ResolvedJavaType memberType,
return result;
}

private static boolean matchesMemberType(Object result, ResolvedJavaType memberType) {
if (result instanceof AnnotationValue av) {
return memberType.equals(av.getAnnotationType());
}
if (result instanceof ResolvedJavaType) {
return memberType.getName().equals("Ljava/lang/Class;");
}
if (result instanceof EnumElement ee) {
return ee.enumType.equals(memberType);
}
if (memberType.isPrimitive()) {
return result.getClass() == memberType.getJavaKind().toBoxedJavaClass();
}
return memberType.toJavaName().equals(result.getClass().getName());
}

private static Object parsePrimitiveConst(char tag,
ByteBuffer buf, ConstantPool constPool) {
int constIndex = buf.getShort() & 0xFFFF;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,29 @@ private AnnotationValueType(ResolvedJavaType annotationClass) {
}
}

/**
* Determines if the type of {@code elementValue} matches {@code elementType}.
*
* @param elementValue a value of a type returned by {@link AnnotationValue#get}
* @param elementType an annotation element type (i.e. the return type of an annotation
* interface method)
*/
public static boolean matchesElementType(Object elementValue, ResolvedJavaType elementType) {
if (elementValue instanceof AnnotationValue av) {
return elementType.equals(av.getAnnotationType());
}
if (elementValue instanceof ResolvedJavaType) {
return elementType.getName().equals("Ljava/lang/Class;");
}
if (elementValue instanceof EnumElement ee) {
return ee.enumType.equals(elementType);
}
if (elementType.isPrimitive()) {
return elementValue.getClass() == elementType.getJavaKind().toBoxedJavaClass();
}
return elementType.toJavaName().equals(elementValue.getClass().getName());
}

/**
* Gets the element types for the annotation represented by this object.
*
Expand Down
14 changes: 13 additions & 1 deletion substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,13 @@
"compiler:GRAAL",
],
"requiresConcealed" : {
"java.base" : ["jdk.internal.module"],
"java.base" : [
"jdk.internal.module",
"sun.reflect.annotation"
],
"jdk.internal.vm.ci": [
"jdk.vm.ci.meta",
"jdk.vm.ci.meta.annotation",
"jdk.vm.ci.code",
"jdk.vm.ci.runtime"
]
Expand All @@ -242,6 +246,10 @@
"checkstyle": "com.oracle.svm.core",
"workingSets": "SVM",
"jacoco" : "include",

# Direct reference to jdk.vm.ci.meta.annotation.Annotated
# causes spotbugs analysis to fail with "missing class" error.
"spotbugs": "false",
},

"com.oracle.svm.common": {
Expand Down Expand Up @@ -378,6 +386,7 @@
],
"jdk.internal.vm.ci": [
"jdk.vm.ci.meta",
"jdk.vm.ci.meta.annotation",
"jdk.vm.ci.code",
"jdk.vm.ci.aarch64",
"jdk.vm.ci.amd64",
Expand Down Expand Up @@ -1373,6 +1382,7 @@
"jdk.internal.vm.ci": [
"jdk.vm.ci.aarch64",
"jdk.vm.ci.meta",
"jdk.vm.ci.meta.annotation",
"jdk.vm.ci.code",
"jdk.vm.ci.code.stack"
]
Expand Down Expand Up @@ -1583,6 +1593,7 @@
"requiresConcealed": {
"jdk.internal.vm.ci": [
"jdk.vm.ci.meta",
"jdk.vm.ci.meta.annotation",
"jdk.vm.ci.code",
"jdk.vm.ci.common",
]
Expand Down Expand Up @@ -1632,6 +1643,7 @@
"requiresConcealed" : {
"jdk.internal.vm.ci" : [
"jdk.vm.ci.meta",
"jdk.vm.ci.meta.annotation",
"jdk.vm.ci.code",
],
"java.base" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@

package com.oracle.graal.pointsto.standalone;

import org.graalvm.nativeimage.impl.AnnotationExtractor;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.util.Arrays;

import org.graalvm.nativeimage.impl.AnnotationExtractor;

public class StandaloneAnnotationExtractor implements AnnotationExtractor {
// Checkstyle: allow direct annotation access
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
import java.util.function.Consumer;
import java.util.stream.StreamSupport;

import org.graalvm.nativeimage.AnnotationAccess;

import com.oracle.graal.pointsto.api.HostVM;
import com.oracle.graal.pointsto.api.PointstoOptions;
import com.oracle.graal.pointsto.constraints.UnsupportedFeatures;
Expand Down Expand Up @@ -77,6 +75,7 @@
import com.oracle.graal.pointsto.util.Timer.StopTimer;
import com.oracle.graal.pointsto.util.TimerCollection;
import com.oracle.svm.common.meta.MultiMethod;
import com.oracle.svm.util.AnnotationUtil;
import com.oracle.svm.util.ClassUtil;

import jdk.graal.compiler.api.replacements.Fold;
Expand Down Expand Up @@ -166,7 +165,7 @@ public PointsToAnalysis(OptionValues options, AnalysisUniverse universe, HostVM
* this type cannot be extended outside the observable universe.</li>
* <li>In <b>closed type world</b> all types are considered closed.</li>
* </ul>
*
*
* This method is conservative, it returns false in cases where we are not sure, and further
* refining when a type is closed will improve analysis. For example GR-59311 will also define
* when a sealed type can be treated as a closed type.
Expand Down Expand Up @@ -394,7 +393,7 @@ public AnalysisMethod addRootMethod(AnalysisMethod aMethod, boolean invokeSpecia
assert !universe.sealed() : "Cannot register root methods after analysis universe is sealed.";
validateRootMethodRegistration(aMethod, invokeSpecial);
AnalysisError.guarantee(aMethod.isOriginalMethod());
AnalysisError.guarantee(!AnnotationAccess.isAnnotationPresent(aMethod, Fold.class), "@Fold annotated method cannot be a root method.");
AnalysisError.guarantee(!AnnotationUtil.isAnnotationPresent(aMethod, Fold.class), "@Fold annotated method cannot be a root method.");
boolean isStatic = aMethod.isStatic();
int paramCount = aMethod.getSignature().getParameterCount(!isStatic);
PointsToAnalysisMethod originalPTAMethod = assertPointsToAnalysisMethod(aMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
import java.util.Map;
import java.util.Optional;

import org.graalvm.nativeimage.AnnotationAccess;

import com.oracle.graal.pointsto.AbstractAnalysisEngine;
import com.oracle.graal.pointsto.ObjectScanner.EmbeddedRootScan;
import com.oracle.graal.pointsto.PointsToAnalysis;
Expand All @@ -62,6 +60,7 @@
import com.oracle.graal.pointsto.typestate.TypeState;
import com.oracle.graal.pointsto.util.AnalysisError;
import com.oracle.svm.common.meta.MultiMethod;
import com.oracle.svm.util.AnnotationUtil;

import jdk.graal.compiler.core.common.SuppressFBWarnings;
import jdk.graal.compiler.core.common.spi.ForeignCallDescriptor;
Expand Down Expand Up @@ -509,7 +508,7 @@ private static void registerForeignCall(AbstractAnalysisEngine bb, ForeignCallsP
}

private boolean handleNodeIntrinsic() {
if (AnnotationAccess.isAnnotationPresent(method, NodeIntrinsic.class)) {
if (AnnotationUtil.isAnnotationPresent(method, NodeIntrinsic.class)) {
graph.getDebug().log("apply MethodTypeFlow on node intrinsic %s", method);
AnalysisType returnType = method.getSignature().getReturnType();
if (bb.isSupportedJavaKind(returnType.getJavaKind())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@
*/
package com.oracle.graal.pointsto.infrastructure;

import com.oracle.svm.util.AnnotatedWrapper;

import jdk.vm.ci.meta.ResolvedJavaField;
import jdk.vm.ci.meta.annotation.Annotated;

public interface WrappedJavaField extends ResolvedJavaField, WrappedElement {
public interface WrappedJavaField extends ResolvedJavaField, WrappedElement, AnnotatedWrapper {

@Override
ResolvedJavaField getWrapped();

@Override
default Annotated getWrappedAnnotated() {
return getWrapped();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@
*/
package com.oracle.graal.pointsto.infrastructure;

import com.oracle.svm.util.AnnotatedWrapper;

import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.meta.annotation.Annotated;

public interface WrappedJavaMethod extends WrappedElement, ResolvedJavaMethod {
public interface WrappedJavaMethod extends WrappedElement, AnnotatedWrapper, ResolvedJavaMethod {

@Override
ResolvedJavaMethod getWrapped();

@Override
default Annotated getWrappedAnnotated() {
return getWrapped();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@
*/
package com.oracle.graal.pointsto.infrastructure;

import com.oracle.svm.util.AnnotatedWrapper;

import jdk.vm.ci.meta.ResolvedJavaType;
import jdk.vm.ci.meta.annotation.Annotated;

public interface WrappedJavaType extends WrappedElement, ResolvedJavaType {
public interface WrappedJavaType extends WrappedElement, AnnotatedWrapper, ResolvedJavaType {

@Override
ResolvedJavaType getWrapped();

@Override
default Annotated getWrappedAnnotated() {
return getWrapped();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import com.oracle.graal.pointsto.util.AnalysisFuture;
import com.oracle.graal.pointsto.util.AtomicUtils;
import com.oracle.graal.pointsto.util.ConcurrentLightHashSet;
import com.oracle.svm.util.AnnotationUtil;

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

@Override
public final boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
return getUniverse().getAnnotationExtractor().hasAnnotation(getWrapped(), annotationClass);
return AnnotationUtil.isAnnotationPresent((Annotated) getWrapped(), annotationClass);
}

@Override
public final <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
return getUniverse().getAnnotationExtractor().extractAnnotation(getWrapped(), annotationClass, false);
return AnnotationUtil.getAnnotation((Annotated) getWrapped(), annotationClass);
}

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.oracle.graal.pointsto.util.AnalysisFuture;
import com.oracle.graal.pointsto.util.AtomicUtils;
import com.oracle.svm.common.meta.GuaranteeFolded;
import com.oracle.svm.util.AnnotationUtil;
import com.oracle.svm.util.OriginalClassProvider;
import com.oracle.svm.util.OriginalFieldProvider;

Expand Down Expand Up @@ -257,7 +258,7 @@ public void injectDeclaredType() {
}

public boolean isGuaranteeFolded() {
return getAnnotation(GuaranteeFolded.class) != null;
return AnnotationUtil.getAnnotation(this, GuaranteeFolded.class) != null;
}

public void checkGuaranteeFolded() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

import java.lang.annotation.Annotation;

import com.oracle.svm.util.AnnotationsContainer;

import jdk.graal.compiler.debug.GraalError;
import jdk.vm.ci.meta.JavaType;
import jdk.vm.ci.meta.ResolvedJavaField;
Expand All @@ -37,7 +39,7 @@
* If a field cannot be looked up by name, a {@link BaseLayerField} is created and put in an
* {@link AnalysisField} to represent this missing field, using the information from the base layer.
*/
public class BaseLayerField extends BaseLayerElement implements ResolvedJavaField {
public class BaseLayerField extends AnnotationsContainer implements ResolvedJavaField {
private final int id;
private final String name;
private final ResolvedJavaType declaringClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.lang.reflect.Type;

import com.oracle.graal.pointsto.infrastructure.ResolvedSignature;
import com.oracle.svm.util.AnnotationsContainer;

import jdk.graal.compiler.debug.GraalError;
import jdk.vm.ci.meta.Constant;
Expand All @@ -50,7 +51,7 @@
* {@link BaseLayerMethod} is created and put in an {@link AnalysisMethod} to represent this missing
* method, using the information from the base layer.
*/
public class BaseLayerMethod extends BaseLayerElement implements ResolvedJavaMethod {
public class BaseLayerMethod extends AnnotationsContainer implements ResolvedJavaMethod {
private static final String CLINIT = "<clinit>";

private final int id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.List;

import com.oracle.graal.pointsto.util.AnalysisError;
import com.oracle.svm.util.AnnotationsContainer;
import com.oracle.svm.util.OriginalClassProvider;

import jdk.vm.ci.meta.Assumptions;
Expand All @@ -47,7 +48,7 @@
* this case, a {@link BaseLayerType} is created using information from the base layer and wrapped
* in an {@link AnalysisType} to replace this missing type is the new layer.
*/
public class BaseLayerType extends BaseLayerElement implements ResolvedJavaType, OriginalClassProvider {
public class BaseLayerType extends AnnotationsContainer implements ResolvedJavaType, OriginalClassProvider {
/**
* The type corresponding to this {@link BaseLayerType} can be created later while building the
* new layer. To avoid both types having the same name, the name of the {@link BaseLayerType} is
Expand Down
Loading