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