comparison src/share/vm/c1/c1_Runtime1.cpp @ 0:a61af66fc99e jdk7-b24

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