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