Skip to content

Commit 669ab51

Browse files
Some methods must not be executed before feature registration has finished.
1 parent d2dc49a commit 669ab51

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
@Platforms(Platform.HOSTED_ONLY.class)
3434
public final class BuildPhaseProvider {
3535

36+
private boolean featureRegistrationFinished;
3637
private boolean analysisFinished;
3738
private boolean hostedUniverseBuilt;
3839
private boolean readyForCompilation;
@@ -51,6 +52,14 @@ static BuildPhaseProvider singleton() {
5152
BuildPhaseProvider() {
5253
}
5354

55+
public static void markFeatureRegistrationFinished() {
56+
singleton().featureRegistrationFinished = true;
57+
}
58+
59+
public static boolean isFeatureRegistrationFinished() {
60+
return ImageSingletons.contains(BuildPhaseProvider.class) && singleton().featureRegistrationFinished;
61+
}
62+
5463
public static void markAnalysisFinished() {
5564
singleton().analysisFinished = true;
5665
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@
3939
public class DumpRuntimeCompilationOnSignalFeature implements InternalFeature {
4040
@Override
4141
public boolean isInConfiguration(IsInConfigurationAccess access) {
42-
return VMInspectionOptions.DumpRuntimeCompilationOnSignal.getValue() && !Platform.includedIn(WINDOWS.class) && RuntimeCompilation.isEnabled();
42+
return VMInspectionOptions.DumpRuntimeCompilationOnSignal.getValue() && !Platform.includedIn(WINDOWS.class);
4343
}
4444

4545
@Override
4646
public void beforeAnalysis(BeforeAnalysisAccess access) {
47-
RuntimeSupport.getRuntimeSupport().addStartupHook(new DumpRuntimeCompilationStartupHook());
47+
if (RuntimeCompilation.isEnabled()) {
48+
RuntimeSupport.getRuntimeSupport().addStartupHook(new DumpRuntimeCompilationStartupHook());
49+
}
4850
}
4951
}
5052

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/RuntimeCompilation.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@
2424
*/
2525
package com.oracle.svm.core.graal;
2626

27-
import jdk.graal.compiler.api.replacements.Fold;
2827
import org.graalvm.nativeimage.ImageSingletons;
2928
import org.graalvm.nativeimage.hosted.Feature;
3029

30+
import com.oracle.svm.core.BuildPhaseProvider;
3131
import com.oracle.svm.core.deopt.DeoptimizationSupport;
32+
import com.oracle.svm.core.util.VMError;
33+
34+
import jdk.graal.compiler.api.replacements.Fold;
3235

3336
public final class RuntimeCompilation {
3437
/**
@@ -38,6 +41,7 @@ public final class RuntimeCompilation {
3841
*/
3942
@Fold
4043
public static boolean isEnabled() {
44+
VMError.guarantee(BuildPhaseProvider.isFeatureRegistrationFinished(), "RuntimeCompilation.isEnabled() must not be called before the feature registration is finished.");
4145
boolean enabled = ImageSingletons.contains(RuntimeCompilationCanaryFeature.class);
4246
assert !enabled || DeoptimizationSupport.enabled();
4347
return enabled;

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/HasJfrSupport.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,15 @@
2626

2727
import java.util.function.BooleanSupplier;
2828

29-
import jdk.graal.compiler.api.replacements.Fold;
3029
import org.graalvm.nativeimage.ImageSingletons;
3130
import org.graalvm.nativeimage.Platform;
3231
import org.graalvm.nativeimage.Platforms;
3332

33+
import com.oracle.svm.core.BuildPhaseProvider;
34+
import com.oracle.svm.core.util.VMError;
35+
36+
import jdk.graal.compiler.api.replacements.Fold;
37+
3438
/**
3539
* Returns {@code true} if the Native Image is built with JFR support. This does not necessarily
3640
* mean that JFR is really enabled at runtime.
@@ -43,6 +47,7 @@ public boolean getAsBoolean() {
4347

4448
@Fold
4549
public static boolean get() {
50+
VMError.guarantee(BuildPhaseProvider.isFeatureRegistrationFinished(), "HasJfrSupport.get() must not be called before the feature registration is finished.");
4651
return ImageSingletons.contains(JfrManager.class);
4752
}
4853
}
@@ -55,6 +60,7 @@ public static boolean get() {
5560
class JfrHostedEnabled implements BooleanSupplier {
5661
@Override
5762
public boolean getAsBoolean() {
63+
VMError.guarantee(BuildPhaseProvider.isFeatureRegistrationFinished(), "JfrHostedEnabled.get() must not be called before the feature registration is finished.");
5864
return ImageSingletons.contains(JfrManager.class) && ImageSingletons.lookup(JfrManager.class).hostedEnabled;
5965
}
6066
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrExecutionSamplerSupported.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,11 @@
3636
*/
3737
@Platforms(Platform.HOSTED_ONLY.class)
3838
public class JfrExecutionSamplerSupported {
39-
4039
public static boolean isSupported() {
4140
if (ImageSingletons.contains(JfrExecutionSamplerSupported.class)) {
4241
return !RuntimeCompilation.isEnabled() && ImageSingletons.lookup(JfrExecutionSamplerSupported.class).isSupported0();
43-
} else {
44-
return false;
4542
}
43+
return false;
4644
}
4745

4846
protected boolean isSupported0() {

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,8 @@ protected void setupNativeImage(String imageName, OptionValues options, Map<Meth
944944
BuildPhaseProvider.init();
945945

946946
featureHandler.registerFeatures(loader, debug);
947+
BuildPhaseProvider.markFeatureRegistrationFinished();
948+
947949
AfterRegistrationAccessImpl access = new AfterRegistrationAccessImpl(featureHandler, loader, originalMetaAccess, mainEntryPoint, debug);
948950
featureHandler.forEachFeature(feature -> feature.afterRegistration(access));
949951
setDefaultLibCIfMissing();

0 commit comments

Comments
 (0)