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