comparison jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java @ 23379:24505bf61633

allow JVMCI compiler to change the compilation policy for a method (JDK-8152311)
author Doug Simon <doug.simon@oracle.com>
date Mon, 09 May 2016 16:08:16 +0200
parents 56479400913e
children 0226d6bcb0d2
comparison
equal deleted inserted replaced
23378:b11f345e4af4 23379:24505bf61633
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.JVMCIError; 44 import jdk.vm.ci.common.JVMCIError;
45 import jdk.vm.ci.hotspot.services.HotSpotJVMCICompilerFactory;
45 import jdk.vm.ci.hotspot.services.HotSpotVMEventListener; 46 import jdk.vm.ci.hotspot.services.HotSpotVMEventListener;
46 import jdk.vm.ci.inittimer.InitTimer; 47 import jdk.vm.ci.inittimer.InitTimer;
47 import jdk.vm.ci.inittimer.SuppressFBWarnings; 48 import jdk.vm.ci.inittimer.SuppressFBWarnings;
48 import jdk.vm.ci.meta.JVMCIMetaAccessContext; 49 import jdk.vm.ci.meta.JVMCIMetaAccessContext;
49 import jdk.vm.ci.meta.JavaKind; 50 import jdk.vm.ci.meta.JavaKind;
50 import jdk.vm.ci.meta.JavaType; 51 import jdk.vm.ci.meta.JavaType;
51 import jdk.vm.ci.meta.ResolvedJavaType; 52 import jdk.vm.ci.meta.ResolvedJavaType;
52 import jdk.vm.ci.runtime.JVMCI; 53 import jdk.vm.ci.runtime.JVMCI;
53 import jdk.vm.ci.runtime.JVMCIBackend; 54 import jdk.vm.ci.runtime.JVMCIBackend;
54 import jdk.vm.ci.runtime.JVMCICompiler; 55 import jdk.vm.ci.runtime.JVMCICompiler;
56 import jdk.vm.ci.runtime.services.JVMCICompilerFactory;
55 import jdk.vm.ci.services.Services; 57 import jdk.vm.ci.services.Services;
56 import sun.misc.VM; 58 import sun.misc.VM;
57 59
58 //JaCoCo Exclude 60 //JaCoCo Exclude
59 61
202 protected final CompilerToVM compilerToVm; 204 protected final CompilerToVM compilerToVm;
203 205
204 protected final HotSpotVMConfig config; 206 protected final HotSpotVMConfig config;
205 private final JVMCIBackend hostBackend; 207 private final JVMCIBackend hostBackend;
206 208
209 private final JVMCICompilerFactory compilerFactory;
210 private final HotSpotJVMCICompilerFactory hsCompilerFactory;
207 private volatile JVMCICompiler compiler; 211 private volatile JVMCICompiler compiler;
208 protected final JVMCIMetaAccessContext metaAccessContext; 212 protected final JVMCIMetaAccessContext metaAccessContext;
209 213
214 /**
215 * Stores the result of {@link HotSpotJVMCICompilerFactory#getCompilationLevelAdjustment} so
216 * that it can be read from the VM.
217 */
218 @SuppressWarnings("unused") private final int compilationLevelAdjustment;
219
210 private final Map<Class<? extends Architecture>, JVMCIBackend> backends = new HashMap<>(); 220 private final Map<Class<? extends Architecture>, JVMCIBackend> backends = new HashMap<>();
211 221
212 private final Iterable<HotSpotVMEventListener> vmEventListeners; 222 private final Iterable<HotSpotVMEventListener> vmEventListeners;
213 223
224 /**
225 * Stores the result of {@link HotSpotJVMCICompilerFactory#getTrivialPrefixes()} so that it can
226 * be read from the VM.
227 */
214 @SuppressWarnings("unused") private final String[] trivialPrefixes; 228 @SuppressWarnings("unused") private final String[] trivialPrefixes;
215 229
216 @SuppressWarnings("try") 230 @SuppressWarnings("try")
217 private HotSpotJVMCIRuntime() { 231 private HotSpotJVMCIRuntime() {
218 compilerToVm = new CompilerToVM(); 232 compilerToVm = new CompilerToVM();
257 271
258 if (Option.PrintConfig.getBoolean()) { 272 if (Option.PrintConfig.getBoolean()) {
259 printConfig(config, compilerToVm); 273 printConfig(config, compilerToVm);
260 } 274 }
261 275
262 trivialPrefixes = HotSpotJVMCICompilerConfig.getCompilerFactory().getTrivialPrefixes(); 276 compilerFactory = HotSpotJVMCICompilerConfig.getCompilerFactory();
277 if (compilerFactory instanceof HotSpotJVMCICompilerFactory) {
278 hsCompilerFactory = (HotSpotJVMCICompilerFactory) compilerFactory;
279 trivialPrefixes = hsCompilerFactory.getTrivialPrefixes();
280 compilationLevelAdjustment = hsCompilerFactory.getCompilationLevelAdjustment(config);
281 } else {
282 hsCompilerFactory = null;
283 trivialPrefixes = null;
284 compilationLevelAdjustment = 0;
285 }
263 } 286 }
264 287
265 private JVMCIBackend registerBackend(JVMCIBackend backend) { 288 private JVMCIBackend registerBackend(JVMCIBackend backend) {
266 Class<? extends Architecture> arch = backend.getCodeCache().getTarget().arch.getClass(); 289 Class<? extends Architecture> arch = backend.getCodeCache().getTarget().arch.getClass();
267 JVMCIBackend oldValue = backends.put(arch, backend); 290 JVMCIBackend oldValue = backends.put(arch, backend);
287 310
288 public JVMCICompiler getCompiler() { 311 public JVMCICompiler getCompiler() {
289 if (compiler == null) { 312 if (compiler == null) {
290 synchronized (this) { 313 synchronized (this) {
291 if (compiler == null) { 314 if (compiler == null) {
292 compiler = HotSpotJVMCICompilerConfig.getCompilerFactory().createCompiler(this); 315 compiler = compilerFactory.createCompiler(this);
293 } 316 }
294 } 317 }
295 } 318 }
296 return compiler; 319 return compiler;
297 } 320 }
324 return backends.get(arch); 347 return backends.get(arch);
325 } 348 }
326 349
327 public Map<Class<? extends Architecture>, JVMCIBackend> getJVMCIBackends() { 350 public Map<Class<? extends Architecture>, JVMCIBackend> getJVMCIBackends() {
328 return Collections.unmodifiableMap(backends); 351 return Collections.unmodifiableMap(backends);
352 }
353
354 /**
355 * Called from the VM.
356 */
357 @SuppressWarnings({"unused"})
358 private int adjustCompilationLevel(Class<?> declaringClass, String name, String signature, boolean isOsr, int level) {
359 return hsCompilerFactory.adjustCompilationLevel(config, declaringClass, name, signature, isOsr, level);
329 } 360 }
330 361
331 /** 362 /**
332 * Called from the VM. 363 * Called from the VM.
333 */ 364 */