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