Skip to content

Commit

Permalink
Some methods must not be executed before feature registration has fin…
Browse files Browse the repository at this point in the history
…ished.
  • Loading branch information
christianhaeubl committed Dec 4, 2024
1 parent d2dc49a commit 669ab51
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}
}
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,8 @@ protected void setupNativeImage(String imageName, OptionValues options, Map<Meth
BuildPhaseProvider.init();

featureHandler.registerFeatures(loader, debug);
BuildPhaseProvider.markFeatureRegistrationFinished();

AfterRegistrationAccessImpl access = new AfterRegistrationAccessImpl(featureHandler, loader, originalMetaAccess, mainEntryPoint, debug);
featureHandler.forEachFeature(feature -> feature.afterRegistration(access));
setDefaultLibCIfMissing();
Expand Down

0 comments on commit 669ab51

Please sign in to comment.