diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/BuildPhaseProvider.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/BuildPhaseProvider.java index 1977582a3bab..ed8dd47df91e 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/BuildPhaseProvider.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/BuildPhaseProvider.java @@ -33,6 +33,7 @@ @Platforms(Platform.HOSTED_ONLY.class) public final class BuildPhaseProvider { + private boolean featureRegistrationFinished; private boolean analysisFinished; private boolean hostedUniverseBuilt; private boolean readyForCompilation; @@ -51,6 +52,14 @@ static BuildPhaseProvider singleton() { BuildPhaseProvider() { } + public static void markFeatureRegistrationFinished() { + singleton().featureRegistrationFinished = true; + } + + public static boolean isFeatureRegistrationFinished() { + return ImageSingletons.contains(BuildPhaseProvider.class) && singleton().featureRegistrationFinished; + } + public static void markAnalysisFinished() { singleton().analysisFinished = true; } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/DumpRuntimeCompilationOnSignalFeature.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/DumpRuntimeCompilationOnSignalFeature.java index cfaf48ba7b87..9d0104b0754c 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/DumpRuntimeCompilationOnSignalFeature.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/DumpRuntimeCompilationOnSignalFeature.java @@ -39,12 +39,14 @@ public class DumpRuntimeCompilationOnSignalFeature implements InternalFeature { @Override public boolean isInConfiguration(IsInConfigurationAccess access) { - return VMInspectionOptions.DumpRuntimeCompilationOnSignal.getValue() && !Platform.includedIn(WINDOWS.class) && RuntimeCompilation.isEnabled(); + return VMInspectionOptions.DumpRuntimeCompilationOnSignal.getValue() && !Platform.includedIn(WINDOWS.class); } @Override public void beforeAnalysis(BeforeAnalysisAccess access) { - RuntimeSupport.getRuntimeSupport().addStartupHook(new DumpRuntimeCompilationStartupHook()); + if (RuntimeCompilation.isEnabled()) { + RuntimeSupport.getRuntimeSupport().addStartupHook(new DumpRuntimeCompilationStartupHook()); + } } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/RuntimeCompilation.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/RuntimeCompilation.java index 1954418d5116..d234446571fb 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/RuntimeCompilation.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/RuntimeCompilation.java @@ -24,11 +24,14 @@ */ package com.oracle.svm.core.graal; -import jdk.graal.compiler.api.replacements.Fold; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.hosted.Feature; +import com.oracle.svm.core.BuildPhaseProvider; import com.oracle.svm.core.deopt.DeoptimizationSupport; +import com.oracle.svm.core.util.VMError; + +import jdk.graal.compiler.api.replacements.Fold; public final class RuntimeCompilation { /** @@ -38,6 +41,7 @@ public final class RuntimeCompilation { */ @Fold public static boolean isEnabled() { + VMError.guarantee(BuildPhaseProvider.isFeatureRegistrationFinished(), "RuntimeCompilation.isEnabled() must not be called before the feature registration is finished."); boolean enabled = ImageSingletons.contains(RuntimeCompilationCanaryFeature.class); assert !enabled || DeoptimizationSupport.enabled(); return enabled; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/HasJfrSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/HasJfrSupport.java index 976a9005c27f..83a69108af5c 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/HasJfrSupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/HasJfrSupport.java @@ -26,11 +26,15 @@ import java.util.function.BooleanSupplier; -import jdk.graal.compiler.api.replacements.Fold; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; +import com.oracle.svm.core.BuildPhaseProvider; +import com.oracle.svm.core.util.VMError; + +import jdk.graal.compiler.api.replacements.Fold; + /** * Returns {@code true} if the Native Image is built with JFR support. This does not necessarily * mean that JFR is really enabled at runtime. @@ -43,6 +47,7 @@ public boolean getAsBoolean() { @Fold public static boolean get() { + VMError.guarantee(BuildPhaseProvider.isFeatureRegistrationFinished(), "HasJfrSupport.get() must not be called before the feature registration is finished."); return ImageSingletons.contains(JfrManager.class); } } @@ -55,6 +60,7 @@ public static boolean get() { class JfrHostedEnabled implements BooleanSupplier { @Override public boolean getAsBoolean() { + VMError.guarantee(BuildPhaseProvider.isFeatureRegistrationFinished(), "JfrHostedEnabled.get() must not be called before the feature registration is finished."); return ImageSingletons.contains(JfrManager.class) && ImageSingletons.lookup(JfrManager.class).hostedEnabled; } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrExecutionSamplerSupported.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrExecutionSamplerSupported.java index 60ab5fe561e3..d2a4fed9f99a 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrExecutionSamplerSupported.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrExecutionSamplerSupported.java @@ -36,13 +36,11 @@ */ @Platforms(Platform.HOSTED_ONLY.class) public class JfrExecutionSamplerSupported { - public static boolean isSupported() { if (ImageSingletons.contains(JfrExecutionSamplerSupported.class)) { return !RuntimeCompilation.isEnabled() && ImageSingletons.lookup(JfrExecutionSamplerSupported.class).isSupported0(); - } else { - return false; } + return false; } protected boolean isSupported0() { diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java index 7f512b8eb3f0..796b8d6e1928 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java @@ -944,6 +944,8 @@ protected void setupNativeImage(String imageName, OptionValues options, Map feature.afterRegistration(access)); setDefaultLibCIfMissing();