Skip to content

Commit

Permalink
8315566: [JVMCI] deadlock in JVMCI startup when bad option specified
Browse files Browse the repository at this point in the history
Reviewed-by: thartmann, never
  • Loading branch information
Doug Simon committed Sep 4, 2023
1 parent 94a74a0 commit d1cabe4
Showing 1 changed file with 11 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.ServiceLoader;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -509,18 +510,7 @@ T get() {

private final Map<Class<? extends Architecture>, JVMCIBackend> backends = new HashMap<>();

private volatile List<HotSpotVMEventListener> vmEventListeners;

private Iterable<HotSpotVMEventListener> getVmEventListeners() {
if (vmEventListeners == null) {
synchronized (this) {
if (vmEventListeners == null) {
vmEventListeners = JVMCIServiceLocator.getProviders(HotSpotVMEventListener.class);
}
}
}
return vmEventListeners;
}
private final List<HotSpotVMEventListener> vmEventListeners;

@SuppressWarnings("try")
private HotSpotJVMCIRuntime() {
Expand Down Expand Up @@ -580,6 +570,8 @@ private HotSpotJVMCIRuntime() {
if (Option.PrintConfig.getBoolean()) {
configStore.printConfig(this);
}

vmEventListeners = JVMCIServiceLocator.getProviders(HotSpotVMEventListener.class);
}

/**
Expand Down Expand Up @@ -938,22 +930,21 @@ private boolean isGCSupported(int gcIdentifier) {
}

/**
* Guard to ensure shut down actions are performed at most once.
* Guard to ensure shut down actions are performed by at most one thread.
*/
private boolean isShutdown;
private final AtomicBoolean isShutdown = new AtomicBoolean();

/**
* Shuts down the runtime.
*/
@VMEntryPoint
private synchronized void shutdown() throws Exception {
if (!isShutdown) {
isShutdown = true;
private void shutdown() throws Exception {
if (isShutdown.compareAndSet(false, true)) {
// Cleaners are normally only processed when a new Cleaner is
// instantiated so process all remaining cleaners now.
Cleaner.clean();

for (HotSpotVMEventListener vmEventListener : getVmEventListeners()) {
for (HotSpotVMEventListener vmEventListener : vmEventListeners) {
vmEventListener.notifyShutdown();
}
}
Expand All @@ -964,7 +955,7 @@ private synchronized void shutdown() throws Exception {
*/
@VMEntryPoint
private void bootstrapFinished() throws Exception {
for (HotSpotVMEventListener vmEventListener : getVmEventListeners()) {
for (HotSpotVMEventListener vmEventListener : vmEventListeners) {
vmEventListener.notifyBootstrapFinished();
}
}
Expand All @@ -977,7 +968,7 @@ private void bootstrapFinished() throws Exception {
* @param compiledCode
*/
void notifyInstall(HotSpotCodeCacheProvider hotSpotCodeCacheProvider, InstalledCode installedCode, CompiledCode compiledCode) {
for (HotSpotVMEventListener vmEventListener : getVmEventListeners()) {
for (HotSpotVMEventListener vmEventListener : vmEventListeners) {
vmEventListener.notifyInstall(hotSpotCodeCacheProvider, installedCode, compiledCode);
}
}
Expand Down

1 comment on commit d1cabe4

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.