comparison jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java @ 23393:1d4ce2d19e52

clean up and minimize JVMCI (JDK-8156835)
author Doug Simon <doug.simon@oracle.com>
date Thu, 12 May 2016 20:57:31 +0200
parents b3a816d3b844
children 7743f81f8c4a
comparison
equal deleted inserted replaced
23392:b3a816d3b844 23393:1d4ce2d19e52
20 * or visit www.oracle.com if you need additional information or have any 20 * or visit www.oracle.com if you need additional information or have any
21 * questions. 21 * questions.
22 */ 22 */
23 package jdk.vm.ci.hotspot; 23 package jdk.vm.ci.hotspot;
24 24
25 import static jdk.vm.ci.inittimer.InitTimer.timer; 25 import static jdk.vm.ci.common.InitTimer.timer;
26 26
27 import java.io.IOException; 27 import java.io.IOException;
28 import java.io.OutputStream; 28 import java.io.OutputStream;
29 import java.io.PrintStream; 29 import java.io.PrintStream;
30 import java.lang.reflect.Array; 30 import java.lang.reflect.Array;
39 39
40 import jdk.vm.ci.code.Architecture; 40 import jdk.vm.ci.code.Architecture;
41 import jdk.vm.ci.code.CompilationRequestResult; 41 import jdk.vm.ci.code.CompilationRequestResult;
42 import jdk.vm.ci.code.CompiledCode; 42 import jdk.vm.ci.code.CompiledCode;
43 import jdk.vm.ci.code.InstalledCode; 43 import jdk.vm.ci.code.InstalledCode;
44 import jdk.vm.ci.common.InitTimer;
44 import jdk.vm.ci.common.JVMCIError; 45 import jdk.vm.ci.common.JVMCIError;
45 import jdk.vm.ci.hotspot.services.HotSpotJVMCICompilerFactory; 46 import jdk.vm.ci.hotspot.services.HotSpotJVMCICompilerFactory;
46 import jdk.vm.ci.hotspot.services.HotSpotVMEventListener; 47 import jdk.vm.ci.hotspot.services.HotSpotVMEventListener;
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; 48 import jdk.vm.ci.meta.JavaKind;
51 import jdk.vm.ci.meta.JavaType; 49 import jdk.vm.ci.meta.JavaType;
52 import jdk.vm.ci.meta.ResolvedJavaType; 50 import jdk.vm.ci.meta.ResolvedJavaType;
53 import jdk.vm.ci.runtime.JVMCI; 51 import jdk.vm.ci.runtime.JVMCI;
54 import jdk.vm.ci.runtime.JVMCIBackend; 52 import jdk.vm.ci.runtime.JVMCIBackend;
55 import jdk.vm.ci.runtime.JVMCICompiler; 53 import jdk.vm.ci.runtime.JVMCICompiler;
56 import jdk.vm.ci.runtime.services.JVMCICompilerFactory; 54 import jdk.vm.ci.runtime.services.JVMCICompilerFactory;
57 import jdk.vm.ci.services.Services; 55 import jdk.vm.ci.services.Services;
58 import sun.misc.VM; 56 import sun.misc.VM;
59
60 //JaCoCo Exclude
61 57
62 /** 58 /**
63 * HotSpot implementation of a JVMCI runtime. 59 * HotSpot implementation of a JVMCI runtime.
64 * 60 *
65 * The initialization of this class is very fragile since it's initialized both through 61 * The initialization of this class is very fragile since it's initialized both through
67 * {@link HotSpotJVMCIRuntime#runtime()} is also called by {@link JVMCI#initialize()}. So this class 63 * {@link HotSpotJVMCIRuntime#runtime()} is also called by {@link JVMCI#initialize()}. So this class
68 * can't have a static initializer and any required initialization must be done as part of 64 * can't have a static initializer and any required initialization must be done as part of
69 * {@link #runtime()}. This allows the initialization to funnel back through 65 * {@link #runtime()}. This allows the initialization to funnel back through
70 * {@link JVMCI#initialize()} without deadlocking. 66 * {@link JVMCI#initialize()} without deadlocking.
71 */ 67 */
72 public final class HotSpotJVMCIRuntime implements HotSpotJVMCIRuntimeProvider, HotSpotProxified { 68 public final class HotSpotJVMCIRuntime implements HotSpotJVMCIRuntimeProvider {
73 69
74 @SuppressWarnings("try") 70 @SuppressWarnings("try")
75 static class DelayedInit { 71 static class DelayedInit {
76 private static final HotSpotJVMCIRuntime instance; 72 private static final HotSpotJVMCIRuntime instance;
77 73
93 /** 89 /**
94 * A list of all supported JVMCI options. 90 * A list of all supported JVMCI options.
95 */ 91 */
96 public enum Option { 92 public enum Option {
97 Compiler(String.class, null, "Selects the system compiler."), 93 Compiler(String.class, null, "Selects the system compiler."),
98 // Note: The following one is not used (see InitTimer.ENABLED). 94 // Note: The following one is not used (see InitTimer.ENABLED). It is added here
95 // so that -Djvmci.PrintFlags=true shows the option.
99 InitTimer(boolean.class, false, "Specifies if initialization timing is enabled."), 96 InitTimer(boolean.class, false, "Specifies if initialization timing is enabled."),
100 PrintConfig(boolean.class, false, "Prints all HotSpotVMConfig fields."), 97 PrintConfig(boolean.class, false, "Prints all HotSpotVMConfig fields."),
101 PrintFlags(boolean.class, false, "Prints all JVMCI flags and exits."), 98 PrintFlags(boolean.class, false, "Prints all JVMCI flags and exits."),
102 ShowFlags(boolean.class, false, "Prints all JVMCI flags and continues."), 99 ShowFlags(boolean.class, false, "Prints all JVMCI flags and continues."),
103 TraceMethodDataFilter(String.class, null, ""); 100 TraceMethodDataFilter(String.class, null, "");
205 private final JVMCIBackend hostBackend; 202 private final JVMCIBackend hostBackend;
206 203
207 private final JVMCICompilerFactory compilerFactory; 204 private final JVMCICompilerFactory compilerFactory;
208 private final HotSpotJVMCICompilerFactory hsCompilerFactory; 205 private final HotSpotJVMCICompilerFactory hsCompilerFactory;
209 private volatile JVMCICompiler compiler; 206 private volatile JVMCICompiler compiler;
210 protected final JVMCIMetaAccessContext metaAccessContext; 207 protected final HotSpotJVMCIMetaAccessContext metaAccessContext;
211 208
212 /** 209 /**
213 * Stores the result of {@link HotSpotJVMCICompilerFactory#getCompilationLevelAdjustment} so 210 * Stores the result of {@link HotSpotJVMCICompilerFactory#getCompilationLevelAdjustment} so
214 * that it can be read from the VM. 211 * that it can be read from the VM.
215 */ 212 */
243 try (InitTimer t = timer("create JVMCI backend:", hostArchitecture)) { 240 try (InitTimer t = timer("create JVMCI backend:", hostArchitecture)) {
244 hostBackend = registerBackend(factory.createJVMCIBackend(this, null)); 241 hostBackend = registerBackend(factory.createJVMCIBackend(this, null));
245 } 242 }
246 243
247 vmEventListeners = Services.load(HotSpotVMEventListener.class); 244 vmEventListeners = Services.load(HotSpotVMEventListener.class);
248 245 metaAccessContext = new HotSpotJVMCIMetaAccessContext();
249 JVMCIMetaAccessContext context = null;
250 for (HotSpotVMEventListener vmEventListener : vmEventListeners) {
251 context = vmEventListener.createMetaAccessContext(this);
252 if (context != null) {
253 break;
254 }
255 }
256 if (context == null) {
257 context = new HotSpotJVMCIMetaAccessContext();
258 }
259 metaAccessContext = context;
260 246
261 boolean printFlags = Option.PrintFlags.getBoolean(); 247 boolean printFlags = Option.PrintFlags.getBoolean();
262 boolean showFlags = Option.ShowFlags.getBoolean(); 248 boolean showFlags = Option.ShowFlags.getBoolean();
263 if (printFlags || showFlags) { 249 if (printFlags || showFlags) {
264 Option.printFlags(System.out); 250 Option.printFlags(System.out);
298 return config; 284 return config;
299 } 285 }
300 286
301 public CompilerToVM getCompilerToVM() { 287 public CompilerToVM getCompilerToVM() {
302 return compilerToVm; 288 return compilerToVm;
303 }
304
305 public JVMCIMetaAccessContext getMetaAccessContext() {
306 return metaAccessContext;
307 } 289 }
308 290
309 public JVMCICompiler getCompiler() { 291 public JVMCICompiler getCompiler() {
310 if (compiler == null) { 292 if (compiler == null) {
311 synchronized (this) { 293 synchronized (this) {