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
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);
110 if (graalOptions.exists()) {
111 try (FileReader fr = new FileReader(graalOptions)) {
112 Properties props = new Properties();
113 props.load(fr);
114 EconomicMap<String, String> optionSettings = EconomicMap.create();
115 for (Map.Entry<Object, Object> e : props.entrySet()) {
116 optionSettings.put((String) e.getKey(), (String) e.getValue());
117 }
118 try {
119 OptionsParser.parseOptions(optionSettings, values, loader);
120 } catch (Throwable e) {
125 }
126 }
127 }
128
129 EconomicMap<String, String> optionSettings = EconomicMap.create();
130 for (Map.Entry<String, String> e : savedProps.entrySet()) {
131 String name = e.getKey();
132 if (name.startsWith(GRAAL_OPTION_PROPERTY_PREFIX)) {
133 if (name.equals("graal.PrintFlags") || name.equals("graal.ShowFlags")) {
134 System.err.println("The " + name + " option has been removed and will be ignored. Use -XX:+JVMCIPrintProperties instead.");
135 } else if (name.equals(GRAAL_OPTIONS_FILE_PROPERTY_NAME) || name.equals(GRAAL_VERSION_PROPERTY_NAME)) {
136 // Ignore well known properties that do not denote an option
137 } else {
138 String value = e.getValue();
139 optionSettings.put(name.substring(GRAAL_OPTION_PROPERTY_PREFIX.length()), value);
140 }
141 }
142 }
143
144 OptionsParser.parseOptions(optionSettings, values, loader);
145 return new OptionValues(values);
146 }
147 }
148 }
|
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 import jdk.vm.ci.services.Services;
45
46 /**
47 * The {@link #defaultOptions()} method returns the options values initialized in a HotSpot VM. The
48 * values are set via system properties with the {@value #GRAAL_OPTION_PROPERTY_PREFIX} prefix.
49 */
50 public class HotSpotGraalOptionValues {
51
52 /**
53 * The name of the system property specifying a file containing extra Graal option settings.
54 */
55 private static final String GRAAL_OPTIONS_FILE_PROPERTY_NAME = "graal.options.file";
56
57 /**
58 * The name of the system property specifying the Graal version.
59 */
60 private static final String GRAAL_VERSION_PROPERTY_NAME = "graal.version";
61
62 /**
63 * The prefix for system properties that correspond to {@link Option} annotated fields. A field
64 * named {@code MyOption} will have its value set from a system property with the name
73 return GRAAL_OPTION_PROPERTY_PREFIX + value.getName() + "=" + value.getValue(options);
74 }
75
76 @NativeImageReinitialize private static volatile OptionValues hotspotOptions;
77
78 public static OptionValues defaultOptions() {
79 OptionValues res = hotspotOptions;
80 if (res == null) {
81 synchronized (HotSpotGraalOptionValues.class) {
82 res = hotspotOptions;
83 if (res == null) {
84 res = initializeOptions();
85 hotspotOptions = res;
86 }
87 }
88 }
89 return res;
90 }
91
92 /**
93 * Gets and parses options based on {@linkplain Services#getSavedProperties() saved system
94 * properties}. The values for these options are initialized by parsing the file denoted by the
95 * {@value #GRAAL_OPTIONS_FILE_PROPERTY_NAME} property followed by parsing the options encoded
96 * in properties whose names start with {@value #GRAAL_OPTION_PROPERTY_PREFIX}. Key/value pairs
97 * are parsed from the aforementioned file with {@link Properties#load(java.io.Reader)}.
98 */
99 @SuppressWarnings("try")
100 public static EconomicMap<OptionKey<?>, Object> parseOptions() {
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);
110 if (graalOptions.exists()) {
111 try (FileReader fr = new FileReader(graalOptions)) {
112 Properties props = new Properties();
113 props.load(fr);
114 EconomicMap<String, String> optionSettings = EconomicMap.create();
115 for (Map.Entry<Object, Object> e : props.entrySet()) {
116 optionSettings.put((String) e.getKey(), (String) e.getValue());
117 }
118 try {
119 OptionsParser.parseOptions(optionSettings, values, loader);
120 } catch (Throwable e) {
125 }
126 }
127 }
128
129 EconomicMap<String, String> optionSettings = EconomicMap.create();
130 for (Map.Entry<String, String> e : savedProps.entrySet()) {
131 String name = e.getKey();
132 if (name.startsWith(GRAAL_OPTION_PROPERTY_PREFIX)) {
133 if (name.equals("graal.PrintFlags") || name.equals("graal.ShowFlags")) {
134 System.err.println("The " + name + " option has been removed and will be ignored. Use -XX:+JVMCIPrintProperties instead.");
135 } else if (name.equals(GRAAL_OPTIONS_FILE_PROPERTY_NAME) || name.equals(GRAAL_VERSION_PROPERTY_NAME)) {
136 // Ignore well known properties that do not denote an option
137 } else {
138 String value = e.getValue();
139 optionSettings.put(name.substring(GRAAL_OPTION_PROPERTY_PREFIX.length()), value);
140 }
141 }
142 }
143
144 OptionsParser.parseOptions(optionSettings, values, loader);
145 return values;
146 }
147 }
148
149 /**
150 * Substituted by
151 * {@code com.oracle.svm.graal.hotspot.libgraal.Target_org_graalvm_compiler_hotspot_HotSpotGraalOptionValues}
152 * to update {@code com.oracle.svm.core.option.RuntimeOptionValues.singleton()} instead of
153 * creating a new {@link OptionValues} object.
154 */
155 private static OptionValues initializeOptions() {
156 return new OptionValues(parseOptions());
157 }
158 }
|