Tue, 19 Oct 2010 16:14:34 -0700
6968367: can_post_on_exceptions is still using VM_DeoptimizeFrame in some places
Reviewed-by: kvn, twisti
1 /*
2 * Copyright (c) 1999, 2010, 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 */
25 #include "incls/_precompiled.incl"
26 #include "incls/_c1_Runtime1.cpp.incl"
29 // Implementation of StubAssembler
31 StubAssembler::StubAssembler(CodeBuffer* code, const char * name, int stub_id) : C1_MacroAssembler(code) {
32 _name = name;
33 _must_gc_arguments = false;
34 _frame_size = no_frame_size;
35 _num_rt_args = 0;
36 _stub_id = stub_id;
37 }
40 void StubAssembler::set_info(const char* name, bool must_gc_arguments) {
41 _name = name;
42 _must_gc_arguments = must_gc_arguments;
43 }
46 void StubAssembler::set_frame_size(int size) {
47 if (_frame_size == no_frame_size) {
48 _frame_size = size;
49 }
50 assert(_frame_size == size, "can't change the frame size");
51 }
54 void StubAssembler::set_num_rt_args(int args) {
55 if (_num_rt_args == 0) {
56 _num_rt_args = args;
57 }
58 assert(_num_rt_args == args, "can't change the number of args");
59 }
61 // Implementation of Runtime1
63 CodeBlob* Runtime1::_blobs[Runtime1::number_of_ids];
64 const char *Runtime1::_blob_names[] = {
65 RUNTIME1_STUBS(STUB_NAME, LAST_STUB_NAME)
66 };
68 #ifndef PRODUCT
69 // statistics
70 int Runtime1::_generic_arraycopy_cnt = 0;
71 int Runtime1::_primitive_arraycopy_cnt = 0;
72 int Runtime1::_oop_arraycopy_cnt = 0;
73 int Runtime1::_arraycopy_slowcase_cnt = 0;
74 int Runtime1::_new_type_array_slowcase_cnt = 0;
75 int Runtime1::_new_object_array_slowcase_cnt = 0;
76 int Runtime1::_new_instance_slowcase_cnt = 0;
77 int Runtime1::_new_multi_array_slowcase_cnt = 0;
78 int Runtime1::_monitorenter_slowcase_cnt = 0;
79 int Runtime1::_monitorexit_slowcase_cnt = 0;
80 int Runtime1::_patch_code_slowcase_cnt = 0;
81 int Runtime1::_throw_range_check_exception_count = 0;
82 int Runtime1::_throw_index_exception_count = 0;
83 int Runtime1::_throw_div0_exception_count = 0;
84 int Runtime1::_throw_null_pointer_exception_count = 0;
85 int Runtime1::_throw_class_cast_exception_count = 0;
86 int Runtime1::_throw_incompatible_class_change_error_count = 0;
87 int Runtime1::_throw_array_store_exception_count = 0;
88 int Runtime1::_throw_count = 0;
89 #endif
91 // Simple helper to see if the caller of a runtime stub which
92 // entered the VM has been deoptimized
94 static bool caller_is_deopted() {
95 JavaThread* thread = JavaThread::current();
96 RegisterMap reg_map(thread, false);
97 frame runtime_frame = thread->last_frame();
98 frame caller_frame = runtime_frame.sender(®_map);
99 assert(caller_frame.is_compiled_frame(), "must be compiled");
100 return caller_frame.is_deoptimized_frame();
101 }
103 // Stress deoptimization
104 static void deopt_caller() {
105 if ( !caller_is_deopted()) {
106 JavaThread* thread = JavaThread::current();
107 RegisterMap reg_map(thread, false);
108 frame runtime_frame = thread->last_frame();
109 frame caller_frame = runtime_frame.sender(®_map);
110 Deoptimization::deoptimize_frame(thread, caller_frame.id());
111 assert(caller_is_deopted(), "Must be deoptimized");
112 }
113 }
116 void Runtime1::generate_blob_for(BufferBlob* buffer_blob, StubID id) {
117 assert(0 <= id && id < number_of_ids, "illegal stub id");
118 ResourceMark rm;
119 // create code buffer for code storage
120 CodeBuffer code(buffer_blob);
122 Compilation::setup_code_buffer(&code, 0);
124 // create assembler for code generation
125 StubAssembler* sasm = new StubAssembler(&code, name_for(id), id);
126 // generate code for runtime stub
127 OopMapSet* oop_maps;
128 oop_maps = generate_code_for(id, sasm);
129 assert(oop_maps == NULL || sasm->frame_size() != no_frame_size,
130 "if stub has an oop map it must have a valid frame size");
132 #ifdef ASSERT
133 // Make sure that stubs that need oopmaps have them
134 switch (id) {
135 // These stubs don't need to have an oopmap
136 case dtrace_object_alloc_id:
137 case g1_pre_barrier_slow_id:
138 case g1_post_barrier_slow_id:
139 case slow_subtype_check_id:
140 case fpu2long_stub_id:
141 case unwind_exception_id:
142 case counter_overflow_id:
143 #if defined(SPARC) || defined(PPC)
144 case handle_exception_nofpu_id: // Unused on sparc
145 #endif
146 break;
148 // All other stubs should have oopmaps
149 default:
150 assert(oop_maps != NULL, "must have an oopmap");
151 }
152 #endif
154 // align so printing shows nop's instead of random code at the end (SimpleStubs are aligned)
155 sasm->align(BytesPerWord);
156 // make sure all code is in code buffer
157 sasm->flush();
158 // create blob - distinguish a few special cases
159 CodeBlob* blob = RuntimeStub::new_runtime_stub(name_for(id),
160 &code,
161 CodeOffsets::frame_never_safe,
162 sasm->frame_size(),
163 oop_maps,
164 sasm->must_gc_arguments());
165 // install blob
166 assert(blob != NULL, "blob must exist");
167 _blobs[id] = blob;
168 }
171 void Runtime1::initialize(BufferBlob* blob) {
172 // platform-dependent initialization
173 initialize_pd();
174 // generate stubs
175 for (int id = 0; id < number_of_ids; id++) generate_blob_for(blob, (StubID)id);
176 // printing
177 #ifndef PRODUCT
178 if (PrintSimpleStubs) {
179 ResourceMark rm;
180 for (int id = 0; id < number_of_ids; id++) {
181 _blobs[id]->print();
182 if (_blobs[id]->oop_maps() != NULL) {
183 _blobs[id]->oop_maps()->print();
184 }
185 }
186 }
187 #endif
188 }
191 CodeBlob* Runtime1::blob_for(StubID id) {
192 assert(0 <= id && id < number_of_ids, "illegal stub id");
193 return _blobs[id];
194 }
197 const char* Runtime1::name_for(StubID id) {
198 assert(0 <= id && id < number_of_ids, "illegal stub id");
199 return _blob_names[id];
200 }
202 const char* Runtime1::name_for_address(address entry) {
203 for (int id = 0; id < number_of_ids; id++) {
204 if (entry == entry_for((StubID)id)) return name_for((StubID)id);
205 }
207 #define FUNCTION_CASE(a, f) \
208 if ((intptr_t)a == CAST_FROM_FN_PTR(intptr_t, f)) return #f
210 FUNCTION_CASE(entry, os::javaTimeMillis);
211 FUNCTION_CASE(entry, os::javaTimeNanos);
212 FUNCTION_CASE(entry, SharedRuntime::OSR_migration_end);
213 FUNCTION_CASE(entry, SharedRuntime::d2f);
214 FUNCTION_CASE(entry, SharedRuntime::d2i);
215 FUNCTION_CASE(entry, SharedRuntime::d2l);
216 FUNCTION_CASE(entry, SharedRuntime::dcos);
217 FUNCTION_CASE(entry, SharedRuntime::dexp);
218 FUNCTION_CASE(entry, SharedRuntime::dlog);
219 FUNCTION_CASE(entry, SharedRuntime::dlog10);
220 FUNCTION_CASE(entry, SharedRuntime::dpow);
221 FUNCTION_CASE(entry, SharedRuntime::drem);
222 FUNCTION_CASE(entry, SharedRuntime::dsin);
223 FUNCTION_CASE(entry, SharedRuntime::dtan);
224 FUNCTION_CASE(entry, SharedRuntime::f2i);
225 FUNCTION_CASE(entry, SharedRuntime::f2l);
226 FUNCTION_CASE(entry, SharedRuntime::frem);
227 FUNCTION_CASE(entry, SharedRuntime::l2d);
228 FUNCTION_CASE(entry, SharedRuntime::l2f);
229 FUNCTION_CASE(entry, SharedRuntime::ldiv);
230 FUNCTION_CASE(entry, SharedRuntime::lmul);
231 FUNCTION_CASE(entry, SharedRuntime::lrem);
232 FUNCTION_CASE(entry, SharedRuntime::lrem);
233 FUNCTION_CASE(entry, SharedRuntime::dtrace_method_entry);
234 FUNCTION_CASE(entry, SharedRuntime::dtrace_method_exit);
235 FUNCTION_CASE(entry, trace_block_entry);
237 #undef FUNCTION_CASE
239 // Soft float adds more runtime names.
240 return pd_name_for_address(entry);
241 }
244 JRT_ENTRY(void, Runtime1::new_instance(JavaThread* thread, klassOopDesc* klass))
245 NOT_PRODUCT(_new_instance_slowcase_cnt++;)
247 assert(oop(klass)->is_klass(), "not a class");
248 instanceKlassHandle h(thread, klass);
249 h->check_valid_for_instantiation(true, CHECK);
250 // make sure klass is initialized
251 h->initialize(CHECK);
252 // allocate instance and return via TLS
253 oop obj = h->allocate_instance(CHECK);
254 thread->set_vm_result(obj);
255 JRT_END
258 JRT_ENTRY(void, Runtime1::new_type_array(JavaThread* thread, klassOopDesc* klass, jint length))
259 NOT_PRODUCT(_new_type_array_slowcase_cnt++;)
260 // Note: no handle for klass needed since they are not used
261 // anymore after new_typeArray() and no GC can happen before.
262 // (This may have to change if this code changes!)
263 assert(oop(klass)->is_klass(), "not a class");
264 BasicType elt_type = typeArrayKlass::cast(klass)->element_type();
265 oop obj = oopFactory::new_typeArray(elt_type, length, CHECK);
266 thread->set_vm_result(obj);
267 // This is pretty rare but this runtime patch is stressful to deoptimization
268 // if we deoptimize here so force a deopt to stress the path.
269 if (DeoptimizeALot) {
270 deopt_caller();
271 }
273 JRT_END
276 JRT_ENTRY(void, Runtime1::new_object_array(JavaThread* thread, klassOopDesc* array_klass, jint length))
277 NOT_PRODUCT(_new_object_array_slowcase_cnt++;)
279 // Note: no handle for klass needed since they are not used
280 // anymore after new_objArray() and no GC can happen before.
281 // (This may have to change if this code changes!)
282 assert(oop(array_klass)->is_klass(), "not a class");
283 klassOop elem_klass = objArrayKlass::cast(array_klass)->element_klass();
284 objArrayOop obj = oopFactory::new_objArray(elem_klass, length, CHECK);
285 thread->set_vm_result(obj);
286 // This is pretty rare but this runtime patch is stressful to deoptimization
287 // if we deoptimize here so force a deopt to stress the path.
288 if (DeoptimizeALot) {
289 deopt_caller();
290 }
291 JRT_END
294 JRT_ENTRY(void, Runtime1::new_multi_array(JavaThread* thread, klassOopDesc* klass, int rank, jint* dims))
295 NOT_PRODUCT(_new_multi_array_slowcase_cnt++;)
297 assert(oop(klass)->is_klass(), "not a class");
298 assert(rank >= 1, "rank must be nonzero");
299 oop obj = arrayKlass::cast(klass)->multi_allocate(rank, dims, CHECK);
300 thread->set_vm_result(obj);
301 JRT_END
304 JRT_ENTRY(void, Runtime1::unimplemented_entry(JavaThread* thread, StubID id))
305 tty->print_cr("Runtime1::entry_for(%d) returned unimplemented entry point", id);
306 JRT_END
309 JRT_ENTRY(void, Runtime1::throw_array_store_exception(JavaThread* thread))
310 THROW(vmSymbolHandles::java_lang_ArrayStoreException());
311 JRT_END
314 JRT_ENTRY(void, Runtime1::post_jvmti_exception_throw(JavaThread* thread))
315 if (JvmtiExport::can_post_on_exceptions()) {
316 vframeStream vfst(thread, true);
317 address bcp = vfst.method()->bcp_from(vfst.bci());
318 JvmtiExport::post_exception_throw(thread, vfst.method(), bcp, thread->exception_oop());
319 }
320 JRT_END
322 // This is a helper to allow us to safepoint but allow the outer entry
323 // to be safepoint free if we need to do an osr
324 static nmethod* counter_overflow_helper(JavaThread* THREAD, int branch_bci, methodOopDesc* m) {
325 nmethod* osr_nm = NULL;
326 methodHandle method(THREAD, m);
328 RegisterMap map(THREAD, false);
329 frame fr = THREAD->last_frame().sender(&map);
330 nmethod* nm = (nmethod*) fr.cb();
331 assert(nm!= NULL && nm->is_nmethod(), "Sanity check");
332 methodHandle enclosing_method(THREAD, nm->method());
334 CompLevel level = (CompLevel)nm->comp_level();
335 int bci = InvocationEntryBci;
336 if (branch_bci != InvocationEntryBci) {
337 // Compute desination bci
338 address pc = method()->code_base() + branch_bci;
339 Bytecodes::Code branch = Bytecodes::code_at(pc, method());
340 int offset = 0;
341 switch (branch) {
342 case Bytecodes::_if_icmplt: case Bytecodes::_iflt:
343 case Bytecodes::_if_icmpgt: case Bytecodes::_ifgt:
344 case Bytecodes::_if_icmple: case Bytecodes::_ifle:
345 case Bytecodes::_if_icmpge: case Bytecodes::_ifge:
346 case Bytecodes::_if_icmpeq: case Bytecodes::_if_acmpeq: case Bytecodes::_ifeq:
347 case Bytecodes::_if_icmpne: case Bytecodes::_if_acmpne: case Bytecodes::_ifne:
348 case Bytecodes::_ifnull: case Bytecodes::_ifnonnull: case Bytecodes::_goto:
349 offset = (int16_t)Bytes::get_Java_u2(pc + 1);
350 break;
351 case Bytecodes::_goto_w:
352 offset = Bytes::get_Java_u4(pc + 1);
353 break;
354 default: ;
355 }
356 bci = branch_bci + offset;
357 }
359 osr_nm = CompilationPolicy::policy()->event(enclosing_method, method, branch_bci, bci, level, THREAD);
360 return osr_nm;
361 }
363 JRT_BLOCK_ENTRY(address, Runtime1::counter_overflow(JavaThread* thread, int bci, methodOopDesc* method))
364 nmethod* osr_nm;
365 JRT_BLOCK
366 osr_nm = counter_overflow_helper(thread, bci, method);
367 if (osr_nm != NULL) {
368 RegisterMap map(thread, false);
369 frame fr = thread->last_frame().sender(&map);
370 Deoptimization::deoptimize_frame(thread, fr.id());
371 }
372 JRT_BLOCK_END
373 return NULL;
374 JRT_END
376 extern void vm_exit(int code);
378 // Enter this method from compiled code handler below. This is where we transition
379 // to VM mode. This is done as a helper routine so that the method called directly
380 // from compiled code does not have to transition to VM. This allows the entry
381 // method to see if the nmethod that we have just looked up a handler for has
382 // been deoptimized while we were in the vm. This simplifies the assembly code
383 // cpu directories.
384 //
385 // We are entering here from exception stub (via the entry method below)
386 // If there is a compiled exception handler in this method, we will continue there;
387 // otherwise we will unwind the stack and continue at the caller of top frame method
388 // Note: we enter in Java using a special JRT wrapper. This wrapper allows us to
389 // control the area where we can allow a safepoint. After we exit the safepoint area we can
390 // check to see if the handler we are going to return is now in a nmethod that has
391 // been deoptimized. If that is the case we return the deopt blob
392 // unpack_with_exception entry instead. This makes life for the exception blob easier
393 // because making that same check and diverting is painful from assembly language.
394 //
397 JRT_ENTRY_NO_ASYNC(static address, exception_handler_for_pc_helper(JavaThread* thread, oopDesc* ex, address pc, nmethod*& nm))
399 Handle exception(thread, ex);
400 nm = CodeCache::find_nmethod(pc);
401 assert(nm != NULL, "this is not an nmethod");
402 // Adjust the pc as needed/
403 if (nm->is_deopt_pc(pc)) {
404 RegisterMap map(thread, false);
405 frame exception_frame = thread->last_frame().sender(&map);
406 // if the frame isn't deopted then pc must not correspond to the caller of last_frame
407 assert(exception_frame.is_deoptimized_frame(), "must be deopted");
408 pc = exception_frame.pc();
409 }
410 #ifdef ASSERT
411 assert(exception.not_null(), "NULL exceptions should be handled by throw_exception");
412 assert(exception->is_oop(), "just checking");
413 // Check that exception is a subclass of Throwable, otherwise we have a VerifyError
414 if (!(exception->is_a(SystemDictionary::Throwable_klass()))) {
415 if (ExitVMOnVerifyError) vm_exit(-1);
416 ShouldNotReachHere();
417 }
418 #endif
420 // Check the stack guard pages and reenable them if necessary and there is
421 // enough space on the stack to do so. Use fast exceptions only if the guard
422 // pages are enabled.
423 bool guard_pages_enabled = thread->stack_yellow_zone_enabled();
424 if (!guard_pages_enabled) guard_pages_enabled = thread->reguard_stack();
426 if (JvmtiExport::can_post_on_exceptions()) {
427 // To ensure correct notification of exception catches and throws
428 // we have to deoptimize here. If we attempted to notify the
429 // catches and throws during this exception lookup it's possible
430 // we could deoptimize on the way out of the VM and end back in
431 // the interpreter at the throw site. This would result in double
432 // notifications since the interpreter would also notify about
433 // these same catches and throws as it unwound the frame.
435 RegisterMap reg_map(thread);
436 frame stub_frame = thread->last_frame();
437 frame caller_frame = stub_frame.sender(®_map);
439 // We don't really want to deoptimize the nmethod itself since we
440 // can actually continue in the exception handler ourselves but I
441 // don't see an easy way to have the desired effect.
442 Deoptimization::deoptimize_frame(thread, caller_frame.id());
443 assert(caller_is_deopted(), "Must be deoptimized");
445 return SharedRuntime::deopt_blob()->unpack_with_exception_in_tls();
446 }
448 // ExceptionCache is used only for exceptions at call and not for implicit exceptions
449 if (guard_pages_enabled) {
450 address fast_continuation = nm->handler_for_exception_and_pc(exception, pc);
451 if (fast_continuation != NULL) {
452 if (fast_continuation == ExceptionCache::unwind_handler()) fast_continuation = NULL;
453 return fast_continuation;
454 }
455 }
457 // If the stack guard pages are enabled, check whether there is a handler in
458 // the current method. Otherwise (guard pages disabled), force an unwind and
459 // skip the exception cache update (i.e., just leave continuation==NULL).
460 address continuation = NULL;
461 if (guard_pages_enabled) {
463 // New exception handling mechanism can support inlined methods
464 // with exception handlers since the mappings are from PC to PC
466 // debugging support
467 // tracing
468 if (TraceExceptions) {
469 ttyLocker ttyl;
470 ResourceMark rm;
471 tty->print_cr("Exception <%s> (0x%x) thrown in compiled method <%s> at PC " PTR_FORMAT " for thread 0x%x",
472 exception->print_value_string(), (address)exception(), nm->method()->print_value_string(), pc, thread);
473 }
474 // for AbortVMOnException flag
475 NOT_PRODUCT(Exceptions::debug_check_abort(exception));
477 // Clear out the exception oop and pc since looking up an
478 // exception handler can cause class loading, which might throw an
479 // exception and those fields are expected to be clear during
480 // normal bytecode execution.
481 thread->set_exception_oop(NULL);
482 thread->set_exception_pc(NULL);
484 continuation = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, false, false);
485 // If an exception was thrown during exception dispatch, the exception oop may have changed
486 thread->set_exception_oop(exception());
487 thread->set_exception_pc(pc);
489 // the exception cache is used only by non-implicit exceptions
490 if (continuation == NULL) {
491 nm->add_handler_for_exception_and_pc(exception, pc, ExceptionCache::unwind_handler());
492 } else {
493 nm->add_handler_for_exception_and_pc(exception, pc, continuation);
494 }
495 }
497 thread->set_vm_result(exception());
499 if (TraceExceptions) {
500 ttyLocker ttyl;
501 ResourceMark rm;
502 tty->print_cr("Thread " PTR_FORMAT " continuing at PC " PTR_FORMAT " for exception thrown at PC " PTR_FORMAT,
503 thread, continuation, pc);
504 }
506 return continuation;
507 JRT_END
509 // Enter this method from compiled code only if there is a Java exception handler
510 // in the method handling the exception
511 // We are entering here from exception stub. We don't do a normal VM transition here.
512 // We do it in a helper. This is so we can check to see if the nmethod we have just
513 // searched for an exception handler has been deoptimized in the meantime.
514 address Runtime1::exception_handler_for_pc(JavaThread* thread) {
515 oop exception = thread->exception_oop();
516 address pc = thread->exception_pc();
517 // Still in Java mode
518 debug_only(ResetNoHandleMark rnhm);
519 nmethod* nm = NULL;
520 address continuation = NULL;
521 {
522 // Enter VM mode by calling the helper
524 ResetNoHandleMark rnhm;
525 continuation = exception_handler_for_pc_helper(thread, exception, pc, nm);
526 }
527 // Back in JAVA, use no oops DON'T safepoint
529 // Now check to see if the nmethod we were called from is now deoptimized.
530 // If so we must return to the deopt blob and deoptimize the nmethod
532 if (nm != NULL && caller_is_deopted()) {
533 continuation = SharedRuntime::deopt_blob()->unpack_with_exception_in_tls();
534 }
536 return continuation;
537 }
540 JRT_ENTRY(void, Runtime1::throw_range_check_exception(JavaThread* thread, int index))
541 NOT_PRODUCT(_throw_range_check_exception_count++;)
542 Events::log("throw_range_check");
543 char message[jintAsStringSize];
544 sprintf(message, "%d", index);
545 SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), message);
546 JRT_END
549 JRT_ENTRY(void, Runtime1::throw_index_exception(JavaThread* thread, int index))
550 NOT_PRODUCT(_throw_index_exception_count++;)
551 Events::log("throw_index");
552 char message[16];
553 sprintf(message, "%d", index);
554 SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_IndexOutOfBoundsException(), message);
555 JRT_END
558 JRT_ENTRY(void, Runtime1::throw_div0_exception(JavaThread* thread))
559 NOT_PRODUCT(_throw_div0_exception_count++;)
560 SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_ArithmeticException(), "/ by zero");
561 JRT_END
564 JRT_ENTRY(void, Runtime1::throw_null_pointer_exception(JavaThread* thread))
565 NOT_PRODUCT(_throw_null_pointer_exception_count++;)
566 SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_NullPointerException());
567 JRT_END
570 JRT_ENTRY(void, Runtime1::throw_class_cast_exception(JavaThread* thread, oopDesc* object))
571 NOT_PRODUCT(_throw_class_cast_exception_count++;)
572 ResourceMark rm(thread);
573 char* message = SharedRuntime::generate_class_cast_message(
574 thread, Klass::cast(object->klass())->external_name());
575 SharedRuntime::throw_and_post_jvmti_exception(
576 thread, vmSymbols::java_lang_ClassCastException(), message);
577 JRT_END
580 JRT_ENTRY(void, Runtime1::throw_incompatible_class_change_error(JavaThread* thread))
581 NOT_PRODUCT(_throw_incompatible_class_change_error_count++;)
582 ResourceMark rm(thread);
583 SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_IncompatibleClassChangeError());
584 JRT_END
587 JRT_ENTRY_NO_ASYNC(void, Runtime1::monitorenter(JavaThread* thread, oopDesc* obj, BasicObjectLock* lock))
588 NOT_PRODUCT(_monitorenter_slowcase_cnt++;)
589 if (PrintBiasedLockingStatistics) {
590 Atomic::inc(BiasedLocking::slow_path_entry_count_addr());
591 }
592 Handle h_obj(thread, obj);
593 assert(h_obj()->is_oop(), "must be NULL or an object");
594 if (UseBiasedLocking) {
595 // Retry fast entry if bias is revoked to avoid unnecessary inflation
596 ObjectSynchronizer::fast_enter(h_obj, lock->lock(), true, CHECK);
597 } else {
598 if (UseFastLocking) {
599 // When using fast locking, the compiled code has already tried the fast case
600 assert(obj == lock->obj(), "must match");
601 ObjectSynchronizer::slow_enter(h_obj, lock->lock(), THREAD);
602 } else {
603 lock->set_obj(obj);
604 ObjectSynchronizer::fast_enter(h_obj, lock->lock(), false, THREAD);
605 }
606 }
607 JRT_END
610 JRT_LEAF(void, Runtime1::monitorexit(JavaThread* thread, BasicObjectLock* lock))
611 NOT_PRODUCT(_monitorexit_slowcase_cnt++;)
612 assert(thread == JavaThread::current(), "threads must correspond");
613 assert(thread->last_Java_sp(), "last_Java_sp must be set");
614 // monitorexit is non-blocking (leaf routine) => no exceptions can be thrown
615 EXCEPTION_MARK;
617 oop obj = lock->obj();
618 assert(obj->is_oop(), "must be NULL or an object");
619 if (UseFastLocking) {
620 // When using fast locking, the compiled code has already tried the fast case
621 ObjectSynchronizer::slow_exit(obj, lock->lock(), THREAD);
622 } else {
623 ObjectSynchronizer::fast_exit(obj, lock->lock(), THREAD);
624 }
625 JRT_END
628 static klassOop resolve_field_return_klass(methodHandle caller, int bci, TRAPS) {
629 Bytecode_field* field_access = Bytecode_field_at(caller, bci);
630 // This can be static or non-static field access
631 Bytecodes::Code code = field_access->code();
633 // We must load class, initialize class and resolvethe field
634 FieldAccessInfo result; // initialize class if needed
635 constantPoolHandle constants(THREAD, caller->constants());
636 LinkResolver::resolve_field(result, constants, field_access->index(), Bytecodes::java_code(code), false, CHECK_NULL);
637 return result.klass()();
638 }
641 //
642 // This routine patches sites where a class wasn't loaded or
643 // initialized at the time the code was generated. It handles
644 // references to classes, fields and forcing of initialization. Most
645 // of the cases are straightforward and involving simply forcing
646 // resolution of a class, rewriting the instruction stream with the
647 // needed constant and replacing the call in this function with the
648 // patched code. The case for static field is more complicated since
649 // the thread which is in the process of initializing a class can
650 // access it's static fields but other threads can't so the code
651 // either has to deoptimize when this case is detected or execute a
652 // check that the current thread is the initializing thread. The
653 // current
654 //
655 // Patches basically look like this:
656 //
657 //
658 // patch_site: jmp patch stub ;; will be patched
659 // continue: ...
660 // ...
661 // ...
662 // ...
663 //
664 // They have a stub which looks like this:
665 //
666 // ;; patch body
667 // movl <const>, reg (for class constants)
668 // <or> movl [reg1 + <const>], reg (for field offsets)
669 // <or> movl reg, [reg1 + <const>] (for field offsets)
670 // <being_init offset> <bytes to copy> <bytes to skip>
671 // patch_stub: call Runtime1::patch_code (through a runtime stub)
672 // jmp patch_site
673 //
674 //
675 // A normal patch is done by rewriting the patch body, usually a move,
676 // and then copying it into place over top of the jmp instruction
677 // being careful to flush caches and doing it in an MP-safe way. The
678 // constants following the patch body are used to find various pieces
679 // of the patch relative to the call site for Runtime1::patch_code.
680 // The case for getstatic and putstatic is more complicated because
681 // getstatic and putstatic have special semantics when executing while
682 // the class is being initialized. getstatic/putstatic on a class
683 // which is being_initialized may be executed by the initializing
684 // thread but other threads have to block when they execute it. This
685 // is accomplished in compiled code by executing a test of the current
686 // thread against the initializing thread of the class. It's emitted
687 // as boilerplate in their stub which allows the patched code to be
688 // executed before it's copied back into the main body of the nmethod.
689 //
690 // being_init: get_thread(<tmp reg>
691 // cmpl [reg1 + <init_thread_offset>], <tmp reg>
692 // jne patch_stub
693 // movl [reg1 + <const>], reg (for field offsets) <or>
694 // movl reg, [reg1 + <const>] (for field offsets)
695 // jmp continue
696 // <being_init offset> <bytes to copy> <bytes to skip>
697 // patch_stub: jmp Runtim1::patch_code (through a runtime stub)
698 // jmp patch_site
699 //
700 // If the class is being initialized the patch body is rewritten and
701 // the patch site is rewritten to jump to being_init, instead of
702 // patch_stub. Whenever this code is executed it checks the current
703 // thread against the intializing thread so other threads will enter
704 // the runtime and end up blocked waiting the class to finish
705 // initializing inside the calls to resolve_field below. The
706 // initializing class will continue on it's way. Once the class is
707 // fully_initialized, the intializing_thread of the class becomes
708 // NULL, so the next thread to execute this code will fail the test,
709 // call into patch_code and complete the patching process by copying
710 // the patch body back into the main part of the nmethod and resume
711 // executing.
712 //
713 //
715 JRT_ENTRY(void, Runtime1::patch_code(JavaThread* thread, Runtime1::StubID stub_id ))
716 NOT_PRODUCT(_patch_code_slowcase_cnt++;)
718 ResourceMark rm(thread);
719 RegisterMap reg_map(thread, false);
720 frame runtime_frame = thread->last_frame();
721 frame caller_frame = runtime_frame.sender(®_map);
723 // last java frame on stack
724 vframeStream vfst(thread, true);
725 assert(!vfst.at_end(), "Java frame must exist");
727 methodHandle caller_method(THREAD, vfst.method());
728 // Note that caller_method->code() may not be same as caller_code because of OSR's
729 // Note also that in the presence of inlining it is not guaranteed
730 // that caller_method() == caller_code->method()
733 int bci = vfst.bci();
735 Events::log("patch_code @ " INTPTR_FORMAT , caller_frame.pc());
737 Bytecodes::Code code = Bytecode_at(caller_method->bcp_from(bci))->java_code();
739 #ifndef PRODUCT
740 // this is used by assertions in the access_field_patching_id
741 BasicType patch_field_type = T_ILLEGAL;
742 #endif // PRODUCT
743 bool deoptimize_for_volatile = false;
744 int patch_field_offset = -1;
745 KlassHandle init_klass(THREAD, klassOop(NULL)); // klass needed by access_field_patching code
746 Handle load_klass(THREAD, NULL); // oop needed by load_klass_patching code
747 if (stub_id == Runtime1::access_field_patching_id) {
749 Bytecode_field* field_access = Bytecode_field_at(caller_method, bci);
750 FieldAccessInfo result; // initialize class if needed
751 Bytecodes::Code code = field_access->code();
752 constantPoolHandle constants(THREAD, caller_method->constants());
753 LinkResolver::resolve_field(result, constants, field_access->index(), Bytecodes::java_code(code), false, CHECK);
754 patch_field_offset = result.field_offset();
756 // If we're patching a field which is volatile then at compile it
757 // must not have been know to be volatile, so the generated code
758 // isn't correct for a volatile reference. The nmethod has to be
759 // deoptimized so that the code can be regenerated correctly.
760 // This check is only needed for access_field_patching since this
761 // is the path for patching field offsets. load_klass is only
762 // used for patching references to oops which don't need special
763 // handling in the volatile case.
764 deoptimize_for_volatile = result.access_flags().is_volatile();
766 #ifndef PRODUCT
767 patch_field_type = result.field_type();
768 #endif
769 } else if (stub_id == Runtime1::load_klass_patching_id) {
770 oop k;
771 switch (code) {
772 case Bytecodes::_putstatic:
773 case Bytecodes::_getstatic:
774 { klassOop klass = resolve_field_return_klass(caller_method, bci, CHECK);
775 // Save a reference to the class that has to be checked for initialization
776 init_klass = KlassHandle(THREAD, klass);
777 k = klass;
778 }
779 break;
780 case Bytecodes::_new:
781 { Bytecode_new* bnew = Bytecode_new_at(caller_method->bcp_from(bci));
782 k = caller_method->constants()->klass_at(bnew->index(), CHECK);
783 }
784 break;
785 case Bytecodes::_multianewarray:
786 { Bytecode_multianewarray* mna = Bytecode_multianewarray_at(caller_method->bcp_from(bci));
787 k = caller_method->constants()->klass_at(mna->index(), CHECK);
788 }
789 break;
790 case Bytecodes::_instanceof:
791 { Bytecode_instanceof* io = Bytecode_instanceof_at(caller_method->bcp_from(bci));
792 k = caller_method->constants()->klass_at(io->index(), CHECK);
793 }
794 break;
795 case Bytecodes::_checkcast:
796 { Bytecode_checkcast* cc = Bytecode_checkcast_at(caller_method->bcp_from(bci));
797 k = caller_method->constants()->klass_at(cc->index(), CHECK);
798 }
799 break;
800 case Bytecodes::_anewarray:
801 { Bytecode_anewarray* anew = Bytecode_anewarray_at(caller_method->bcp_from(bci));
802 klassOop ek = caller_method->constants()->klass_at(anew->index(), CHECK);
803 k = Klass::cast(ek)->array_klass(CHECK);
804 }
805 break;
806 case Bytecodes::_ldc:
807 case Bytecodes::_ldc_w:
808 {
809 Bytecode_loadconstant* cc = Bytecode_loadconstant_at(caller_method, bci);
810 k = cc->resolve_constant(CHECK);
811 assert(k != NULL && !k->is_klass(), "must be class mirror or other Java constant");
812 }
813 break;
814 default: Unimplemented();
815 }
816 // convert to handle
817 load_klass = Handle(THREAD, k);
818 } else {
819 ShouldNotReachHere();
820 }
822 if (deoptimize_for_volatile) {
823 // At compile time we assumed the field wasn't volatile but after
824 // loading it turns out it was volatile so we have to throw the
825 // compiled code out and let it be regenerated.
826 if (TracePatching) {
827 tty->print_cr("Deoptimizing for patching volatile field reference");
828 }
829 // It's possible the nmethod was invalidated in the last
830 // safepoint, but if it's still alive then make it not_entrant.
831 nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());
832 if (nm != NULL) {
833 nm->make_not_entrant();
834 }
836 Deoptimization::deoptimize_frame(thread, caller_frame.id());
838 // Return to the now deoptimized frame.
839 }
841 // If we are patching in a non-perm oop, make sure the nmethod
842 // is on the right list.
843 if (ScavengeRootsInCode && load_klass.not_null() && load_klass->is_scavengable()) {
844 MutexLockerEx ml_code (CodeCache_lock, Mutex::_no_safepoint_check_flag);
845 nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());
846 guarantee(nm != NULL, "only nmethods can contain non-perm oops");
847 if (!nm->on_scavenge_root_list())
848 CodeCache::add_scavenge_root_nmethod(nm);
849 }
851 // Now copy code back
853 {
854 MutexLockerEx ml_patch (Patching_lock, Mutex::_no_safepoint_check_flag);
855 //
856 // Deoptimization may have happened while we waited for the lock.
857 // In that case we don't bother to do any patching we just return
858 // and let the deopt happen
859 if (!caller_is_deopted()) {
860 NativeGeneralJump* jump = nativeGeneralJump_at(caller_frame.pc());
861 address instr_pc = jump->jump_destination();
862 NativeInstruction* ni = nativeInstruction_at(instr_pc);
863 if (ni->is_jump() ) {
864 // the jump has not been patched yet
865 // The jump destination is slow case and therefore not part of the stubs
866 // (stubs are only for StaticCalls)
868 // format of buffer
869 // ....
870 // instr byte 0 <-- copy_buff
871 // instr byte 1
872 // ..
873 // instr byte n-1
874 // n
875 // .... <-- call destination
877 address stub_location = caller_frame.pc() + PatchingStub::patch_info_offset();
878 unsigned char* byte_count = (unsigned char*) (stub_location - 1);
879 unsigned char* byte_skip = (unsigned char*) (stub_location - 2);
880 unsigned char* being_initialized_entry_offset = (unsigned char*) (stub_location - 3);
881 address copy_buff = stub_location - *byte_skip - *byte_count;
882 address being_initialized_entry = stub_location - *being_initialized_entry_offset;
883 if (TracePatching) {
884 tty->print_cr(" Patching %s at bci %d at address 0x%x (%s)", Bytecodes::name(code), bci,
885 instr_pc, (stub_id == Runtime1::access_field_patching_id) ? "field" : "klass");
886 nmethod* caller_code = CodeCache::find_nmethod(caller_frame.pc());
887 assert(caller_code != NULL, "nmethod not found");
889 // NOTE we use pc() not original_pc() because we already know they are
890 // identical otherwise we'd have never entered this block of code
892 OopMap* map = caller_code->oop_map_for_return_address(caller_frame.pc());
893 assert(map != NULL, "null check");
894 map->print();
895 tty->cr();
897 Disassembler::decode(copy_buff, copy_buff + *byte_count, tty);
898 }
899 // depending on the code below, do_patch says whether to copy the patch body back into the nmethod
900 bool do_patch = true;
901 if (stub_id == Runtime1::access_field_patching_id) {
902 // The offset may not be correct if the class was not loaded at code generation time.
903 // Set it now.
904 NativeMovRegMem* n_move = nativeMovRegMem_at(copy_buff);
905 assert(n_move->offset() == 0 || (n_move->offset() == 4 && (patch_field_type == T_DOUBLE || patch_field_type == T_LONG)), "illegal offset for type");
906 assert(patch_field_offset >= 0, "illegal offset");
907 n_move->add_offset_in_bytes(patch_field_offset);
908 } else if (stub_id == Runtime1::load_klass_patching_id) {
909 // If a getstatic or putstatic is referencing a klass which
910 // isn't fully initialized, the patch body isn't copied into
911 // place until initialization is complete. In this case the
912 // patch site is setup so that any threads besides the
913 // initializing thread are forced to come into the VM and
914 // block.
915 do_patch = (code != Bytecodes::_getstatic && code != Bytecodes::_putstatic) ||
916 instanceKlass::cast(init_klass())->is_initialized();
917 NativeGeneralJump* jump = nativeGeneralJump_at(instr_pc);
918 if (jump->jump_destination() == being_initialized_entry) {
919 assert(do_patch == true, "initialization must be complete at this point");
920 } else {
921 // patch the instruction <move reg, klass>
922 NativeMovConstReg* n_copy = nativeMovConstReg_at(copy_buff);
924 assert(n_copy->data() == 0 ||
925 n_copy->data() == (intptr_t)Universe::non_oop_word(),
926 "illegal init value");
927 assert(load_klass() != NULL, "klass not set");
928 n_copy->set_data((intx) (load_klass()));
930 if (TracePatching) {
931 Disassembler::decode(copy_buff, copy_buff + *byte_count, tty);
932 }
934 #if defined(SPARC) || defined(PPC)
935 // Update the oop location in the nmethod with the proper
936 // oop. When the code was generated, a NULL was stuffed
937 // in the oop table and that table needs to be update to
938 // have the right value. On intel the value is kept
939 // directly in the instruction instead of in the oop
940 // table, so set_data above effectively updated the value.
941 nmethod* nm = CodeCache::find_nmethod(instr_pc);
942 assert(nm != NULL, "invalid nmethod_pc");
943 RelocIterator oops(nm, copy_buff, copy_buff + 1);
944 bool found = false;
945 while (oops.next() && !found) {
946 if (oops.type() == relocInfo::oop_type) {
947 oop_Relocation* r = oops.oop_reloc();
948 oop* oop_adr = r->oop_addr();
949 *oop_adr = load_klass();
950 r->fix_oop_relocation();
951 found = true;
952 }
953 }
954 assert(found, "the oop must exist!");
955 #endif
957 }
958 } else {
959 ShouldNotReachHere();
960 }
961 if (do_patch) {
962 // replace instructions
963 // first replace the tail, then the call
964 #ifdef ARM
965 if(stub_id == Runtime1::load_klass_patching_id && !VM_Version::supports_movw()) {
966 copy_buff -= *byte_count;
967 NativeMovConstReg* n_copy2 = nativeMovConstReg_at(copy_buff);
968 n_copy2->set_data((intx) (load_klass()), instr_pc);
969 }
970 #endif
972 for (int i = NativeCall::instruction_size; i < *byte_count; i++) {
973 address ptr = copy_buff + i;
974 int a_byte = (*ptr) & 0xFF;
975 address dst = instr_pc + i;
976 *(unsigned char*)dst = (unsigned char) a_byte;
977 }
978 ICache::invalidate_range(instr_pc, *byte_count);
979 NativeGeneralJump::replace_mt_safe(instr_pc, copy_buff);
981 if (stub_id == Runtime1::load_klass_patching_id) {
982 // update relocInfo to oop
983 nmethod* nm = CodeCache::find_nmethod(instr_pc);
984 assert(nm != NULL, "invalid nmethod_pc");
986 // The old patch site is now a move instruction so update
987 // the reloc info so that it will get updated during
988 // future GCs.
989 RelocIterator iter(nm, (address)instr_pc, (address)(instr_pc + 1));
990 relocInfo::change_reloc_info_for_address(&iter, (address) instr_pc,
991 relocInfo::none, relocInfo::oop_type);
992 #ifdef SPARC
993 // Sparc takes two relocations for an oop so update the second one.
994 address instr_pc2 = instr_pc + NativeMovConstReg::add_offset;
995 RelocIterator iter2(nm, instr_pc2, instr_pc2 + 1);
996 relocInfo::change_reloc_info_for_address(&iter2, (address) instr_pc2,
997 relocInfo::none, relocInfo::oop_type);
998 #endif
999 #ifdef PPC
1000 { address instr_pc2 = instr_pc + NativeMovConstReg::lo_offset;
1001 RelocIterator iter2(nm, instr_pc2, instr_pc2 + 1);
1002 relocInfo::change_reloc_info_for_address(&iter2, (address) instr_pc2, relocInfo::none, relocInfo::oop_type);
1003 }
1004 #endif
1005 }
1007 } else {
1008 ICache::invalidate_range(copy_buff, *byte_count);
1009 NativeGeneralJump::insert_unconditional(instr_pc, being_initialized_entry);
1010 }
1011 }
1012 }
1013 }
1014 JRT_END
1016 //
1017 // Entry point for compiled code. We want to patch a nmethod.
1018 // We don't do a normal VM transition here because we want to
1019 // know after the patching is complete and any safepoint(s) are taken
1020 // if the calling nmethod was deoptimized. We do this by calling a
1021 // helper method which does the normal VM transition and when it
1022 // completes we can check for deoptimization. This simplifies the
1023 // assembly code in the cpu directories.
1024 //
1025 int Runtime1::move_klass_patching(JavaThread* thread) {
1026 //
1027 // NOTE: we are still in Java
1028 //
1029 Thread* THREAD = thread;
1030 debug_only(NoHandleMark nhm;)
1031 {
1032 // Enter VM mode
1034 ResetNoHandleMark rnhm;
1035 patch_code(thread, load_klass_patching_id);
1036 }
1037 // Back in JAVA, use no oops DON'T safepoint
1039 // Return true if calling code is deoptimized
1041 return caller_is_deopted();
1042 }
1044 //
1045 // Entry point for compiled code. We want to patch a nmethod.
1046 // We don't do a normal VM transition here because we want to
1047 // know after the patching is complete and any safepoint(s) are taken
1048 // if the calling nmethod was deoptimized. We do this by calling a
1049 // helper method which does the normal VM transition and when it
1050 // completes we can check for deoptimization. This simplifies the
1051 // assembly code in the cpu directories.
1052 //
1054 int Runtime1::access_field_patching(JavaThread* thread) {
1055 //
1056 // NOTE: we are still in Java
1057 //
1058 Thread* THREAD = thread;
1059 debug_only(NoHandleMark nhm;)
1060 {
1061 // Enter VM mode
1063 ResetNoHandleMark rnhm;
1064 patch_code(thread, access_field_patching_id);
1065 }
1066 // Back in JAVA, use no oops DON'T safepoint
1068 // Return true if calling code is deoptimized
1070 return caller_is_deopted();
1071 JRT_END
1074 JRT_LEAF(void, Runtime1::trace_block_entry(jint block_id))
1075 // for now we just print out the block id
1076 tty->print("%d ", block_id);
1077 JRT_END
1080 // Array copy return codes.
1081 enum {
1082 ac_failed = -1, // arraycopy failed
1083 ac_ok = 0 // arraycopy succeeded
1084 };
1087 // Below length is the # elements copied.
1088 template <class T> int obj_arraycopy_work(oopDesc* src, T* src_addr,
1089 oopDesc* dst, T* dst_addr,
1090 int length) {
1092 // For performance reasons, we assume we are using a card marking write
1093 // barrier. The assert will fail if this is not the case.
1094 // Note that we use the non-virtual inlineable variant of write_ref_array.
1095 BarrierSet* bs = Universe::heap()->barrier_set();
1096 assert(bs->has_write_ref_array_opt(), "Barrier set must have ref array opt");
1097 assert(bs->has_write_ref_array_pre_opt(), "For pre-barrier as well.");
1098 if (src == dst) {
1099 // same object, no check
1100 bs->write_ref_array_pre(dst_addr, length);
1101 Copy::conjoint_oops_atomic(src_addr, dst_addr, length);
1102 bs->write_ref_array((HeapWord*)dst_addr, length);
1103 return ac_ok;
1104 } else {
1105 klassOop bound = objArrayKlass::cast(dst->klass())->element_klass();
1106 klassOop stype = objArrayKlass::cast(src->klass())->element_klass();
1107 if (stype == bound || Klass::cast(stype)->is_subtype_of(bound)) {
1108 // Elements are guaranteed to be subtypes, so no check necessary
1109 bs->write_ref_array_pre(dst_addr, length);
1110 Copy::conjoint_oops_atomic(src_addr, dst_addr, length);
1111 bs->write_ref_array((HeapWord*)dst_addr, length);
1112 return ac_ok;
1113 }
1114 }
1115 return ac_failed;
1116 }
1118 // fast and direct copy of arrays; returning -1, means that an exception may be thrown
1119 // and we did not copy anything
1120 JRT_LEAF(int, Runtime1::arraycopy(oopDesc* src, int src_pos, oopDesc* dst, int dst_pos, int length))
1121 #ifndef PRODUCT
1122 _generic_arraycopy_cnt++; // Slow-path oop array copy
1123 #endif
1125 if (src == NULL || dst == NULL || src_pos < 0 || dst_pos < 0 || length < 0) return ac_failed;
1126 if (!dst->is_array() || !src->is_array()) return ac_failed;
1127 if ((unsigned int) arrayOop(src)->length() < (unsigned int)src_pos + (unsigned int)length) return ac_failed;
1128 if ((unsigned int) arrayOop(dst)->length() < (unsigned int)dst_pos + (unsigned int)length) return ac_failed;
1130 if (length == 0) return ac_ok;
1131 if (src->is_typeArray()) {
1132 const klassOop klass_oop = src->klass();
1133 if (klass_oop != dst->klass()) return ac_failed;
1134 typeArrayKlass* klass = typeArrayKlass::cast(klass_oop);
1135 const int l2es = klass->log2_element_size();
1136 const int ihs = klass->array_header_in_bytes() / wordSize;
1137 char* src_addr = (char*) ((oopDesc**)src + ihs) + (src_pos << l2es);
1138 char* dst_addr = (char*) ((oopDesc**)dst + ihs) + (dst_pos << l2es);
1139 // Potential problem: memmove is not guaranteed to be word atomic
1140 // Revisit in Merlin
1141 memmove(dst_addr, src_addr, length << l2es);
1142 return ac_ok;
1143 } else if (src->is_objArray() && dst->is_objArray()) {
1144 if (UseCompressedOops) { // will need for tiered
1145 narrowOop *src_addr = objArrayOop(src)->obj_at_addr<narrowOop>(src_pos);
1146 narrowOop *dst_addr = objArrayOop(dst)->obj_at_addr<narrowOop>(dst_pos);
1147 return obj_arraycopy_work(src, src_addr, dst, dst_addr, length);
1148 } else {
1149 oop *src_addr = objArrayOop(src)->obj_at_addr<oop>(src_pos);
1150 oop *dst_addr = objArrayOop(dst)->obj_at_addr<oop>(dst_pos);
1151 return obj_arraycopy_work(src, src_addr, dst, dst_addr, length);
1152 }
1153 }
1154 return ac_failed;
1155 JRT_END
1158 JRT_LEAF(void, Runtime1::primitive_arraycopy(HeapWord* src, HeapWord* dst, int length))
1159 #ifndef PRODUCT
1160 _primitive_arraycopy_cnt++;
1161 #endif
1163 if (length == 0) return;
1164 // Not guaranteed to be word atomic, but that doesn't matter
1165 // for anything but an oop array, which is covered by oop_arraycopy.
1166 Copy::conjoint_jbytes(src, dst, length);
1167 JRT_END
1169 JRT_LEAF(void, Runtime1::oop_arraycopy(HeapWord* src, HeapWord* dst, int num))
1170 #ifndef PRODUCT
1171 _oop_arraycopy_cnt++;
1172 #endif
1174 if (num == 0) return;
1175 BarrierSet* bs = Universe::heap()->barrier_set();
1176 assert(bs->has_write_ref_array_opt(), "Barrier set must have ref array opt");
1177 assert(bs->has_write_ref_array_pre_opt(), "For pre-barrier as well.");
1178 if (UseCompressedOops) {
1179 bs->write_ref_array_pre((narrowOop*)dst, num);
1180 } else {
1181 bs->write_ref_array_pre((oop*)dst, num);
1182 }
1183 Copy::conjoint_oops_atomic((oop*) src, (oop*) dst, num);
1184 bs->write_ref_array(dst, num);
1185 JRT_END
1188 #ifndef PRODUCT
1189 void Runtime1::print_statistics() {
1190 tty->print_cr("C1 Runtime statistics:");
1191 tty->print_cr(" _resolve_invoke_virtual_cnt: %d", SharedRuntime::_resolve_virtual_ctr);
1192 tty->print_cr(" _resolve_invoke_opt_virtual_cnt: %d", SharedRuntime::_resolve_opt_virtual_ctr);
1193 tty->print_cr(" _resolve_invoke_static_cnt: %d", SharedRuntime::_resolve_static_ctr);
1194 tty->print_cr(" _handle_wrong_method_cnt: %d", SharedRuntime::_wrong_method_ctr);
1195 tty->print_cr(" _ic_miss_cnt: %d", SharedRuntime::_ic_miss_ctr);
1196 tty->print_cr(" _generic_arraycopy_cnt: %d", _generic_arraycopy_cnt);
1197 tty->print_cr(" _primitive_arraycopy_cnt: %d", _primitive_arraycopy_cnt);
1198 tty->print_cr(" _oop_arraycopy_cnt: %d", _oop_arraycopy_cnt);
1199 tty->print_cr(" _arraycopy_slowcase_cnt: %d", _arraycopy_slowcase_cnt);
1201 tty->print_cr(" _new_type_array_slowcase_cnt: %d", _new_type_array_slowcase_cnt);
1202 tty->print_cr(" _new_object_array_slowcase_cnt: %d", _new_object_array_slowcase_cnt);
1203 tty->print_cr(" _new_instance_slowcase_cnt: %d", _new_instance_slowcase_cnt);
1204 tty->print_cr(" _new_multi_array_slowcase_cnt: %d", _new_multi_array_slowcase_cnt);
1205 tty->print_cr(" _monitorenter_slowcase_cnt: %d", _monitorenter_slowcase_cnt);
1206 tty->print_cr(" _monitorexit_slowcase_cnt: %d", _monitorexit_slowcase_cnt);
1207 tty->print_cr(" _patch_code_slowcase_cnt: %d", _patch_code_slowcase_cnt);
1209 tty->print_cr(" _throw_range_check_exception_count: %d:", _throw_range_check_exception_count);
1210 tty->print_cr(" _throw_index_exception_count: %d:", _throw_index_exception_count);
1211 tty->print_cr(" _throw_div0_exception_count: %d:", _throw_div0_exception_count);
1212 tty->print_cr(" _throw_null_pointer_exception_count: %d:", _throw_null_pointer_exception_count);
1213 tty->print_cr(" _throw_class_cast_exception_count: %d:", _throw_class_cast_exception_count);
1214 tty->print_cr(" _throw_incompatible_class_change_error_count: %d:", _throw_incompatible_class_change_error_count);
1215 tty->print_cr(" _throw_array_store_exception_count: %d:", _throw_array_store_exception_count);
1216 tty->print_cr(" _throw_count: %d:", _throw_count);
1218 SharedRuntime::print_ic_miss_histogram();
1219 tty->cr();
1220 }
1221 #endif // PRODUCT