Mercurial > hg > graal-compiler
annotate src/share/vm/graal/graalRuntime.cpp @ 9577:ffd3d85e055f
replaced OSR_migration_end assembler stub with a compiled stub (GRAAL-81)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 06 May 2013 15:22:59 +0200 |
parents | df3aa336a313 |
children | d84ea522800e |
rev | line source |
---|---|
7221 | 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 #include "precompiled.hpp" | |
7735 | 25 #include "asm/codeBuffer.hpp" |
7221 | 26 #include "graal/graalRuntime.hpp" |
27 #include "graal/graalVMToCompiler.hpp" | |
7735 | 28 #include "memory/oopFactory.hpp" |
29 #include "prims/jvm.h" | |
7221 | 30 #include "runtime/biasedLocking.hpp" |
7735 | 31 #include "runtime/interfaceSupport.hpp" |
8499
96a337d307bd
-More progress in G1 WBs
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
8496
diff
changeset
|
32 #include "utilities/debug.hpp" |
7221 | 33 // Implementation of GraalStubAssembler |
34 | |
35 GraalStubAssembler::GraalStubAssembler(CodeBuffer* code, const char * name, int stub_id) : MacroAssembler(code) { | |
36 _name = name; | |
37 _must_gc_arguments = false; | |
38 _frame_size = no_frame_size; | |
39 _num_rt_args = 0; | |
40 _stub_id = stub_id; | |
41 } | |
42 | |
43 | |
44 void GraalStubAssembler::set_info(const char* name, bool must_gc_arguments) { | |
45 _name = name; | |
46 _must_gc_arguments = must_gc_arguments; | |
47 } | |
48 | |
49 | |
50 void GraalStubAssembler::set_frame_size(int size) { | |
51 if (_frame_size == no_frame_size) { | |
52 _frame_size = size; | |
53 } | |
54 assert(_frame_size == size, "can't change the frame size"); | |
55 } | |
56 | |
57 | |
58 void GraalStubAssembler::set_num_rt_args(int args) { | |
59 if (_num_rt_args == 0) { | |
60 _num_rt_args = args; | |
61 } | |
62 assert(_num_rt_args == args, "can't change the number of args"); | |
63 } | |
64 | |
65 // Implementation of GraalRuntime | |
66 | |
67 CodeBlob* GraalRuntime::_blobs[GraalRuntime::number_of_ids]; | |
68 const char *GraalRuntime::_blob_names[] = { | |
69 GRAAL_STUBS(STUB_NAME, LAST_STUB_NAME) | |
70 }; | |
71 | |
72 // Simple helper to see if the caller of a runtime stub which | |
73 // entered the VM has been deoptimized | |
74 | |
75 static bool caller_is_deopted() { | |
76 JavaThread* thread = JavaThread::current(); | |
77 RegisterMap reg_map(thread, false); | |
78 frame runtime_frame = thread->last_frame(); | |
79 frame caller_frame = runtime_frame.sender(®_map); | |
80 assert(caller_frame.is_compiled_frame(), "must be compiled"); | |
81 return caller_frame.is_deoptimized_frame(); | |
82 } | |
83 | |
84 // Stress deoptimization | |
85 static void deopt_caller() { | |
86 if ( !caller_is_deopted()) { | |
87 JavaThread* thread = JavaThread::current(); | |
88 RegisterMap reg_map(thread, false); | |
89 frame runtime_frame = thread->last_frame(); | |
90 frame caller_frame = runtime_frame.sender(®_map); | |
91 Deoptimization::deoptimize_frame(thread, caller_frame.id(), Deoptimization::Reason_constraint); | |
92 assert(caller_is_deopted(), "Must be deoptimized"); | |
93 } | |
94 } | |
95 | |
96 static bool setup_code_buffer(CodeBuffer* code) { | |
97 // Preinitialize the consts section to some large size: | |
98 int locs_buffer_size = 1 * (relocInfo::length_limit + sizeof(relocInfo)); | |
99 char* locs_buffer = NEW_RESOURCE_ARRAY(char, locs_buffer_size); | |
100 code->insts()->initialize_shared_locs((relocInfo*)locs_buffer, | |
101 locs_buffer_size / sizeof(relocInfo)); | |
102 | |
103 // Global stubs have neither constants nor local stubs | |
104 code->initialize_consts_size(0); | |
105 code->initialize_stubs_size(0); | |
106 | |
107 return true; | |
108 } | |
109 | |
110 void GraalRuntime::generate_blob_for(BufferBlob* buffer_blob, StubID id) { | |
111 assert(0 <= id && id < number_of_ids, "illegal stub id"); | |
112 ResourceMark rm; | |
113 // create code buffer for code storage | |
114 CodeBuffer code(buffer_blob); | |
115 | |
116 setup_code_buffer(&code); | |
117 | |
118 // create assembler for code generation | |
119 GraalStubAssembler* sasm = new GraalStubAssembler(&code, name_for(id), id); | |
120 // generate code for runtime stub | |
121 OopMapSet* oop_maps; | |
122 oop_maps = generate_code_for(id, sasm); | |
7226 | 123 assert(oop_maps == NULL || sasm->frame_size() != GraalStubAssembler::no_frame_size, |
7221 | 124 "if stub has an oop map it must have a valid frame size"); |
125 | |
126 #ifdef ASSERT | |
127 // Make sure that stubs that need oopmaps have them | |
128 switch (id) { | |
129 // These stubs don't need to have an oopmap | |
7911
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
130 case arithmetic_frem_id: |
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
131 case arithmetic_drem_id: |
7221 | 132 break; |
133 // All other stubs should have oopmaps | |
134 default: | |
135 assert(oop_maps != NULL, "must have an oopmap"); | |
136 } | |
137 #endif | |
138 | |
139 // align so printing shows nop's instead of random code at the end (SimpleStubs are aligned) | |
140 sasm->align(BytesPerWord); | |
141 // make sure all code is in code buffer | |
142 sasm->flush(); | |
143 // create blob - distinguish a few special cases | |
144 CodeBlob* blob = RuntimeStub::new_runtime_stub(name_for(id), | |
145 &code, | |
146 CodeOffsets::frame_never_safe, | |
147 sasm->frame_size(), | |
148 oop_maps, | |
149 sasm->must_gc_arguments()); | |
150 // install blob | |
151 assert(blob != NULL, "blob must exist"); | |
152 _blobs[id] = blob; | |
153 } | |
154 | |
155 | |
156 void GraalRuntime::initialize(BufferBlob* blob) { | |
157 // generate stubs | |
158 for (int id = 0; id < number_of_ids; id++) generate_blob_for(blob, (StubID)id); | |
159 // printing | |
160 #ifndef PRODUCT | |
7226 | 161 if (GraalPrintSimpleStubs) { |
7221 | 162 ResourceMark rm; |
163 for (int id = 0; id < number_of_ids; id++) { | |
164 _blobs[id]->print(); | |
165 if (_blobs[id]->oop_maps() != NULL) { | |
166 _blobs[id]->oop_maps()->print(); | |
167 } | |
168 } | |
169 } | |
170 #endif | |
171 } | |
172 | |
173 | |
174 CodeBlob* GraalRuntime::blob_for(StubID id) { | |
175 assert(0 <= id && id < number_of_ids, "illegal stub id"); | |
176 return _blobs[id]; | |
177 } | |
178 | |
179 | |
180 const char* GraalRuntime::name_for(StubID id) { | |
181 assert(0 <= id && id < number_of_ids, "illegal stub id"); | |
182 return _blob_names[id]; | |
183 } | |
184 | |
185 const char* GraalRuntime::name_for_address(address entry) { | |
186 for (int id = 0; id < number_of_ids; id++) { | |
187 if (entry == entry_for((StubID)id)) return name_for((StubID)id); | |
188 } | |
189 | |
190 #define FUNCTION_CASE(a, f) \ | |
191 if ((intptr_t)a == CAST_FROM_FN_PTR(intptr_t, f)) return #f | |
192 | |
193 FUNCTION_CASE(entry, os::javaTimeMillis); | |
194 FUNCTION_CASE(entry, os::javaTimeNanos); | |
195 FUNCTION_CASE(entry, SharedRuntime::OSR_migration_end); | |
196 FUNCTION_CASE(entry, SharedRuntime::d2f); | |
197 FUNCTION_CASE(entry, SharedRuntime::d2i); | |
198 FUNCTION_CASE(entry, SharedRuntime::d2l); | |
199 FUNCTION_CASE(entry, SharedRuntime::dcos); | |
200 FUNCTION_CASE(entry, SharedRuntime::dexp); | |
201 FUNCTION_CASE(entry, SharedRuntime::dlog); | |
202 FUNCTION_CASE(entry, SharedRuntime::dlog10); | |
203 FUNCTION_CASE(entry, SharedRuntime::dpow); | |
204 FUNCTION_CASE(entry, SharedRuntime::drem); | |
205 FUNCTION_CASE(entry, SharedRuntime::dsin); | |
206 FUNCTION_CASE(entry, SharedRuntime::dtan); | |
207 FUNCTION_CASE(entry, SharedRuntime::f2i); | |
208 FUNCTION_CASE(entry, SharedRuntime::f2l); | |
209 FUNCTION_CASE(entry, SharedRuntime::frem); | |
210 FUNCTION_CASE(entry, SharedRuntime::l2d); | |
211 FUNCTION_CASE(entry, SharedRuntime::l2f); | |
212 FUNCTION_CASE(entry, SharedRuntime::ldiv); | |
213 FUNCTION_CASE(entry, SharedRuntime::lmul); | |
214 FUNCTION_CASE(entry, SharedRuntime::lrem); | |
215 FUNCTION_CASE(entry, SharedRuntime::lrem); | |
216 FUNCTION_CASE(entry, SharedRuntime::dtrace_method_entry); | |
217 FUNCTION_CASE(entry, SharedRuntime::dtrace_method_exit); | |
218 #ifdef TRACE_HAVE_INTRINSICS | |
219 FUNCTION_CASE(entry, TRACE_TIME_METHOD); | |
220 #endif | |
221 | |
222 ShouldNotReachHere(); | |
223 return NULL; | |
224 | |
225 #undef FUNCTION_CASE | |
226 } | |
227 | |
228 | |
229 JRT_ENTRY(void, GraalRuntime::new_instance(JavaThread* thread, Klass* klass)) | |
230 assert(klass->is_klass(), "not a class"); | |
231 instanceKlassHandle h(thread, klass); | |
232 h->check_valid_for_instantiation(true, CHECK); | |
233 // make sure klass is initialized | |
234 h->initialize(CHECK); | |
235 // allocate instance and return via TLS | |
236 oop obj = h->allocate_instance(CHECK); | |
237 thread->set_vm_result(obj); | |
238 JRT_END | |
239 | |
240 JRT_ENTRY(void, GraalRuntime::new_array(JavaThread* thread, Klass* array_klass, jint length)) | |
241 // Note: no handle for klass needed since they are not used | |
242 // anymore after new_objArray() and no GC can happen before. | |
243 // (This may have to change if this code changes!) | |
244 assert(array_klass->is_klass(), "not a class"); | |
245 oop obj; | |
246 if (array_klass->oop_is_typeArray()) { | |
247 BasicType elt_type = TypeArrayKlass::cast(array_klass)->element_type(); | |
248 obj = oopFactory::new_typeArray(elt_type, length, CHECK); | |
249 } else { | |
250 Klass* elem_klass = ObjArrayKlass::cast(array_klass)->element_klass(); | |
251 obj = oopFactory::new_objArray(elem_klass, length, CHECK); | |
252 } | |
253 thread->set_vm_result(obj); | |
254 // This is pretty rare but this runtime patch is stressful to deoptimization | |
255 // if we deoptimize here so force a deopt to stress the path. | |
256 if (DeoptimizeALot) { | |
9338
0266549ff6e0
added support from compiled stubs to be installed as RuntimeStubs and to be able to directly call C/C++ runtime functions (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
9232
diff
changeset
|
257 static int deopts = 0; |
0266549ff6e0
added support from compiled stubs to be installed as RuntimeStubs and to be able to directly call C/C++ runtime functions (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
9232
diff
changeset
|
258 // Alternate between deoptimizing and raising an error (which will also cause a deopt) |
0266549ff6e0
added support from compiled stubs to be installed as RuntimeStubs and to be able to directly call C/C++ runtime functions (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
9232
diff
changeset
|
259 if (deopts++ % 2 == 0) { |
0266549ff6e0
added support from compiled stubs to be installed as RuntimeStubs and to be able to directly call C/C++ runtime functions (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
9232
diff
changeset
|
260 ResourceMark rm(THREAD); |
0266549ff6e0
added support from compiled stubs to be installed as RuntimeStubs and to be able to directly call C/C++ runtime functions (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
9232
diff
changeset
|
261 THROW(vmSymbols::java_lang_OutOfMemoryError()); |
0266549ff6e0
added support from compiled stubs to be installed as RuntimeStubs and to be able to directly call C/C++ runtime functions (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
9232
diff
changeset
|
262 } else { |
0266549ff6e0
added support from compiled stubs to be installed as RuntimeStubs and to be able to directly call C/C++ runtime functions (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
9232
diff
changeset
|
263 deopt_caller(); |
0266549ff6e0
added support from compiled stubs to be installed as RuntimeStubs and to be able to directly call C/C++ runtime functions (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
9232
diff
changeset
|
264 } |
7221 | 265 } |
9338
0266549ff6e0
added support from compiled stubs to be installed as RuntimeStubs and to be able to directly call C/C++ runtime functions (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
9232
diff
changeset
|
266 JRT_END |
7221 | 267 |
268 JRT_ENTRY(void, GraalRuntime::new_multi_array(JavaThread* thread, Klass* klass, int rank, jint* dims)) | |
269 assert(klass->is_klass(), "not a class"); | |
270 assert(rank >= 1, "rank must be nonzero"); | |
271 oop obj = ArrayKlass::cast(klass)->multi_allocate(rank, dims, CHECK); | |
272 thread->set_vm_result(obj); | |
273 JRT_END | |
274 | |
275 JRT_ENTRY(void, GraalRuntime::unimplemented_entry(JavaThread* thread, StubID id)) | |
276 tty->print_cr("GraalRuntime::entry_for(%d) returned unimplemented entry point", id); | |
277 JRT_END | |
278 | |
279 extern void vm_exit(int code); | |
280 | |
281 // Enter this method from compiled code handler below. This is where we transition | |
282 // to VM mode. This is done as a helper routine so that the method called directly | |
283 // from compiled code does not have to transition to VM. This allows the entry | |
284 // method to see if the nmethod that we have just looked up a handler for has | |
285 // been deoptimized while we were in the vm. This simplifies the assembly code | |
286 // cpu directories. | |
287 // | |
288 // We are entering here from exception stub (via the entry method below) | |
289 // If there is a compiled exception handler in this method, we will continue there; | |
290 // otherwise we will unwind the stack and continue at the caller of top frame method | |
291 // Note: we enter in Java using a special JRT wrapper. This wrapper allows us to | |
292 // control the area where we can allow a safepoint. After we exit the safepoint area we can | |
293 // check to see if the handler we are going to return is now in a nmethod that has | |
294 // been deoptimized. If that is the case we return the deopt blob | |
295 // unpack_with_exception entry instead. This makes life for the exception blob easier | |
296 // because making that same check and diverting is painful from assembly language. | |
297 JRT_ENTRY_NO_ASYNC(static address, exception_handler_for_pc_helper(JavaThread* thread, oopDesc* ex, address pc, nmethod*& nm)) | |
298 // Reset method handle flag. | |
299 thread->set_is_method_handle_return(false); | |
300 | |
301 Handle exception(thread, ex); | |
302 nm = CodeCache::find_nmethod(pc); | |
303 assert(nm != NULL, "this is not an nmethod"); | |
304 // Adjust the pc as needed/ | |
305 if (nm->is_deopt_pc(pc)) { | |
306 RegisterMap map(thread, false); | |
307 frame exception_frame = thread->last_frame().sender(&map); | |
308 // if the frame isn't deopted then pc must not correspond to the caller of last_frame | |
309 assert(exception_frame.is_deoptimized_frame(), "must be deopted"); | |
310 pc = exception_frame.pc(); | |
311 } | |
312 #ifdef ASSERT | |
313 assert(exception.not_null(), "NULL exceptions should be handled by throw_exception"); | |
314 assert(exception->is_oop(), "just checking"); | |
315 // Check that exception is a subclass of Throwable, otherwise we have a VerifyError | |
316 if (!(exception->is_a(SystemDictionary::Throwable_klass()))) { | |
317 if (ExitVMOnVerifyError) vm_exit(-1); | |
318 ShouldNotReachHere(); | |
319 } | |
320 #endif | |
321 | |
322 // Check the stack guard pages and reenable them if necessary and there is | |
323 // enough space on the stack to do so. Use fast exceptions only if the guard | |
324 // pages are enabled. | |
325 bool guard_pages_enabled = thread->stack_yellow_zone_enabled(); | |
326 if (!guard_pages_enabled) guard_pages_enabled = thread->reguard_stack(); | |
327 | |
328 if (JvmtiExport::can_post_on_exceptions()) { | |
329 // To ensure correct notification of exception catches and throws | |
330 // we have to deoptimize here. If we attempted to notify the | |
331 // catches and throws during this exception lookup it's possible | |
332 // we could deoptimize on the way out of the VM and end back in | |
333 // the interpreter at the throw site. This would result in double | |
334 // notifications since the interpreter would also notify about | |
335 // these same catches and throws as it unwound the frame. | |
336 | |
337 RegisterMap reg_map(thread); | |
338 frame stub_frame = thread->last_frame(); | |
339 frame caller_frame = stub_frame.sender(®_map); | |
340 | |
341 // We don't really want to deoptimize the nmethod itself since we | |
342 // can actually continue in the exception handler ourselves but I | |
343 // don't see an easy way to have the desired effect. | |
344 Deoptimization::deoptimize_frame(thread, caller_frame.id(), Deoptimization::Reason_constraint); | |
345 assert(caller_is_deopted(), "Must be deoptimized"); | |
346 | |
347 return SharedRuntime::deopt_blob()->unpack_with_exception_in_tls(); | |
348 } | |
349 | |
350 // ExceptionCache is used only for exceptions at call sites and not for implicit exceptions | |
351 if (guard_pages_enabled) { | |
352 address fast_continuation = nm->handler_for_exception_and_pc(exception, pc); | |
353 if (fast_continuation != NULL) { | |
354 // Set flag if return address is a method handle call site. | |
355 thread->set_is_method_handle_return(nm->is_method_handle_return(pc)); | |
356 return fast_continuation; | |
357 } | |
358 } | |
359 | |
360 // If the stack guard pages are enabled, check whether there is a handler in | |
361 // the current method. Otherwise (guard pages disabled), force an unwind and | |
362 // skip the exception cache update (i.e., just leave continuation==NULL). | |
363 address continuation = NULL; | |
364 if (guard_pages_enabled) { | |
365 | |
366 // New exception handling mechanism can support inlined methods | |
367 // with exception handlers since the mappings are from PC to PC | |
368 | |
369 // debugging support | |
370 // tracing | |
371 if (TraceExceptions) { | |
372 ttyLocker ttyl; | |
373 ResourceMark rm; | |
374 int offset = pc - nm->code_begin(); | |
375 tty->print_cr("Exception <%s> (0x%x) thrown in compiled method <%s> at PC " PTR_FORMAT " [" PTR_FORMAT "+%d] for thread 0x%x", | |
376 exception->print_value_string(), (address)exception(), nm->method()->print_value_string(), pc, nm->code_begin(), offset, thread); | |
377 } | |
378 // for AbortVMOnException flag | |
379 NOT_PRODUCT(Exceptions::debug_check_abort(exception)); | |
380 | |
381 // Clear out the exception oop and pc since looking up an | |
382 // exception handler can cause class loading, which might throw an | |
383 // exception and those fields are expected to be clear during | |
384 // normal bytecode execution. | |
385 thread->set_exception_oop(NULL); | |
386 thread->set_exception_pc(NULL); | |
387 | |
388 continuation = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, false, false); | |
389 // If an exception was thrown during exception dispatch, the exception oop may have changed | |
390 thread->set_exception_oop(exception()); | |
391 thread->set_exception_pc(pc); | |
392 | |
393 // the exception cache is used only by non-implicit exceptions | |
394 if (continuation != NULL && !SharedRuntime::deopt_blob()->contains(continuation)) { | |
395 nm->add_handler_for_exception_and_pc(exception, pc, continuation); | |
396 } | |
397 } | |
398 | |
399 // Set flag if return address is a method handle call site. | |
400 thread->set_is_method_handle_return(nm->is_method_handle_return(pc)); | |
401 | |
402 if (TraceExceptions) { | |
403 ttyLocker ttyl; | |
404 ResourceMark rm; | |
405 tty->print_cr("Thread " PTR_FORMAT " continuing at PC " PTR_FORMAT " for exception thrown at PC " PTR_FORMAT, | |
406 thread, continuation, pc); | |
407 } | |
408 | |
409 return continuation; | |
410 JRT_END | |
411 | |
412 // Enter this method from compiled code only if there is a Java exception handler | |
413 // in the method handling the exception. | |
414 // We are entering here from exception stub. We don't do a normal VM transition here. | |
415 // We do it in a helper. This is so we can check to see if the nmethod we have just | |
416 // searched for an exception handler has been deoptimized in the meantime. | |
417 address GraalRuntime::exception_handler_for_pc(JavaThread* thread) { | |
418 oop exception = thread->exception_oop(); | |
419 address pc = thread->exception_pc(); | |
420 // Still in Java mode | |
421 DEBUG_ONLY(ResetNoHandleMark rnhm); | |
422 nmethod* nm = NULL; | |
423 address continuation = NULL; | |
424 { | |
425 // Enter VM mode by calling the helper | |
426 ResetNoHandleMark rnhm; | |
427 continuation = exception_handler_for_pc_helper(thread, exception, pc, nm); | |
428 } | |
429 // Back in JAVA, use no oops DON'T safepoint | |
430 | |
431 // Now check to see if the nmethod we were called from is now deoptimized. | |
432 // If so we must return to the deopt blob and deoptimize the nmethod | |
433 if (nm != NULL && caller_is_deopted()) { | |
434 continuation = SharedRuntime::deopt_blob()->unpack_with_exception_in_tls(); | |
435 } | |
436 | |
437 assert(continuation != NULL, "no handler found"); | |
438 return continuation; | |
439 } | |
440 | |
7911
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
441 JRT_ENTRY(void, GraalRuntime::create_null_exception(JavaThread* thread)) |
7221 | 442 thread->set_vm_result(Exceptions::new_exception(thread, vmSymbols::java_lang_NullPointerException(), NULL)()); |
443 JRT_END | |
444 | |
7911
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
445 JRT_ENTRY(void, GraalRuntime::create_out_of_bounds_exception(JavaThread* thread, jint index)) |
7221 | 446 char message[jintAsStringSize]; |
447 sprintf(message, "%d", index); | |
448 thread->set_vm_result(Exceptions::new_exception(thread, vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), message)()); | |
449 JRT_END | |
450 | |
7911
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
451 JRT_ENTRY_NO_ASYNC(void, GraalRuntime::monitorenter(JavaThread* thread, oopDesc* obj, BasicLock* lock)) |
7221 | 452 if (TraceGraal >= 3) { |
453 char type[O_BUFLEN]; | |
454 obj->klass()->name()->as_C_string(type, O_BUFLEN); | |
455 markOop mark = obj->mark(); | |
456 tty->print_cr("%s: entered locking slow case with obj=" INTPTR_FORMAT ", type=%s, mark=" INTPTR_FORMAT ", lock=" INTPTR_FORMAT, thread->name(), obj, type, mark, lock); | |
457 tty->flush(); | |
458 } | |
459 #ifdef ASSERT | |
460 if (PrintBiasedLockingStatistics) { | |
461 Atomic::inc(BiasedLocking::slow_path_entry_count_addr()); | |
462 } | |
463 #endif | |
464 Handle h_obj(thread, obj); | |
465 assert(h_obj()->is_oop(), "must be NULL or an object"); | |
466 if (UseBiasedLocking) { | |
467 // Retry fast entry if bias is revoked to avoid unnecessary inflation | |
468 ObjectSynchronizer::fast_enter(h_obj, lock, true, CHECK); | |
469 } else { | |
7226 | 470 if (GraalUseFastLocking) { |
7221 | 471 // When using fast locking, the compiled code has already tried the fast case |
472 ObjectSynchronizer::slow_enter(h_obj, lock, THREAD); | |
473 } else { | |
474 ObjectSynchronizer::fast_enter(h_obj, lock, false, THREAD); | |
475 } | |
476 } | |
477 if (TraceGraal >= 3) { | |
478 tty->print_cr("%s: exiting locking slow with obj=" INTPTR_FORMAT, thread->name(), obj); | |
479 } | |
480 JRT_END | |
481 | |
8506 | 482 JRT_LEAF(void, GraalRuntime::wb_pre_call(JavaThread* thread, oopDesc* obj)) |
8502
ff4fa8b0516e
-Create push patch
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
8501
diff
changeset
|
483 thread->satb_mark_queue().enqueue(obj); |
8490
1567c6cc6561
Towards porting G1 WBs
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
8489
diff
changeset
|
484 JRT_END |
1567c6cc6561
Towards porting G1 WBs
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
8489
diff
changeset
|
485 |
8506 | 486 JRT_LEAF(void, GraalRuntime::wb_post_call(JavaThread* thread, oopDesc* obj, void* card_addr)) |
8495
9131c075be7b
-More porting to G1 WBs
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
8492
diff
changeset
|
487 thread->dirty_card_queue().enqueue(card_addr); |
8489
92d21814cf7b
-Implement WB primitive stub call for G1's slow path later
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
7735
diff
changeset
|
488 JRT_END |
7221 | 489 |
7911
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
490 JRT_LEAF(void, GraalRuntime::monitorexit(JavaThread* thread, oopDesc* obj, BasicLock* lock)) |
7221 | 491 assert(thread == JavaThread::current(), "threads must correspond"); |
492 assert(thread->last_Java_sp(), "last_Java_sp must be set"); | |
493 // monitorexit is non-blocking (leaf routine) => no exceptions can be thrown | |
494 EXCEPTION_MARK; | |
495 | |
496 #ifdef DEBUG | |
497 if (!obj->is_oop()) { | |
498 ResetNoHandleMark rhm; | |
499 nmethod* method = thread->last_frame().cb()->as_nmethod_or_null(); | |
500 if (method != NULL) { | |
501 tty->print_cr("ERROR in monitorexit in method %s wrong obj " INTPTR_FORMAT, method->name(), obj); | |
502 } | |
503 thread->print_stack_on(tty); | |
504 assert(false, "invalid lock object pointer dected"); | |
505 } | |
506 #endif | |
507 | |
7226 | 508 if (GraalUseFastLocking) { |
7221 | 509 // When using fast locking, the compiled code has already tried the fast case |
510 ObjectSynchronizer::slow_exit(obj, lock, THREAD); | |
511 } else { | |
512 ObjectSynchronizer::fast_exit(obj, lock, THREAD); | |
513 } | |
514 if (TraceGraal >= 3) { | |
515 char type[O_BUFLEN]; | |
516 obj->klass()->name()->as_C_string(type, O_BUFLEN); | |
517 tty->print_cr("%s: exited locking slow case with obj=" INTPTR_FORMAT ", type=%s, mark=" INTPTR_FORMAT ", lock=" INTPTR_FORMAT, thread->name(), obj, type, obj->mark(), lock); | |
518 tty->flush(); | |
519 } | |
520 JRT_END | |
521 | |
7911
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
522 JRT_ENTRY(void, GraalRuntime::log_object(JavaThread* thread, oop obj, jint flags)) |
7221 | 523 bool string = mask_bits_are_true(flags, LOG_OBJECT_STRING); |
524 bool address = mask_bits_are_true(flags, LOG_OBJECT_ADDRESS); | |
525 bool newline = mask_bits_are_true(flags, LOG_OBJECT_NEWLINE); | |
526 if (!string) { | |
527 if (!address && obj->is_oop_or_null(true)) { | |
528 char buf[O_BUFLEN]; | |
529 tty->print("%s@%p", obj->klass()->name()->as_C_string(buf, O_BUFLEN), obj); | |
530 } else { | |
531 tty->print("%p", obj); | |
532 } | |
533 } else { | |
534 ResourceMark rm; | |
535 assert(obj != NULL && java_lang_String::is_instance(obj), "must be"); | |
536 char *buf = java_lang_String::as_utf8_string(obj); | |
537 tty->print(buf); | |
538 } | |
539 if (newline) { | |
540 tty->cr(); | |
541 } | |
542 JRT_END | |
543 | |
7911
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
544 JRT_ENTRY(void, GraalRuntime::vm_error(JavaThread* thread, oop where, oop format, jlong value)) |
7221 | 545 ResourceMark rm; |
546 assert(where == NULL || java_lang_String::is_instance(where), "must be"); | |
547 const char *error_msg = where == NULL ? "<internal Graal error>" : java_lang_String::as_utf8_string(where); | |
548 char *detail_msg = NULL; | |
549 if (format != NULL) { | |
550 const char* buf = java_lang_String::as_utf8_string(format); | |
551 size_t detail_msg_length = strlen(buf) * 2; | |
552 detail_msg = (char *) NEW_RESOURCE_ARRAY(u_char, detail_msg_length); | |
553 jio_snprintf(detail_msg, detail_msg_length, buf, value); | |
554 } | |
555 report_vm_error(__FILE__, __LINE__, error_msg, detail_msg); | |
556 JRT_END | |
557 | |
8506 | 558 |
559 JRT_LEAF(void, GraalRuntime::log_printf(JavaThread* thread, oop format, jlong v1, jlong v2, jlong v3)) | |
7221 | 560 ResourceMark rm; |
561 assert(format != NULL && java_lang_String::is_instance(format), "must be"); | |
562 char *buf = java_lang_String::as_utf8_string(format); | |
7235
a6bd253a770f
expanded LOG_PRINTF stub to handle up to 3 arguments in addition to the format string
Doug Simon <doug.simon@oracle.com>
parents:
7226
diff
changeset
|
563 tty->print(buf, v1, v2, v3); |
7221 | 564 JRT_END |
565 | |
9573
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
566 static void decipher(jlong v, bool ignoreZero) { |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
567 if (v != 0 || !ignoreZero) { |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
568 void* p = (void *)(address) v; |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
569 CodeBlob* cb = CodeCache::find_blob(p); |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
570 if (cb) { |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
571 if (cb->is_nmethod()) { |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
572 char buf[O_BUFLEN]; |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
573 tty->print("%s [%p+%d]", cb->as_nmethod_or_null()->method()->name_and_sig_as_C_string(buf, O_BUFLEN), cb->code_begin(), (address)v - cb->code_begin()); |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
574 return; |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
575 } |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
576 cb->print_value_on(tty); |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
577 return; |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
578 } |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
579 if (Universe::heap()->is_in(p)) { |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
580 oop obj = oop(p); |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
581 obj->print_value_on(tty); |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
582 return; |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
583 } |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
584 tty->print("%p [long: %d, double %f, char %c]", v, v, v, v); |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
585 } |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
586 } |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
587 |
9471
5fa54bf57f8c
replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
9457
diff
changeset
|
588 JRT_LEAF(void, GraalRuntime::vm_message(jboolean vmError, jlong format, jlong v1, jlong v2, jlong v3)) |
9232
bb2447c64055
strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
8506
diff
changeset
|
589 ResourceMark rm; |
bb2447c64055
strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
8506
diff
changeset
|
590 char *buf = (char*) (address) format; |
9471
5fa54bf57f8c
replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
9457
diff
changeset
|
591 if (vmError) { |
9573
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
592 if (buf != NULL) { |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
593 fatal(err_msg(buf, v1, v2, v3)); |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
594 } else { |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
595 fatal("<anonymous error>"); |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
596 } |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
597 } else if (buf != NULL) { |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
598 tty->print(buf, v1, v2, v3); |
9471
5fa54bf57f8c
replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
9457
diff
changeset
|
599 } else { |
9573
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
600 assert(v2 == 0, "v2 != 0"); |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
601 assert(v3 == 0, "v3 != 0"); |
a79e8020ad4b
added Stub.decipher() to print information about values in stubs
Doug Simon <doug.simon@oracle.com>
parents:
9565
diff
changeset
|
602 decipher(v1, false); |
9471
5fa54bf57f8c
replaced exception_handler_nofpu assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
9457
diff
changeset
|
603 } |
9232
bb2447c64055
strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
8506
diff
changeset
|
604 JRT_END |
bb2447c64055
strings used in compiled stubs are lowered to malloc'ed C strings so that there are no embedded oops (for the strings) in the resulting installed code
Doug Simon <doug.simon@oracle.com>
parents:
8506
diff
changeset
|
605 |
7911
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
606 JRT_ENTRY(void, GraalRuntime::log_primitive(JavaThread* thread, jchar typeChar, jlong value, jboolean newline)) |
7221 | 607 union { |
608 jlong l; | |
609 jdouble d; | |
610 jfloat f; | |
611 } uu; | |
612 uu.l = value; | |
613 switch (typeChar) { | |
614 case 'z': tty->print(value == 0 ? "false" : "true"); break; | |
615 case 'b': tty->print("%d", (jbyte) value); break; | |
616 case 'c': tty->print("%c", (jchar) value); break; | |
617 case 's': tty->print("%d", (jshort) value); break; | |
618 case 'i': tty->print("%d", (jint) value); break; | |
619 case 'f': tty->print("%f", uu.f); break; | |
620 case 'j': tty->print(INT64_FORMAT, value); break; | |
621 case 'd': tty->print("%lf", uu.d); break; | |
622 default: assert(false, "unknown typeChar"); break; | |
623 } | |
624 if (newline) { | |
625 tty->cr(); | |
626 } | |
627 JRT_END | |
628 | |
7911
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
629 JRT_ENTRY(jint, GraalRuntime::identity_hash_code(JavaThread* thread, oop obj)) |
7221 | 630 return (jint) obj->identity_hash(); |
631 JRT_END | |
632 | |
7911
983f7bdb85ff
removed redundant graal_ prefix from Graal specific functions and variable in native code
Doug Simon <doug.simon@oracle.com>
parents:
7735
diff
changeset
|
633 JRT_ENTRY(jboolean, GraalRuntime::thread_is_interrupted(JavaThread* thread, oop receiver, jboolean clear_interrupted)) |
7220
fcae6d960acd
added more compiler intrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents:
7216
diff
changeset
|
634 // Ensure that the C++ Thread and OSThread structures aren't freed before we operate |
fcae6d960acd
added more compiler intrinsics
Christian Haeubl <haeubl@ssw.jku.at>
parents:
7216
diff
changeset
|
635 Handle receiverHandle(thread, receiver); |
7386
707e9cca11de
fixed HotSpot windows build
Christian Haeubl <haeubl@ssw.jku.at>
parents:
7235
diff
changeset
|
636 MutexLockerEx ml(thread->threadObj() == receiver ? NULL : Threads_lock); |
707e9cca11de
fixed HotSpot windows build
Christian Haeubl <haeubl@ssw.jku.at>
parents:
7235
diff
changeset
|
637 JavaThread* receiverThread = java_lang_Thread::thread(receiverHandle()); |
707e9cca11de
fixed HotSpot windows build
Christian Haeubl <haeubl@ssw.jku.at>
parents:
7235
diff
changeset
|
638 return (jint) Thread::is_interrupted(receiverThread, clear_interrupted != 0); |
7221 | 639 JRT_END |
640 | |
641 // JVM_InitializeGraalRuntime | |
642 JVM_ENTRY(jobject, JVM_InitializeGraalRuntime(JNIEnv *env, jclass graalclass)) | |
643 return VMToCompiler::graalRuntimePermObject(); | |
644 JVM_END |