Skip to content

Commit 5eb87ce

Browse files
author
Christian Wimmer
committed
[GR-39848] Do not use method and field annotations during JIT compilation.
PullRequest: graal/14106
2 parents 3d5b989 + 5a28df9 commit 5eb87ce

File tree

34 files changed

+723
-478
lines changed

34 files changed

+723
-478
lines changed

compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/StructuredGraph.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
*/
2525
package org.graalvm.compiler.nodes;
2626

27-
import static jdk.vm.ci.services.Services.IS_BUILDING_NATIVE_IMAGE;
28-
import static jdk.vm.ci.services.Services.IS_IN_NATIVE_IMAGE;
29-
3027
import java.util.ArrayList;
3128
import java.util.Collections;
3229
import java.util.Iterator;
@@ -336,26 +333,12 @@ private StructuredGraph(String name,
336333
assert !isSubstitution || profileProvider == null;
337334
this.profileProvider = profileProvider;
338335
this.isSubstitution = isSubstitution;
339-
assert checkIsSubstitutionInvariants(method, isSubstitution);
340336
this.cancellable = cancellable;
341337
this.inliningLog = GraalOptions.TraceInlining.getValue(options) || OptimizationLog.isOptimizationLogEnabled(options) ? new InliningLog(rootMethod) : null;
342338
this.callerContext = context;
343339
this.optimizationLog = OptimizationLog.getInstance(this);
344340
}
345341

