18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package jdk.vm.ci.hotspot;
24
25 import static jdk.vm.ci.inittimer.InitTimer.timer;
26
27 import java.io.IOException;
28 import java.io.OutputStream;
29 import java.io.PrintStream;
30 import java.lang.reflect.Array;
31 import java.lang.reflect.Field;
32 import java.lang.reflect.Method;
33 import java.lang.reflect.Modifier;
34 import java.util.Collections;
35 import java.util.HashMap;
36 import java.util.Map;
37 import java.util.Objects;
38 import java.util.TreeMap;
39
40 import jdk.vm.ci.code.Architecture;
41 import jdk.vm.ci.code.CompilationRequestResult;
42 import jdk.vm.ci.code.CompiledCode;
43 import jdk.vm.ci.code.InstalledCode;
44 import jdk.vm.ci.common.JVMCIError;
45 import jdk.vm.ci.inittimer.InitTimer;
46 import jdk.vm.ci.inittimer.SuppressFBWarnings;
47 import jdk.vm.ci.meta.JVMCIMetaAccessContext;
48 import jdk.vm.ci.meta.JavaKind;
49 import jdk.vm.ci.meta.JavaType;
50 import jdk.vm.ci.meta.ResolvedJavaType;
51 import jdk.vm.ci.runtime.JVMCI;
52 import jdk.vm.ci.runtime.JVMCIBackend;
53 import jdk.vm.ci.runtime.JVMCICompiler;
54 import jdk.vm.ci.services.Services;
55 import jdk.internal.misc.VM;
56
57 //JaCoCo Exclude
58
59 /**
60 * HotSpot implementation of a JVMCI runtime.
61 *
62 * The initialization of this class is very fragile since it's initialized both through
63 * {@link JVMCI#initialize()} or through calling {@link HotSpotJVMCIRuntime#runtime()} and
64 * {@link HotSpotJVMCIRuntime#runtime()} is also called by {@link JVMCI#initialize()}. So this class
65 * can't have a static initializer and any required initialization must be done as part of
66 * {@link #runtime()}. This allows the initialization to funnel back through
67 * {@link JVMCI#initialize()} without deadlocking.
68 */
69 public final class HotSpotJVMCIRuntime implements HotSpotJVMCIRuntimeProvider, HotSpotProxified {
70
71 @SuppressWarnings("try")
72 static class DelayedInit {
73 private static final HotSpotJVMCIRuntime instance;
74
75 static {
165 public String getString() {
166 return (String) getValue();
167 }
168
169 /**
170 * Prints all option flags to {@code out}.
171 *
172 * @param out stream to print to
173 */
174 public static void printFlags(PrintStream out) {
175 out.println("[List of JVMCI options]");
176 for (Option option : values()) {
177 Object value = option.getValue();
178 String assign = option.isDefault ? ":=" : " =";
179 out.printf("%9s %-40s %s %-14s %s%n", option.type.getSimpleName(), option, assign, value, option.help);
180 }
181 }
182 }
183
184 public static HotSpotJVMCIBackendFactory findFactory(String architecture) {
185 for (HotSpotJVMCIBackendFactory factory : Services.load(HotSpotJVMCIBackendFactory.class)) {
186 if (factory.getArchitecture().equalsIgnoreCase(architecture)) {
187 return factory;
188 }
189 }
190
191 throw new JVMCIError("No JVMCI runtime available for the %s architecture", architecture);
192 }
193
194 /**
195 * Gets the kind of a word value on the {@linkplain #getHostJVMCIBackend() host} backend.
196 */
197 public static JavaKind getHostWordKind() {
198 return runtime().getHostJVMCIBackend().getCodeCache().getTarget().wordJavaKind;
199 }
200
201 protected final CompilerToVM compilerToVm;
202
203 protected final HotSpotVMConfig config;
204 private final JVMCIBackend hostBackend;
205
214
215 @SuppressWarnings("try")
216 private HotSpotJVMCIRuntime() {
217 compilerToVm = new CompilerToVM();
218
219 try (InitTimer t = timer("HotSpotVMConfig<init>")) {
220 config = new HotSpotVMConfig(compilerToVm);
221 }
222
223 String hostArchitecture = config.getHostArchitectureName();
224
225 HotSpotJVMCIBackendFactory factory;
226 try (InitTimer t = timer("find factory:", hostArchitecture)) {
227 factory = findFactory(hostArchitecture);
228 }
229
230 try (InitTimer t = timer("create JVMCI backend:", hostArchitecture)) {
231 hostBackend = registerBackend(factory.createJVMCIBackend(this, null));
232 }
233
234 vmEventListeners = Services.load(HotSpotVMEventListener.class);
235
236 JVMCIMetaAccessContext context = null;
237 for (HotSpotVMEventListener vmEventListener : vmEventListeners) {
238 context = vmEventListener.createMetaAccessContext(this);
239 if (context != null) {
240 break;
241 }
242 }
243 if (context == null) {
244 context = new HotSpotJVMCIMetaAccessContext();
245 }
246 metaAccessContext = context;
247
248 boolean printFlags = Option.PrintFlags.getBoolean();
249 boolean showFlags = Option.ShowFlags.getBoolean();
250 if (printFlags || showFlags) {
251 Option.printFlags(System.out);
252 if (printFlags) {
253 System.exit(0);
254 }
|
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package jdk.vm.ci.hotspot;
24
25 import static jdk.vm.ci.inittimer.InitTimer.timer;
26
27 import java.io.IOException;
28 import java.io.OutputStream;
29 import java.io.PrintStream;
30 import java.lang.reflect.Array;
31 import java.lang.reflect.Field;
32 import java.lang.reflect.Method;
33 import java.lang.reflect.Modifier;
34 import java.util.Collections;
35 import java.util.HashMap;
36 import java.util.Map;
37 import java.util.Objects;
38 import java.util.ServiceLoader;
39 import java.util.TreeMap;
40
41 import jdk.internal.misc.VM;
42 import jdk.vm.ci.code.Architecture;
43 import jdk.vm.ci.code.CompilationRequestResult;
44 import jdk.vm.ci.code.CompiledCode;
45 import jdk.vm.ci.code.InstalledCode;
46 import jdk.vm.ci.common.JVMCIError;
47 import jdk.vm.ci.inittimer.InitTimer;
48 import jdk.vm.ci.inittimer.SuppressFBWarnings;
49 import jdk.vm.ci.meta.JVMCIMetaAccessContext;
50 import jdk.vm.ci.meta.JavaKind;
51 import jdk.vm.ci.meta.JavaType;
52 import jdk.vm.ci.meta.ResolvedJavaType;
53 import jdk.vm.ci.runtime.JVMCI;
54 import jdk.vm.ci.runtime.JVMCIBackend;
55 import jdk.vm.ci.runtime.JVMCICompiler;
56
57 //JaCoCo Exclude
58
59 /**
60 * HotSpot implementation of a JVMCI runtime.
61 *
62 * The initialization of this class is very fragile since it's initialized both through
63 * {@link JVMCI#initialize()} or through calling {@link HotSpotJVMCIRuntime#runtime()} and
64 * {@link HotSpotJVMCIRuntime#runtime()} is also called by {@link JVMCI#initialize()}. So this class
65 * can't have a static initializer and any required initialization must be done as part of
66 * {@link #runtime()}. This allows the initialization to funnel back through
67 * {@link JVMCI#initialize()} without deadlocking.
68 */
69 public final class HotSpotJVMCIRuntime implements HotSpotJVMCIRuntimeProvider, HotSpotProxified {
70
71 @SuppressWarnings("try")
72 static class DelayedInit {
73 private static final HotSpotJVMCIRuntime instance;
74
75 static {
165 public String getString() {
166 return (String) getValue();
167 }
168
169 /**
170 * Prints all option flags to {@code out}.
171 *
172 * @param out stream to print to
173 */
174 public static void printFlags(PrintStream out) {
175 out.println("[List of JVMCI options]");
176 for (Option option : values()) {
177 Object value = option.getValue();
178 String assign = option.isDefault ? ":=" : " =";
179 out.printf("%9s %-40s %s %-14s %s%n", option.type.getSimpleName(), option, assign, value, option.help);
180 }
181 }
182 }
183
184 public static HotSpotJVMCIBackendFactory findFactory(String architecture) {
185 for (HotSpotJVMCIBackendFactory factory : ServiceLoader.load(HotSpotJVMCIBackendFactory.class)) {
186 if (factory.getArchitecture().equalsIgnoreCase(architecture)) {
187 return factory;
188 }
189 }
190
191 throw new JVMCIError("No JVMCI runtime available for the %s architecture", architecture);
192 }
193
194 /**
195 * Gets the kind of a word value on the {@linkplain #getHostJVMCIBackend() host} backend.
196 */
197 public static JavaKind getHostWordKind() {
198 return runtime().getHostJVMCIBackend().getCodeCache().getTarget().wordJavaKind;
199 }
200
201 protected final CompilerToVM compilerToVm;
202
203 protected final HotSpotVMConfig config;
204 private final JVMCIBackend hostBackend;
205
214
215 @SuppressWarnings("try")
216 private HotSpotJVMCIRuntime() {
217 compilerToVm = new CompilerToVM();
218
219 try (InitTimer t = timer("HotSpotVMConfig<init>")) {
220 config = new HotSpotVMConfig(compilerToVm);
221 }
222
223 String hostArchitecture = config.getHostArchitectureName();
224
225 HotSpotJVMCIBackendFactory factory;
226 try (InitTimer t = timer("find factory:", hostArchitecture)) {
227 factory = findFactory(hostArchitecture);
228 }
229
230 try (InitTimer t = timer("create JVMCI backend:", hostArchitecture)) {
231 hostBackend = registerBackend(factory.createJVMCIBackend(this, null));
232 }
233
234 vmEventListeners = ServiceLoader.load(HotSpotVMEventListener.class);
235
236 JVMCIMetaAccessContext context = null;
237 for (HotSpotVMEventListener vmEventListener : vmEventListeners) {
238 context = vmEventListener.createMetaAccessContext(this);
239 if (context != null) {
240 break;
241 }
242 }
243 if (context == null) {
244 context = new HotSpotJVMCIMetaAccessContext();
245 }
246 metaAccessContext = context;
247
248 boolean printFlags = Option.PrintFlags.getBoolean();
249 boolean showFlags = Option.ShowFlags.getBoolean();
250 if (printFlags || showFlags) {
251 Option.printFlags(System.out);
252 if (printFlags) {
253 System.exit(0);
254 }
|