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