< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotGraalOptionValues.java

Print this page




  23 
  24 
  25 package org.graalvm.compiler.hotspot;
  26 
  27 import static jdk.vm.ci.common.InitTimer.timer;
  28 
  29 import java.io.File;
  30 import java.io.FileReader;
  31 import java.io.IOException;
  32 import java.util.Map;
  33 import java.util.Properties;
  34 
  35 import jdk.internal.vm.compiler.collections.EconomicMap;
  36 import org.graalvm.compiler.options.Option;
  37 import org.graalvm.compiler.options.OptionDescriptors;
  38 import org.graalvm.compiler.options.OptionKey;
  39 import org.graalvm.compiler.options.OptionValues;
  40 import org.graalvm.compiler.options.OptionsParser;
  41 
  42 import jdk.vm.ci.common.InitTimer;

  43 
  44 /**
  45  * The {@link #HOTSPOT_OPTIONS} value contains the options values initialized in a HotSpot VM. The
  46  * values are set via system properties with the {@value #GRAAL_OPTION_PROPERTY_PREFIX} prefix.
  47  */
  48 public class HotSpotGraalOptionValues {
  49 
  50     /**
  51      * The name of the system property specifying a file containing extra Graal option settings.
  52      */
  53     private static final String GRAAL_OPTIONS_FILE_PROPERTY_NAME = "graal.options.file";
  54 
  55     /**
  56      * The name of the system property specifying the Graal version.
  57      */
  58     private static final String GRAAL_VERSION_PROPERTY_NAME = "graal.version";
  59 
  60     /**
  61      * The prefix for system properties that correspond to {@link Option} annotated fields. A field
  62      * named {@code MyOption} will have its value set from a system property with the name
  63      * {@code GRAAL_OPTION_PROPERTY_PREFIX + "MyOption"}.
  64      */
  65     public static final String GRAAL_OPTION_PROPERTY_PREFIX = "graal.";
  66 
  67     /**
  68      * Gets the system property assignment that would set the current value for a given option.
  69      */
  70     public static String asSystemPropertySetting(OptionValues options, OptionKey<?> value) {
  71         return GRAAL_OPTION_PROPERTY_PREFIX + value.getName() + "=" + value.getValue(options);
  72     }
  73 
  74     public static final OptionValues HOTSPOT_OPTIONS = initializeOptions();














  75 
  76     /**
  77      * Global options. The values for these options are initialized by parsing the file denoted by
  78      * the {@code VM.getSavedProperty(String) saved} system property named
  79      * {@value #GRAAL_OPTIONS_FILE_PROPERTY_NAME} if the file exists followed by parsing the options
  80      * encoded in saved system properties whose names start with
  81      * {@value #GRAAL_OPTION_PROPERTY_PREFIX}. Key/value pairs are parsed from the aforementioned
  82      * file with {@link Properties#load(java.io.Reader)}.
  83      */
  84     @SuppressWarnings("try")
  85     private static OptionValues initializeOptions() {
  86         EconomicMap<OptionKey<?>, Object> values = OptionValues.newOptionMap();
  87         try (InitTimer t = timer("InitializeOptions")) {
  88 
  89             Iterable<OptionDescriptors> loader = OptionsParser.getOptionsLoader();
  90             Map<String, String> savedProps = jdk.vm.ci.services.Services.getSavedProperties();
  91             String optionsFile = savedProps.get(GRAAL_OPTIONS_FILE_PROPERTY_NAME);
  92 
  93             if (optionsFile != null) {
  94                 File graalOptions = new File(optionsFile);




  23 
  24 
  25 package org.graalvm.compiler.hotspot;
  26 
  27 import static jdk.vm.ci.common.InitTimer.timer;
  28 
  29 import java.io.File;
  30 import java.io.FileReader;
  31 import java.io.IOException;
  32 import java.util.Map;
  33 import java.util.Properties;
  34 
  35 import jdk.internal.vm.compiler.collections.EconomicMap;
  36 import org.graalvm.compiler.options.Option;
  37 import org.graalvm.compiler.options.OptionDescriptors;
  38 import org.graalvm.compiler.options.OptionKey;
  39 import org.graalvm.compiler.options.OptionValues;
  40 import org.graalvm.compiler.options.OptionsParser;
  41 
  42 import jdk.vm.ci.common.InitTimer;
  43 import jdk.vm.ci.common.NativeImageReinitialize;
  44 
  45 /**
  46  * The {@link #defaultOptions()} method returns the options values initialized in a HotSpot VM. The
  47  * values are set via system properties with the {@value #GRAAL_OPTION_PROPERTY_PREFIX} prefix.
  48  */
  49 public class HotSpotGraalOptionValues {
  50 
  51     /**
  52      * The name of the system property specifying a file containing extra Graal option settings.
  53      */
  54     private static final String GRAAL_OPTIONS_FILE_PROPERTY_NAME = "graal.options.file";
  55 
  56     /**
  57      * The name of the system property specifying the Graal version.
  58      */
  59     private static final String GRAAL_VERSION_PROPERTY_NAME = "graal.version";
  60 
  61     /**
  62      * The prefix for system properties that correspond to {@link Option} annotated fields. A field
  63      * named {@code MyOption} will have its value set from a system property with the name
  64      * {@code GRAAL_OPTION_PROPERTY_PREFIX + "MyOption"}.
  65      */
  66     public static final String GRAAL_OPTION_PROPERTY_PREFIX = "graal.";
  67 
  68     /**
  69      * Gets the system property assignment that would set the current value for a given option.
  70      */
  71     public static String asSystemPropertySetting(OptionValues options, OptionKey<?> value) {
  72         return GRAAL_OPTION_PROPERTY_PREFIX + value.getName() + "=" + value.getValue(options);
  73     }
  74 
  75     @NativeImageReinitialize private static volatile OptionValues hotspotOptions;
  76 
  77     public static OptionValues defaultOptions() {
  78         OptionValues res = hotspotOptions;
  79         if (res == null) {
  80             synchronized (HotSpotGraalOptionValues.class) {
  81                 res = hotspotOptions;
  82                 if (res == null) {
  83                     res = initializeOptions();
  84                     hotspotOptions = res;
  85                 }
  86             }
  87         }
  88         return res;
  89     }
  90 
  91     /**
  92      * Global options. The values for these options are initialized by parsing the file denoted by
  93      * the {@code VM.getSavedProperty(String) saved} system property named
  94      * {@value #GRAAL_OPTIONS_FILE_PROPERTY_NAME} if the file exists followed by parsing the options
  95      * encoded in saved system properties whose names start with
  96      * {@value #GRAAL_OPTION_PROPERTY_PREFIX}. Key/value pairs are parsed from the aforementioned
  97      * file with {@link Properties#load(java.io.Reader)}.
  98      */
  99     @SuppressWarnings("try")
 100     private static OptionValues initializeOptions() {
 101         EconomicMap<OptionKey<?>, Object> values = OptionValues.newOptionMap();
 102         try (InitTimer t = timer("InitializeOptions")) {
 103 
 104             Iterable<OptionDescriptors> loader = OptionsParser.getOptionsLoader();
 105             Map<String, String> savedProps = jdk.vm.ci.services.Services.getSavedProperties();
 106             String optionsFile = savedProps.get(GRAAL_OPTIONS_FILE_PROPERTY_NAME);
 107 
 108             if (optionsFile != null) {
 109                 File graalOptions = new File(optionsFile);


< prev index next >