Skip to content

Commit d1cabe4

Browse files
author
Doug Simon
committed
8315566: [JVMCI] deadlock in JVMCI startup when bad option specified
Reviewed-by: thartmann, never
1 parent 94a74a0 commit d1cabe4

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import java.util.Map;
5050
import java.util.Objects;
5151
import java.util.ServiceLoader;
52+
import java.util.concurrent.atomic.AtomicBoolean;
5253
import java.util.function.Predicate;
5354
import java.util.regex.Matcher;
5455
import java.util.regex.Pattern;
@@ -509,18 +510,7 @@ T get() {
509510

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

512-
private volatile List<HotSpotVMEventListener> vmEventListeners;
513-
514-
private Iterable<HotSpotVMEventListener> getVmEventListeners() {
515-
if (vmEventListeners == null) {
516-
synchronized (this) {
517-
if (vmEventListeners == null) {
518-
vmEventListeners = JVMCIServiceLocator.getProviders(HotSpotVMEventListener.class);
519-
}
520-
}
521-
}
522-
return vmEventListeners;
523-
}
513+
private final List<HotSpotVMEventListener> vmEventListeners;
524514

525515
@SuppressWarnings("try")
526516
private HotSpotJVMCIRuntime() {
@@ -580,6 +570,8 @@ private HotSpotJVMCIRuntime() {
580570
if (Option.PrintConfig.getBoolean()) {
581571
configStore.printConfig(this);
582572
}
573+
574+
vmEventListeners = JVMCIServiceLocator.getProviders(HotSpotVMEventListener.class);
583575
}
584576

585577
/**
@@ -938,22 +930,21 @@ private boolean isGCSupported(int gcIdentifier) {
938930
}
939931

940932
/**
941-
* Guard to ensure shut down actions are performed at most once.
933+
* Guard to ensure shut down actions are performed by at most one thread.
942934
*/
943-
private boolean isShutdown;
935+
private final AtomicBoolean isShutdown = new AtomicBoolean();
944936

945937
/**
946938
* Shuts down the runtime.
947939
*/
948940
@VMEntryPoint
949-
private synchronized void shutdown() throws Exception {
950-
if (!isShutdown) {
951-
isShutdown = true;
941+
private void shutdown() throws Exception {
942+
if (isShutdown.compareAndSet(false, true)) {
952943
// Cleaners are normally only processed when a new Cleaner is
953944
// instantiated so process all remaining cleaners now.
954945
Cleaner.clean();
955946

956-
for (HotSpotVMEventListener vmEventListener : getVmEventListeners()) {
947+
for (HotSpotVMEventListener vmEventListener : vmEventListeners) {
957948
vmEventListener.notifyShutdown();
958949
}
959950
}
@@ -964,7 +955,7 @@ private synchronized void shutdown() throws Exception {
964955
*/
965956
@VMEntryPoint
966957
private void bootstrapFinished() throws Exception {
967-
for (HotSpotVMEventListener vmEventListener : getVmEventListeners()) {
958+
for (HotSpotVMEventListener vmEventListener : vmEventListeners) {
968959
vmEventListener.notifyBootstrapFinished();
969960
}
970961
}
@@ -977,7 +968,7 @@ private void bootstrapFinished() throws Exception {
977968
* @param compiledCode
978969
*/
979970
void notifyInstall(HotSpotCodeCacheProvider hotSpotCodeCacheProvider, InstalledCode installedCode, CompiledCode compiledCode) {
980-
for (HotSpotVMEventListener vmEventListener : getVmEventListeners()) {
971+
for (HotSpotVMEventListener vmEventListener : vmEventListeners) {
981972
vmEventListener.notifyInstall(hotSpotCodeCacheProvider, installedCode, compiledCode);
982973
}
983974
}

0 commit comments

Comments
 (0)