< prev index next >

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

Print this page




  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  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.common.InitTimer.timer;
  26 
  27 import java.io.IOException;
  28 import java.io.OutputStream;
  29 import java.io.PrintStream;
  30 import java.util.Collections;
  31 import java.util.HashMap;
  32 import java.util.List;
  33 import java.util.Map;
  34 import java.util.Objects;

  35 import java.util.TreeMap;
  36 
  37 import jdk.internal.misc.VM;
  38 import jdk.vm.ci.code.Architecture;
  39 import jdk.vm.ci.code.CompilationRequestResult;
  40 import jdk.vm.ci.code.CompiledCode;
  41 import jdk.vm.ci.code.InstalledCode;
  42 import jdk.vm.ci.common.InitTimer;
  43 import jdk.vm.ci.common.JVMCIError;
  44 import jdk.vm.ci.hotspot.HotSpotJVMCICompilerFactory.CompilationLevel;
  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.runtime.JVMCICompilerFactory;
  52 import jdk.vm.ci.services.JVMCIServiceLocator;
  53 import jdk.vm.ci.services.Services;
  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 {
  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     /**
  87      * A list of all supported JVMCI options.
  88      */
  89     public enum Option {
  90         // @formatter:off
  91         Compiler(String.class, null, "Selects the system compiler."),



  92         // Note: The following one is not used (see InitTimer.ENABLED). It is added here
  93         // so that -XX:+JVMCIPrintProperties shows the option.
  94         InitTimer(Boolean.class, false, "Specifies if initialization timing is enabled."),
  95         PrintConfig(Boolean.class, false, "Prints VM configuration available via JVMCI."),
  96         TraceMethodDataFilter(String.class, null,
  97                         "Enables tracing of profiling info when read by JVMCI.",
  98                         "Empty value: trace all methods",
  99                         "Non-empty value: trace methods whose fully qualified name contains the value."),
 100         UseProfilingInformation(Boolean.class, true, "");
 101         // @formatter:on
 102 
 103         /**
 104          * The prefix for system properties that are JVMCI options.
 105          */
 106         private static final String JVMCI_OPTION_PROPERTY_PREFIX = "jvmci.";
 107 
 108         /**
 109          * Marker for uninitialized flags.
 110          */
 111         private static final String UNINITIALIZED = "UNINITIALIZED";


 191 
 192                 String name = option.getPropertyName();
 193                 String assign = option.isDefault ? "=" : ":=";
 194                 String typeName = option.type.getSimpleName();
 195                 String linePrefix = String.format("%s %s %s ", name, assign, value);
 196                 int typeStartPos = PROPERTY_LINE_WIDTH - typeName.length();
 197                 int linePad = typeStartPos - linePrefix.length();
 198                 if (linePad > 0) {
 199                     out.printf("%s%-" + linePad + "s[%s]%n", linePrefix, "", typeName);
 200                 } else {
 201                     out.printf("%s[%s]%n", linePrefix, typeName);
 202                 }
 203                 for (String line : option.helpLines) {
 204                     out.printf("%" + PROPERTY_HELP_INDENT + "s%s%n", "", line);
 205                 }
 206             }
 207         }
 208     }
 209 
 210     public static HotSpotJVMCIBackendFactory findFactory(String architecture) {
 211         for (HotSpotJVMCIBackendFactory factory : Services.load(HotSpotJVMCIBackendFactory.class)) {
 212             if (factory.getArchitecture().equalsIgnoreCase(architecture)) {
 213                 return factory;
 214             }
 215         }
 216 
 217         throw new JVMCIError("No JVMCI runtime available for the %s architecture", architecture);
 218     }
 219 
 220     /**
 221      * Gets the kind of a word value on the {@linkplain #getHostJVMCIBackend() host} backend.
 222      */
 223     public static JavaKind getHostWordKind() {
 224         return runtime().getHostJVMCIBackend().getCodeCache().getTarget().wordJavaKind;
 225     }
 226 
 227     protected final CompilerToVM compilerToVm;
 228 
 229     protected final HotSpotVMConfigStore configStore;
 230     protected final HotSpotVMConfig config;
 231     private final JVMCIBackend hostBackend;




  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  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.common.InitTimer.timer;
  26 
  27 import java.io.IOException;
  28 import java.io.OutputStream;
  29 import java.io.PrintStream;
  30 import java.util.Collections;
  31 import java.util.HashMap;
  32 import java.util.List;
  33 import java.util.Map;
  34 import java.util.Objects;
  35 import java.util.ServiceLoader;
  36 import java.util.TreeMap;
  37 
  38 import jdk.internal.misc.VM;
  39 import jdk.vm.ci.code.Architecture;
  40 import jdk.vm.ci.code.CompilationRequestResult;
  41 import jdk.vm.ci.code.CompiledCode;
  42 import jdk.vm.ci.code.InstalledCode;
  43 import jdk.vm.ci.common.InitTimer;
  44 import jdk.vm.ci.common.JVMCIError;
  45 import jdk.vm.ci.hotspot.HotSpotJVMCICompilerFactory.CompilationLevel;
  46 import jdk.vm.ci.meta.JavaKind;
  47 import jdk.vm.ci.meta.JavaType;
  48 import jdk.vm.ci.meta.ResolvedJavaType;
  49 import jdk.vm.ci.runtime.JVMCI;
  50 import jdk.vm.ci.runtime.JVMCIBackend;
  51 import jdk.vm.ci.runtime.JVMCICompiler;
  52 import jdk.vm.ci.runtime.JVMCICompilerFactory;
  53 import jdk.vm.ci.services.JVMCIServiceLocator;

  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 {
  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     /**
  87      * A list of all supported JVMCI options.
  88      */
  89     public enum Option {
  90         // @formatter:off
  91         Compiler(String.class, null, "Selects the system compiler. This must match the getCompilerName() value returned " +
  92                                      "by a jdk.vm.ci.runtime.JVMCICompilerFactory provider. " +
  93                                      "An empty string or the value \"null\" selects a compiler " +
  94                                      "that will raise an exception upon receiving a compilation request."),
  95         // Note: The following one is not used (see InitTimer.ENABLED). It is added here
  96         // so that -XX:+JVMCIPrintProperties shows the option.
  97         InitTimer(Boolean.class, false, "Specifies if initialization timing is enabled."),
  98         PrintConfig(Boolean.class, false, "Prints VM configuration available via JVMCI."),
  99         TraceMethodDataFilter(String.class, null,
 100                         "Enables tracing of profiling info when read by JVMCI.",
 101                         "Empty value: trace all methods",
 102                         "Non-empty value: trace methods whose fully qualified name contains the value."),
 103         UseProfilingInformation(Boolean.class, true, "");
 104         // @formatter:on
 105 
 106         /**
 107          * The prefix for system properties that are JVMCI options.
 108          */
 109         private static final String JVMCI_OPTION_PROPERTY_PREFIX = "jvmci.";
 110 
 111         /**
 112          * Marker for uninitialized flags.
 113          */
 114         private static final String UNINITIALIZED = "UNINITIALIZED";


 194 
 195                 String name = option.getPropertyName();
 196                 String assign = option.isDefault ? "=" : ":=";
 197                 String typeName = option.type.getSimpleName();
 198                 String linePrefix = String.format("%s %s %s ", name, assign, value);
 199                 int typeStartPos = PROPERTY_LINE_WIDTH - typeName.length();
 200                 int linePad = typeStartPos - linePrefix.length();
 201                 if (linePad > 0) {
 202                     out.printf("%s%-" + linePad + "s[%s]%n", linePrefix, "", typeName);
 203                 } else {
 204                     out.printf("%s[%s]%n", linePrefix, typeName);
 205                 }
 206                 for (String line : option.helpLines) {
 207                     out.printf("%" + PROPERTY_HELP_INDENT + "s%s%n", "", line);
 208                 }
 209             }
 210         }
 211     }
 212 
 213     public static HotSpotJVMCIBackendFactory findFactory(String architecture) {
 214         for (HotSpotJVMCIBackendFactory factory : ServiceLoader.load(HotSpotJVMCIBackendFactory.class, ClassLoader.getSystemClassLoader())) {
 215             if (factory.getArchitecture().equalsIgnoreCase(architecture)) {
 216                 return factory;
 217             }
 218         }
 219 
 220         throw new JVMCIError("No JVMCI runtime available for the %s architecture", architecture);
 221     }
 222 
 223     /**
 224      * Gets the kind of a word value on the {@linkplain #getHostJVMCIBackend() host} backend.
 225      */
 226     public static JavaKind getHostWordKind() {
 227         return runtime().getHostJVMCIBackend().getCodeCache().getTarget().wordJavaKind;
 228     }
 229 
 230     protected final CompilerToVM compilerToVm;
 231 
 232     protected final HotSpotVMConfigStore configStore;
 233     protected final HotSpotVMConfig config;
 234     private final JVMCIBackend hostBackend;


< prev index next >