comparison jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java @ 22694:023981d7f257

Fix deadlock between JVMCI.initialize and HotSpotJVMCIRuntime.runtime
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Mon, 19 Oct 2015 10:24:05 -0700
parents 1bbd4a7c274b
children 57646377e480
comparison
equal deleted inserted replaced
22693:af01df1b8f0d 22694:023981d7f257
52 52
53 //JaCoCo Exclude 53 //JaCoCo Exclude
54 54
55 /** 55 /**
56 * HotSpot implementation of a JVMCI runtime. 56 * HotSpot implementation of a JVMCI runtime.
57 *
58 * The initialization of this class is very fragile since it's initialized both through
59 * {@link JVMCI#initialize()} or through calling {@link HotSpotJVMCIRuntime#runtime()} and
60 * {@link HotSpotJVMCIRuntime#runtime()} is also called by {@link JVMCI#initialize()}. So this class
61 * can't have a static initializer and any required initialization must be done as part of
62 * {@link #runtime()}. This allows the initialization to funnel back through
63 * {@link JVMCI#initialize()} without deadlocking.
57 */ 64 */
58 public final class HotSpotJVMCIRuntime implements HotSpotJVMCIRuntimeProvider, HotSpotProxified { 65 public final class HotSpotJVMCIRuntime implements HotSpotJVMCIRuntimeProvider, HotSpotProxified {
59
60 /**
61 * The proper initialization of this class is complex because it's tangled up with the
62 * initialization of the JVMCI and really should only ever be triggered through
63 * {@link JVMCI#getRuntime}. However since {@link #runtime} can also be called directly it
64 * should also trigger proper initialization. To ensure proper ordering, the static initializer
65 * of this class initializes {@link JVMCI} and then access to
66 * {@link HotSpotJVMCIRuntime.DelayedInit#instance} triggers the final initialization of the
67 * {@link HotSpotJVMCIRuntime}.
68 */
69 private static void initializeJVMCI() {
70 JVMCI.initialize();
71 }
72
73 static {
74 initializeJVMCI();
75 }
76 66
77 @SuppressWarnings("try") 67 @SuppressWarnings("try")
78 static class DelayedInit { 68 static class DelayedInit {
79 private static final HotSpotJVMCIRuntime instance; 69 private static final HotSpotJVMCIRuntime instance;
80 70
87 77
88 /** 78 /**
89 * Gets the singleton {@link HotSpotJVMCIRuntime} object. 79 * Gets the singleton {@link HotSpotJVMCIRuntime} object.
90 */ 80 */
91 public static HotSpotJVMCIRuntime runtime() { 81 public static HotSpotJVMCIRuntime runtime() {
82 JVMCI.initialize();
92 return DelayedInit.instance; 83 return DelayedInit.instance;
93 } 84 }
94 85
95 public static HotSpotJVMCIBackendFactory findFactory(String architecture) { 86 public static HotSpotJVMCIBackendFactory findFactory(String architecture) {
96 for (HotSpotJVMCIBackendFactory factory : Services.load(HotSpotJVMCIBackendFactory.class)) { 87 for (HotSpotJVMCIBackendFactory factory : Services.load(HotSpotJVMCIBackendFactory.class)) {