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

Print this page




  32 import java.lang.reflect.Modifier;
  33 import java.util.Collections;
  34 import java.util.HashMap;
  35 import java.util.Map;
  36 import java.util.Objects;
  37 import java.util.TreeMap;
  38 
  39 import jdk.vm.ci.code.Architecture;
  40 import jdk.vm.ci.code.CompilationResult;
  41 import jdk.vm.ci.code.InstalledCode;
  42 import jdk.vm.ci.common.JVMCIError;
  43 import jdk.vm.ci.inittimer.InitTimer;
  44 import jdk.vm.ci.meta.JVMCIMetaAccessContext;
  45 import jdk.vm.ci.meta.JavaKind;
  46 import jdk.vm.ci.meta.JavaType;
  47 import jdk.vm.ci.meta.ResolvedJavaType;
  48 import jdk.vm.ci.runtime.JVMCI;
  49 import jdk.vm.ci.runtime.JVMCIBackend;
  50 import jdk.vm.ci.runtime.JVMCICompiler;
  51 import jdk.vm.ci.service.Services;

  52 
  53 //JaCoCo Exclude
  54 
  55 /**
  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.
  64  */
  65 public final class HotSpotJVMCIRuntime implements HotSpotJVMCIRuntimeProvider, HotSpotProxified {
  66 
  67     @SuppressWarnings("try")
  68     static class DelayedInit {
  69         private static final HotSpotJVMCIRuntime instance;
  70 
  71         static {
  72             try (InitTimer t = timer("HotSpotJVMCIRuntime.<init>")) {
  73                 instance = new HotSpotJVMCIRuntime();
  74             }
  75         }
  76     }
  77 
  78     /**
  79      * Gets the singleton {@link HotSpotJVMCIRuntime} object.
  80      */
  81     public static HotSpotJVMCIRuntime runtime() {
  82         JVMCI.initialize();
  83         return DelayedInit.instance;
  84     }
  85 
















  86     public static HotSpotJVMCIBackendFactory findFactory(String architecture) {
  87         for (HotSpotJVMCIBackendFactory factory : Services.load(HotSpotJVMCIBackendFactory.class)) {
  88             if (factory.getArchitecture().equalsIgnoreCase(architecture)) {
  89                 return factory;
  90             }
  91         }
  92 
  93         throw new JVMCIError("No JVMCI runtime available for the %s architecture", architecture);
  94     }
  95 
  96     /**
  97      * Gets the kind of a word value on the {@linkplain #getHostJVMCIBackend() host} backend.
  98      */
  99     public static JavaKind getHostWordKind() {
 100         return runtime().getHostJVMCIBackend().getCodeCache().getTarget().wordJavaKind;
 101     }
 102 
 103     protected final CompilerToVM compilerToVm;
 104 
 105     protected final HotSpotVMConfig config;




  32 import java.lang.reflect.Modifier;
  33 import java.util.Collections;
  34 import java.util.HashMap;
  35 import java.util.Map;
  36 import java.util.Objects;
  37 import java.util.TreeMap;
  38 
  39 import jdk.vm.ci.code.Architecture;
  40 import jdk.vm.ci.code.CompilationResult;
  41 import jdk.vm.ci.code.InstalledCode;
  42 import jdk.vm.ci.common.JVMCIError;
  43 import jdk.vm.ci.inittimer.InitTimer;
  44 import jdk.vm.ci.meta.JVMCIMetaAccessContext;
  45 import jdk.vm.ci.meta.JavaKind;
  46 import jdk.vm.ci.meta.JavaType;
  47 import jdk.vm.ci.meta.ResolvedJavaType;
  48 import jdk.vm.ci.runtime.JVMCI;
  49 import jdk.vm.ci.runtime.JVMCIBackend;
  50 import jdk.vm.ci.runtime.JVMCICompiler;
  51 import jdk.vm.ci.service.Services;
  52 import sun.misc.VM;
  53 
  54 //JaCoCo Exclude
  55 
  56 /**
  57  * HotSpot implementation of a JVMCI runtime.
  58  *
  59  * The initialization of this class is very fragile since it's initialized both through
  60  * {@link JVMCI#initialize()} or through calling {@link HotSpotJVMCIRuntime#runtime()} and
  61  * {@link HotSpotJVMCIRuntime#runtime()} is also called by {@link JVMCI#initialize()}. So this class
  62  * can't have a static initializer and any required initialization must be done as part of
  63  * {@link #runtime()}. This allows the initialization to funnel back through
  64  * {@link JVMCI#initialize()} without deadlocking.
  65  */
  66 public final class HotSpotJVMCIRuntime implements HotSpotJVMCIRuntimeProvider, HotSpotProxified {
  67 
  68     @SuppressWarnings("try")
  69     static class DelayedInit {
  70         private static final HotSpotJVMCIRuntime instance;
  71 
  72         static {
  73             try (InitTimer t = timer("HotSpotJVMCIRuntime.<init>")) {
  74                 instance = new HotSpotJVMCIRuntime();
  75             }
  76         }
  77     }
  78 
  79     /**
  80      * Gets the singleton {@link HotSpotJVMCIRuntime} object.
  81      */
  82     public static HotSpotJVMCIRuntime runtime() {
  83         JVMCI.initialize();
  84         return DelayedInit.instance;
  85     }
  86 
  87     /**
  88      * Gets a boolean value based on a system property {@linkplain VM#getSavedProperty(String)
  89      * saved} at system initialization time.
  90      *
  91      * @param name the name of the system property to derive a boolean value from using
  92      *            {@link Boolean#parseBoolean(String)}
  93      * @param def the value to return if there is no system property corresponding to {@code name}
  94      */
  95     public static boolean getBooleanProperty(String name, boolean def) {
  96         String value = VM.getSavedProperty(name);
  97         if (value == null) {
  98             return def;
  99         }
 100         return Boolean.parseBoolean(value);
 101     }
 102 
 103     public static HotSpotJVMCIBackendFactory findFactory(String architecture) {
 104         for (HotSpotJVMCIBackendFactory factory : Services.load(HotSpotJVMCIBackendFactory.class)) {
 105             if (factory.getArchitecture().equalsIgnoreCase(architecture)) {
 106                 return factory;
 107             }
 108         }
 109 
 110         throw new JVMCIError("No JVMCI runtime available for the %s architecture", architecture);
 111     }
 112 
 113     /**
 114      * Gets the kind of a word value on the {@linkplain #getHostJVMCIBackend() host} backend.
 115      */
 116     public static JavaKind getHostWordKind() {
 117         return runtime().getHostJVMCIBackend().getCodeCache().getTarget().wordJavaKind;
 118     }
 119 
 120     protected final CompilerToVM compilerToVm;
 121 
 122     protected final HotSpotVMConfig config;