< prev index next >

src/hotspot/share/c1/c1_Runtime1.cpp

Print this page

   1 /*
   2  * Copyright (c) 1999, 2024, 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  *

  36 #include "code/codeBlob.hpp"
  37 #include "code/compiledIC.hpp"
  38 #include "code/pcDesc.hpp"
  39 #include "code/scopeDesc.hpp"
  40 #include "code/vtableStubs.hpp"
  41 #include "compiler/compilationPolicy.hpp"
  42 #include "compiler/disassembler.hpp"
  43 #include "compiler/oopMap.hpp"
  44 #include "gc/shared/barrierSet.hpp"
  45 #include "gc/shared/c1/barrierSetC1.hpp"
  46 #include "gc/shared/collectedHeap.hpp"
  47 #include "interpreter/bytecode.hpp"
  48 #include "interpreter/interpreter.hpp"
  49 #include "jfr/support/jfrIntrinsics.hpp"
  50 #include "logging/log.hpp"
  51 #include "memory/allocation.inline.hpp"
  52 #include "memory/oopFactory.hpp"
  53 #include "memory/resourceArea.hpp"
  54 #include "memory/universe.hpp"
  55 #include "oops/access.inline.hpp"


  56 #include "oops/klass.inline.hpp"
  57 #include "oops/objArrayOop.inline.hpp"
  58 #include "oops/objArrayKlass.hpp"
  59 #include "oops/oop.inline.hpp"
  60 #include "prims/jvmtiExport.hpp"
  61 #include "runtime/atomic.hpp"
  62 #include "runtime/fieldDescriptor.inline.hpp"
  63 #include "runtime/frame.inline.hpp"
  64 #include "runtime/handles.inline.hpp"
  65 #include "runtime/interfaceSupport.inline.hpp"
  66 #include "runtime/javaCalls.hpp"
  67 #include "runtime/sharedRuntime.hpp"
  68 #include "runtime/stackWatermarkSet.hpp"
  69 #include "runtime/stubRoutines.hpp"
  70 #include "runtime/threadCritical.hpp"
  71 #include "runtime/vframe.inline.hpp"
  72 #include "runtime/vframeArray.hpp"
  73 #include "runtime/vm_version.hpp"
  74 #include "utilities/copy.hpp"
  75 #include "utilities/events.hpp"

 108 }
 109 
 110 // Implementation of Runtime1
 111 
 112 CodeBlob* Runtime1::_blobs[(int)C1StubId::NUM_STUBIDS];
 113 
 114 #define C1_BLOB_NAME_DEFINE(name)  "C1 Runtime " # name "_blob",
 115 const char *Runtime1::_blob_names[] = {
 116   C1_STUBS_DO(C1_BLOB_NAME_DEFINE)
 117 };
 118 #undef C1_STUB_NAME_DEFINE
 119 
 120 #ifndef PRODUCT
 121 // statistics
 122 uint Runtime1::_generic_arraycopystub_cnt = 0;
 123 uint Runtime1::_arraycopy_slowcase_cnt = 0;
 124 uint Runtime1::_arraycopy_checkcast_cnt = 0;
 125 uint Runtime1::_arraycopy_checkcast_attempt_cnt = 0;
 126 uint Runtime1::_new_type_array_slowcase_cnt = 0;
 127 uint Runtime1::_new_object_array_slowcase_cnt = 0;

 128 uint Runtime1::_new_instance_slowcase_cnt = 0;
 129 uint Runtime1::_new_multi_array_slowcase_cnt = 0;





 130 uint Runtime1::_monitorenter_slowcase_cnt = 0;
 131 uint Runtime1::_monitorexit_slowcase_cnt = 0;
 132 uint Runtime1::_patch_code_slowcase_cnt = 0;
 133 uint Runtime1::_throw_range_check_exception_count = 0;
 134 uint Runtime1::_throw_index_exception_count = 0;
 135 uint Runtime1::_throw_div0_exception_count = 0;
 136 uint Runtime1::_throw_null_pointer_exception_count = 0;
 137 uint Runtime1::_throw_class_cast_exception_count = 0;
 138 uint Runtime1::_throw_incompatible_class_change_error_count = 0;


 139 uint Runtime1::_throw_count = 0;
 140 
 141 static uint _byte_arraycopy_stub_cnt = 0;
 142 static uint _short_arraycopy_stub_cnt = 0;
 143 static uint _int_arraycopy_stub_cnt = 0;
 144 static uint _long_arraycopy_stub_cnt = 0;
 145 static uint _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;

 338   FUNCTION_CASE(entry, JfrTime::time_function());
 339 #endif
 340   FUNCTION_CASE(entry, StubRoutines::updateBytesCRC32());
 341   FUNCTION_CASE(entry, StubRoutines::updateBytesCRC32C());
 342   FUNCTION_CASE(entry, StubRoutines::vectorizedMismatch());
 343   FUNCTION_CASE(entry, StubRoutines::dexp());
 344   FUNCTION_CASE(entry, StubRoutines::dlog());
 345   FUNCTION_CASE(entry, StubRoutines::dlog10());
 346   FUNCTION_CASE(entry, StubRoutines::dpow());
 347   FUNCTION_CASE(entry, StubRoutines::dsin());
 348   FUNCTION_CASE(entry, StubRoutines::dcos());
 349   FUNCTION_CASE(entry, StubRoutines::dtan());
 350   FUNCTION_CASE(entry, StubRoutines::dtanh());
 351 
 352 #undef FUNCTION_CASE
 353 
 354   // Soft float adds more runtime names.
 355   return pd_name_for_address(entry);
 356 }
 357 
 358 
 359 JRT_ENTRY(void, Runtime1::new_instance(JavaThread* current, Klass* klass))
 360 #ifndef PRODUCT
 361   if (PrintC1Statistics) {
 362     _new_instance_slowcase_cnt++;
 363   }
 364 #endif
 365   assert(klass->is_klass(), "not a class");
 366   Handle holder(current, klass->klass_holder()); // keep the klass alive
 367   InstanceKlass* h = InstanceKlass::cast(klass);
 368   h->check_valid_for_instantiation(true, CHECK);
 369   // make sure klass is initialized
 370   h->initialize(CHECK);
 371   // allocate instance and return via TLS
 372   oop obj = h->allocate_instance(CHECK);






 373   current->set_vm_result(obj);
 374 JRT_END
 375 



 376 
 377 JRT_ENTRY(void, Runtime1::new_type_array(JavaThread* current, Klass* klass, jint length))
 378 #ifndef PRODUCT
 379   if (PrintC1Statistics) {
 380     _new_type_array_slowcase_cnt++;
 381   }
 382 #endif
 383   // Note: no handle for klass needed since they are not used
 384   //       anymore after new_typeArray() and no GC can happen before.
 385   //       (This may have to change if this code changes!)
 386   assert(klass->is_klass(), "not a class");
 387   BasicType elt_type = TypeArrayKlass::cast(klass)->element_type();
 388   oop obj = oopFactory::new_typeArray(elt_type, length, CHECK);
 389   current->set_vm_result(obj);
 390   // This is pretty rare but this runtime patch is stressful to deoptimization
 391   // if we deoptimize here so force a deopt to stress the path.
 392   if (DeoptimizeALot) {
 393     deopt_caller(current);
 394   }
 395 
 396 JRT_END
 397 
 398 
 399 JRT_ENTRY(void, Runtime1::new_object_array(JavaThread* current, Klass* array_klass, jint length))
 400 #ifndef PRODUCT
 401   if (PrintC1Statistics) {
 402     _new_object_array_slowcase_cnt++;
 403   }
 404 #endif
 405   // Note: no handle for klass needed since they are not used
 406   //       anymore after new_objArray() and no GC can happen before.
 407   //       (This may have to change if this code changes!)
 408   assert(array_klass->is_klass(), "not a class");
 409   Handle holder(current, array_klass->klass_holder()); // keep the klass alive
 410   Klass* elem_klass = ObjArrayKlass::cast(array_klass)->element_klass();
 411   objArrayOop obj = oopFactory::new_objArray(elem_klass, length, CHECK);
 412   current->set_vm_result(obj);
 413   // This is pretty rare but this runtime patch is stressful to deoptimization
 414   // if we deoptimize here so force a deopt to stress the path.
 415   if (DeoptimizeALot) {
 416     deopt_caller(current);
 417   }
 418 JRT_END
 419 
 420 





























 421 JRT_ENTRY(void, Runtime1::new_multi_array(JavaThread* current, Klass* klass, int rank, jint* dims))
 422 #ifndef PRODUCT
 423   if (PrintC1Statistics) {
 424     _new_multi_array_slowcase_cnt++;
 425   }
 426 #endif
 427   assert(klass->is_klass(), "not a class");
 428   assert(rank >= 1, "rank must be nonzero");
 429   Handle holder(current, klass->klass_holder()); // keep the klass alive
 430   oop obj = ArrayKlass::cast(klass)->multi_allocate(rank, dims, CHECK);
 431   current->set_vm_result(obj);
 432 JRT_END
 433 
 434 




























































































 435 JRT_ENTRY(void, Runtime1::unimplemented_entry(JavaThread* current, C1StubId id))
 436   tty->print_cr("Runtime1::entry_for(%d) returned unimplemented entry point", (int)id);
 437 JRT_END
 438 
 439 
 440 JRT_ENTRY(void, Runtime1::throw_array_store_exception(JavaThread* current, oopDesc* obj))
 441   ResourceMark rm(current);
 442   const char* klass_name = obj->klass()->external_name();
 443   SharedRuntime::throw_and_post_jvmti_exception(current, vmSymbols::java_lang_ArrayStoreException(), klass_name);
 444 JRT_END
 445 
 446 
 447 // counter_overflow() is called from within C1-compiled methods. The enclosing method is the method
 448 // associated with the top activation record. The inlinee (that is possibly included in the enclosing
 449 // method) method is passed as an argument. In order to do that it is embedded in the code as
 450 // a constant.
 451 static nmethod* counter_overflow_helper(JavaThread* current, int branch_bci, Method* m) {
 452   nmethod* osr_nm = nullptr;
 453   methodHandle method(current, m);
 454 

 738     _throw_class_cast_exception_count++;
 739   }
 740 #endif
 741   ResourceMark rm(current);
 742   char* message = SharedRuntime::generate_class_cast_message(current, object->klass());
 743   SharedRuntime::throw_and_post_jvmti_exception(current, vmSymbols::java_lang_ClassCastException(), message);
 744 JRT_END
 745 
 746 
 747 JRT_ENTRY(void, Runtime1::throw_incompatible_class_change_error(JavaThread* current))
 748 #ifndef PRODUCT
 749   if (PrintC1Statistics) {
 750     _throw_incompatible_class_change_error_count++;
 751   }
 752 #endif
 753   ResourceMark rm(current);
 754   SharedRuntime::throw_and_post_jvmti_exception(current, vmSymbols::java_lang_IncompatibleClassChangeError());
 755 JRT_END
 756 
 757 













 758 JRT_BLOCK_ENTRY(void, Runtime1::monitorenter(JavaThread* current, oopDesc* obj, BasicObjectLock* lock))
 759 #ifndef PRODUCT
 760   if (PrintC1Statistics) {
 761     _monitorenter_slowcase_cnt++;
 762   }
 763 #endif
 764   if (LockingMode == LM_MONITOR) {
 765     lock->set_obj(obj);
 766   }
 767   assert(obj == lock->obj(), "must match");
 768   SharedRuntime::monitor_enter_helper(obj, lock->lock(), current);
 769 JRT_END
 770 
 771 
 772 JRT_LEAF(void, Runtime1::monitorexit(JavaThread* current, BasicObjectLock* lock))
 773   assert(current == JavaThread::current(), "pre-condition");
 774 #ifndef PRODUCT
 775   if (PrintC1Statistics) {
 776     _monitorexit_slowcase_cnt++;
 777   }

 943                       RegisterMap::WalkContinuation::skip);
 944   frame runtime_frame = current->last_frame();
 945   frame caller_frame = runtime_frame.sender(&reg_map);
 946 
 947   // last java frame on stack
 948   vframeStream vfst(current, true);
 949   assert(!vfst.at_end(), "Java frame must exist");
 950 
 951   methodHandle caller_method(current, vfst.method());
 952   // Note that caller_method->code() may not be same as caller_code because of OSR's
 953   // Note also that in the presence of inlining it is not guaranteed
 954   // that caller_method() == caller_code->method()
 955 
 956   int bci = vfst.bci();
 957   Bytecodes::Code code = caller_method()->java_code_at(bci);
 958 
 959   // this is used by assertions in the access_field_patching_id
 960   BasicType patch_field_type = T_ILLEGAL;
 961   bool deoptimize_for_volatile = false;
 962   bool deoptimize_for_atomic = false;


 963   int patch_field_offset = -1;
 964   Klass* init_klass = nullptr; // klass needed by load_klass_patching code
 965   Klass* load_klass = nullptr; // klass needed by load_klass_patching code
 966   Handle mirror(current, nullptr); // oop needed by load_mirror_patching code
 967   Handle appendix(current, nullptr); // oop needed by appendix_patching code
 968   bool load_klass_or_mirror_patch_id =
 969     (stub_id == C1StubId::load_klass_patching_id || stub_id == C1StubId::load_mirror_patching_id);
 970 
 971   if (stub_id == C1StubId::access_field_patching_id) {
 972 
 973     Bytecode_field field_access(caller_method, bci);
 974     fieldDescriptor result; // initialize class if needed
 975     Bytecodes::Code code = field_access.code();
 976     constantPoolHandle constants(current, caller_method->constants());
 977     LinkResolver::resolve_field_access(result, constants, field_access.index(), caller_method, Bytecodes::java_code(code), CHECK);
 978     patch_field_offset = result.offset();
 979 
 980     // If we're patching a field which is volatile then at compile it
 981     // must not have been know to be volatile, so the generated code
 982     // isn't correct for a volatile reference.  The nmethod has to be

 986     // used for patching references to oops which don't need special
 987     // handling in the volatile case.
 988 
 989     deoptimize_for_volatile = result.access_flags().is_volatile();
 990 
 991     // If we are patching a field which should be atomic, then
 992     // the generated code is not correct either, force deoptimizing.
 993     // We need to only cover T_LONG and T_DOUBLE fields, as we can
 994     // break access atomicity only for them.
 995 
 996     // Strictly speaking, the deoptimization on 64-bit platforms
 997     // is unnecessary, and T_LONG stores on 32-bit platforms need
 998     // to be handled by special patching code when AlwaysAtomicAccesses
 999     // becomes product feature. At this point, we are still going
1000     // for the deoptimization for consistency against volatile
1001     // accesses.
1002 
1003     patch_field_type = result.field_type();
1004     deoptimize_for_atomic = (AlwaysAtomicAccesses && (patch_field_type == T_DOUBLE || patch_field_type == T_LONG));
1005 










1006   } else if (load_klass_or_mirror_patch_id) {
1007     Klass* k = nullptr;
1008     switch (code) {
1009       case Bytecodes::_putstatic:
1010       case Bytecodes::_getstatic:
1011         { Klass* klass = resolve_field_return_klass(caller_method, bci, CHECK);
1012           init_klass = klass;
1013           mirror = Handle(current, klass->java_mirror());
1014         }
1015         break;
1016       case Bytecodes::_new:
1017         { Bytecode_new bnew(caller_method(), caller_method->bcp_from(bci));
1018           k = caller_method->constants()->klass_at(bnew.index(), CHECK);
1019         }
1020         break;
1021       case Bytecodes::_multianewarray:
1022         { Bytecode_multianewarray mna(caller_method(), caller_method->bcp_from(bci));
1023           k = caller_method->constants()->klass_at(mna.index(), CHECK);
1024         }
1025         break;

1058     CallInfo info;
1059     constantPoolHandle pool(current, 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         ResolvedMethodEntry* entry = pool->cache()->set_method_handle(index, info);
1065         appendix = Handle(current, pool->cache()->appendix_if_resolved(entry));
1066         break;
1067       }
1068       case Bytecodes::_invokedynamic: {
1069         appendix = Handle(current, pool->cache()->set_dynamic_call(info, index));
1070         break;
1071       }
1072       default: fatal("unexpected bytecode for load_appendix_patching_id");
1073     }
1074   } else {
1075     ShouldNotReachHere();
1076   }
1077 
1078   if (deoptimize_for_volatile || deoptimize_for_atomic) {
1079     // At compile time we assumed the field wasn't volatile/atomic but after
1080     // loading it turns out it was volatile/atomic so we have to throw the
1081     // compiled code out and let it be regenerated.
1082     if (TracePatching) {
1083       if (deoptimize_for_volatile) {
1084         tty->print_cr("Deoptimizing for patching volatile field reference");
1085       }
1086       if (deoptimize_for_atomic) {
1087         tty->print_cr("Deoptimizing for patching atomic field reference");
1088       }






1089     }
1090 
1091     // It's possible the nmethod was invalidated in the last
1092     // safepoint, but if it's still alive then make it not_entrant.
1093     nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());
1094     if (nm != nullptr) {
1095       nm->make_not_entrant();
1096     }
1097 
1098     Deoptimization::deoptimize_frame(current, caller_frame.id());
1099 
1100     // Return to the now deoptimized frame.
1101   }
1102 
1103   // Now copy code back
1104 
1105   {
1106     MutexLocker ml_code (current, CodeCache_lock, Mutex::_no_safepoint_check_flag);
1107     //
1108     // Deoptimization may have happened while we waited for the lock.

1519 #ifndef PRODUCT
1520 void Runtime1::print_statistics() {
1521   tty->print_cr("C1 Runtime statistics:");
1522   tty->print_cr(" _resolve_invoke_virtual_cnt:     %u", SharedRuntime::_resolve_virtual_ctr);
1523   tty->print_cr(" _resolve_invoke_opt_virtual_cnt: %u", SharedRuntime::_resolve_opt_virtual_ctr);
1524   tty->print_cr(" _resolve_invoke_static_cnt:      %u", SharedRuntime::_resolve_static_ctr);
1525   tty->print_cr(" _handle_wrong_method_cnt:        %u", SharedRuntime::_wrong_method_ctr);
1526   tty->print_cr(" _ic_miss_cnt:                    %u", SharedRuntime::_ic_miss_ctr);
1527   tty->print_cr(" _generic_arraycopystub_cnt:      %u", _generic_arraycopystub_cnt);
1528   tty->print_cr(" _byte_arraycopy_cnt:             %u", _byte_arraycopy_stub_cnt);
1529   tty->print_cr(" _short_arraycopy_cnt:            %u", _short_arraycopy_stub_cnt);
1530   tty->print_cr(" _int_arraycopy_cnt:              %u", _int_arraycopy_stub_cnt);
1531   tty->print_cr(" _long_arraycopy_cnt:             %u", _long_arraycopy_stub_cnt);
1532   tty->print_cr(" _oop_arraycopy_cnt:              %u", _oop_arraycopy_stub_cnt);
1533   tty->print_cr(" _arraycopy_slowcase_cnt:         %u", _arraycopy_slowcase_cnt);
1534   tty->print_cr(" _arraycopy_checkcast_cnt:        %u", _arraycopy_checkcast_cnt);
1535   tty->print_cr(" _arraycopy_checkcast_attempt_cnt:%u", _arraycopy_checkcast_attempt_cnt);
1536 
1537   tty->print_cr(" _new_type_array_slowcase_cnt:    %u", _new_type_array_slowcase_cnt);
1538   tty->print_cr(" _new_object_array_slowcase_cnt:  %u", _new_object_array_slowcase_cnt);

1539   tty->print_cr(" _new_instance_slowcase_cnt:      %u", _new_instance_slowcase_cnt);
1540   tty->print_cr(" _new_multi_array_slowcase_cnt:   %u", _new_multi_array_slowcase_cnt);






1541   tty->print_cr(" _monitorenter_slowcase_cnt:      %u", _monitorenter_slowcase_cnt);
1542   tty->print_cr(" _monitorexit_slowcase_cnt:       %u", _monitorexit_slowcase_cnt);
1543   tty->print_cr(" _patch_code_slowcase_cnt:        %u", _patch_code_slowcase_cnt);
1544 
1545   tty->print_cr(" _throw_range_check_exception_count:            %u:", _throw_range_check_exception_count);
1546   tty->print_cr(" _throw_index_exception_count:                  %u:", _throw_index_exception_count);
1547   tty->print_cr(" _throw_div0_exception_count:                   %u:", _throw_div0_exception_count);
1548   tty->print_cr(" _throw_null_pointer_exception_count:           %u:", _throw_null_pointer_exception_count);
1549   tty->print_cr(" _throw_class_cast_exception_count:             %u:", _throw_class_cast_exception_count);
1550   tty->print_cr(" _throw_incompatible_class_change_error_count:  %u:", _throw_incompatible_class_change_error_count);


1551   tty->print_cr(" _throw_count:                                  %u:", _throw_count);
1552 
1553   SharedRuntime::print_ic_miss_histogram();
1554   tty->cr();
1555 }
1556 #endif // PRODUCT

   1 /*
   2  * Copyright (c) 1999, 2025, 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  *

  36 #include "code/codeBlob.hpp"
  37 #include "code/compiledIC.hpp"
  38 #include "code/pcDesc.hpp"
  39 #include "code/scopeDesc.hpp"
  40 #include "code/vtableStubs.hpp"
  41 #include "compiler/compilationPolicy.hpp"
  42 #include "compiler/disassembler.hpp"
  43 #include "compiler/oopMap.hpp"
  44 #include "gc/shared/barrierSet.hpp"
  45 #include "gc/shared/c1/barrierSetC1.hpp"
  46 #include "gc/shared/collectedHeap.hpp"
  47 #include "interpreter/bytecode.hpp"
  48 #include "interpreter/interpreter.hpp"
  49 #include "jfr/support/jfrIntrinsics.hpp"
  50 #include "logging/log.hpp"
  51 #include "memory/allocation.inline.hpp"
  52 #include "memory/oopFactory.hpp"
  53 #include "memory/resourceArea.hpp"
  54 #include "memory/universe.hpp"
  55 #include "oops/access.inline.hpp"
  56 #include "oops/flatArrayKlass.hpp"
  57 #include "oops/flatArrayOop.inline.hpp"
  58 #include "oops/klass.inline.hpp"
  59 #include "oops/objArrayOop.inline.hpp"
  60 #include "oops/objArrayKlass.hpp"
  61 #include "oops/oop.inline.hpp"
  62 #include "prims/jvmtiExport.hpp"
  63 #include "runtime/atomic.hpp"
  64 #include "runtime/fieldDescriptor.inline.hpp"
  65 #include "runtime/frame.inline.hpp"
  66 #include "runtime/handles.inline.hpp"
  67 #include "runtime/interfaceSupport.inline.hpp"
  68 #include "runtime/javaCalls.hpp"
  69 #include "runtime/sharedRuntime.hpp"
  70 #include "runtime/stackWatermarkSet.hpp"
  71 #include "runtime/stubRoutines.hpp"
  72 #include "runtime/threadCritical.hpp"
  73 #include "runtime/vframe.inline.hpp"
  74 #include "runtime/vframeArray.hpp"
  75 #include "runtime/vm_version.hpp"
  76 #include "utilities/copy.hpp"
  77 #include "utilities/events.hpp"

 110 }
 111 
 112 // Implementation of Runtime1
 113 
 114 CodeBlob* Runtime1::_blobs[(int)C1StubId::NUM_STUBIDS];
 115 
 116 #define C1_BLOB_NAME_DEFINE(name)  "C1 Runtime " # name "_blob",
 117 const char *Runtime1::_blob_names[] = {
 118   C1_STUBS_DO(C1_BLOB_NAME_DEFINE)
 119 };
 120 #undef C1_STUB_NAME_DEFINE
 121 
 122 #ifndef PRODUCT
 123 // statistics
 124 uint Runtime1::_generic_arraycopystub_cnt = 0;
 125 uint Runtime1::_arraycopy_slowcase_cnt = 0;
 126 uint Runtime1::_arraycopy_checkcast_cnt = 0;
 127 uint Runtime1::_arraycopy_checkcast_attempt_cnt = 0;
 128 uint Runtime1::_new_type_array_slowcase_cnt = 0;
 129 uint Runtime1::_new_object_array_slowcase_cnt = 0;
 130 uint Runtime1::_new_null_free_array_slowcase_cnt = 0;
 131 uint Runtime1::_new_instance_slowcase_cnt = 0;
 132 uint Runtime1::_new_multi_array_slowcase_cnt = 0;
 133 uint Runtime1::_load_flat_array_slowcase_cnt = 0;
 134 uint Runtime1::_store_flat_array_slowcase_cnt = 0;
 135 uint Runtime1::_substitutability_check_slowcase_cnt = 0;
 136 uint Runtime1::_buffer_inline_args_slowcase_cnt = 0;
 137 uint Runtime1::_buffer_inline_args_no_receiver_slowcase_cnt = 0;
 138 uint Runtime1::_monitorenter_slowcase_cnt = 0;
 139 uint Runtime1::_monitorexit_slowcase_cnt = 0;
 140 uint Runtime1::_patch_code_slowcase_cnt = 0;
 141 uint Runtime1::_throw_range_check_exception_count = 0;
 142 uint Runtime1::_throw_index_exception_count = 0;
 143 uint Runtime1::_throw_div0_exception_count = 0;
 144 uint Runtime1::_throw_null_pointer_exception_count = 0;
 145 uint Runtime1::_throw_class_cast_exception_count = 0;
 146 uint Runtime1::_throw_incompatible_class_change_error_count = 0;
 147 uint Runtime1::_throw_illegal_monitor_state_exception_count = 0;
 148 uint Runtime1::_throw_identity_exception_count = 0;
 149 uint Runtime1::_throw_count = 0;
 150 
 151 static uint _byte_arraycopy_stub_cnt = 0;
 152 static uint _short_arraycopy_stub_cnt = 0;
 153 static uint _int_arraycopy_stub_cnt = 0;
 154 static uint _long_arraycopy_stub_cnt = 0;
 155 static uint _oop_arraycopy_stub_cnt = 0;
 156 
 157 address Runtime1::arraycopy_count_address(BasicType type) {
 158   switch (type) {
 159   case T_BOOLEAN:
 160   case T_BYTE:   return (address)&_byte_arraycopy_stub_cnt;
 161   case T_CHAR:
 162   case T_SHORT:  return (address)&_short_arraycopy_stub_cnt;
 163   case T_FLOAT:
 164   case T_INT:    return (address)&_int_arraycopy_stub_cnt;
 165   case T_DOUBLE:
 166   case T_LONG:   return (address)&_long_arraycopy_stub_cnt;
 167   case T_ARRAY:
 168   case T_OBJECT: return (address)&_oop_arraycopy_stub_cnt;

 348   FUNCTION_CASE(entry, JfrTime::time_function());
 349 #endif
 350   FUNCTION_CASE(entry, StubRoutines::updateBytesCRC32());
 351   FUNCTION_CASE(entry, StubRoutines::updateBytesCRC32C());
 352   FUNCTION_CASE(entry, StubRoutines::vectorizedMismatch());
 353   FUNCTION_CASE(entry, StubRoutines::dexp());
 354   FUNCTION_CASE(entry, StubRoutines::dlog());
 355   FUNCTION_CASE(entry, StubRoutines::dlog10());
 356   FUNCTION_CASE(entry, StubRoutines::dpow());
 357   FUNCTION_CASE(entry, StubRoutines::dsin());
 358   FUNCTION_CASE(entry, StubRoutines::dcos());
 359   FUNCTION_CASE(entry, StubRoutines::dtan());
 360   FUNCTION_CASE(entry, StubRoutines::dtanh());
 361 
 362 #undef FUNCTION_CASE
 363 
 364   // Soft float adds more runtime names.
 365   return pd_name_for_address(entry);
 366 }
 367 
 368 static void allocate_instance(JavaThread* current, Klass* klass, TRAPS) {

 369 #ifndef PRODUCT
 370   if (PrintC1Statistics) {
 371     Runtime1::_new_instance_slowcase_cnt++;
 372   }
 373 #endif
 374   assert(klass->is_klass(), "not a class");
 375   Handle holder(current, klass->klass_holder()); // keep the klass alive
 376   InstanceKlass* h = InstanceKlass::cast(klass);
 377   h->check_valid_for_instantiation(true, CHECK);
 378   // make sure klass is initialized
 379   h->initialize(CHECK);
 380   oop obj = nullptr;
 381   if (h->is_inline_klass() &&  InlineKlass::cast(h)->is_empty_inline_type()) {
 382     obj = InlineKlass::cast(h)->default_value();
 383     assert(obj != nullptr, "default value must exist");
 384   } else {
 385     // allocate instance and return via TLS
 386     obj = h->allocate_instance(CHECK);
 387   }
 388   current->set_vm_result(obj);
 389 JRT_END
 390 
 391 JRT_ENTRY(void, Runtime1::new_instance(JavaThread* current, Klass* klass))
 392   allocate_instance(current, klass, CHECK);
 393 JRT_END
 394 
 395 JRT_ENTRY(void, Runtime1::new_type_array(JavaThread* current, Klass* klass, jint length))
 396 #ifndef PRODUCT
 397   if (PrintC1Statistics) {
 398     _new_type_array_slowcase_cnt++;
 399   }
 400 #endif
 401   // Note: no handle for klass needed since they are not used
 402   //       anymore after new_typeArray() and no GC can happen before.
 403   //       (This may have to change if this code changes!)
 404   assert(klass->is_klass(), "not a class");
 405   BasicType elt_type = TypeArrayKlass::cast(klass)->element_type();
 406   oop obj = oopFactory::new_typeArray(elt_type, length, CHECK);
 407   current->set_vm_result(obj);
 408   // This is pretty rare but this runtime patch is stressful to deoptimization
 409   // if we deoptimize here so force a deopt to stress the path.
 410   if (DeoptimizeALot) {
 411     deopt_caller(current);
 412   }
 413 
 414 JRT_END
 415 
 416 
 417 JRT_ENTRY(void, Runtime1::new_object_array(JavaThread* current, Klass* array_klass, jint length))
 418 #ifndef PRODUCT
 419   if (PrintC1Statistics) {
 420     _new_object_array_slowcase_cnt++;
 421   }
 422 #endif
 423   // Note: no handle for klass needed since they are not used
 424   //       anymore after new_objArray() and no GC can happen before.
 425   //       (This may have to change if this code changes!)
 426   assert(array_klass->is_klass(), "not a class");
 427   Handle holder(current, array_klass->klass_holder()); // keep the klass alive
 428   Klass* elem_klass = ArrayKlass::cast(array_klass)->element_klass();
 429   objArrayOop obj = oopFactory::new_objArray(elem_klass, length, CHECK);
 430   current->set_vm_result(obj);
 431   // This is pretty rare but this runtime patch is stressful to deoptimization
 432   // if we deoptimize here so force a deopt to stress the path.
 433   if (DeoptimizeALot) {
 434     deopt_caller(current);
 435   }
 436 JRT_END
 437 
 438 
 439 JRT_ENTRY(void, Runtime1::new_null_free_array(JavaThread* current, Klass* array_klass, jint length))
 440   NOT_PRODUCT(_new_null_free_array_slowcase_cnt++;)
 441 
 442   // Note: no handle for klass needed since they are not used
 443   //       anymore after new_objArray() and no GC can happen before.
 444   //       (This may have to change if this code changes!)
 445   assert(array_klass->is_klass(), "not a class");
 446   Handle holder(THREAD, array_klass->klass_holder()); // keep the klass alive
 447   Klass* elem_klass = ArrayKlass::cast(array_klass)->element_klass();
 448   assert(elem_klass->is_inline_klass(), "must be");
 449   InlineKlass* vk = InlineKlass::cast(elem_klass);
 450   // Logically creates elements, ensure klass init
 451   elem_klass->initialize(CHECK);
 452   arrayOop obj= nullptr;
 453   //  Limitation here, only non-atomic layouts are supported
 454   if (UseFlatArray && vk->has_non_atomic_layout()) {
 455     obj = oopFactory::new_flatArray(elem_klass, length, LayoutKind::NON_ATOMIC_FLAT, CHECK);
 456   } else {
 457     obj = oopFactory::new_null_free_objArray(elem_klass, length, CHECK);
 458   }
 459   current->set_vm_result(obj);
 460   // This is pretty rare but this runtime patch is stressful to deoptimization
 461   // if we deoptimize here so force a deopt to stress the path.
 462   if (DeoptimizeALot) {
 463     deopt_caller(current);
 464   }
 465 JRT_END
 466 
 467 
 468 JRT_ENTRY(void, Runtime1::new_multi_array(JavaThread* current, Klass* klass, int rank, jint* dims))
 469 #ifndef PRODUCT
 470   if (PrintC1Statistics) {
 471     _new_multi_array_slowcase_cnt++;
 472   }
 473 #endif
 474   assert(klass->is_klass(), "not a class");
 475   assert(rank >= 1, "rank must be nonzero");
 476   Handle holder(current, klass->klass_holder()); // keep the klass alive
 477   oop obj = ArrayKlass::cast(klass)->multi_allocate(rank, dims, CHECK);
 478   current->set_vm_result(obj);
 479 JRT_END
 480 
 481 
 482 static void profile_flat_array(JavaThread* current, bool load) {
 483   ResourceMark rm(current);
 484   vframeStream vfst(current, true);
 485   assert(!vfst.at_end(), "Java frame must exist");
 486   // Check if array access profiling is enabled
 487   if (vfst.nm()->comp_level() != CompLevel_full_profile || !C1UpdateMethodData) {
 488     return;
 489   }
 490   int bci = vfst.bci();
 491   Method* method = vfst.method();
 492   MethodData* md = method->method_data();
 493   if (md != nullptr) {
 494     // Lock to access ProfileData, and ensure lock is not broken by a safepoint
 495     MutexLocker ml(md->extra_data_lock(), Mutex::_no_safepoint_check_flag);
 496 
 497     ProfileData* data = md->bci_to_data(bci);
 498     assert(data != nullptr, "incorrect profiling entry");
 499     if (data->is_ArrayLoadData()) {
 500       assert(load, "should be an array load");
 501       ArrayLoadData* load_data = (ArrayLoadData*) data;
 502       load_data->set_flat_array();
 503     } else {
 504       assert(data->is_ArrayStoreData(), "");
 505       assert(!load, "should be an array store");
 506       ArrayStoreData* store_data = (ArrayStoreData*) data;
 507       store_data->set_flat_array();
 508     }
 509   }
 510 }
 511 
 512 JRT_ENTRY(void, Runtime1::load_flat_array(JavaThread* current, flatArrayOopDesc* array, int index))
 513   assert(array->klass()->is_flatArray_klass(), "should not be called");
 514   profile_flat_array(current, true);
 515 
 516   NOT_PRODUCT(_load_flat_array_slowcase_cnt++;)
 517   assert(array->length() > 0 && index < array->length(), "already checked");
 518   flatArrayHandle vah(current, array);
 519   oop obj = array->read_value_from_flat_array(index, CHECK);
 520   current->set_vm_result(obj);
 521 JRT_END
 522 
 523 
 524 JRT_ENTRY(void, Runtime1::store_flat_array(JavaThread* current, flatArrayOopDesc* array, int index, oopDesc* value))
 525   if (array->klass()->is_flatArray_klass()) {
 526     profile_flat_array(current, false);
 527   }
 528 
 529   NOT_PRODUCT(_store_flat_array_slowcase_cnt++;)
 530   if (value == nullptr) {
 531     assert(array->klass()->is_flatArray_klass() || array->klass()->is_null_free_array_klass(), "should not be called");
 532     SharedRuntime::throw_and_post_jvmti_exception(current, vmSymbols::java_lang_NullPointerException());
 533   } else {
 534     assert(array->klass()->is_flatArray_klass(), "should not be called");
 535     array->write_value_to_flat_array(value, index, CHECK);
 536   }
 537 JRT_END
 538 
 539 
 540 JRT_ENTRY(int, Runtime1::substitutability_check(JavaThread* current, oopDesc* left, oopDesc* right))
 541   NOT_PRODUCT(_substitutability_check_slowcase_cnt++;)
 542   JavaCallArguments args;
 543   args.push_oop(Handle(THREAD, left));
 544   args.push_oop(Handle(THREAD, right));
 545   JavaValue result(T_BOOLEAN);
 546   JavaCalls::call_static(&result,
 547                          vmClasses::ValueObjectMethods_klass(),
 548                          vmSymbols::isSubstitutable_name(),
 549                          vmSymbols::object_object_boolean_signature(),
 550                          &args, CHECK_0);
 551   return result.get_jboolean() ? 1 : 0;
 552 JRT_END
 553 
 554 
 555 extern "C" void ps();
 556 
 557 void Runtime1::buffer_inline_args_impl(JavaThread* current, Method* m, bool allocate_receiver) {
 558   JavaThread* THREAD = current;
 559   methodHandle method(current, m); // We are inside the verified_entry or verified_inline_ro_entry of this method.
 560   oop obj = SharedRuntime::allocate_inline_types_impl(current, method, allocate_receiver, CHECK);
 561   current->set_vm_result(obj);
 562 }
 563 
 564 JRT_ENTRY(void, Runtime1::buffer_inline_args(JavaThread* current, Method* method))
 565   NOT_PRODUCT(_buffer_inline_args_slowcase_cnt++;)
 566   buffer_inline_args_impl(current, method, true);
 567 JRT_END
 568 
 569 JRT_ENTRY(void, Runtime1::buffer_inline_args_no_receiver(JavaThread* current, Method* method))
 570   NOT_PRODUCT(_buffer_inline_args_no_receiver_slowcase_cnt++;)
 571   buffer_inline_args_impl(current, method, false);
 572 JRT_END
 573 
 574 JRT_ENTRY(void, Runtime1::unimplemented_entry(JavaThread* current, C1StubId id))
 575   tty->print_cr("Runtime1::entry_for(%d) returned unimplemented entry point", (int)id);
 576 JRT_END
 577 
 578 
 579 JRT_ENTRY(void, Runtime1::throw_array_store_exception(JavaThread* current, oopDesc* obj))
 580   ResourceMark rm(current);
 581   const char* klass_name = obj->klass()->external_name();
 582   SharedRuntime::throw_and_post_jvmti_exception(current, vmSymbols::java_lang_ArrayStoreException(), klass_name);
 583 JRT_END
 584 
 585 
 586 // counter_overflow() is called from within C1-compiled methods. The enclosing method is the method
 587 // associated with the top activation record. The inlinee (that is possibly included in the enclosing
 588 // method) method is passed as an argument. In order to do that it is embedded in the code as
 589 // a constant.
 590 static nmethod* counter_overflow_helper(JavaThread* current, int branch_bci, Method* m) {
 591   nmethod* osr_nm = nullptr;
 592   methodHandle method(current, m);
 593 

 877     _throw_class_cast_exception_count++;
 878   }
 879 #endif
 880   ResourceMark rm(current);
 881   char* message = SharedRuntime::generate_class_cast_message(current, object->klass());
 882   SharedRuntime::throw_and_post_jvmti_exception(current, vmSymbols::java_lang_ClassCastException(), message);
 883 JRT_END
 884 
 885 
 886 JRT_ENTRY(void, Runtime1::throw_incompatible_class_change_error(JavaThread* current))
 887 #ifndef PRODUCT
 888   if (PrintC1Statistics) {
 889     _throw_incompatible_class_change_error_count++;
 890   }
 891 #endif
 892   ResourceMark rm(current);
 893   SharedRuntime::throw_and_post_jvmti_exception(current, vmSymbols::java_lang_IncompatibleClassChangeError());
 894 JRT_END
 895 
 896 
 897 JRT_ENTRY(void, Runtime1::throw_illegal_monitor_state_exception(JavaThread* current))
 898   NOT_PRODUCT(_throw_illegal_monitor_state_exception_count++;)
 899   ResourceMark rm(current);
 900   SharedRuntime::throw_and_post_jvmti_exception(current, vmSymbols::java_lang_IllegalMonitorStateException());
 901 JRT_END
 902 
 903 JRT_ENTRY(void, Runtime1::throw_identity_exception(JavaThread* current, oopDesc* object))
 904   NOT_PRODUCT(_throw_identity_exception_count++;)
 905   ResourceMark rm(current);
 906   char* message = SharedRuntime::generate_identity_exception_message(current, object->klass());
 907   SharedRuntime::throw_and_post_jvmti_exception(current, vmSymbols::java_lang_IdentityException(), message);
 908 JRT_END
 909 
 910 JRT_BLOCK_ENTRY(void, Runtime1::monitorenter(JavaThread* current, oopDesc* obj, BasicObjectLock* lock))
 911 #ifndef PRODUCT
 912   if (PrintC1Statistics) {
 913     _monitorenter_slowcase_cnt++;
 914   }
 915 #endif
 916   if (LockingMode == LM_MONITOR) {
 917     lock->set_obj(obj);
 918   }
 919   assert(obj == lock->obj(), "must match");
 920   SharedRuntime::monitor_enter_helper(obj, lock->lock(), current);
 921 JRT_END
 922 
 923 
 924 JRT_LEAF(void, Runtime1::monitorexit(JavaThread* current, BasicObjectLock* lock))
 925   assert(current == JavaThread::current(), "pre-condition");
 926 #ifndef PRODUCT
 927   if (PrintC1Statistics) {
 928     _monitorexit_slowcase_cnt++;
 929   }

1095                       RegisterMap::WalkContinuation::skip);
1096   frame runtime_frame = current->last_frame();
1097   frame caller_frame = runtime_frame.sender(&reg_map);
1098 
1099   // last java frame on stack
1100   vframeStream vfst(current, true);
1101   assert(!vfst.at_end(), "Java frame must exist");
1102 
1103   methodHandle caller_method(current, vfst.method());
1104   // Note that caller_method->code() may not be same as caller_code because of OSR's
1105   // Note also that in the presence of inlining it is not guaranteed
1106   // that caller_method() == caller_code->method()
1107 
1108   int bci = vfst.bci();
1109   Bytecodes::Code code = caller_method()->java_code_at(bci);
1110 
1111   // this is used by assertions in the access_field_patching_id
1112   BasicType patch_field_type = T_ILLEGAL;
1113   bool deoptimize_for_volatile = false;
1114   bool deoptimize_for_atomic = false;
1115   bool deoptimize_for_null_free = false;
1116   bool deoptimize_for_flat = false;
1117   int patch_field_offset = -1;
1118   Klass* init_klass = nullptr; // klass needed by load_klass_patching code
1119   Klass* load_klass = nullptr; // klass needed by load_klass_patching code
1120   Handle mirror(current, nullptr); // oop needed by load_mirror_patching code
1121   Handle appendix(current, nullptr); // oop needed by appendix_patching code
1122   bool load_klass_or_mirror_patch_id =
1123     (stub_id == C1StubId::load_klass_patching_id || stub_id == C1StubId::load_mirror_patching_id);
1124 
1125   if (stub_id == C1StubId::access_field_patching_id) {
1126 
1127     Bytecode_field field_access(caller_method, bci);
1128     fieldDescriptor result; // initialize class if needed
1129     Bytecodes::Code code = field_access.code();
1130     constantPoolHandle constants(current, caller_method->constants());
1131     LinkResolver::resolve_field_access(result, constants, field_access.index(), caller_method, Bytecodes::java_code(code), CHECK);
1132     patch_field_offset = result.offset();
1133 
1134     // If we're patching a field which is volatile then at compile it
1135     // must not have been know to be volatile, so the generated code
1136     // isn't correct for a volatile reference.  The nmethod has to be

1140     // used for patching references to oops which don't need special
1141     // handling in the volatile case.
1142 
1143     deoptimize_for_volatile = result.access_flags().is_volatile();
1144 
1145     // If we are patching a field which should be atomic, then
1146     // the generated code is not correct either, force deoptimizing.
1147     // We need to only cover T_LONG and T_DOUBLE fields, as we can
1148     // break access atomicity only for them.
1149 
1150     // Strictly speaking, the deoptimization on 64-bit platforms
1151     // is unnecessary, and T_LONG stores on 32-bit platforms need
1152     // to be handled by special patching code when AlwaysAtomicAccesses
1153     // becomes product feature. At this point, we are still going
1154     // for the deoptimization for consistency against volatile
1155     // accesses.
1156 
1157     patch_field_type = result.field_type();
1158     deoptimize_for_atomic = (AlwaysAtomicAccesses && (patch_field_type == T_DOUBLE || patch_field_type == T_LONG));
1159 
1160     // The field we are patching is null-free. Deoptimize and regenerate
1161     // the compiled code if we patch a putfield/putstatic because it
1162     // does not contain the required null check.
1163     deoptimize_for_null_free = result.is_null_free_inline_type() && (field_access.is_putfield() || field_access.is_putstatic());
1164 
1165     // The field we are patching is flat. Deoptimize and regenerate
1166     // the compiled code which can't handle the layout of the flat
1167     // field because it was unknown at compile time.
1168     deoptimize_for_flat = result.is_flat();
1169 
1170   } else if (load_klass_or_mirror_patch_id) {
1171     Klass* k = nullptr;
1172     switch (code) {
1173       case Bytecodes::_putstatic:
1174       case Bytecodes::_getstatic:
1175         { Klass* klass = resolve_field_return_klass(caller_method, bci, CHECK);
1176           init_klass = klass;
1177           mirror = Handle(current, klass->java_mirror());
1178         }
1179         break;
1180       case Bytecodes::_new:
1181         { Bytecode_new bnew(caller_method(), caller_method->bcp_from(bci));
1182           k = caller_method->constants()->klass_at(bnew.index(), CHECK);
1183         }
1184         break;
1185       case Bytecodes::_multianewarray:
1186         { Bytecode_multianewarray mna(caller_method(), caller_method->bcp_from(bci));
1187           k = caller_method->constants()->klass_at(mna.index(), CHECK);
1188         }
1189         break;

1222     CallInfo info;
1223     constantPoolHandle pool(current, caller_method->constants());
1224     int index = bytecode.index();
1225     LinkResolver::resolve_invoke(info, Handle(), pool, index, bc, CHECK);
1226     switch (bc) {
1227       case Bytecodes::_invokehandle: {
1228         ResolvedMethodEntry* entry = pool->cache()->set_method_handle(index, info);
1229         appendix = Handle(current, pool->cache()->appendix_if_resolved(entry));
1230         break;
1231       }
1232       case Bytecodes::_invokedynamic: {
1233         appendix = Handle(current, pool->cache()->set_dynamic_call(info, index));
1234         break;
1235       }
1236       default: fatal("unexpected bytecode for load_appendix_patching_id");
1237     }
1238   } else {
1239     ShouldNotReachHere();
1240   }
1241 
1242   if (deoptimize_for_volatile || deoptimize_for_atomic || deoptimize_for_null_free || deoptimize_for_flat) {
1243     // At compile time we assumed the field wasn't volatile/atomic but after
1244     // loading it turns out it was volatile/atomic so we have to throw the
1245     // compiled code out and let it be regenerated.
1246     if (TracePatching) {
1247       if (deoptimize_for_volatile) {
1248         tty->print_cr("Deoptimizing for patching volatile field reference");
1249       }
1250       if (deoptimize_for_atomic) {
1251         tty->print_cr("Deoptimizing for patching atomic field reference");
1252       }
1253       if (deoptimize_for_null_free) {
1254         tty->print_cr("Deoptimizing for patching null-free field reference");
1255       }
1256       if (deoptimize_for_flat) {
1257         tty->print_cr("Deoptimizing for patching flat field reference");
1258       }
1259     }
1260 
1261     // It's possible the nmethod was invalidated in the last
1262     // safepoint, but if it's still alive then make it not_entrant.
1263     nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());
1264     if (nm != nullptr) {
1265       nm->make_not_entrant();
1266     }
1267 
1268     Deoptimization::deoptimize_frame(current, caller_frame.id());
1269 
1270     // Return to the now deoptimized frame.
1271   }
1272 
1273   // Now copy code back
1274 
1275   {
1276     MutexLocker ml_code (current, CodeCache_lock, Mutex::_no_safepoint_check_flag);
1277     //
1278     // Deoptimization may have happened while we waited for the lock.

1689 #ifndef PRODUCT
1690 void Runtime1::print_statistics() {
1691   tty->print_cr("C1 Runtime statistics:");
1692   tty->print_cr(" _resolve_invoke_virtual_cnt:     %u", SharedRuntime::_resolve_virtual_ctr);
1693   tty->print_cr(" _resolve_invoke_opt_virtual_cnt: %u", SharedRuntime::_resolve_opt_virtual_ctr);
1694   tty->print_cr(" _resolve_invoke_static_cnt:      %u", SharedRuntime::_resolve_static_ctr);
1695   tty->print_cr(" _handle_wrong_method_cnt:        %u", SharedRuntime::_wrong_method_ctr);
1696   tty->print_cr(" _ic_miss_cnt:                    %u", SharedRuntime::_ic_miss_ctr);
1697   tty->print_cr(" _generic_arraycopystub_cnt:      %u", _generic_arraycopystub_cnt);
1698   tty->print_cr(" _byte_arraycopy_cnt:             %u", _byte_arraycopy_stub_cnt);
1699   tty->print_cr(" _short_arraycopy_cnt:            %u", _short_arraycopy_stub_cnt);
1700   tty->print_cr(" _int_arraycopy_cnt:              %u", _int_arraycopy_stub_cnt);
1701   tty->print_cr(" _long_arraycopy_cnt:             %u", _long_arraycopy_stub_cnt);
1702   tty->print_cr(" _oop_arraycopy_cnt:              %u", _oop_arraycopy_stub_cnt);
1703   tty->print_cr(" _arraycopy_slowcase_cnt:         %u", _arraycopy_slowcase_cnt);
1704   tty->print_cr(" _arraycopy_checkcast_cnt:        %u", _arraycopy_checkcast_cnt);
1705   tty->print_cr(" _arraycopy_checkcast_attempt_cnt:%u", _arraycopy_checkcast_attempt_cnt);
1706 
1707   tty->print_cr(" _new_type_array_slowcase_cnt:    %u", _new_type_array_slowcase_cnt);
1708   tty->print_cr(" _new_object_array_slowcase_cnt:  %u", _new_object_array_slowcase_cnt);
1709   tty->print_cr(" _new_null_free_array_slowcase_cnt: %u", _new_null_free_array_slowcase_cnt);
1710   tty->print_cr(" _new_instance_slowcase_cnt:      %u", _new_instance_slowcase_cnt);
1711   tty->print_cr(" _new_multi_array_slowcase_cnt:   %u", _new_multi_array_slowcase_cnt);
1712   tty->print_cr(" _load_flat_array_slowcase_cnt:   %u", _load_flat_array_slowcase_cnt);
1713   tty->print_cr(" _store_flat_array_slowcase_cnt:  %u", _store_flat_array_slowcase_cnt);
1714   tty->print_cr(" _substitutability_check_slowcase_cnt: %u", _substitutability_check_slowcase_cnt);
1715   tty->print_cr(" _buffer_inline_args_slowcase_cnt:%u", _buffer_inline_args_slowcase_cnt);
1716   tty->print_cr(" _buffer_inline_args_no_receiver_slowcase_cnt:%u", _buffer_inline_args_no_receiver_slowcase_cnt);
1717 
1718   tty->print_cr(" _monitorenter_slowcase_cnt:      %u", _monitorenter_slowcase_cnt);
1719   tty->print_cr(" _monitorexit_slowcase_cnt:       %u", _monitorexit_slowcase_cnt);
1720   tty->print_cr(" _patch_code_slowcase_cnt:        %u", _patch_code_slowcase_cnt);
1721 
1722   tty->print_cr(" _throw_range_check_exception_count:            %u:", _throw_range_check_exception_count);
1723   tty->print_cr(" _throw_index_exception_count:                  %u:", _throw_index_exception_count);
1724   tty->print_cr(" _throw_div0_exception_count:                   %u:", _throw_div0_exception_count);
1725   tty->print_cr(" _throw_null_pointer_exception_count:           %u:", _throw_null_pointer_exception_count);
1726   tty->print_cr(" _throw_class_cast_exception_count:             %u:", _throw_class_cast_exception_count);
1727   tty->print_cr(" _throw_incompatible_class_change_error_count:  %u:", _throw_incompatible_class_change_error_count);
1728   tty->print_cr(" _throw_illegal_monitor_state_exception_count:  %u:", _throw_illegal_monitor_state_exception_count);
1729   tty->print_cr(" _throw_identity_exception_count:               %u:", _throw_identity_exception_count);
1730   tty->print_cr(" _throw_count:                                  %u:", _throw_count);
1731 
1732   SharedRuntime::print_ic_miss_histogram();
1733   tty->cr();
1734 }
1735 #endif // PRODUCT
< prev index next >