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