1 /*
   2  * Copyright (c) 1999, 2016, 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 "precompiled.hpp"
  26 #include "asm/codeBuffer.hpp"
  27 #include "c1/c1_CodeStubs.hpp"
  28 #include "c1/c1_Defs.hpp"
  29 #include "c1/c1_FrameMap.hpp"
  30 #include "c1/c1_LIRAssembler.hpp"
  31 #include "c1/c1_MacroAssembler.hpp"
  32 #include "c1/c1_Runtime1.hpp"
  33 #include "classfile/systemDictionary.hpp"
  34 #include "classfile/vmSymbols.hpp"
  35 #include "code/codeBlob.hpp"
  36 #include "code/codeCacheExtensions.hpp"
  37 #include "code/compiledIC.hpp"
  38 #include "code/pcDesc.hpp"
  39 #include "code/scopeDesc.hpp"
  40 #include "code/vtableStubs.hpp"
  41 #include "compiler/disassembler.hpp"
  42 #include "gc/shared/barrierSet.hpp"
  43 #include "gc/shared/collectedHeap.hpp"
  44 #include "interpreter/bytecode.hpp"
  45 #include "interpreter/interpreter.hpp"
  46 #include "logging/log.hpp"
  47 #include "memory/allocation.inline.hpp"
  48 #include "memory/oopFactory.hpp"
  49 #include "memory/resourceArea.hpp"
  50 #include "oops/objArrayKlass.hpp"
  51 #include "oops/oop.inline.hpp"
  52 #include "runtime/atomic.inline.hpp"
  53 #include "runtime/biasedLocking.hpp"
  54 #include "runtime/compilationPolicy.hpp"
  55 #include "runtime/interfaceSupport.hpp"
  56 #include "runtime/javaCalls.hpp"
  57 #include "runtime/sharedRuntime.hpp"
  58 #include "runtime/threadCritical.hpp"
  59 #include "runtime/vframe.hpp"
  60 #include "runtime/vframeArray.hpp"
  61 #include "runtime/vm_version.hpp"
  62 #include "utilities/copy.hpp"
  63 #include "utilities/events.hpp"
  64 
  65 
  66 // Implementation of StubAssembler
  67 
  68 StubAssembler::StubAssembler(CodeBuffer* code, const char * name, int stub_id) : C1_MacroAssembler(code) {
  69   _name = name;
  70   _must_gc_arguments = false;
  71   _frame_size = no_frame_size;
  72   _num_rt_args = 0;
  73   _stub_id = stub_id;
  74 }
  75 
  76 
  77 void StubAssembler::set_info(const char* name, bool must_gc_arguments) {
  78   _name = name;
  79   _must_gc_arguments = must_gc_arguments;
  80 }
  81 
  82 
  83 void StubAssembler::set_frame_size(int size) {
  84   if (_frame_size == no_frame_size) {
  85     _frame_size = size;
  86   }
  87   assert(_frame_size == size, "can't change the frame size");
  88 }
  89 
  90 
  91 void StubAssembler::set_num_rt_args(int args) {
  92   if (_num_rt_args == 0) {
  93     _num_rt_args = args;
  94   }
  95   assert(_num_rt_args == args, "can't change the number of args");
  96 }
  97 
  98 // Implementation of Runtime1
  99 
 100 CodeBlob* Runtime1::_blobs[Runtime1::number_of_ids];
 101 const char *Runtime1::_blob_names[] = {
 102   RUNTIME1_STUBS(STUB_NAME, LAST_STUB_NAME)
 103 };
 104 
 105 #ifndef PRODUCT
 106 // statistics
 107 int Runtime1::_generic_arraycopy_cnt = 0;
 108 int Runtime1::_primitive_arraycopy_cnt = 0;
 109 int Runtime1::_oop_arraycopy_cnt = 0;
 110 int Runtime1::_generic_arraycopystub_cnt = 0;
 111 int Runtime1::_arraycopy_slowcase_cnt = 0;
 112 int Runtime1::_arraycopy_checkcast_cnt = 0;
 113 int Runtime1::_arraycopy_checkcast_attempt_cnt = 0;
 114 int Runtime1::_new_type_array_slowcase_cnt = 0;
 115 int Runtime1::_new_object_array_slowcase_cnt = 0;
 116 int Runtime1::_new_instance_slowcase_cnt = 0;
 117 int Runtime1::_new_multi_array_slowcase_cnt = 0;
 118 int Runtime1::_monitorenter_slowcase_cnt = 0;
 119 int Runtime1::_monitorexit_slowcase_cnt = 0;
 120 int Runtime1::_patch_code_slowcase_cnt = 0;
 121 int Runtime1::_throw_range_check_exception_count = 0;
 122 int Runtime1::_throw_index_exception_count = 0;
 123 int Runtime1::_throw_div0_exception_count = 0;
 124 int Runtime1::_throw_null_pointer_exception_count = 0;
 125 int Runtime1::_throw_class_cast_exception_count = 0;
 126 int Runtime1::_throw_incompatible_class_change_error_count = 0;
 127 int Runtime1::_throw_array_store_exception_count = 0;
 128 int Runtime1::_throw_count = 0;
 129 
 130 static int _byte_arraycopy_stub_cnt = 0;
 131 static int _short_arraycopy_stub_cnt = 0;
 132 static int _int_arraycopy_stub_cnt = 0;
 133 static int _long_arraycopy_stub_cnt = 0;
 134 static int _oop_arraycopy_stub_cnt = 0;
 135 
 136 address Runtime1::arraycopy_count_address(BasicType type) {
 137   switch (type) {
 138   case T_BOOLEAN:
 139   case T_BYTE:   return (address)&_byte_arraycopy_stub_cnt;
 140   case T_CHAR:
 141   case T_SHORT:  return (address)&_short_arraycopy_stub_cnt;
 142   case T_FLOAT:
 143   case T_INT:    return (address)&_int_arraycopy_stub_cnt;
 144   case T_DOUBLE:
 145   case T_LONG:   return (address)&_long_arraycopy_stub_cnt;
 146   case T_ARRAY:
 147   case T_OBJECT: return (address)&_oop_arraycopy_stub_cnt;
 148   default:
 149     ShouldNotReachHere();
 150     return NULL;
 151   }
 152 }
 153 
 154 
 155 #endif
 156 
 157 // Simple helper to see if the caller of a runtime stub which
 158 // entered the VM has been deoptimized
 159 
 160 static bool caller_is_deopted() {
 161   JavaThread* thread = JavaThread::current();
 162   RegisterMap reg_map(thread, false);
 163   frame runtime_frame = thread->last_frame();
 164   frame caller_frame = runtime_frame.sender(&reg_map);
 165   assert(caller_frame.is_compiled_frame(), "must be compiled");
 166   return caller_frame.is_deoptimized_frame();
 167 }
 168 
 169 // Stress deoptimization
 170 static void deopt_caller() {
 171   if ( !caller_is_deopted()) {
 172     JavaThread* thread = JavaThread::current();
 173     RegisterMap reg_map(thread, false);
 174     frame runtime_frame = thread->last_frame();
 175     frame caller_frame = runtime_frame.sender(&reg_map);
 176     Deoptimization::deoptimize_frame(thread, caller_frame.id());
 177     assert(caller_is_deopted(), "Must be deoptimized");
 178   }
 179 }
 180 
 181 
 182 void Runtime1::generate_blob_for(BufferBlob* buffer_blob, StubID id) {
 183   assert(0 <= id && id < number_of_ids, "illegal stub id");
 184   ResourceMark rm;
 185   // create code buffer for code storage
 186   CodeBuffer code(buffer_blob);
 187 
 188   OopMapSet* oop_maps;
 189   int frame_size;
 190   bool must_gc_arguments;
 191 
 192   if (!CodeCacheExtensions::skip_compiler_support()) {
 193     // bypass useless code generation
 194     Compilation::setup_code_buffer(&code, 0);
 195 
 196     // create assembler for code generation
 197     StubAssembler* sasm = new StubAssembler(&code, name_for(id), id);
 198     // generate code for runtime stub
 199     oop_maps = generate_code_for(id, sasm);
 200     assert(oop_maps == NULL || sasm->frame_size() != no_frame_size,
 201            "if stub has an oop map it must have a valid frame size");
 202 
 203 #ifdef ASSERT
 204     // Make sure that stubs that need oopmaps have them
 205     switch (id) {
 206       // These stubs don't need to have an oopmap
 207     case dtrace_object_alloc_id:
 208     case g1_pre_barrier_slow_id:
 209     case g1_post_barrier_slow_id:
 210     case slow_subtype_check_id:
 211     case fpu2long_stub_id:
 212     case unwind_exception_id:
 213     case counter_overflow_id:
 214 #if defined(SPARC) || defined(PPC32)
 215     case handle_exception_nofpu_id:  // Unused on sparc
 216 #endif
 217       break;
 218 
 219       // All other stubs should have oopmaps
 220     default:
 221       assert(oop_maps != NULL, "must have an oopmap");
 222     }
 223 #endif
 224 
 225     // align so printing shows nop's instead of random code at the end (SimpleStubs are aligned)
 226     sasm->align(BytesPerWord);
 227     // make sure all code is in code buffer
 228     sasm->flush();
 229 
 230     frame_size = sasm->frame_size();
 231     must_gc_arguments = sasm->must_gc_arguments();
 232   } else {
 233     /* ignored values */
 234     oop_maps = NULL;
 235     frame_size = 0;
 236     must_gc_arguments = false;
 237   }
 238   // create blob - distinguish a few special cases
 239   CodeBlob* blob = RuntimeStub::new_runtime_stub(name_for(id),
 240                                                  &code,
 241                                                  CodeOffsets::frame_never_safe,
 242                                                  frame_size,
 243                                                  oop_maps,
 244                                                  must_gc_arguments);
 245   // install blob
 246   assert(blob != NULL, "blob must exist");
 247   _blobs[id] = blob;
 248 }
 249 
 250 
 251 void Runtime1::initialize(BufferBlob* blob) {
 252   // platform-dependent initialization
 253   initialize_pd();
 254   // generate stubs
 255   for (int id = 0; id < number_of_ids; id++) generate_blob_for(blob, (StubID)id);
 256   // printing
 257 #ifndef PRODUCT
 258   if (PrintSimpleStubs) {
 259     ResourceMark rm;
 260     for (int id = 0; id < number_of_ids; id++) {
 261       _blobs[id]->print();
 262       if (_blobs[id]->oop_maps() != NULL) {
 263         _blobs[id]->oop_maps()->print();
 264       }
 265     }
 266   }
 267 #endif
 268 }
 269 
 270 
 271 CodeBlob* Runtime1::blob_for(StubID id) {
 272   assert(0 <= id && id < number_of_ids, "illegal stub id");
 273   return _blobs[id];
 274 }
 275 
 276 
 277 const char* Runtime1::name_for(StubID id) {
 278   assert(0 <= id && id < number_of_ids, "illegal stub id");
 279   return _blob_names[id];
 280 }
 281 
 282 const char* Runtime1::name_for_address(address entry) {
 283   for (int id = 0; id < number_of_ids; id++) {
 284     if (entry == entry_for((StubID)id)) return name_for((StubID)id);
 285   }
 286 
 287 #define FUNCTION_CASE(a, f) \
 288   if ((intptr_t)a == CAST_FROM_FN_PTR(intptr_t, f))  return #f
 289 
 290   FUNCTION_CASE(entry, os::javaTimeMillis);
 291   FUNCTION_CASE(entry, os::javaTimeNanos);
 292   FUNCTION_CASE(entry, SharedRuntime::OSR_migration_end);
 293   FUNCTION_CASE(entry, SharedRuntime::d2f);
 294   FUNCTION_CASE(entry, SharedRuntime::d2i);
 295   FUNCTION_CASE(entry, SharedRuntime::d2l);
 296   FUNCTION_CASE(entry, SharedRuntime::dcos);
 297   FUNCTION_CASE(entry, SharedRuntime::dexp);
 298   FUNCTION_CASE(entry, SharedRuntime::dlog);
 299   FUNCTION_CASE(entry, SharedRuntime::dlog10);
 300   FUNCTION_CASE(entry, SharedRuntime::dpow);
 301   FUNCTION_CASE(entry, SharedRuntime::drem);
 302   FUNCTION_CASE(entry, SharedRuntime::dsin);
 303   FUNCTION_CASE(entry, SharedRuntime::dtan);
 304   FUNCTION_CASE(entry, SharedRuntime::f2i);
 305   FUNCTION_CASE(entry, SharedRuntime::f2l);
 306   FUNCTION_CASE(entry, SharedRuntime::frem);
 307   FUNCTION_CASE(entry, SharedRuntime::l2d);
 308   FUNCTION_CASE(entry, SharedRuntime::l2f);
 309   FUNCTION_CASE(entry, SharedRuntime::ldiv);
 310   FUNCTION_CASE(entry, SharedRuntime::lmul);
 311   FUNCTION_CASE(entry, SharedRuntime::lrem);
 312   FUNCTION_CASE(entry, SharedRuntime::lrem);
 313   FUNCTION_CASE(entry, SharedRuntime::dtrace_method_entry);
 314   FUNCTION_CASE(entry, SharedRuntime::dtrace_method_exit);
 315   FUNCTION_CASE(entry, is_instance_of);
 316   FUNCTION_CASE(entry, trace_block_entry);
 317 #ifdef TRACE_HAVE_INTRINSICS
 318   FUNCTION_CASE(entry, TRACE_TIME_METHOD);
 319 #endif
 320   FUNCTION_CASE(entry, StubRoutines::updateBytesCRC32());
 321   FUNCTION_CASE(entry, StubRoutines::dexp());
 322   FUNCTION_CASE(entry, StubRoutines::dlog());
 323   FUNCTION_CASE(entry, StubRoutines::dlog10());
 324   FUNCTION_CASE(entry, StubRoutines::dpow());
 325   FUNCTION_CASE(entry, StubRoutines::dsin());
 326   FUNCTION_CASE(entry, StubRoutines::dcos());
 327   FUNCTION_CASE(entry, StubRoutines::dtan());
 328 
 329 #undef FUNCTION_CASE
 330 
 331   // Soft float adds more runtime names.
 332   return pd_name_for_address(entry);
 333 }
 334 
 335 
 336 JRT_ENTRY(void, Runtime1::new_instance(JavaThread* thread, Klass* klass))
 337   NOT_PRODUCT(_new_instance_slowcase_cnt++;)
 338 
 339   assert(klass->is_klass(), "not a class");
 340   Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
 341   instanceKlassHandle h(thread, klass);
 342   h->check_valid_for_instantiation(true, CHECK);
 343   // make sure klass is initialized
 344   h->initialize(CHECK);
 345   // allocate instance and return via TLS
 346   oop obj = h->allocate_instance(CHECK);
 347   thread->set_vm_result(obj);
 348 JRT_END
 349 
 350 
 351 JRT_ENTRY(void, Runtime1::new_type_array(JavaThread* thread, Klass* klass, jint length))
 352   NOT_PRODUCT(_new_type_array_slowcase_cnt++;)
 353   // Note: no handle for klass needed since they are not used
 354   //       anymore after new_typeArray() and no GC can happen before.
 355   //       (This may have to change if this code changes!)
 356   assert(klass->is_klass(), "not a class");
 357   BasicType elt_type = TypeArrayKlass::cast(klass)->element_type();
 358   oop obj = oopFactory::new_typeArray(elt_type, length, CHECK);
 359   thread->set_vm_result(obj);
 360   // This is pretty rare but this runtime patch is stressful to deoptimization
 361   // if we deoptimize here so force a deopt to stress the path.
 362   if (DeoptimizeALot) {
 363     deopt_caller();
 364   }
 365 
 366 JRT_END
 367 
 368 
 369 JRT_ENTRY(void, Runtime1::new_object_array(JavaThread* thread, Klass* array_klass, jint length))
 370   NOT_PRODUCT(_new_object_array_slowcase_cnt++;)
 371 
 372   // Note: no handle for klass needed since they are not used
 373   //       anymore after new_objArray() and no GC can happen before.
 374   //       (This may have to change if this code changes!)
 375   assert(array_klass->is_klass(), "not a class");
 376   Handle holder(THREAD, array_klass->klass_holder()); // keep the klass alive
 377   Klass* elem_klass = ObjArrayKlass::cast(array_klass)->element_klass();
 378   objArrayOop obj = oopFactory::new_objArray(elem_klass, length, CHECK);
 379   thread->set_vm_result(obj);
 380   // This is pretty rare but this runtime patch is stressful to deoptimization
 381   // if we deoptimize here so force a deopt to stress the path.
 382   if (DeoptimizeALot) {
 383     deopt_caller();
 384   }
 385 JRT_END
 386 
 387 
 388 JRT_ENTRY(void, Runtime1::new_multi_array(JavaThread* thread, Klass* klass, int rank, jint* dims))
 389   NOT_PRODUCT(_new_multi_array_slowcase_cnt++;)
 390 
 391   assert(klass->is_klass(), "not a class");
 392   assert(rank >= 1, "rank must be nonzero");
 393   Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
 394   oop obj = ArrayKlass::cast(klass)->multi_allocate(rank, dims, CHECK);
 395   thread->set_vm_result(obj);
 396 JRT_END
 397 
 398 
 399 JRT_ENTRY(void, Runtime1::unimplemented_entry(JavaThread* thread, StubID id))
 400   tty->print_cr("Runtime1::entry_for(%d) returned unimplemented entry point", id);
 401 JRT_END
 402 
 403 
 404 JRT_ENTRY(void, Runtime1::throw_array_store_exception(JavaThread* thread, oopDesc* obj))
 405   ResourceMark rm(thread);
 406   const char* klass_name = obj->klass()->external_name();
 407   SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_ArrayStoreException(), klass_name);
 408 JRT_END
 409 
 410 
 411 // counter_overflow() is called from within C1-compiled methods. The enclosing method is the method
 412 // associated with the top activation record. The inlinee (that is possibly included in the enclosing
 413 // method) method oop is passed as an argument. In order to do that it is embedded in the code as
 414 // a constant.
 415 static nmethod* counter_overflow_helper(JavaThread* THREAD, int branch_bci, Method* m) {
 416   nmethod* osr_nm = NULL;
 417   methodHandle method(THREAD, m);
 418 
 419   RegisterMap map(THREAD, false);
 420   frame fr =  THREAD->last_frame().sender(&map);
 421   nmethod* nm = (nmethod*) fr.cb();
 422   assert(nm!= NULL && nm->is_nmethod(), "Sanity check");
 423   methodHandle enclosing_method(THREAD, nm->method());
 424 
 425   CompLevel level = (CompLevel)nm->comp_level();
 426   int bci = InvocationEntryBci;
 427   if (branch_bci != InvocationEntryBci) {
 428     // Compute destination bci
 429     address pc = method()->code_base() + branch_bci;
 430     Bytecodes::Code branch = Bytecodes::code_at(method(), pc);
 431     int offset = 0;
 432     switch (branch) {
 433       case Bytecodes::_if_icmplt: case Bytecodes::_iflt:
 434       case Bytecodes::_if_icmpgt: case Bytecodes::_ifgt:
 435       case Bytecodes::_if_icmple: case Bytecodes::_ifle:
 436       case Bytecodes::_if_icmpge: case Bytecodes::_ifge:
 437       case Bytecodes::_if_icmpeq: case Bytecodes::_if_acmpeq: case Bytecodes::_ifeq:
 438       case Bytecodes::_if_icmpne: case Bytecodes::_if_acmpne: case Bytecodes::_ifne:
 439       case Bytecodes::_ifnull: case Bytecodes::_ifnonnull: case Bytecodes::_goto:
 440         offset = (int16_t)Bytes::get_Java_u2(pc + 1);
 441         break;
 442       case Bytecodes::_goto_w:
 443         offset = Bytes::get_Java_u4(pc + 1);
 444         break;
 445       default: ;
 446     }
 447     bci = branch_bci + offset;
 448   }
 449   assert(!HAS_PENDING_EXCEPTION, "Should not have any exceptions pending");
 450   osr_nm = CompilationPolicy::policy()->event(enclosing_method, method, branch_bci, bci, level, nm, THREAD);
 451   assert(!HAS_PENDING_EXCEPTION, "Event handler should not throw any exceptions");
 452   return osr_nm;
 453 }
 454 
 455 JRT_BLOCK_ENTRY(address, Runtime1::counter_overflow(JavaThread* thread, int bci, Method* method))
 456   nmethod* osr_nm;
 457   JRT_BLOCK
 458     osr_nm = counter_overflow_helper(thread, bci, method);
 459     if (osr_nm != NULL) {
 460       RegisterMap map(thread, false);
 461       frame fr =  thread->last_frame().sender(&map);
 462       Deoptimization::deoptimize_frame(thread, fr.id());
 463     }
 464   JRT_BLOCK_END
 465   return NULL;
 466 JRT_END
 467 
 468 extern void vm_exit(int code);
 469 
 470 // Enter this method from compiled code handler below. This is where we transition
 471 // to VM mode. This is done as a helper routine so that the method called directly
 472 // from compiled code does not have to transition to VM. This allows the entry
 473 // method to see if the nmethod that we have just looked up a handler for has
 474 // been deoptimized while we were in the vm. This simplifies the assembly code
 475 // cpu directories.
 476 //
 477 // We are entering here from exception stub (via the entry method below)
 478 // If there is a compiled exception handler in this method, we will continue there;
 479 // otherwise we will unwind the stack and continue at the caller of top frame method
 480 // Note: we enter in Java using a special JRT wrapper. This wrapper allows us to
 481 // control the area where we can allow a safepoint. After we exit the safepoint area we can
 482 // check to see if the handler we are going to return is now in a nmethod that has
 483 // been deoptimized. If that is the case we return the deopt blob
 484 // unpack_with_exception entry instead. This makes life for the exception blob easier
 485 // because making that same check and diverting is painful from assembly language.
 486 JRT_ENTRY_NO_ASYNC(static address, exception_handler_for_pc_helper(JavaThread* thread, oopDesc* ex, address pc, nmethod*& nm))
 487   // Reset method handle flag.
 488   thread->set_is_method_handle_return(false);
 489 
 490   Handle exception(thread, ex);
 491   nm = CodeCache::find_nmethod(pc);
 492   assert(nm != NULL, "this is not an nmethod");
 493   // Adjust the pc as needed/
 494   if (nm->is_deopt_pc(pc)) {
 495     RegisterMap map(thread, false);
 496     frame exception_frame = thread->last_frame().sender(&map);
 497     // if the frame isn't deopted then pc must not correspond to the caller of last_frame
 498     assert(exception_frame.is_deoptimized_frame(), "must be deopted");
 499     pc = exception_frame.pc();
 500   }
 501 #ifdef ASSERT
 502   assert(exception.not_null(), "NULL exceptions should be handled by throw_exception");
 503   assert(exception->is_oop(), "just checking");
 504   // Check that exception is a subclass of Throwable, otherwise we have a VerifyError
 505   if (!(exception->is_a(SystemDictionary::Throwable_klass()))) {
 506     if (ExitVMOnVerifyError) vm_exit(-1);
 507     ShouldNotReachHere();
 508   }
 509 #endif
 510 
 511   // Check the stack guard pages and reenable them if necessary and there is
 512   // enough space on the stack to do so.  Use fast exceptions only if the guard
 513   // pages are enabled.
 514   bool guard_pages_enabled = thread->stack_guards_enabled();
 515   if (!guard_pages_enabled) guard_pages_enabled = thread->reguard_stack();
 516 
 517   if (JvmtiExport::can_post_on_exceptions()) {
 518     // To ensure correct notification of exception catches and throws
 519     // we have to deoptimize here.  If we attempted to notify the
 520     // catches and throws during this exception lookup it's possible
 521     // we could deoptimize on the way out of the VM and end back in
 522     // the interpreter at the throw site.  This would result in double
 523     // notifications since the interpreter would also notify about
 524     // these same catches and throws as it unwound the frame.
 525 
 526     RegisterMap reg_map(thread);
 527     frame stub_frame = thread->last_frame();
 528     frame caller_frame = stub_frame.sender(&reg_map);
 529 
 530     // We don't really want to deoptimize the nmethod itself since we
 531     // can actually continue in the exception handler ourselves but I
 532     // don't see an easy way to have the desired effect.
 533     Deoptimization::deoptimize_frame(thread, caller_frame.id());
 534     assert(caller_is_deopted(), "Must be deoptimized");
 535 
 536     return SharedRuntime::deopt_blob()->unpack_with_exception_in_tls();
 537   }
 538 
 539   // ExceptionCache is used only for exceptions at call sites and not for implicit exceptions
 540   if (guard_pages_enabled) {
 541     address fast_continuation = nm->handler_for_exception_and_pc(exception, pc);
 542     if (fast_continuation != NULL) {
 543       // Set flag if return address is a method handle call site.
 544       thread->set_is_method_handle_return(nm->is_method_handle_return(pc));
 545       return fast_continuation;
 546     }
 547   }
 548 
 549   // If the stack guard pages are enabled, check whether there is a handler in
 550   // the current method.  Otherwise (guard pages disabled), force an unwind and
 551   // skip the exception cache update (i.e., just leave continuation==NULL).
 552   address continuation = NULL;
 553   if (guard_pages_enabled) {
 554 
 555     // New exception handling mechanism can support inlined methods
 556     // with exception handlers since the mappings are from PC to PC
 557 
 558     // debugging support
 559     // tracing
 560     if (log_is_enabled(Info, exceptions)) {
 561       ResourceMark rm;
 562       stringStream tempst;
 563       tempst.print("compiled method <%s>\n"
 564                    " at PC" INTPTR_FORMAT " for thread " INTPTR_FORMAT,
 565                    nm->method()->print_value_string(), p2i(pc), p2i(thread));
 566       Exceptions::log_exception(exception, tempst);
 567     }
 568     // for AbortVMOnException flag
 569     Exceptions::debug_check_abort(exception);
 570 
 571     // Clear out the exception oop and pc since looking up an
 572     // exception handler can cause class loading, which might throw an
 573     // exception and those fields are expected to be clear during
 574     // normal bytecode execution.
 575     thread->clear_exception_oop_and_pc();
 576 
 577     Handle original_exception(thread, exception());
 578 
 579     continuation = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, false, false);
 580     // If an exception was thrown during exception dispatch, the exception oop may have changed
 581     thread->set_exception_oop(exception());
 582     thread->set_exception_pc(pc);
 583 
 584     // the exception cache is used only by non-implicit exceptions
 585     // Update the exception cache only when there didn't happen
 586     // another exception during the computation of the compiled
 587     // exception handler.
 588     if (continuation != NULL && original_exception() == exception()) {
 589       nm->add_handler_for_exception_and_pc(exception, pc, continuation);
 590     }
 591   }
 592 
 593   thread->set_vm_result(exception());
 594   // Set flag if return address is a method handle call site.
 595   thread->set_is_method_handle_return(nm->is_method_handle_return(pc));
 596 
 597   if (log_is_enabled(Info, exceptions)) {
 598     ResourceMark rm;
 599     log_info(exceptions)("Thread " PTR_FORMAT " continuing at PC " PTR_FORMAT
 600                          " for exception thrown at PC " PTR_FORMAT,
 601                          p2i(thread), p2i(continuation), p2i(pc));
 602   }
 603 
 604   return continuation;
 605 JRT_END
 606 
 607 // Enter this method from compiled code only if there is a Java exception handler
 608 // in the method handling the exception.
 609 // We are entering here from exception stub. We don't do a normal VM transition here.
 610 // We do it in a helper. This is so we can check to see if the nmethod we have just
 611 // searched for an exception handler has been deoptimized in the meantime.
 612 address Runtime1::exception_handler_for_pc(JavaThread* thread) {
 613   oop exception = thread->exception_oop();
 614   address pc = thread->exception_pc();
 615   // Still in Java mode
 616   DEBUG_ONLY(ResetNoHandleMark rnhm);
 617   nmethod* nm = NULL;
 618   address continuation = NULL;
 619   {
 620     // Enter VM mode by calling the helper
 621     ResetNoHandleMark rnhm;
 622     continuation = exception_handler_for_pc_helper(thread, exception, pc, nm);
 623   }
 624   // Back in JAVA, use no oops DON'T safepoint
 625 
 626   // Now check to see if the nmethod we were called from is now deoptimized.
 627   // If so we must return to the deopt blob and deoptimize the nmethod
 628   if (nm != NULL && caller_is_deopted()) {
 629     continuation = SharedRuntime::deopt_blob()->unpack_with_exception_in_tls();
 630   }
 631 
 632   assert(continuation != NULL, "no handler found");
 633   return continuation;
 634 }
 635 
 636 
 637 JRT_ENTRY(void, Runtime1::throw_range_check_exception(JavaThread* thread, int index))
 638   NOT_PRODUCT(_throw_range_check_exception_count++;)
 639   char message[jintAsStringSize];
 640   sprintf(message, "%d", index);
 641   SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), message);
 642 JRT_END
 643 
 644 
 645 JRT_ENTRY(void, Runtime1::throw_index_exception(JavaThread* thread, int index))
 646   NOT_PRODUCT(_throw_index_exception_count++;)
 647   char message[16];
 648   sprintf(message, "%d", index);
 649   SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_IndexOutOfBoundsException(), message);
 650 JRT_END
 651 
 652 
 653 JRT_ENTRY(void, Runtime1::throw_div0_exception(JavaThread* thread))
 654   NOT_PRODUCT(_throw_div0_exception_count++;)
 655   SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_ArithmeticException(), "/ by zero");
 656 JRT_END
 657 
 658 
 659 JRT_ENTRY(void, Runtime1::throw_null_pointer_exception(JavaThread* thread))
 660   NOT_PRODUCT(_throw_null_pointer_exception_count++;)
 661   SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_NullPointerException());
 662 JRT_END
 663 
 664 
 665 JRT_ENTRY(void, Runtime1::throw_class_cast_exception(JavaThread* thread, oopDesc* object))
 666   NOT_PRODUCT(_throw_class_cast_exception_count++;)
 667   ResourceMark rm(thread);
 668   char* message = SharedRuntime::generate_class_cast_message(
 669     thread, object->klass());
 670   SharedRuntime::throw_and_post_jvmti_exception(
 671     thread, vmSymbols::java_lang_ClassCastException(), message);
 672 JRT_END
 673 
 674 
 675 JRT_ENTRY(void, Runtime1::throw_incompatible_class_change_error(JavaThread* thread))
 676   NOT_PRODUCT(_throw_incompatible_class_change_error_count++;)
 677   ResourceMark rm(thread);
 678   SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_IncompatibleClassChangeError());
 679 JRT_END
 680 
 681 
 682 JRT_ENTRY_NO_ASYNC(void, Runtime1::monitorenter(JavaThread* thread, oopDesc* obj, BasicObjectLock* lock))
 683   NOT_PRODUCT(_monitorenter_slowcase_cnt++;)
 684   if (PrintBiasedLockingStatistics) {
 685     Atomic::inc(BiasedLocking::slow_path_entry_count_addr());
 686   }
 687   Handle h_obj(thread, obj);
 688   assert(h_obj()->is_oop(), "must be NULL or an object");
 689   if (UseBiasedLocking) {
 690     // Retry fast entry if bias is revoked to avoid unnecessary inflation
 691     ObjectSynchronizer::fast_enter(h_obj, lock->lock(), true, CHECK);
 692   } else {
 693     if (UseFastLocking) {
 694       // When using fast locking, the compiled code has already tried the fast case
 695       assert(obj == lock->obj(), "must match");
 696       ObjectSynchronizer::slow_enter(h_obj, lock->lock(), THREAD);
 697     } else {
 698       lock->set_obj(obj);
 699       ObjectSynchronizer::fast_enter(h_obj, lock->lock(), false, THREAD);
 700     }
 701   }
 702 JRT_END
 703 
 704 
 705 JRT_LEAF(void, Runtime1::monitorexit(JavaThread* thread, BasicObjectLock* lock))
 706   NOT_PRODUCT(_monitorexit_slowcase_cnt++;)
 707   assert(thread == JavaThread::current(), "threads must correspond");
 708   assert(thread->last_Java_sp(), "last_Java_sp must be set");
 709   // monitorexit is non-blocking (leaf routine) => no exceptions can be thrown
 710   EXCEPTION_MARK;
 711 
 712   oop obj = lock->obj();
 713   assert(obj->is_oop(), "must be NULL or an object");
 714   if (UseFastLocking) {
 715     // When using fast locking, the compiled code has already tried the fast case
 716     ObjectSynchronizer::slow_exit(obj, lock->lock(), THREAD);
 717   } else {
 718     ObjectSynchronizer::fast_exit(obj, lock->lock(), THREAD);
 719   }
 720 JRT_END
 721 
 722 // Cf. OptoRuntime::deoptimize_caller_frame
 723 JRT_ENTRY(void, Runtime1::deoptimize(JavaThread* thread, jint trap_request))
 724   // Called from within the owner thread, so no need for safepoint
 725   RegisterMap reg_map(thread, false);
 726   frame stub_frame = thread->last_frame();
 727   assert(stub_frame.is_runtime_frame(), "Sanity check");
 728   frame caller_frame = stub_frame.sender(&reg_map);
 729   nmethod* nm = caller_frame.cb()->as_nmethod_or_null();
 730   assert(nm != NULL, "Sanity check");
 731   methodHandle method(thread, nm->method());
 732   assert(nm == CodeCache::find_nmethod(caller_frame.pc()), "Should be the same");
 733   Deoptimization::DeoptAction action = Deoptimization::trap_request_action(trap_request);
 734   Deoptimization::DeoptReason reason = Deoptimization::trap_request_reason(trap_request);
 735 
 736   if (action == Deoptimization::Action_make_not_entrant) {
 737     if (nm->make_not_entrant()) {
 738       if (reason == Deoptimization::Reason_tenured) {
 739         MethodData* trap_mdo = Deoptimization::get_method_data(thread, method, true /*create_if_missing*/);
 740         if (trap_mdo != NULL) {
 741           trap_mdo->inc_tenure_traps();
 742         }
 743       }
 744     }
 745   }
 746 
 747   // Deoptimize the caller frame.
 748   Deoptimization::deoptimize_frame(thread, caller_frame.id());
 749   // Return to the now deoptimized frame.
 750 JRT_END
 751 
 752 
 753 #ifndef DEOPTIMIZE_WHEN_PATCHING
 754 
 755 static Klass* resolve_field_return_klass(methodHandle caller, int bci, TRAPS) {
 756   Bytecode_field field_access(caller, bci);
 757   // This can be static or non-static field access
 758   Bytecodes::Code code       = field_access.code();
 759 
 760   // We must load class, initialize class and resolvethe field
 761   fieldDescriptor result; // initialize class if needed
 762   constantPoolHandle constants(THREAD, caller->constants());
 763   LinkResolver::resolve_field_access(result, constants, field_access.index(), Bytecodes::java_code(code), CHECK_NULL);
 764   return result.field_holder();
 765 }
 766 
 767 
 768 //
 769 // This routine patches sites where a class wasn't loaded or
 770 // initialized at the time the code was generated.  It handles
 771 // references to classes, fields and forcing of initialization.  Most
 772 // of the cases are straightforward and involving simply forcing
 773 // resolution of a class, rewriting the instruction stream with the
 774 // needed constant and replacing the call in this function with the
 775 // patched code.  The case for static field is more complicated since
 776 // the thread which is in the process of initializing a class can
 777 // access it's static fields but other threads can't so the code
 778 // either has to deoptimize when this case is detected or execute a
 779 // check that the current thread is the initializing thread.  The
 780 // current
 781 //
 782 // Patches basically look like this:
 783 //
 784 //
 785 // patch_site: jmp patch stub     ;; will be patched
 786 // continue:   ...
 787 //             ...
 788 //             ...
 789 //             ...
 790 //
 791 // They have a stub which looks like this:
 792 //
 793 //             ;; patch body
 794 //             movl <const>, reg           (for class constants)
 795 //        <or> movl [reg1 + <const>], reg  (for field offsets)
 796 //        <or> movl reg, [reg1 + <const>]  (for field offsets)
 797 //             <being_init offset> <bytes to copy> <bytes to skip>
 798 // patch_stub: call Runtime1::patch_code (through a runtime stub)
 799 //             jmp patch_site
 800 //
 801 //
 802 // A normal patch is done by rewriting the patch body, usually a move,
 803 // and then copying it into place over top of the jmp instruction
 804 // being careful to flush caches and doing it in an MP-safe way.  The
 805 // constants following the patch body are used to find various pieces
 806 // of the patch relative to the call site for Runtime1::patch_code.
 807 // The case for getstatic and putstatic is more complicated because
 808 // getstatic and putstatic have special semantics when executing while
 809 // the class is being initialized.  getstatic/putstatic on a class
 810 // which is being_initialized may be executed by the initializing
 811 // thread but other threads have to block when they execute it.  This
 812 // is accomplished in compiled code by executing a test of the current
 813 // thread against the initializing thread of the class.  It's emitted
 814 // as boilerplate in their stub which allows the patched code to be
 815 // executed before it's copied back into the main body of the nmethod.
 816 //
 817 // being_init: get_thread(<tmp reg>
 818 //             cmpl [reg1 + <init_thread_offset>], <tmp reg>
 819 //             jne patch_stub
 820 //             movl [reg1 + <const>], reg  (for field offsets)  <or>
 821 //             movl reg, [reg1 + <const>]  (for field offsets)
 822 //             jmp continue
 823 //             <being_init offset> <bytes to copy> <bytes to skip>
 824 // patch_stub: jmp Runtim1::patch_code (through a runtime stub)
 825 //             jmp patch_site
 826 //
 827 // If the class is being initialized the patch body is rewritten and
 828 // the patch site is rewritten to jump to being_init, instead of
 829 // patch_stub.  Whenever this code is executed it checks the current
 830 // thread against the intializing thread so other threads will enter
 831 // the runtime and end up blocked waiting the class to finish
 832 // initializing inside the calls to resolve_field below.  The
 833 // initializing class will continue on it's way.  Once the class is
 834 // fully_initialized, the intializing_thread of the class becomes
 835 // NULL, so the next thread to execute this code will fail the test,
 836 // call into patch_code and complete the patching process by copying
 837 // the patch body back into the main part of the nmethod and resume
 838 // executing.
 839 //
 840 //
 841 
 842 JRT_ENTRY(void, Runtime1::patch_code(JavaThread* thread, Runtime1::StubID stub_id ))
 843   NOT_PRODUCT(_patch_code_slowcase_cnt++;)
 844 
 845   ResourceMark rm(thread);
 846   RegisterMap reg_map(thread, false);
 847   frame runtime_frame = thread->last_frame();
 848   frame caller_frame = runtime_frame.sender(&reg_map);
 849 
 850   // last java frame on stack
 851   vframeStream vfst(thread, true);
 852   assert(!vfst.at_end(), "Java frame must exist");
 853 
 854   methodHandle caller_method(THREAD, vfst.method());
 855   // Note that caller_method->code() may not be same as caller_code because of OSR's
 856   // Note also that in the presence of inlining it is not guaranteed
 857   // that caller_method() == caller_code->method()
 858 
 859   int bci = vfst.bci();
 860   Bytecodes::Code code = caller_method()->java_code_at(bci);
 861 
 862   // this is used by assertions in the access_field_patching_id
 863   BasicType patch_field_type = T_ILLEGAL;
 864   bool deoptimize_for_volatile = false;
 865   bool deoptimize_for_atomic = false;
 866   int patch_field_offset = -1;
 867   KlassHandle init_klass(THREAD, NULL); // klass needed by load_klass_patching code
 868   KlassHandle load_klass(THREAD, NULL); // klass needed by load_klass_patching code
 869   Handle mirror(THREAD, NULL);                    // oop needed by load_mirror_patching code
 870   Handle appendix(THREAD, NULL);                  // oop needed by appendix_patching code
 871   bool load_klass_or_mirror_patch_id =
 872     (stub_id == Runtime1::load_klass_patching_id || stub_id == Runtime1::load_mirror_patching_id);
 873 
 874   if (stub_id == Runtime1::access_field_patching_id) {
 875 
 876     Bytecode_field field_access(caller_method, bci);
 877     fieldDescriptor result; // initialize class if needed
 878     Bytecodes::Code code = field_access.code();
 879     constantPoolHandle constants(THREAD, caller_method->constants());
 880     LinkResolver::resolve_field_access(result, constants, field_access.index(), Bytecodes::java_code(code), CHECK);
 881     patch_field_offset = result.offset();
 882 
 883     // If we're patching a field which is volatile then at compile it
 884     // must not have been know to be volatile, so the generated code
 885     // isn't correct for a volatile reference.  The nmethod has to be
 886     // deoptimized so that the code can be regenerated correctly.
 887     // This check is only needed for access_field_patching since this
 888     // is the path for patching field offsets.  load_klass is only
 889     // used for patching references to oops which don't need special
 890     // handling in the volatile case.
 891 
 892     deoptimize_for_volatile = result.access_flags().is_volatile();
 893 
 894     // If we are patching a field which should be atomic, then
 895     // the generated code is not correct either, force deoptimizing.
 896     // We need to only cover T_LONG and T_DOUBLE fields, as we can
 897     // break access atomicity only for them.
 898 
 899     // Strictly speaking, the deoptimizaation on 64-bit platforms
 900     // is unnecessary, and T_LONG stores on 32-bit platforms need
 901     // to be handled by special patching code when AlwaysAtomicAccesses
 902     // becomes product feature. At this point, we are still going
 903     // for the deoptimization for consistency against volatile
 904     // accesses.
 905 
 906     patch_field_type = result.field_type();
 907     deoptimize_for_atomic = (AlwaysAtomicAccesses && (patch_field_type == T_DOUBLE || patch_field_type == T_LONG));
 908 
 909   } else if (load_klass_or_mirror_patch_id) {
 910     Klass* k = NULL;
 911     switch (code) {
 912       case Bytecodes::_putstatic:
 913       case Bytecodes::_getstatic:
 914         { Klass* klass = resolve_field_return_klass(caller_method, bci, CHECK);
 915           init_klass = KlassHandle(THREAD, klass);
 916           mirror = Handle(THREAD, klass->java_mirror());
 917         }
 918         break;
 919       case Bytecodes::_new:
 920         { Bytecode_new bnew(caller_method(), caller_method->bcp_from(bci));
 921           k = caller_method->constants()->klass_at(bnew.index(), CHECK);
 922         }
 923         break;
 924       case Bytecodes::_multianewarray:
 925         { Bytecode_multianewarray mna(caller_method(), caller_method->bcp_from(bci));
 926           k = caller_method->constants()->klass_at(mna.index(), CHECK);
 927         }
 928         break;
 929       case Bytecodes::_instanceof:
 930         { Bytecode_instanceof io(caller_method(), caller_method->bcp_from(bci));
 931           k = caller_method->constants()->klass_at(io.index(), CHECK);
 932         }
 933         break;
 934       case Bytecodes::_checkcast:
 935         { Bytecode_checkcast cc(caller_method(), caller_method->bcp_from(bci));
 936           k = caller_method->constants()->klass_at(cc.index(), CHECK);
 937         }
 938         break;
 939       case Bytecodes::_anewarray:
 940         { Bytecode_anewarray anew(caller_method(), caller_method->bcp_from(bci));
 941           Klass* ek = caller_method->constants()->klass_at(anew.index(), CHECK);
 942           k = ek->array_klass(CHECK);
 943         }
 944         break;
 945       case Bytecodes::_ldc:
 946       case Bytecodes::_ldc_w:
 947         {
 948           Bytecode_loadconstant cc(caller_method, bci);
 949           oop m = cc.resolve_constant(CHECK);
 950           mirror = Handle(THREAD, m);
 951         }
 952         break;
 953       default: fatal("unexpected bytecode for load_klass_or_mirror_patch_id");
 954     }
 955     // convert to handle
 956     load_klass = KlassHandle(THREAD, k);
 957   } else if (stub_id == load_appendix_patching_id) {
 958     Bytecode_invoke bytecode(caller_method, bci);
 959     Bytecodes::Code bc = bytecode.invoke_code();
 960 
 961     CallInfo info;
 962     constantPoolHandle pool(thread, caller_method->constants());
 963     int index = bytecode.index();
 964     LinkResolver::resolve_invoke(info, Handle(), pool, index, bc, CHECK);
 965     switch (bc) {
 966       case Bytecodes::_invokehandle: {
 967         int cache_index = ConstantPool::decode_cpcache_index(index, true);
 968         assert(cache_index >= 0 && cache_index < pool->cache()->length(), "unexpected cache index");
 969         ConstantPoolCacheEntry* cpce = pool->cache()->entry_at(cache_index);
 970         cpce->set_method_handle(pool, info);
 971         appendix = cpce->appendix_if_resolved(pool); // just in case somebody already resolved the entry
 972         break;
 973       }
 974       case Bytecodes::_invokedynamic: {
 975         ConstantPoolCacheEntry* cpce = pool->invokedynamic_cp_cache_entry_at(index);
 976         cpce->set_dynamic_call(pool, info);
 977         appendix = cpce->appendix_if_resolved(pool); // just in case somebody already resolved the entry
 978         break;
 979       }
 980       default: fatal("unexpected bytecode for load_appendix_patching_id");
 981     }
 982   } else {
 983     ShouldNotReachHere();
 984   }
 985 
 986   if (deoptimize_for_volatile || deoptimize_for_atomic) {
 987     // At compile time we assumed the field wasn't volatile/atomic but after
 988     // loading it turns out it was volatile/atomic so we have to throw the
 989     // compiled code out and let it be regenerated.
 990     if (TracePatching) {
 991       if (deoptimize_for_volatile) {
 992         tty->print_cr("Deoptimizing for patching volatile field reference");
 993       }
 994       if (deoptimize_for_atomic) {
 995         tty->print_cr("Deoptimizing for patching atomic field reference");
 996       }
 997     }
 998 
 999     // It's possible the nmethod was invalidated in the last
1000     // safepoint, but if it's still alive then make it not_entrant.
1001     nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());
1002     if (nm != NULL) {
1003       nm->make_not_entrant();
1004     }
1005 
1006     Deoptimization::deoptimize_frame(thread, caller_frame.id());
1007 
1008     // Return to the now deoptimized frame.
1009   }
1010 
1011   // Now copy code back
1012 
1013   {
1014     MutexLockerEx ml_patch (Patching_lock, Mutex::_no_safepoint_check_flag);
1015     //
1016     // Deoptimization may have happened while we waited for the lock.
1017     // In that case we don't bother to do any patching we just return
1018     // and let the deopt happen
1019     if (!caller_is_deopted()) {
1020       NativeGeneralJump* jump = nativeGeneralJump_at(caller_frame.pc());
1021       address instr_pc = jump->jump_destination();
1022       NativeInstruction* ni = nativeInstruction_at(instr_pc);
1023       if (ni->is_jump() ) {
1024         // the jump has not been patched yet
1025         // The jump destination is slow case and therefore not part of the stubs
1026         // (stubs are only for StaticCalls)
1027 
1028         // format of buffer
1029         //    ....
1030         //    instr byte 0     <-- copy_buff
1031         //    instr byte 1
1032         //    ..
1033         //    instr byte n-1
1034         //      n
1035         //    ....             <-- call destination
1036 
1037         address stub_location = caller_frame.pc() + PatchingStub::patch_info_offset();
1038         unsigned char* byte_count = (unsigned char*) (stub_location - 1);
1039         unsigned char* byte_skip = (unsigned char*) (stub_location - 2);
1040         unsigned char* being_initialized_entry_offset = (unsigned char*) (stub_location - 3);
1041         address copy_buff = stub_location - *byte_skip - *byte_count;
1042         address being_initialized_entry = stub_location - *being_initialized_entry_offset;
1043         if (TracePatching) {
1044           ttyLocker ttyl;
1045           tty->print_cr(" Patching %s at bci %d at address " INTPTR_FORMAT "  (%s)", Bytecodes::name(code), bci,
1046                         p2i(instr_pc), (stub_id == Runtime1::access_field_patching_id) ? "field" : "klass");
1047           nmethod* caller_code = CodeCache::find_nmethod(caller_frame.pc());
1048           assert(caller_code != NULL, "nmethod not found");
1049 
1050           // NOTE we use pc() not original_pc() because we already know they are
1051           // identical otherwise we'd have never entered this block of code
1052 
1053           const ImmutableOopMap* map = caller_code->oop_map_for_return_address(caller_frame.pc());
1054           assert(map != NULL, "null check");
1055           map->print();
1056           tty->cr();
1057 
1058           Disassembler::decode(copy_buff, copy_buff + *byte_count, tty);
1059         }
1060         // depending on the code below, do_patch says whether to copy the patch body back into the nmethod
1061         bool do_patch = true;
1062         if (stub_id == Runtime1::access_field_patching_id) {
1063           // The offset may not be correct if the class was not loaded at code generation time.
1064           // Set it now.
1065           NativeMovRegMem* n_move = nativeMovRegMem_at(copy_buff);
1066           assert(n_move->offset() == 0 || (n_move->offset() == 4 && (patch_field_type == T_DOUBLE || patch_field_type == T_LONG)), "illegal offset for type");
1067           assert(patch_field_offset >= 0, "illegal offset");
1068           n_move->add_offset_in_bytes(patch_field_offset);
1069         } else if (load_klass_or_mirror_patch_id) {
1070           // If a getstatic or putstatic is referencing a klass which
1071           // isn't fully initialized, the patch body isn't copied into
1072           // place until initialization is complete.  In this case the
1073           // patch site is setup so that any threads besides the
1074           // initializing thread are forced to come into the VM and
1075           // block.
1076           do_patch = (code != Bytecodes::_getstatic && code != Bytecodes::_putstatic) ||
1077                      InstanceKlass::cast(init_klass())->is_initialized();
1078           NativeGeneralJump* jump = nativeGeneralJump_at(instr_pc);
1079           if (jump->jump_destination() == being_initialized_entry) {
1080             assert(do_patch == true, "initialization must be complete at this point");
1081           } else {
1082             // patch the instruction <move reg, klass>
1083             NativeMovConstReg* n_copy = nativeMovConstReg_at(copy_buff);
1084 
1085             assert(n_copy->data() == 0 ||
1086                    n_copy->data() == (intptr_t)Universe::non_oop_word(),
1087                    "illegal init value");
1088             if (stub_id == Runtime1::load_klass_patching_id) {
1089               assert(load_klass() != NULL, "klass not set");
1090               n_copy->set_data((intx) (load_klass()));
1091             } else {
1092               assert(mirror() != NULL, "klass not set");
1093               // Don't need a G1 pre-barrier here since we assert above that data isn't an oop.
1094               n_copy->set_data(cast_from_oop<intx>(mirror()));
1095             }
1096 
1097             if (TracePatching) {
1098               Disassembler::decode(copy_buff, copy_buff + *byte_count, tty);
1099             }
1100           }
1101         } else if (stub_id == Runtime1::load_appendix_patching_id) {
1102           NativeMovConstReg* n_copy = nativeMovConstReg_at(copy_buff);
1103           assert(n_copy->data() == 0 ||
1104                  n_copy->data() == (intptr_t)Universe::non_oop_word(),
1105                  "illegal init value");
1106           n_copy->set_data(cast_from_oop<intx>(appendix()));
1107 
1108           if (TracePatching) {
1109             Disassembler::decode(copy_buff, copy_buff + *byte_count, tty);
1110           }
1111         } else {
1112           ShouldNotReachHere();
1113         }
1114 
1115 #if defined(SPARC) || defined(PPC32)
1116         if (load_klass_or_mirror_patch_id ||
1117             stub_id == Runtime1::load_appendix_patching_id) {
1118           // Update the location in the nmethod with the proper
1119           // metadata.  When the code was generated, a NULL was stuffed
1120           // in the metadata table and that table needs to be update to
1121           // have the right value.  On intel the value is kept
1122           // directly in the instruction instead of in the metadata
1123           // table, so set_data above effectively updated the value.
1124           nmethod* nm = CodeCache::find_nmethod(instr_pc);
1125           assert(nm != NULL, "invalid nmethod_pc");
1126           RelocIterator mds(nm, copy_buff, copy_buff + 1);
1127           bool found = false;
1128           while (mds.next() && !found) {
1129             if (mds.type() == relocInfo::oop_type) {
1130               assert(stub_id == Runtime1::load_mirror_patching_id ||
1131                      stub_id == Runtime1::load_appendix_patching_id, "wrong stub id");
1132               oop_Relocation* r = mds.oop_reloc();
1133               oop* oop_adr = r->oop_addr();
1134               *oop_adr = stub_id == Runtime1::load_mirror_patching_id ? mirror() : appendix();
1135               r->fix_oop_relocation();
1136               found = true;
1137             } else if (mds.type() == relocInfo::metadata_type) {
1138               assert(stub_id == Runtime1::load_klass_patching_id, "wrong stub id");
1139               metadata_Relocation* r = mds.metadata_reloc();
1140               Metadata** metadata_adr = r->metadata_addr();
1141               *metadata_adr = load_klass();
1142               r->fix_metadata_relocation();
1143               found = true;
1144             }
1145           }
1146           assert(found, "the metadata must exist!");
1147         }
1148 #endif
1149         if (do_patch) {
1150           // replace instructions
1151           // first replace the tail, then the call
1152 #ifdef ARM
1153           if((load_klass_or_mirror_patch_id ||
1154               stub_id == Runtime1::load_appendix_patching_id) &&
1155               nativeMovConstReg_at(copy_buff)->is_pc_relative()) {
1156             nmethod* nm = CodeCache::find_nmethod(instr_pc);
1157             address addr = NULL;
1158             assert(nm != NULL, "invalid nmethod_pc");
1159             RelocIterator mds(nm, copy_buff, copy_buff + 1);
1160             while (mds.next()) {
1161               if (mds.type() == relocInfo::oop_type) {
1162                 assert(stub_id == Runtime1::load_mirror_patching_id ||
1163                        stub_id == Runtime1::load_appendix_patching_id, "wrong stub id");
1164                 oop_Relocation* r = mds.oop_reloc();
1165                 addr = (address)r->oop_addr();
1166                 break;
1167               } else if (mds.type() == relocInfo::metadata_type) {
1168                 assert(stub_id == Runtime1::load_klass_patching_id, "wrong stub id");
1169                 metadata_Relocation* r = mds.metadata_reloc();
1170                 addr = (address)r->metadata_addr();
1171                 break;
1172               }
1173             }
1174             assert(addr != NULL, "metadata relocation must exist");
1175             copy_buff -= *byte_count;
1176             NativeMovConstReg* n_copy2 = nativeMovConstReg_at(copy_buff);
1177             n_copy2->set_pc_relative_offset(addr, instr_pc);
1178           }
1179 #endif
1180 
1181           for (int i = NativeGeneralJump::instruction_size; i < *byte_count; i++) {
1182             address ptr = copy_buff + i;
1183             int a_byte = (*ptr) & 0xFF;
1184             address dst = instr_pc + i;
1185             *(unsigned char*)dst = (unsigned char) a_byte;
1186           }
1187           ICache::invalidate_range(instr_pc, *byte_count);
1188           NativeGeneralJump::replace_mt_safe(instr_pc, copy_buff);
1189 
1190           if (load_klass_or_mirror_patch_id ||
1191               stub_id == Runtime1::load_appendix_patching_id) {
1192             relocInfo::relocType rtype =
1193               (stub_id == Runtime1::load_klass_patching_id) ?
1194                                    relocInfo::metadata_type :
1195                                    relocInfo::oop_type;
1196             // update relocInfo to metadata
1197             nmethod* nm = CodeCache::find_nmethod(instr_pc);
1198             assert(nm != NULL, "invalid nmethod_pc");
1199 
1200             // The old patch site is now a move instruction so update
1201             // the reloc info so that it will get updated during
1202             // future GCs.
1203             RelocIterator iter(nm, (address)instr_pc, (address)(instr_pc + 1));
1204             relocInfo::change_reloc_info_for_address(&iter, (address) instr_pc,
1205                                                      relocInfo::none, rtype);
1206 #ifdef SPARC
1207             // Sparc takes two relocations for an metadata so update the second one.
1208             address instr_pc2 = instr_pc + NativeMovConstReg::add_offset;
1209             RelocIterator iter2(nm, instr_pc2, instr_pc2 + 1);
1210             relocInfo::change_reloc_info_for_address(&iter2, (address) instr_pc2,
1211                                                      relocInfo::none, rtype);
1212 #endif
1213 #ifdef PPC32
1214           { address instr_pc2 = instr_pc + NativeMovConstReg::lo_offset;
1215             RelocIterator iter2(nm, instr_pc2, instr_pc2 + 1);
1216             relocInfo::change_reloc_info_for_address(&iter2, (address) instr_pc2,
1217                                                      relocInfo::none, rtype);
1218           }
1219 #endif
1220           }
1221 
1222         } else {
1223           ICache::invalidate_range(copy_buff, *byte_count);
1224           NativeGeneralJump::insert_unconditional(instr_pc, being_initialized_entry);
1225         }
1226       }
1227     }
1228   }
1229 
1230   // If we are patching in a non-perm oop, make sure the nmethod
1231   // is on the right list.
1232   if (ScavengeRootsInCode && ((mirror.not_null() && mirror()->is_scavengable()) ||
1233                               (appendix.not_null() && appendix->is_scavengable()))) {
1234     MutexLockerEx ml_code (CodeCache_lock, Mutex::_no_safepoint_check_flag);
1235     nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());
1236     guarantee(nm != NULL, "only nmethods can contain non-perm oops");
1237     if (!nm->on_scavenge_root_list()) {
1238       CodeCache::add_scavenge_root_nmethod(nm);
1239     }
1240 
1241     // Since we've patched some oops in the nmethod,
1242     // (re)register it with the heap.
1243     Universe::heap()->register_nmethod(nm);
1244   }
1245 JRT_END
1246 
1247 #else // DEOPTIMIZE_WHEN_PATCHING
1248 
1249 JRT_ENTRY(void, Runtime1::patch_code(JavaThread* thread, Runtime1::StubID stub_id ))
1250   RegisterMap reg_map(thread, false);
1251 
1252   NOT_PRODUCT(_patch_code_slowcase_cnt++;)
1253   if (TracePatching) {
1254     tty->print_cr("Deoptimizing because patch is needed");
1255   }
1256 
1257   frame runtime_frame = thread->last_frame();
1258   frame caller_frame = runtime_frame.sender(&reg_map);
1259 
1260   // It's possible the nmethod was invalidated in the last
1261   // safepoint, but if it's still alive then make it not_entrant.
1262   nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());
1263   if (nm != NULL) {
1264     nm->make_not_entrant();
1265   }
1266 
1267   Deoptimization::deoptimize_frame(thread, caller_frame.id());
1268 
1269   // Return to the now deoptimized frame.
1270 JRT_END
1271 
1272 #endif // DEOPTIMIZE_WHEN_PATCHING
1273 
1274 //
1275 // Entry point for compiled code. We want to patch a nmethod.
1276 // We don't do a normal VM transition here because we want to
1277 // know after the patching is complete and any safepoint(s) are taken
1278 // if the calling nmethod was deoptimized. We do this by calling a
1279 // helper method which does the normal VM transition and when it
1280 // completes we can check for deoptimization. This simplifies the
1281 // assembly code in the cpu directories.
1282 //
1283 int Runtime1::move_klass_patching(JavaThread* thread) {
1284 //
1285 // NOTE: we are still in Java
1286 //
1287   Thread* THREAD = thread;
1288   debug_only(NoHandleMark nhm;)
1289   {
1290     // Enter VM mode
1291 
1292     ResetNoHandleMark rnhm;
1293     patch_code(thread, load_klass_patching_id);
1294   }
1295   // Back in JAVA, use no oops DON'T safepoint
1296 
1297   // Return true if calling code is deoptimized
1298 
1299   return caller_is_deopted();
1300 }
1301 
1302 int Runtime1::move_mirror_patching(JavaThread* thread) {
1303 //
1304 // NOTE: we are still in Java
1305 //
1306   Thread* THREAD = thread;
1307   debug_only(NoHandleMark nhm;)
1308   {
1309     // Enter VM mode
1310 
1311     ResetNoHandleMark rnhm;
1312     patch_code(thread, load_mirror_patching_id);
1313   }
1314   // Back in JAVA, use no oops DON'T safepoint
1315 
1316   // Return true if calling code is deoptimized
1317 
1318   return caller_is_deopted();
1319 }
1320 
1321 int Runtime1::move_appendix_patching(JavaThread* thread) {
1322 //
1323 // NOTE: we are still in Java
1324 //
1325   Thread* THREAD = thread;
1326   debug_only(NoHandleMark nhm;)
1327   {
1328     // Enter VM mode
1329 
1330     ResetNoHandleMark rnhm;
1331     patch_code(thread, load_appendix_patching_id);
1332   }
1333   // Back in JAVA, use no oops DON'T safepoint
1334 
1335   // Return true if calling code is deoptimized
1336 
1337   return caller_is_deopted();
1338 }
1339 //
1340 // Entry point for compiled code. We want to patch a nmethod.
1341 // We don't do a normal VM transition here because we want to
1342 // know after the patching is complete and any safepoint(s) are taken
1343 // if the calling nmethod was deoptimized. We do this by calling a
1344 // helper method which does the normal VM transition and when it
1345 // completes we can check for deoptimization. This simplifies the
1346 // assembly code in the cpu directories.
1347 //
1348 
1349 int Runtime1::access_field_patching(JavaThread* thread) {
1350 //
1351 // NOTE: we are still in Java
1352 //
1353   Thread* THREAD = thread;
1354   debug_only(NoHandleMark nhm;)
1355   {
1356     // Enter VM mode
1357 
1358     ResetNoHandleMark rnhm;
1359     patch_code(thread, access_field_patching_id);
1360   }
1361   // Back in JAVA, use no oops DON'T safepoint
1362 
1363   // Return true if calling code is deoptimized
1364 
1365   return caller_is_deopted();
1366 JRT_END
1367 
1368 
1369 JRT_LEAF(void, Runtime1::trace_block_entry(jint block_id))
1370   // for now we just print out the block id
1371   tty->print("%d ", block_id);
1372 JRT_END
1373 
1374 
1375 // Array copy return codes.
1376 enum {
1377   ac_failed = -1, // arraycopy failed
1378   ac_ok = 0       // arraycopy succeeded
1379 };
1380 
1381 
1382 // Below length is the # elements copied.
1383 template <class T> int obj_arraycopy_work(oopDesc* src, T* src_addr,
1384                                           oopDesc* dst, T* dst_addr,
1385                                           int length) {
1386 
1387   // For performance reasons, we assume we are using a card marking write
1388   // barrier. The assert will fail if this is not the case.
1389   // Note that we use the non-virtual inlineable variant of write_ref_array.
1390   BarrierSet* bs = Universe::heap()->barrier_set();
1391   assert(bs->has_write_ref_array_opt(), "Barrier set must have ref array opt");
1392   assert(bs->has_write_ref_array_pre_opt(), "For pre-barrier as well.");
1393   if (src == dst) {
1394     // same object, no check
1395     bs->write_ref_array_pre(dst_addr, length);
1396     Copy::conjoint_oops_atomic(src_addr, dst_addr, length);
1397     bs->write_ref_array((HeapWord*)dst_addr, length);
1398     return ac_ok;
1399   } else {
1400     Klass* bound = ObjArrayKlass::cast(dst->klass())->element_klass();
1401     Klass* stype = ObjArrayKlass::cast(src->klass())->element_klass();
1402     if (stype == bound || stype->is_subtype_of(bound)) {
1403       // Elements are guaranteed to be subtypes, so no check necessary
1404       bs->write_ref_array_pre(dst_addr, length);
1405       Copy::conjoint_oops_atomic(src_addr, dst_addr, length);
1406       bs->write_ref_array((HeapWord*)dst_addr, length);
1407       return ac_ok;
1408     }
1409   }
1410   return ac_failed;
1411 }
1412 
1413 // fast and direct copy of arrays; returning -1, means that an exception may be thrown
1414 // and we did not copy anything
1415 JRT_LEAF(int, Runtime1::arraycopy(oopDesc* src, int src_pos, oopDesc* dst, int dst_pos, int length))
1416 #ifndef PRODUCT
1417   _generic_arraycopy_cnt++;        // Slow-path oop array copy
1418 #endif
1419 
1420   if (src == NULL || dst == NULL || src_pos < 0 || dst_pos < 0 || length < 0) return ac_failed;
1421   if (!dst->is_array() || !src->is_array()) return ac_failed;
1422   if ((unsigned int) arrayOop(src)->length() < (unsigned int)src_pos + (unsigned int)length) return ac_failed;
1423   if ((unsigned int) arrayOop(dst)->length() < (unsigned int)dst_pos + (unsigned int)length) return ac_failed;
1424 
1425   if (length == 0) return ac_ok;
1426   if (src->is_typeArray()) {
1427     Klass* klass_oop = src->klass();
1428     if (klass_oop != dst->klass()) return ac_failed;
1429     TypeArrayKlass* klass = TypeArrayKlass::cast(klass_oop);
1430     const int l2es = klass->log2_element_size();
1431     const int ihs = klass->array_header_in_bytes() / wordSize;
1432     char* src_addr = (char*) ((oopDesc**)src + ihs) + (src_pos << l2es);
1433     char* dst_addr = (char*) ((oopDesc**)dst + ihs) + (dst_pos << l2es);
1434     // Potential problem: memmove is not guaranteed to be word atomic
1435     // Revisit in Merlin
1436     memmove(dst_addr, src_addr, length << l2es);
1437     return ac_ok;
1438   } else if (src->is_objArray() && dst->is_objArray()) {
1439     if (UseCompressedOops) {
1440       narrowOop *src_addr  = objArrayOop(src)->obj_at_addr<narrowOop>(src_pos);
1441       narrowOop *dst_addr  = objArrayOop(dst)->obj_at_addr<narrowOop>(dst_pos);
1442       return obj_arraycopy_work(src, src_addr, dst, dst_addr, length);
1443     } else {
1444       oop *src_addr  = objArrayOop(src)->obj_at_addr<oop>(src_pos);
1445       oop *dst_addr  = objArrayOop(dst)->obj_at_addr<oop>(dst_pos);
1446       return obj_arraycopy_work(src, src_addr, dst, dst_addr, length);
1447     }
1448   }
1449   return ac_failed;
1450 JRT_END
1451 
1452 
1453 JRT_LEAF(void, Runtime1::primitive_arraycopy(HeapWord* src, HeapWord* dst, int length))
1454 #ifndef PRODUCT
1455   _primitive_arraycopy_cnt++;
1456 #endif
1457 
1458   if (length == 0) return;
1459   // Not guaranteed to be word atomic, but that doesn't matter
1460   // for anything but an oop array, which is covered by oop_arraycopy.
1461   Copy::conjoint_jbytes(src, dst, length);
1462 JRT_END
1463 
1464 JRT_LEAF(void, Runtime1::oop_arraycopy(HeapWord* src, HeapWord* dst, int num))
1465 #ifndef PRODUCT
1466   _oop_arraycopy_cnt++;
1467 #endif
1468 
1469   if (num == 0) return;
1470   BarrierSet* bs = Universe::heap()->barrier_set();
1471   assert(bs->has_write_ref_array_opt(), "Barrier set must have ref array opt");
1472   assert(bs->has_write_ref_array_pre_opt(), "For pre-barrier as well.");
1473   if (UseCompressedOops) {
1474     bs->write_ref_array_pre((narrowOop*)dst, num);
1475     Copy::conjoint_oops_atomic((narrowOop*) src, (narrowOop*) dst, num);
1476   } else {
1477     bs->write_ref_array_pre((oop*)dst, num);
1478     Copy::conjoint_oops_atomic((oop*) src, (oop*) dst, num);
1479   }
1480   bs->write_ref_array(dst, num);
1481 JRT_END
1482 
1483 
1484 JRT_LEAF(int, Runtime1::is_instance_of(oopDesc* mirror, oopDesc* obj))
1485   // had to return int instead of bool, otherwise there may be a mismatch
1486   // between the C calling convention and the Java one.
1487   // e.g., on x86, GCC may clear only %al when returning a bool false, but
1488   // JVM takes the whole %eax as the return value, which may misinterpret
1489   // the return value as a boolean true.
1490 
1491   assert(mirror != NULL, "should null-check on mirror before calling");
1492   Klass* k = java_lang_Class::as_Klass(mirror);
1493   return (k != NULL && obj != NULL && obj->is_a(k)) ? 1 : 0;
1494 JRT_END
1495 
1496 JRT_ENTRY(void, Runtime1::predicate_failed_trap(JavaThread* thread))
1497   ResourceMark rm;
1498 
1499   assert(!TieredCompilation, "incompatible with tiered compilation");
1500 
1501   RegisterMap reg_map(thread, false);
1502   frame runtime_frame = thread->last_frame();
1503   frame caller_frame = runtime_frame.sender(&reg_map);
1504 
1505   nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());
1506   assert (nm != NULL, "no more nmethod?");
1507   nm->make_not_entrant();
1508 
1509   methodHandle m(nm->method());
1510   MethodData* mdo = m->method_data();
1511 
1512   if (mdo == NULL && !HAS_PENDING_EXCEPTION) {
1513     // Build an MDO.  Ignore errors like OutOfMemory;
1514     // that simply means we won't have an MDO to update.
1515     Method::build_interpreter_method_data(m, THREAD);
1516     if (HAS_PENDING_EXCEPTION) {
1517       assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");
1518       CLEAR_PENDING_EXCEPTION;
1519     }
1520     mdo = m->method_data();
1521   }
1522 
1523   if (mdo != NULL) {
1524     mdo->inc_trap_count(Deoptimization::Reason_none);
1525   }
1526 
1527   if (TracePredicateFailedTraps) {
1528     stringStream ss1, ss2;
1529     vframeStream vfst(thread);
1530     methodHandle inlinee = methodHandle(vfst.method());
1531     inlinee->print_short_name(&ss1);
1532     m->print_short_name(&ss2);
1533     tty->print_cr("Predicate failed trap in method %s at bci %d inlined in %s at pc " INTPTR_FORMAT, ss1.as_string(), vfst.bci(), ss2.as_string(), p2i(caller_frame.pc()));
1534   }
1535 
1536 
1537   Deoptimization::deoptimize_frame(thread, caller_frame.id());
1538 
1539 JRT_END
1540 
1541 #ifndef PRODUCT
1542 void Runtime1::print_statistics() {
1543   tty->print_cr("C1 Runtime statistics:");
1544   tty->print_cr(" _resolve_invoke_virtual_cnt:     %d", SharedRuntime::_resolve_virtual_ctr);
1545   tty->print_cr(" _resolve_invoke_opt_virtual_cnt: %d", SharedRuntime::_resolve_opt_virtual_ctr);
1546   tty->print_cr(" _resolve_invoke_static_cnt:      %d", SharedRuntime::_resolve_static_ctr);
1547   tty->print_cr(" _handle_wrong_method_cnt:        %d", SharedRuntime::_wrong_method_ctr);
1548   tty->print_cr(" _ic_miss_cnt:                    %d", SharedRuntime::_ic_miss_ctr);
1549   tty->print_cr(" _generic_arraycopy_cnt:          %d", _generic_arraycopy_cnt);
1550   tty->print_cr(" _generic_arraycopystub_cnt:      %d", _generic_arraycopystub_cnt);
1551   tty->print_cr(" _byte_arraycopy_cnt:             %d", _byte_arraycopy_stub_cnt);
1552   tty->print_cr(" _short_arraycopy_cnt:            %d", _short_arraycopy_stub_cnt);
1553   tty->print_cr(" _int_arraycopy_cnt:              %d", _int_arraycopy_stub_cnt);
1554   tty->print_cr(" _long_arraycopy_cnt:             %d", _long_arraycopy_stub_cnt);
1555   tty->print_cr(" _primitive_arraycopy_cnt:        %d", _primitive_arraycopy_cnt);
1556   tty->print_cr(" _oop_arraycopy_cnt (C):          %d", Runtime1::_oop_arraycopy_cnt);
1557   tty->print_cr(" _oop_arraycopy_cnt (stub):       %d", _oop_arraycopy_stub_cnt);
1558   tty->print_cr(" _arraycopy_slowcase_cnt:         %d", _arraycopy_slowcase_cnt);
1559   tty->print_cr(" _arraycopy_checkcast_cnt:        %d", _arraycopy_checkcast_cnt);
1560   tty->print_cr(" _arraycopy_checkcast_attempt_cnt:%d", _arraycopy_checkcast_attempt_cnt);
1561 
1562   tty->print_cr(" _new_type_array_slowcase_cnt:    %d", _new_type_array_slowcase_cnt);
1563   tty->print_cr(" _new_object_array_slowcase_cnt:  %d", _new_object_array_slowcase_cnt);
1564   tty->print_cr(" _new_instance_slowcase_cnt:      %d", _new_instance_slowcase_cnt);
1565   tty->print_cr(" _new_multi_array_slowcase_cnt:   %d", _new_multi_array_slowcase_cnt);
1566   tty->print_cr(" _monitorenter_slowcase_cnt:      %d", _monitorenter_slowcase_cnt);
1567   tty->print_cr(" _monitorexit_slowcase_cnt:       %d", _monitorexit_slowcase_cnt);
1568   tty->print_cr(" _patch_code_slowcase_cnt:        %d", _patch_code_slowcase_cnt);
1569 
1570   tty->print_cr(" _throw_range_check_exception_count:            %d:", _throw_range_check_exception_count);
1571   tty->print_cr(" _throw_index_exception_count:                  %d:", _throw_index_exception_count);
1572   tty->print_cr(" _throw_div0_exception_count:                   %d:", _throw_div0_exception_count);
1573   tty->print_cr(" _throw_null_pointer_exception_count:           %d:", _throw_null_pointer_exception_count);
1574   tty->print_cr(" _throw_class_cast_exception_count:             %d:", _throw_class_cast_exception_count);
1575   tty->print_cr(" _throw_incompatible_class_change_error_count:  %d:", _throw_incompatible_class_change_error_count);
1576   tty->print_cr(" _throw_array_store_exception_count:            %d:", _throw_array_store_exception_count);
1577   tty->print_cr(" _throw_count:                                  %d:", _throw_count);
1578 
1579   SharedRuntime::print_ic_miss_histogram();
1580   tty->cr();
1581 }
1582 #endif // PRODUCT