comparison src/share/vm/jvmci/jvmciRuntime.hpp @ 21559:be896a1983c0

recast all Graal native code as JVMCI code (JBS:GRAAL-53)
author Doug Simon <doug.simon@oracle.com>
date Thu, 28 May 2015 15:36:48 +0200
parents src/share/vm/graal/graalRuntime.hpp@07b088d61d5d
children 47bebae7454f
comparison
equal deleted inserted replaced
21558:d563baeca9df 21559:be896a1983c0
1 /*
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
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
24 #ifndef SHARE_VM_JVMCI_JVMCI_RUNTIME_HPP
25 #define SHARE_VM_JVMCI_JVMCI_RUNTIME_HPP
26
27 #include "interpreter/interpreter.hpp"
28 #include "memory/allocation.hpp"
29 #include "runtime/deoptimization.hpp"
30
31 class JVMCIRuntime: public CHeapObj<mtCompiler> {
32 private:
33
34 static jobject _HotSpotJVMCIRuntime_instance;
35 static bool _HotSpotJVMCIRuntime_initialized;
36 static const char* _generated_sources_sha1;
37
38 static bool _shutdown_called;
39
40 /**
41 * Reads the OptionValue object from a specified static field.
42 *
43 * @throws LinkageError if the field could not be resolved
44 */
45 static Handle get_OptionValue(const char* declaringClass, const char* fieldName, const char* fieldSig, TRAPS);
46
47 /**
48 * Parses the string form of a numeric, float or double option into a jlong (using raw bits for floats/doubles).
49 *
50 * @param spec 'i', 'f' or 'd' (see HotSpotOptions.setOption())
51 * @param name option name
52 * @param name_len length of option name
53 * @param value string value to parse
54 * @throws InternalError if value could not be parsed according to spec
55 */
56 static jlong parse_primitive_option_value(char spec, const char* name, size_t name_len, const char* value, TRAPS);
57
58 /**
59 * Loads default option value overrides from a <jre_home>/lib/jvmci.options if it exists. Each
60 * line in this file must have the format of a JVMCI command line option without the
61 * leading "-G:" prefix. These option values are set prior to processing of any JVMCI
62 * options present on the command line.
63 */
64 static void parse_jvmci_options_file(KlassHandle hotSpotOptionsClass, TRAPS);
65
66 /**
67 * Parses a given argument and sets the denoted JVMCI option.
68 *
69 * @throws InternalError if there was a problem parsing or setting the option
70 */
71 static void parse_argument(KlassHandle hotSpotOptionsClass, char* arg, TRAPS);
72
73 /**
74 * Searches for a Boolean JVMCI option denoted by a given name and sets it value.
75 *
76 * The definition of this method is in jvmciRuntime.inline.hpp
77 * which is generated by com.oracle.jvmci.hotspot.sourcegen.GenJVMCIRuntimeInlineHpp.
78 *
79 * @param hotSpotOptionsClass the HotSpotOptions klass or NULL if only checking for valid option
80 * @param name option name
81 * @param name_len length of option name
82 * @param value '+' to set the option, '-' to reset the option
83 * @returns true if the option was found
84 * @throws InternalError if there was a problem setting the option's value
85 */
86 static bool set_option_bool(KlassHandle hotSpotOptionsClass, char* name, size_t name_len, char value, TRAPS);
87
88 /**
89 * Searches for a JVMCI option denoted by a given name and sets it value.
90 *
91 * The definition of this method is in jvmciRuntime.inline.hpp
92 * which is generated by com.oracle.jvmci.hotspot.sourcegen.GenJVMCIRuntimeInlineHpp.
93 *
94 * @param hotSpotOptionsClass the HotSpotOptions klass or NULL if only checking for valid option
95 * @param name option name
96 * @param name_len length of option name
97 * @returns true if the option was found
98 * @throws InternalError if there was a problem setting the option's value
99 */
100 static bool set_option(KlassHandle hotSpotOptionsClass, char* name, size_t name_len, const char* value, TRAPS);
101
102 /**
103 * Raises an InternalError for an option that expects a value but was specified without a "=<value>" prefix.
104 */
105 static void check_required_value(const char* name, size_t name_len, const char* value, TRAPS);
106
107 /**
108 * Java call to HotSpotOptions.setOption(String name, OptionValue<?> option, char spec, String stringValue, long primitiveValue)
109 *
110 * @param name option name
111 * @param name_len length of option name
112 */
113 static void set_option_helper(KlassHandle hotSpotOptionsClass, char* name, size_t name_len, Handle option, jchar spec, Handle stringValue, jlong primitiveValue);
114
115 /**
116 * Instantiates a service object, calls its default constructor and returns it.
117 *
118 * @param name the name of a class implementing com.oracle.jvmci.api.runtime.Service
119 */
120 static Handle create_Service(const char* name, TRAPS);
121
122 /**
123 * Checks that _generated_sources_sha1 equals GeneratedSourcesSha1.value.
124 */
125 static void check_generated_sources_sha1(TRAPS);
126
127 public:
128
129 /**
130 * Ensures that the JVMCI class loader is initialized and the well known JVMCI classes are loaded.
131 */
132 static void ensure_jvmci_class_loader_is_initialized();
133
134 static void initialize_natives(JNIEnv *env, jclass c2vmClass);
135
136 static bool is_HotSpotJVMCIRuntime_initialized() { return _HotSpotJVMCIRuntime_initialized; }
137
138 /**
139 * Gets the singleton HotSpotJVMCIRuntime instance, initializing it if necessary
140 */
141 static Handle get_HotSpotJVMCIRuntime() {
142 initialize_JVMCI();
143 return Handle(JNIHandles::resolve_non_null(_HotSpotJVMCIRuntime_instance));
144 }
145
146 static jobject get_HotSpotJVMCIRuntime_jobject() {
147 initialize_JVMCI();
148 assert(_HotSpotJVMCIRuntime_initialized, "must be");
149 return _HotSpotJVMCIRuntime_instance;
150 }
151
152 static Handle callInitializer(const char* className, const char* methodName, const char* returnType);
153
154 /**
155 * Trigger initialization of HotSpotJVMCIRuntime through JVMCI.getRuntime()
156 */
157 static void initialize_JVMCI();
158
159 /**
160 * Explicitly initialize HotSpotJVMCIRuntime itself
161 */
162 static void initialize_HotSpotJVMCIRuntime();
163
164 static void shutdown();
165
166 static bool shutdown_called() {
167 return _shutdown_called;
168 }
169
170 /**
171 * Given an interface representing a JVMCI service (i.e. sub-interface of
172 * com.oracle.jvmci.api.runtime.Service), gets an array of objects, one per
173 * known implementation of the service.
174 *
175 * The definition of this method is in jvmciRuntime.inline.hpp
176 * which is generated by com.oracle.jvmci.hotspot.sourcegen.GenJVMCIRuntimeInlineHpp.
177 */
178 static Handle get_service_impls(KlassHandle serviceKlass, TRAPS);
179
180 /**
181 * Aborts the VM due to an unexpected exception.
182 */
183 static void abort_on_pending_exception(Handle exception, const char* message, bool dump_core = false);
184
185 /**
186 * Calls Throwable.printStackTrace() on a given exception.
187 */
188 static void call_printStackTrace(Handle exception, Thread* thread);
189
190 #define CHECK_ABORT THREAD); \
191 if (HAS_PENDING_EXCEPTION) { \
192 char buf[256]; \
193 jio_snprintf(buf, 256, "Uncaught exception at %s:%d", __FILE__, __LINE__); \
194 JVMCIRuntime::abort_on_pending_exception(PENDING_EXCEPTION, buf); \
195 return; \
196 } \
197 (void)(0
198
199 #define CHECK_ABORT_(result) THREAD); \
200 if (HAS_PENDING_EXCEPTION) { \
201 char buf[256]; \
202 jio_snprintf(buf, 256, "Uncaught exception at %s:%d", __FILE__, __LINE__); \
203 JVMCIRuntime::abort_on_pending_exception(PENDING_EXCEPTION, buf); \
204 return result; \
205 } \
206 (void)(0
207
208 /**
209 * Same as SystemDictionary::resolve_or_null but uses the JVMCI loader.
210 */
211 static Klass* resolve_or_null(Symbol* name, TRAPS);
212
213 /**
214 * Same as SystemDictionary::resolve_or_fail but uses the JVMCI loader.
215 */
216 static Klass* resolve_or_fail(Symbol* name, TRAPS);
217
218 /**
219 * Loads a given JVMCI class and aborts the VM if it fails.
220 */
221 static Klass* load_required_class(Symbol* name);
222
223 static BufferBlob* initialize_buffer_blob();
224
225 /**
226 * Checks that all JVMCI specific VM options presented by the launcher are recognized
227 * and formatted correctly. To set relevant Java fields from the option, parse_arguments()
228 * must be called. This method makes no Java calls apart from creating exception objects
229 * if there is an errors in the JVMCI options.
230 */
231 static jint check_arguments(TRAPS);
232
233 /**
234 * Parses the JVMCI specific VM options that were presented by the launcher and sets
235 * the relevants Java fields.
236 */
237 static void parse_arguments(KlassHandle hotSpotOptionsClass, TRAPS);
238
239 static BasicType kindToBasicType(jchar ch);
240
241 // The following routines are all called from compiled JVMCI code
242
243 static void new_instance(JavaThread* thread, Klass* klass);
244 static void new_array(JavaThread* thread, Klass* klass, jint length);
245 static void new_multi_array(JavaThread* thread, Klass* klass, int rank, jint* dims);
246 static void dynamic_new_array(JavaThread* thread, oopDesc* element_mirror, jint length);
247 static void dynamic_new_instance(JavaThread* thread, oopDesc* type_mirror);
248 static jboolean thread_is_interrupted(JavaThread* thread, oopDesc* obj, jboolean clear_interrupted);
249 static void vm_message(jboolean vmError, jlong format, jlong v1, jlong v2, jlong v3);
250 static jint identity_hash_code(JavaThread* thread, oopDesc* obj);
251 static address exception_handler_for_pc(JavaThread* thread);
252 static void monitorenter(JavaThread* thread, oopDesc* obj, BasicLock* lock);
253 static void monitorexit (JavaThread* thread, oopDesc* obj, BasicLock* lock);
254 static void create_null_exception(JavaThread* thread);
255 static void create_out_of_bounds_exception(JavaThread* thread, jint index);
256 static void vm_error(JavaThread* thread, jlong where, jlong format, jlong value);
257 static oopDesc* load_and_clear_exception(JavaThread* thread);
258 static void log_printf(JavaThread* thread, oopDesc* format, jlong v1, jlong v2, jlong v3);
259 static void log_primitive(JavaThread* thread, jchar typeChar, jlong value, jboolean newline);
260 // Note: Must be kept in sync with constants in com.oracle.jvmci.replacements.Log
261 enum {
262 LOG_OBJECT_NEWLINE = 0x01,
263 LOG_OBJECT_STRING = 0x02,
264 LOG_OBJECT_ADDRESS = 0x04
265 };
266 static void log_object(JavaThread* thread, oopDesc* msg, jint flags);
267 static void write_barrier_pre(JavaThread* thread, oopDesc* obj);
268 static void write_barrier_post(JavaThread* thread, void* card);
269 static jboolean validate_object(JavaThread* thread, oopDesc* parent, oopDesc* child);
270 static void new_store_pre_barrier(JavaThread* thread);
271
272 // Test only function
273 static int test_deoptimize_call_int(JavaThread* thread, int value);
274 };
275
276 // Tracing macros
277
278 #define IF_TRACE_jvmci_1 if (!(TraceJVMCI >= 1)) ; else
279 #define IF_TRACE_jvmci_2 if (!(TraceJVMCI >= 2)) ; else
280 #define IF_TRACE_jvmci_3 if (!(TraceJVMCI >= 3)) ; else
281 #define IF_TRACE_jvmci_4 if (!(TraceJVMCI >= 4)) ; else
282 #define IF_TRACE_jvmci_5 if (!(TraceJVMCI >= 5)) ; else
283
284 // using commas and else to keep one-instruction semantics
285
286 #define TRACE_jvmci_1 if (!(TraceJVMCI >= 1 && (tty->print("TraceJVMCI-1: "), true))) ; else tty->print_cr
287 #define TRACE_jvmci_2 if (!(TraceJVMCI >= 2 && (tty->print(" TraceJVMCI-2: "), true))) ; else tty->print_cr
288 #define TRACE_jvmci_3 if (!(TraceJVMCI >= 3 && (tty->print(" TraceJVMCI-3: "), true))) ; else tty->print_cr
289 #define TRACE_jvmci_4 if (!(TraceJVMCI >= 4 && (tty->print(" TraceJVMCI-4: "), true))) ; else tty->print_cr
290 #define TRACE_jvmci_5 if (!(TraceJVMCI >= 5 && (tty->print(" TraceJVMCI-5: "), true))) ; else tty->print_cr
291
292 #endif // SHARE_VM_JVMCI_JVMCI_RUNTIME_HPP