Skip to content

Commit ee5f785

Browse files
committed
Fix @fold check.
1 parent 0d17994 commit ee5f785

File tree

1 file changed

+16
-5
lines changed
  • substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code

1 file changed

+16
-5
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CompileQueue.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@
4242

4343
import com.oracle.graal.pointsto.api.PointstoOptions;
4444
import com.oracle.graal.pointsto.flow.AnalysisParsedGraph;
45+
import com.oracle.graal.pointsto.infrastructure.OriginalClassProvider;
4546
import com.oracle.graal.pointsto.meta.HostedProviders;
4647
import com.oracle.graal.pointsto.util.CompletionExecutor;
4748
import com.oracle.graal.pointsto.util.CompletionExecutor.DebugContextRunnable;
49+
import com.oracle.graal.pointsto.util.GraalAccess;
4850
import com.oracle.svm.common.meta.MultiMethod;
4951
import com.oracle.svm.core.SubstrateOptions;
5052
import com.oracle.svm.core.Uninterruptible;
@@ -137,6 +139,7 @@
137139
import jdk.vm.ci.code.site.Infopoint;
138140
import jdk.vm.ci.meta.MetaAccessProvider;
139141
import jdk.vm.ci.meta.ResolvedJavaMethod;
142+
import jdk.vm.ci.meta.ResolvedJavaType;
140143
import jdk.vm.ci.meta.VMConstant;
141144

142145
public class CompileQueue {
@@ -182,6 +185,9 @@ protected PhaseSuite<HighTierContext> getAfterParseSuite() {
182185

183186
private final boolean printMethodHistogram = NativeImageOptions.PrintMethodHistogram.getValue();
184187
private final boolean optionAOTTrivialInline = SubstrateOptions.AOTTrivialInline.getValue();
188+
private final boolean allowFoldMethods = NativeImageOptions.AllowFoldMethods.getValue();
189+
190+
private final ResolvedJavaType generatedFoldInvocationPluginType;
185191

186192
public record UnpublishedTrivialMethods(CompilationGraph unpublishedGraph, boolean newlyTrivial) {
187193
}
@@ -387,6 +393,7 @@ public CompileQueue(DebugContext debug, FeatureHandler featureHandler, HostedUni
387393
this.defaultParseHooks = new ParseHooks(this);
388394

389395
callForReplacements(debug, runtimeConfig);
396+
generatedFoldInvocationPluginType = GraalAccess.getOriginalProviders().getMetaAccess().lookupJavaType(GeneratedFoldInvocationPlugin.class);
390397
}
391398

392399
protected AnalysisToHostedGraphTransplanter createGraphTransplanter() {
@@ -1003,17 +1010,21 @@ protected void ensureParsed(HostedMethod method, HostedMethod callerMethod, Comp
10031010
return;
10041011
}
10051012

1006-
if (!(NativeImageOptions.AllowFoldMethods.getValue() || method.getAnnotation(Fold.class) == null ||
1007-
(callerMethod != null && metaAccess.lookupJavaType(GeneratedFoldInvocationPlugin.class).isAssignableFrom(callerMethod.getDeclaringClass())))) {
1008-
throw VMError.shouldNotReachHere("Parsing method annotated with @" + Fold.class.getSimpleName() + ": " +
1009-
method.format("%H.%n(%p)") +
1010-
". Make sure you have used Graal annotation processors on the parent-project of the method's declaring class.");
1013+
if (!allowFoldMethods && method.getAnnotation(Fold.class) != null && !isFoldInvocationPluginMethod(callerMethod)) {
1014+
throw VMError.shouldNotReachHere("Parsing method annotated with @%s: %s. " +
1015+
"This could happen if either: the Graal annotation processor was not executed on the parent-project of the method's declaring class, " +
1016+
"the arguments passed to the method were not compile-time constants, or the plugin was disabled by the corresponding %s.",
1017+
Fold.class.getSimpleName(), method.format("%H.%n(%p)"), GraphBuilderContext.class.getSimpleName());
10111018
}
10121019
if (!method.compilationInfo.inParseQueue.getAndSet(true)) {
10131020
executor.execute(new ParseTask(method, reason));
10141021
}
10151022
}
10161023

1024+
private boolean isFoldInvocationPluginMethod(HostedMethod method) {
1025+
return method != null && generatedFoldInvocationPluginType.isAssignableFrom(OriginalClassProvider.getOriginalType(method.getDeclaringClass()));
1026+
}
1027+
10171028
protected final void doParse(DebugContext debug, ParseTask task) {
10181029
HostedMethod method = task.method;
10191030
if (HostedImageLayerBuildingSupport.buildingExtensionLayer()) {

0 commit comments

Comments
 (0)