9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
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.inittimer.InitTimer.timer;
26
27 import java.io.IOException;
28 import java.io.OutputStream;
29 import java.lang.reflect.Array;
30 import java.lang.reflect.Field;
31 import java.lang.reflect.Method;
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;
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. The property name is prefixed with "{@code jvmci.}".
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("jvmci." + 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;
147 }
148
149 try (InitTimer t = timer("create JVMCI backend:", hostArchitecture)) {
150 hostBackend = registerBackend(factory.createJVMCIBackend(this, null));
151 }
152
153 vmEventListeners = Services.load(HotSpotVMEventListener.class);
154
155 JVMCIMetaAccessContext context = null;
156 for (HotSpotVMEventListener vmEventListener : vmEventListeners) {
157 context = vmEventListener.createMetaAccessContext(this);
158 if (context != null) {
159 break;
160 }
161 }
162 if (context == null) {
163 context = new HotSpotJVMCIMetaAccessContext();
164 }
165 metaAccessContext = context;
166
167 if (Boolean.valueOf(System.getProperty("jvmci.printconfig"))) {
168 printConfig(config, compilerToVm);
169 }
170
171 trivialPrefixes = HotSpotJVMCICompilerConfig.getCompilerFactory().getTrivialPrefixes();
172 }
173
174 private JVMCIBackend registerBackend(JVMCIBackend backend) {
175 Class<? extends Architecture> arch = backend.getCodeCache().getTarget().arch.getClass();
176 JVMCIBackend oldValue = backends.put(arch, backend);
177 assert oldValue == null : "cannot overwrite existing backend for architecture " + arch.getSimpleName();
178 return backend;
179 }
180
181 public ResolvedJavaType fromClass(Class<?> javaClass) {
182 return metaAccessContext.fromClass(javaClass);
183 }
184
185 public HotSpotVMConfig getConfig() {
186 return config;
187 }
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
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.inittimer.InitTimer.timer;
26
27 import java.io.IOException;
28 import java.io.OutputStream;
29 import java.io.PrintStream;
30 import java.lang.reflect.Array;
31 import java.lang.reflect.Field;
32 import java.lang.reflect.Method;
33 import java.lang.reflect.Modifier;
34 import java.util.Collections;
35 import java.util.HashMap;
36 import java.util.Map;
37 import java.util.Objects;
38 import java.util.TreeMap;
39
40 import jdk.vm.ci.code.Architecture;
41 import jdk.vm.ci.code.CompilationResult;
42 import jdk.vm.ci.code.InstalledCode;
43 import jdk.vm.ci.common.JVMCIError;
44 import jdk.vm.ci.inittimer.InitTimer;
45 import jdk.vm.ci.meta.JVMCIMetaAccessContext;
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;
69 @SuppressWarnings("try")
70 static class DelayedInit {
71 private static final HotSpotJVMCIRuntime instance;
72
73 static {
74 try (InitTimer t = timer("HotSpotJVMCIRuntime.<init>")) {
75 instance = new HotSpotJVMCIRuntime();
76 }
77 }
78 }
79
80 /**
81 * Gets the singleton {@link HotSpotJVMCIRuntime} object.
82 */
83 public static HotSpotJVMCIRuntime runtime() {
84 JVMCI.initialize();
85 return DelayedInit.instance;
86 }
87
88 /**
89 * A list of all supported JVMCI options.
90 */
91 public enum Option {
92 ImplicitStableValues(boolean.class, true),
93 InitTimer(boolean.class, false), // Note: Not used (see InitTimer.ENABLED).
94 PrintConfig(boolean.class, false),
95 PrintFlags(boolean.class, false),
96 ShowFlags(boolean.class, false),
97 TraceMethodDataFilter(String.class, null),
98 TrustFinalDefaultFields(String.class, true);
99
100 /**
101 * The prefix for system properties that are JVMCI options.
102 */
103 private static final String JVMCI_OPTION_PROPERTY_PREFIX = "jvmci.";
104
105 private final Class<?> type;
106 private final Object value;
107 private final boolean isDefault;
108
109 private Option(Class<?> type, Object defaultValue) {
110 assert Character.isUpperCase(name().charAt(0)) : "Option name must start with upper-case letter: " + name();
111 this.type = type;
112
113 String propertyValue = VM.getSavedProperty(JVMCI_OPTION_PROPERTY_PREFIX + name());
114 if (propertyValue == null) {
115 this.value = defaultValue;
116 this.isDefault = true;
117 } else {
118 if (type == boolean.class) {
119 this.value = Boolean.parseBoolean(propertyValue);
120 } else if (type == String.class) {
121 this.value = propertyValue;
122 } else {
123 throw new JVMCIError("Unexpected option type " + type);
124 }
125 this.isDefault = false;
126 }
127 }
128
129 /**
130 * Returns the option's value as boolean.
131 *
132 * @return option's value
133 */
134 public boolean getBoolean() {
135 return (boolean) value;
136 }
137
138 /**
139 * Returns the option's value as String.
140 *
141 * @return option's value
142 */
143 public String getString() {
144 return (String) value;
145 }
146
147 /**
148 * Prints all option flags to {@code out}.
149 *
150 * @param out stream to print to
151 */
152 public static void printFlags(PrintStream out) {
153 out.println("[List of JVMCI options]");
154 for (Option option : values()) {
155 String assign = option.isDefault ? ":=" : " =";
156 out.printf("%9s %-40s %s %-14s%n", option.type.getSimpleName(), option, assign, option.value);
157 }
158 }
159 }
160
161 public static HotSpotJVMCIBackendFactory findFactory(String architecture) {
162 for (HotSpotJVMCIBackendFactory factory : Services.load(HotSpotJVMCIBackendFactory.class)) {
163 if (factory.getArchitecture().equalsIgnoreCase(architecture)) {
164 return factory;
165 }
166 }
167
168 throw new JVMCIError("No JVMCI runtime available for the %s architecture", architecture);
169 }
170
171 /**
172 * Gets the kind of a word value on the {@linkplain #getHostJVMCIBackend() host} backend.
173 */
174 public static JavaKind getHostWordKind() {
175 return runtime().getHostJVMCIBackend().getCodeCache().getTarget().wordJavaKind;
176 }
177
178 protected final CompilerToVM compilerToVm;
205 }
206
207 try (InitTimer t = timer("create JVMCI backend:", hostArchitecture)) {
208 hostBackend = registerBackend(factory.createJVMCIBackend(this, null));
209 }
210
211 vmEventListeners = Services.load(HotSpotVMEventListener.class);
212
213 JVMCIMetaAccessContext context = null;
214 for (HotSpotVMEventListener vmEventListener : vmEventListeners) {
215 context = vmEventListener.createMetaAccessContext(this);
216 if (context != null) {
217 break;
218 }
219 }
220 if (context == null) {
221 context = new HotSpotJVMCIMetaAccessContext();
222 }
223 metaAccessContext = context;
224
225 boolean printFlags = Option.PrintFlags.getBoolean();
226 boolean showFlags = Option.ShowFlags.getBoolean();
227 if (printFlags || showFlags) {
228 Option.printFlags(System.out);
229 if (printFlags) {
230 System.exit(0);
231 }
232 }
233
234 if (Option.PrintConfig.getBoolean()) {
235 printConfig(config, compilerToVm);
236 }
237
238 trivialPrefixes = HotSpotJVMCICompilerConfig.getCompilerFactory().getTrivialPrefixes();
239 }
240
241 private JVMCIBackend registerBackend(JVMCIBackend backend) {
242 Class<? extends Architecture> arch = backend.getCodeCache().getTarget().arch.getClass();
243 JVMCIBackend oldValue = backends.put(arch, backend);
244 assert oldValue == null : "cannot overwrite existing backend for architecture " + arch.getSimpleName();
245 return backend;
246 }
247
248 public ResolvedJavaType fromClass(Class<?> javaClass) {
249 return metaAccessContext.fromClass(javaClass);
250 }
251
252 public HotSpotVMConfig getConfig() {
253 return config;
254 }
|