346-
private static boolean checkIsSubstitutionInvariants(ResolvedJavaMethod method, boolean isSubstitution) {
347-
if (!IS_IN_NATIVE_IMAGE && !IS_BUILDING_NATIVE_IMAGE) {
348-
if (method != null) {
349-
if (method.getAnnotation(Snippet.class) != null) {
350-
assert isSubstitution : "Graph for method " + method.format("%H.%n(%p)") +
351-
" annotated by " + Snippet.class.getName() +
352-
" must have its `isSubstitution` field set to true";
353-
}
354-
}
355-
}
356-
return true;
357-
}
358-
359342
public void setLastSchedule(ScheduleResult result) {
360343
GraalError.guarantee(result == null || result.cfg.getStartBlock().isModifiable(), "Schedule must use blocks that can be modified");
361344
lastSchedule = result;

compiler/src/org.graalvm.compiler.truffle.common/src/org/graalvm/compiler/truffle/common/TruffleCompilerRuntime.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@ public static ConstantFieldInfo forDimensions(int dimensions) {
9898
private ConstantFieldInfo(int dimensions) {
9999
this.dimensions = dimensions;
100100
}
101+
102+
@Override
103+
public int hashCode() {
104+
return dimensions;
105+
}
106+
107+
@Override
108+
public boolean equals(Object obj) {
109+
if (obj instanceof ConstantFieldInfo other) {
110+
return dimensions == other.dimensions;
111+
}
112+
return false;
113+
}
101114
}
102115

103116
/**

compiler/src/org.graalvm.compiler.truffle.runtime/src/org/graalvm/compiler/truffle/runtime/GraalTruffleRuntime.java

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -948,9 +948,6 @@ public final class KnownMethods {
948948
public final ResolvedJavaMethod callTargetMethod;
949949
public final ResolvedJavaMethod callInlinedCallMethod;
950950
public final ResolvedJavaMethod[] anyFrameMethod;
951-
public final ResolvedJavaMethod inInterpreterMethod;
952-
public final ResolvedJavaMethod inInterpreterFastPathMethod;
953-
public final ResolvedJavaMethod[] transferToInterpreterMethods;
954951

955952
public KnownMethods(MetaAccessProvider metaAccess) {
956953
this.callDirectMethod = metaAccess.lookupJavaMethod(GraalFrameInstance.CALL_DIRECT);
@@ -959,26 +956,9 @@ public KnownMethods(MetaAccessProvider metaAccess) {
959956
this.callInlinedCallMethod = metaAccess.lookupJavaMethod(GraalFrameInstance.CALL_INLINED_CALL);
960957
this.callTargetMethod = metaAccess.lookupJavaMethod(GraalFrameInstance.CALL_TARGET_METHOD);
961958
this.anyFrameMethod = new ResolvedJavaMethod[]{callDirectMethod, callIndirectMethod, callInlinedMethod, callTargetMethod, callInlinedCallMethod};
962-
ResolvedJavaType compilerDirectives = metaAccess.lookupJavaType(CompilerDirectives.class);
963-
this.transferToInterpreterMethods = new ResolvedJavaMethod[2];
964-
this.transferToInterpreterMethods[0] = searchMethod(compilerDirectives, "transferToInterpreter");
965-
this.transferToInterpreterMethods[1] = searchMethod(compilerDirectives, "transferToInterpreterAndInvalidate");
966-
this.inInterpreterMethod = searchMethod(compilerDirectives, "inInterpreter");
967-
968-
ResolvedJavaType hostCompilerDirectives = metaAccess.lookupJavaType(HostCompilerDirectives.class);
969-
this.inInterpreterFastPathMethod = searchMethod(hostCompilerDirectives, "inInterpreterFastPath");
970959
}
971960
}
972961

973-
protected static ResolvedJavaMethod searchMethod(ResolvedJavaType type, String name) {
974-
for (ResolvedJavaMethod searchMethod : type.getDeclaredMethods()) {
975-
if (searchMethod.getName().equals(name)) {
976-
return searchMethod;
977-
}
978-
}
979-
throw CompilerDirectives.shouldNotReachHere(type + "." + name + " method not found.");
980-
}
981-
982962
@Override
983963
public boolean isValueType(ResolvedJavaType type) {
984964
return getAnnotation(CompilerDirectives.ValueType.class, type) != null;
@@ -1042,30 +1022,25 @@ public boolean isInliningCutoff(ResolvedJavaMethod method) {
10421022
* Determines if {@code method} is an inInterpeter method.
10431023
*/
10441024
@Override
1045-
public boolean isInInterpreter(ResolvedJavaMethod targetMethod) {
1046-
return getKnownMethods().inInterpreterMethod.equals(targetMethod);
1025+
public boolean isInInterpreter(ResolvedJavaMethod method) {
1026+
return method.getName().equals("inInterpreter") && method.getDeclaringClass().toClassName().equals(CompilerDirectives.class.getName());
10471027
}
10481028

10491029
/**
10501030
* Determines if {@code method} is an inInterpeter method.
10511031
*/
10521032
@Override
1053-
public boolean isInInterpreterFastPath(ResolvedJavaMethod targetMethod) {
1054-
return getKnownMethods().inInterpreterFastPathMethod.equals(targetMethod);
1033+
public boolean isInInterpreterFastPath(ResolvedJavaMethod method) {
1034+
return method.getName().equals("inInterpreterFastPath") && method.getDeclaringClass().toClassName().equals(HostCompilerDirectives.class.getName());
10551035
}
10561036

10571037
/**
10581038
* Determines if {@code method} is a method is a transferToInterpreter method.
10591039
*/
10601040
@Override
10611041
public boolean isTransferToInterpreterMethod(ResolvedJavaMethod method) {
1062-
ResolvedJavaMethod[] methods = getKnownMethods().transferToInterpreterMethods;
1063-
for (int i = 0; i < methods.length; i++) {
1064-
if (methods[i].equals(method)) {
1065-
return true;
1066-
}
1067-
}
1068-
return false;
1042+
return (method.getName().equals("transferToInterpreter") || method.getName().equals("transferToInterpreterAndInvalidate")) &&
1043+
method.getDeclaringClass().toClassName().equals(CompilerDirectives.class.getName());
10691044
}
10701045

10711046
@SuppressWarnings("deprecation")

substratevm/src/com.oracle.svm.core.graal.aarch64/src/com/oracle/svm/core/graal/aarch64/SubstrateAArch64Backend.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@
117117
import org.graalvm.compiler.phases.BasePhase;
118118
import org.graalvm.compiler.phases.common.AddressLoweringByUsePhase;
119119
import org.graalvm.compiler.phases.util.Providers;
120-
import org.graalvm.nativeimage.AnnotationAccess;
121120
import org.graalvm.nativeimage.ImageSingletons;
122121

123122
import com.oracle.svm.core.FrameAccess;
@@ -152,7 +151,6 @@
152151
import com.oracle.svm.core.meta.SubstrateMethodPointerConstant;
153152
import com.oracle.svm.core.meta.SubstrateObjectConstant;
154153
import com.oracle.svm.core.nodes.SafepointCheckNode;
155-
import com.oracle.svm.core.snippets.SubstrateForeignCallTarget;
156154
import com.oracle.svm.core.thread.VMThreads.StatusSupport;
157155
import com.oracle.svm.core.util.VMError;
158156

@@ -791,8 +789,8 @@ public Variable emitReadReturnAddress() {
791789

792790
@Override
793791
public ForeignCallLinkage lookupGraalStub(ValueNode valueNode, ForeignCallDescriptor foreignCallDescriptor) {
794-
ResolvedJavaMethod method = valueNode.graph().method();
795-
if (method != null && AnnotationAccess.getAnnotation(method, SubstrateForeignCallTarget.class) != null) {
792+
SharedMethod method = (SharedMethod) valueNode.graph().method();
793+
if (method != null && method.isForeignCallTarget()) {
796794
// Emit assembly for snippet stubs
797795
return null;
798796
}

substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64Backend.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@
126126
import org.graalvm.compiler.phases.common.AddressLoweringByNodePhase;
127127
import org.graalvm.compiler.phases.util.Providers;
128128
import org.graalvm.compiler.replacements.amd64.AMD64IntrinsicStubs;
129-
import org.graalvm.nativeimage.AnnotationAccess;
130129
import org.graalvm.nativeimage.ImageSingletons;
131130

132131
import com.oracle.svm.core.CPUFeatureAccess;
@@ -169,7 +168,6 @@
169168
import com.oracle.svm.core.meta.SubstrateMethodPointerConstant;
170169
import com.oracle.svm.core.meta.SubstrateObjectConstant;
171170
import com.oracle.svm.core.nodes.SafepointCheckNode;
172-
import com.oracle.svm.core.snippets.SubstrateForeignCallTarget;
173171
import com.oracle.svm.core.thread.VMThreads.StatusSupport;
174172
import com.oracle.svm.core.util.VMError;
175173

@@ -926,8 +924,8 @@ public Variable emitReadReturnAddress() {
926924

927925
@Override
928926
public ForeignCallLinkage lookupGraalStub(ValueNode valueNode, ForeignCallDescriptor foreignCallDescriptor) {
929-
ResolvedJavaMethod method = valueNode.graph().method();
930-
if (method != null && AnnotationAccess.getAnnotation(method, SubstrateForeignCallTarget.class) != null) {
927+
SharedMethod method = (SharedMethod) valueNode.graph().method();
928+
if (method != null && method.isForeignCallTarget()) {
931929
// Emit assembly for snippet stubs
932930
return null;
933931
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/Uninterruptible.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
import org.graalvm.compiler.api.replacements.Fold;
3636
import org.graalvm.nativeimage.AnnotationAccess;
37+
import org.graalvm.nativeimage.Platform;
38+
import org.graalvm.nativeimage.Platforms;
3739
import org.graalvm.nativeimage.c.function.CFunction;
3840
import org.graalvm.nativeimage.c.function.InvokeCFunctionPointer;
3941
import org.graalvm.word.WordBase;
@@ -202,10 +204,12 @@ public static Uninterruptible getAnnotation(AnnotatedElement method) {
202204
* Returns whether the method is {@link Uninterruptible}, either by explicit annotation of
203205
* the method or implicitly due to other annotations.
204206
*/
207+
@Platforms(Platform.HOSTED_ONLY.class)
205208
public static boolean isUninterruptible(AnnotatedElement method) {
206209
return getAnnotation(method) != null;
207210
}
208211

212+
@Platforms(Platform.HOSTED_ONLY.class)
209213
public static boolean inliningAllowed(AnnotatedElement caller, AnnotatedElement callee) {
210214
boolean callerUninterruptible = isUninterruptible(caller);
211215
boolean calleeUninterruptible = isUninterruptible(callee);

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/code/ExplicitCallingConvention.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,31 @@
2929
import java.lang.annotation.RetentionPolicy;
3030
import java.lang.annotation.Target;
3131

32+
import org.graalvm.nativeimage.AnnotationAccess;
33+
import org.graalvm.nativeimage.Platform;
34+
import org.graalvm.nativeimage.Platforms;
35+
36+
import jdk.vm.ci.meta.ResolvedJavaMethod;
37+
3238
/**
3339
* Annotation that overrides the default calling convention used for a method.
3440
*/
3541
@Retention(RetentionPolicy.RUNTIME)
3642
@Target(value = {ElementType.METHOD})
3743
public @interface ExplicitCallingConvention {
3844
SubstrateCallingConventionKind value();
45+
46+
class Util {
47+
@Platforms(Platform.HOSTED_ONLY.class)
48+
public static SubstrateCallingConventionKind getCallingConventionKind(ResolvedJavaMethod method, boolean isEntryPoint) {
49+
ExplicitCallingConvention explicitCallingConvention = AnnotationAccess.getAnnotation(method, ExplicitCallingConvention.class);
50+
if (explicitCallingConvention != null) {
51+
return explicitCallingConvention.value();
52+
} else if (isEntryPoint) {
53+
return SubstrateCallingConventionKind.Native;
54+
} else {
55+
return SubstrateCallingConventionKind.Java;
56+
}
57+
}
58+
}
3959
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/code/StubCallingConvention.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
public @interface StubCallingConvention {
5252

5353
class Utils {
54+
@Platforms(Platform.HOSTED_ONLY.class)
5455
public static boolean hasStubCallingConvention(ResolvedJavaMethod method) {
5556
boolean result = false;
5657
if (CalleeSavedRegisters.supportedByPlatform()) {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/code/SubstrateMetaAccessExtensionProvider.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
import org.graalvm.compiler.core.common.spi.MetaAccessExtensionProvider;
2929

30-
import com.oracle.svm.core.Uninterruptible;
3130
import com.oracle.svm.core.meta.SharedMethod;
3231
import com.oracle.svm.core.meta.SharedType;
3332

@@ -59,14 +58,14 @@ public boolean isGuaranteedSafepoint(ResolvedJavaMethod method, boolean isDirect
5958

6059
// check if the method itself indicates it will not have a safepoint.
6160
SharedMethod sharedMethod = (SharedMethod) method;
62-
if (Uninterruptible.Utils.isUninterruptible(sharedMethod)) {
61+
if (sharedMethod.isUninterruptible()) {
6362
return false;
6463
}
6564

6665
// for indirect calls, confirming all implementations also have safepoints.
6766
if (!isDirect) {
6867
for (SharedMethod implementation : sharedMethod.getImplementations()) {
69-
if (Uninterruptible.Utils.isUninterruptible(implementation)) {
68+
if (implementation.isUninterruptible()) {
7069
return false;
7170
}
7271
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/meta/SubstrateReplacements.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787

8888
import com.oracle.svm.core.SubstrateTargetDescription;
8989
import com.oracle.svm.core.config.ConfigurationValues;
90+
import com.oracle.svm.core.meta.SharedMethod;
9091
import com.oracle.svm.core.option.HostedOptionValues;
9192
import com.oracle.svm.core.util.VMError;
9293

@@ -407,4 +408,13 @@ public Stamp getInjectedStamp(Class<?> type, boolean nonNull) {
407408
return StampFactory.forKind(kind);
408409
}
409410
}
411+
412+
@Override
413+
public boolean isSnippet(ResolvedJavaMethod method) {
414+
if (method instanceof SharedMethod sharedMethod) {
415+
return sharedMethod.isSnippet();
416+
} else {
417+
return super.isSnippet(method);
418+
}
419+
}
410420
}

0 commit comments

Comments
 (0)