51 #include "oops/klass.hpp"
52 #include "oops/method.inline.hpp"
53 #include "oops/objArrayKlass.hpp"
54 #include "oops/oop.inline.hpp"
55 #include "prims/forte.hpp"
56 #include "prims/jvmtiExport.hpp"
57 #include "prims/jvmtiThreadState.hpp"
58 #include "prims/methodHandles.hpp"
59 #include "prims/nativeLookup.hpp"
60 #include "runtime/arguments.hpp"
61 #include "runtime/atomicAccess.hpp"
62 #include "runtime/basicLock.inline.hpp"
63 #include "runtime/frame.inline.hpp"
64 #include "runtime/handles.inline.hpp"
65 #include "runtime/init.hpp"
66 #include "runtime/interfaceSupport.inline.hpp"
67 #include "runtime/java.hpp"
68 #include "runtime/javaCalls.hpp"
69 #include "runtime/jniHandles.inline.hpp"
70 #include "runtime/osThread.hpp"
71 #include "runtime/perfData.hpp"
72 #include "runtime/sharedRuntime.hpp"
73 #include "runtime/stackWatermarkSet.hpp"
74 #include "runtime/stubRoutines.hpp"
75 #include "runtime/synchronizer.hpp"
76 #include "runtime/timerTrace.hpp"
77 #include "runtime/vframe.inline.hpp"
78 #include "runtime/vframeArray.hpp"
79 #include "runtime/vm_version.hpp"
80 #include "utilities/copy.hpp"
81 #include "utilities/dtrace.hpp"
82 #include "utilities/events.hpp"
83 #include "utilities/globalDefinitions.hpp"
84 #include "utilities/hashTable.hpp"
85 #include "utilities/macros.hpp"
86 #include "utilities/xmlstream.hpp"
87 #ifdef COMPILER1
88 #include "c1/c1_Runtime1.hpp"
89 #endif
90 #if INCLUDE_JFR
91 #include "jfr/jfr.inline.hpp"
92 #endif
93
94 // Shared runtime stub routines reside in their own unique blob with a
95 // single entry point
96
97
98 #define SHARED_STUB_FIELD_DEFINE(name, type) \
99 type* SharedRuntime::BLOB_FIELD_NAME(name);
100 SHARED_STUBS_DO(SHARED_STUB_FIELD_DEFINE)
101 #undef SHARED_STUB_FIELD_DEFINE
102
103 nmethod* SharedRuntime::_cont_doYield_stub;
104
105 #if 0
106 // TODO tweak global stub name generation to match this
107 #define SHARED_STUB_NAME_DECLARE(name, type) "Shared Runtime " # name "_blob",
108 const char *SharedRuntime::_stub_names[] = {
109 SHARED_STUBS_DO(SHARED_STUB_NAME_DECLARE)
110 };
111 #endif
112
113 //----------------------------generate_stubs-----------------------------------
114 void SharedRuntime::generate_initial_stubs() {
115 // Build this early so it's available for the interpreter.
116 _throw_StackOverflowError_blob =
117 generate_throw_exception(StubId::shared_throw_StackOverflowError_id,
118 CAST_FROM_FN_PTR(address, SharedRuntime::throw_StackOverflowError));
119 }
120
121 void SharedRuntime::generate_stubs() {
122 _wrong_method_blob =
123 generate_resolve_blob(StubId::shared_wrong_method_id,
124 CAST_FROM_FN_PTR(address, SharedRuntime::handle_wrong_method));
154 generate_throw_exception(StubId::shared_throw_NullPointerException_at_call_id,
155 CAST_FROM_FN_PTR(address, SharedRuntime::throw_NullPointerException_at_call));
156
157 #if COMPILER2_OR_JVMCI
158 // Vectors are generated only by C2 and JVMCI.
159 bool support_wide = is_wide_vector(MaxVectorSize);
160 if (support_wide) {
161 _polling_page_vectors_safepoint_handler_blob =
162 generate_handler_blob(StubId::shared_polling_page_vectors_safepoint_handler_id,
163 CAST_FROM_FN_PTR(address, SafepointSynchronize::handle_polling_page_exception));
164 }
165 #endif // COMPILER2_OR_JVMCI
166 _polling_page_safepoint_handler_blob =
167 generate_handler_blob(StubId::shared_polling_page_safepoint_handler_id,
168 CAST_FROM_FN_PTR(address, SafepointSynchronize::handle_polling_page_exception));
169 _polling_page_return_handler_blob =
170 generate_handler_blob(StubId::shared_polling_page_return_handler_id,
171 CAST_FROM_FN_PTR(address, SafepointSynchronize::handle_polling_page_exception));
172
173 generate_deopt_blob();
174 }
175
176 void SharedRuntime::init_adapter_library() {
177 AdapterHandlerLibrary::initialize();
178 }
179
180 #if INCLUDE_JFR
181 //------------------------------generate jfr runtime stubs ------
182 void SharedRuntime::generate_jfr_stubs() {
183 ResourceMark rm;
184 const char* timer_msg = "SharedRuntime generate_jfr_stubs";
185 TraceTime timer(timer_msg, TRACETIME_LOG(Info, startuptime));
186
187 _jfr_write_checkpoint_blob = generate_jfr_write_checkpoint();
188 _jfr_return_lease_blob = generate_jfr_return_lease();
189 }
190
191 #endif // INCLUDE_JFR
192
193 #include <math.h>
194
195 // Implementation of SharedRuntime
196
197 #ifndef PRODUCT
198 // For statistics
199 uint SharedRuntime::_ic_miss_ctr = 0;
200 uint SharedRuntime::_wrong_method_ctr = 0;
201 uint SharedRuntime::_resolve_static_ctr = 0;
202 uint SharedRuntime::_resolve_virtual_ctr = 0;
203 uint SharedRuntime::_resolve_opt_virtual_ctr = 0;
204 uint SharedRuntime::_implicit_null_throws = 0;
205 uint SharedRuntime::_implicit_div0_throws = 0;
206
207 int64_t SharedRuntime::_nof_normal_calls = 0;
208 int64_t SharedRuntime::_nof_inlined_calls = 0;
209 int64_t SharedRuntime::_nof_megamorphic_calls = 0;
210 int64_t SharedRuntime::_nof_static_calls = 0;
211 int64_t SharedRuntime::_nof_inlined_static_calls = 0;
212 int64_t SharedRuntime::_nof_interface_calls = 0;
213 int64_t SharedRuntime::_nof_inlined_interface_calls = 0;
214
215 uint SharedRuntime::_new_instance_ctr=0;
216 uint SharedRuntime::_new_array_ctr=0;
217 uint SharedRuntime::_multi2_ctr=0;
218 uint SharedRuntime::_multi3_ctr=0;
219 uint SharedRuntime::_multi4_ctr=0;
220 uint SharedRuntime::_multi5_ctr=0;
221 uint SharedRuntime::_mon_enter_stub_ctr=0;
222 uint SharedRuntime::_mon_exit_stub_ctr=0;
223 uint SharedRuntime::_mon_enter_ctr=0;
237 uint SharedRuntime::_unsafe_set_memory_ctr=0;
238
239 int SharedRuntime::_ICmiss_index = 0;
240 int SharedRuntime::_ICmiss_count[SharedRuntime::maxICmiss_count];
241 address SharedRuntime::_ICmiss_at[SharedRuntime::maxICmiss_count];
242
243
244 void SharedRuntime::trace_ic_miss(address at) {
245 for (int i = 0; i < _ICmiss_index; i++) {
246 if (_ICmiss_at[i] == at) {
247 _ICmiss_count[i]++;
248 return;
249 }
250 }
251 int index = _ICmiss_index++;
252 if (_ICmiss_index >= maxICmiss_count) _ICmiss_index = maxICmiss_count - 1;
253 _ICmiss_at[index] = at;
254 _ICmiss_count[index] = 1;
255 }
256
257 void SharedRuntime::print_ic_miss_histogram() {
258 if (ICMissHistogram) {
259 tty->print_cr("IC Miss Histogram:");
260 int tot_misses = 0;
261 for (int i = 0; i < _ICmiss_index; i++) {
262 tty->print_cr(" at: " INTPTR_FORMAT " nof: %d", p2i(_ICmiss_at[i]), _ICmiss_count[i]);
263 tot_misses += _ICmiss_count[i];
264 }
265 tty->print_cr("Total IC misses: %7d", tot_misses);
266 }
267 }
268
269 #ifdef COMPILER2
270 // Runtime methods for printf-style debug nodes (same printing format as fieldDescriptor::print_on_for)
271 void SharedRuntime::debug_print_value(jboolean x) {
272 tty->print_cr("boolean %d", x);
273 }
274
275 void SharedRuntime::debug_print_value(jbyte x) {
276 tty->print_cr("byte %d", x);
277 }
278
279 void SharedRuntime::debug_print_value(jshort x) {
280 tty->print_cr("short %d", x);
281 }
282
283 void SharedRuntime::debug_print_value(jchar x) {
284 tty->print_cr("char %c %d", isprint(x) ? x : ' ', x);
285 }
754 jobject vthread = JNIHandles::make_local(const_cast<oopDesc*>(vt));
755 JvmtiVTMSTransitionDisabler::VTMS_vthread_unmount(vthread, hide);
756 JNIHandles::destroy_local(vthread);
757 JRT_END
758 #endif // INCLUDE_JVMTI
759
760 // The interpreter code to call this tracing function is only
761 // called/generated when UL is on for redefine, class and has the right level
762 // and tags. Since obsolete methods are never compiled, we don't have
763 // to modify the compilers to generate calls to this function.
764 //
765 JRT_LEAF(int, SharedRuntime::rc_trace_method_entry(
766 JavaThread* thread, Method* method))
767 if (method->is_obsolete()) {
768 // We are calling an obsolete method, but this is not necessarily
769 // an error. Our method could have been redefined just after we
770 // fetched the Method* from the constant pool.
771 ResourceMark rm;
772 log_trace(redefine, class, obsolete)("calling obsolete method '%s'", method->name_and_sig_as_C_string());
773 }
774 return 0;
775 JRT_END
776
777 // ret_pc points into caller; we are returning caller's exception handler
778 // for given exception
779 // Note that the implementation of this method assumes it's only called when an exception has actually occured
780 address SharedRuntime::compute_compiled_exc_handler(nmethod* nm, address ret_pc, Handle& exception,
781 bool force_unwind, bool top_frame_only, bool& recursive_exception_occurred) {
782 assert(nm != nullptr, "must exist");
783 ResourceMark rm;
784
785 #if INCLUDE_JVMCI
786 if (nm->is_compiled_by_jvmci()) {
787 // lookup exception handler for this pc
788 int catch_pco = pointer_delta_as_int(ret_pc, nm->code_begin());
789 ExceptionHandlerTable table(nm);
790 HandlerTableEntry *t = table.entry_for(catch_pco, -1, 0);
791 if (t != nullptr) {
792 return nm->code_begin() + t->pco();
793 } else {
1403
1404 // determine call info & receiver
1405 // note: a) receiver is null for static calls
1406 // b) an exception is thrown if receiver is null for non-static calls
1407 CallInfo call_info;
1408 Bytecodes::Code invoke_code = Bytecodes::_illegal;
1409 Handle receiver = find_callee_info(invoke_code, call_info, CHECK_(methodHandle()));
1410
1411 NoSafepointVerifier nsv;
1412
1413 methodHandle callee_method(current, call_info.selected_method());
1414
1415 assert((!is_virtual && invoke_code == Bytecodes::_invokestatic ) ||
1416 (!is_virtual && invoke_code == Bytecodes::_invokespecial) ||
1417 (!is_virtual && invoke_code == Bytecodes::_invokehandle ) ||
1418 (!is_virtual && invoke_code == Bytecodes::_invokedynamic) ||
1419 ( is_virtual && invoke_code != Bytecodes::_invokestatic ), "inconsistent bytecode");
1420
1421 assert(!caller_nm->is_unloading(), "It should not be unloading");
1422
1423 #ifndef PRODUCT
1424 // tracing/debugging/statistics
1425 uint *addr = (is_optimized) ? (&_resolve_opt_virtual_ctr) :
1426 (is_virtual) ? (&_resolve_virtual_ctr) :
1427 (&_resolve_static_ctr);
1428 AtomicAccess::inc(addr);
1429
1430 if (TraceCallFixup) {
1431 ResourceMark rm(current);
1432 tty->print("resolving %s%s (%s) call to",
1433 (is_optimized) ? "optimized " : "", (is_virtual) ? "virtual" : "static",
1434 Bytecodes::name(invoke_code));
1435 callee_method->print_short_name(tty);
1436 tty->print_cr(" at pc: " INTPTR_FORMAT " to code: " INTPTR_FORMAT,
1437 p2i(caller_frame.pc()), p2i(callee_method->code()));
1438 }
1439 #endif
1440
1441 if (invoke_code == Bytecodes::_invokestatic) {
1442 assert(callee_method->method_holder()->is_initialized() ||
1443 callee_method->method_holder()->is_reentrant_initialization(current),
1444 "invalid class initialization state for invoke_static");
1445 if (!VM_Version::supports_fast_class_init_checks() && callee_method->needs_clinit_barrier()) {
1446 // In order to keep class initialization check, do not patch call
1447 // site for static call when the class is not fully initialized.
1448 // Proper check is enforced by call site re-resolution on every invocation.
1449 //
1465
1466 // Make sure the callee nmethod does not get deoptimized and removed before
1467 // we are done patching the code.
1468
1469
1470 CompiledICLocker ml(caller_nm);
1471 if (is_virtual && !is_optimized) {
1472 CompiledIC* inline_cache = CompiledIC_before(caller_nm, caller_frame.pc());
1473 inline_cache->update(&call_info, receiver->klass());
1474 } else {
1475 // Callsite is a direct call - set it to the destination method
1476 CompiledDirectCall* callsite = CompiledDirectCall::before(caller_frame.pc());
1477 callsite->set(callee_method);
1478 }
1479
1480 return callee_method;
1481 }
1482
1483 // Inline caches exist only in compiled code
1484 JRT_BLOCK_ENTRY(address, SharedRuntime::handle_wrong_method_ic_miss(JavaThread* current))
1485 #ifdef ASSERT
1486 RegisterMap reg_map(current,
1487 RegisterMap::UpdateMap::skip,
1488 RegisterMap::ProcessFrames::include,
1489 RegisterMap::WalkContinuation::skip);
1490 frame stub_frame = current->last_frame();
1491 assert(stub_frame.is_runtime_frame(), "sanity check");
1492 frame caller_frame = stub_frame.sender(®_map);
1493 assert(!caller_frame.is_interpreted_frame() && !caller_frame.is_entry_frame() && !caller_frame.is_upcall_stub_frame(), "unexpected frame");
1494 #endif /* ASSERT */
1495
1496 methodHandle callee_method;
1497 JRT_BLOCK
1498 callee_method = SharedRuntime::handle_ic_miss_helper(CHECK_NULL);
1499 // Return Method* through TLS
1500 current->set_vm_result_metadata(callee_method());
1501 JRT_BLOCK_END
1502 // return compiled code entry point after potential safepoints
1503 return get_resolved_entry(current, callee_method);
1504 JRT_END
1505
1506
1507 // Handle call site that has been made non-entrant
1508 JRT_BLOCK_ENTRY(address, SharedRuntime::handle_wrong_method(JavaThread* current))
1509 // 6243940 We might end up in here if the callee is deoptimized
1510 // as we race to call it. We don't want to take a safepoint if
1511 // the caller was interpreted because the caller frame will look
1512 // interpreted to the stack walkers and arguments are now
1513 // "compiled" so it is much better to make this transition
1514 // invisible to the stack walking code. The i2c path will
1515 // place the callee method in the callee_target. It is stashed
1516 // there because if we try and find the callee by normal means a
1517 // safepoint is possible and have trouble gc'ing the compiled args.
1518 RegisterMap reg_map(current,
1519 RegisterMap::UpdateMap::skip,
1520 RegisterMap::ProcessFrames::include,
1521 RegisterMap::WalkContinuation::skip);
1522 frame stub_frame = current->last_frame();
1523 assert(stub_frame.is_runtime_frame(), "sanity check");
1524 frame caller_frame = stub_frame.sender(®_map);
1525
1526 if (caller_frame.is_interpreted_frame() ||
1527 caller_frame.is_entry_frame() ||
1528 caller_frame.is_upcall_stub_frame()) {
1541 // so bypassing it in c2i adapter is benign.
1542 return callee->get_c2i_no_clinit_check_entry();
1543 } else {
1544 return callee->get_c2i_entry();
1545 }
1546 }
1547
1548 // Must be compiled to compiled path which is safe to stackwalk
1549 methodHandle callee_method;
1550 JRT_BLOCK
1551 // Force resolving of caller (if we called from compiled frame)
1552 callee_method = SharedRuntime::reresolve_call_site(CHECK_NULL);
1553 current->set_vm_result_metadata(callee_method());
1554 JRT_BLOCK_END
1555 // return compiled code entry point after potential safepoints
1556 return get_resolved_entry(current, callee_method);
1557 JRT_END
1558
1559 // Handle abstract method call
1560 JRT_BLOCK_ENTRY(address, SharedRuntime::handle_wrong_method_abstract(JavaThread* current))
1561 // Verbose error message for AbstractMethodError.
1562 // Get the called method from the invoke bytecode.
1563 vframeStream vfst(current, true);
1564 assert(!vfst.at_end(), "Java frame must exist");
1565 methodHandle caller(current, vfst.method());
1566 Bytecode_invoke invoke(caller, vfst.bci());
1567 DEBUG_ONLY( invoke.verify(); )
1568
1569 // Find the compiled caller frame.
1570 RegisterMap reg_map(current,
1571 RegisterMap::UpdateMap::include,
1572 RegisterMap::ProcessFrames::include,
1573 RegisterMap::WalkContinuation::skip);
1574 frame stubFrame = current->last_frame();
1575 assert(stubFrame.is_runtime_frame(), "must be");
1576 frame callerFrame = stubFrame.sender(®_map);
1577 assert(callerFrame.is_compiled_frame(), "must be");
1578
1579 // Install exception and return forward entry.
1580 address res = SharedRuntime::throw_AbstractMethodError_entry();
1587 LinkResolver::throw_abstract_method_error(callee, recv_klass, CHECK_(res));
1588 }
1589 JRT_BLOCK_END
1590 return res;
1591 JRT_END
1592
1593 // return verified_code_entry if interp_only_mode is not set for the current thread;
1594 // otherwise return c2i entry.
1595 address SharedRuntime::get_resolved_entry(JavaThread* current, methodHandle callee_method) {
1596 if (current->is_interp_only_mode() && !callee_method->is_special_native_intrinsic()) {
1597 // In interp_only_mode we need to go to the interpreted entry
1598 // The c2i won't patch in this mode -- see fixup_callers_callsite
1599 return callee_method->get_c2i_entry();
1600 }
1601 assert(callee_method->verified_code_entry() != nullptr, " Jump to zero!");
1602 return callee_method->verified_code_entry();
1603 }
1604
1605 // resolve a static call and patch code
1606 JRT_BLOCK_ENTRY(address, SharedRuntime::resolve_static_call_C(JavaThread* current ))
1607 methodHandle callee_method;
1608 bool enter_special = false;
1609 JRT_BLOCK
1610 callee_method = SharedRuntime::resolve_helper(false, false, CHECK_NULL);
1611 current->set_vm_result_metadata(callee_method());
1612 JRT_BLOCK_END
1613 // return compiled code entry point after potential safepoints
1614 return get_resolved_entry(current, callee_method);
1615 JRT_END
1616
1617 // resolve virtual call and update inline cache to monomorphic
1618 JRT_BLOCK_ENTRY(address, SharedRuntime::resolve_virtual_call_C(JavaThread* current))
1619 methodHandle callee_method;
1620 JRT_BLOCK
1621 callee_method = SharedRuntime::resolve_helper(true, false, CHECK_NULL);
1622 current->set_vm_result_metadata(callee_method());
1623 JRT_BLOCK_END
1624 // return compiled code entry point after potential safepoints
1625 return get_resolved_entry(current, callee_method);
1626 JRT_END
1627
1628
1629 // Resolve a virtual call that can be statically bound (e.g., always
1630 // monomorphic, so it has no inline cache). Patch code to resolved target.
1631 JRT_BLOCK_ENTRY(address, SharedRuntime::resolve_opt_virtual_call_C(JavaThread* current))
1632 methodHandle callee_method;
1633 JRT_BLOCK
1634 callee_method = SharedRuntime::resolve_helper(true, true, CHECK_NULL);
1635 current->set_vm_result_metadata(callee_method());
1636 JRT_BLOCK_END
1637 // return compiled code entry point after potential safepoints
1638 return get_resolved_entry(current, callee_method);
1639 JRT_END
1640
1641 methodHandle SharedRuntime::handle_ic_miss_helper(TRAPS) {
1642 JavaThread* current = THREAD;
1643 ResourceMark rm(current);
1644 CallInfo call_info;
1645 Bytecodes::Code bc;
1646
1647 // receiver is null for static calls. An exception is thrown for null
1648 // receivers for non-static calls
1649 Handle receiver = find_callee_info(bc, call_info, CHECK_(methodHandle()));
1650
1651 methodHandle callee_method(current, call_info.selected_method());
1652
1653 #ifndef PRODUCT
1654 AtomicAccess::inc(&_ic_miss_ctr);
1655
1656 // Statistics & Tracing
1657 if (TraceCallFixup) {
1658 ResourceMark rm(current);
1659 tty->print("IC miss (%s) call to", Bytecodes::name(bc));
1660 callee_method->print_short_name(tty);
1661 tty->print_cr(" code: " INTPTR_FORMAT, p2i(callee_method->code()));
1662 }
1663
1664 if (ICMissHistogram) {
1665 MutexLocker m(VMStatistic_lock);
1666 RegisterMap reg_map(current,
1667 RegisterMap::UpdateMap::skip,
1668 RegisterMap::ProcessFrames::include,
1669 RegisterMap::WalkContinuation::skip);
1670 frame f = current->last_frame().real_sender(®_map);// skip runtime stub
1671 // produce statistics under the lock
1672 trace_ic_miss(f.pc());
1673 }
1674 #endif
1675
1758 CompiledDirectCall* cdc = CompiledDirectCall::at(call_addr);
1759 cdc->set_to_clean();
1760 break;
1761 }
1762
1763 case relocInfo::virtual_call_type: {
1764 // compiled, dispatched call (which used to call an interpreted method)
1765 CompiledIC* inline_cache = CompiledIC_at(caller_nm, call_addr);
1766 inline_cache->set_to_clean();
1767 break;
1768 }
1769 default:
1770 break;
1771 }
1772 }
1773 }
1774 }
1775
1776 methodHandle callee_method = find_callee_method(CHECK_(methodHandle()));
1777
1778
1779 #ifndef PRODUCT
1780 AtomicAccess::inc(&_wrong_method_ctr);
1781
1782 if (TraceCallFixup) {
1783 ResourceMark rm(current);
1784 tty->print("handle_wrong_method reresolving call to");
1785 callee_method->print_short_name(tty);
1786 tty->print_cr(" code: " INTPTR_FORMAT, p2i(callee_method->code()));
1787 }
1788 #endif
1789
1790 return callee_method;
1791 }
1792
1793 address SharedRuntime::handle_unsafe_access(JavaThread* thread, address next_pc) {
1794 // The faulting unsafe accesses should be changed to throw the error
1795 // synchronously instead. Meanwhile the faulting instruction will be
1796 // skipped over (effectively turning it into a no-op) and an
1797 // asynchronous exception will be raised which the thread will
1798 // handle at a later point. If the instruction is a load it will
1799 // return garbage.
1800
1801 // Request an async exception.
2044 if (CheckJNICalls) {
2045 fatal("Object has been unlocked by JNI");
2046 }
2047 return;
2048 }
2049 ObjectSynchronizer::exit(obj, lock, current);
2050 }
2051
2052 // Handles the uncommon cases of monitor unlocking in compiled code
2053 JRT_LEAF(void, SharedRuntime::complete_monitor_unlocking_C(oopDesc* obj, BasicLock* lock, JavaThread* current))
2054 assert(current == JavaThread::current(), "pre-condition");
2055 SharedRuntime::monitor_exit_helper(obj, lock, current);
2056 JRT_END
2057
2058 #ifndef PRODUCT
2059
2060 void SharedRuntime::print_statistics() {
2061 ttyLocker ttyl;
2062 if (xtty != nullptr) xtty->head("statistics type='SharedRuntime'");
2063
2064 SharedRuntime::print_ic_miss_histogram();
2065
2066 // Dump the JRT_ENTRY counters
2067 if (_new_instance_ctr) tty->print_cr("%5u new instance requires GC", _new_instance_ctr);
2068 if (_new_array_ctr) tty->print_cr("%5u new array requires GC", _new_array_ctr);
2069 if (_multi2_ctr) tty->print_cr("%5u multianewarray 2 dim", _multi2_ctr);
2070 if (_multi3_ctr) tty->print_cr("%5u multianewarray 3 dim", _multi3_ctr);
2071 if (_multi4_ctr) tty->print_cr("%5u multianewarray 4 dim", _multi4_ctr);
2072 if (_multi5_ctr) tty->print_cr("%5u multianewarray 5 dim", _multi5_ctr);
2073
2074 tty->print_cr("%5u inline cache miss in compiled", _ic_miss_ctr);
2075 tty->print_cr("%5u wrong method", _wrong_method_ctr);
2076 tty->print_cr("%5u unresolved static call site", _resolve_static_ctr);
2077 tty->print_cr("%5u unresolved virtual call site", _resolve_virtual_ctr);
2078 tty->print_cr("%5u unresolved opt virtual call site", _resolve_opt_virtual_ctr);
2079
2080 if (_mon_enter_stub_ctr) tty->print_cr("%5u monitor enter stub", _mon_enter_stub_ctr);
2081 if (_mon_exit_stub_ctr) tty->print_cr("%5u monitor exit stub", _mon_exit_stub_ctr);
2082 if (_mon_enter_ctr) tty->print_cr("%5u monitor enter slow", _mon_enter_ctr);
2083 if (_mon_exit_ctr) tty->print_cr("%5u monitor exit slow", _mon_exit_ctr);
2084 if (_partial_subtype_ctr) tty->print_cr("%5u slow partial subtype", _partial_subtype_ctr);
2085 if (_jbyte_array_copy_ctr) tty->print_cr("%5u byte array copies", _jbyte_array_copy_ctr);
2086 if (_jshort_array_copy_ctr) tty->print_cr("%5u short array copies", _jshort_array_copy_ctr);
2087 if (_jint_array_copy_ctr) tty->print_cr("%5u int array copies", _jint_array_copy_ctr);
2088 if (_jlong_array_copy_ctr) tty->print_cr("%5u long array copies", _jlong_array_copy_ctr);
2089 if (_oop_array_copy_ctr) tty->print_cr("%5u oop array copies", _oop_array_copy_ctr);
2090 if (_checkcast_array_copy_ctr) tty->print_cr("%5u checkcast array copies", _checkcast_array_copy_ctr);
2091 if (_unsafe_array_copy_ctr) tty->print_cr("%5u unsafe array copies", _unsafe_array_copy_ctr);
2092 if (_generic_array_copy_ctr) tty->print_cr("%5u generic array copies", _generic_array_copy_ctr);
2093 if (_slow_array_copy_ctr) tty->print_cr("%5u slow array copies", _slow_array_copy_ctr);
2094 if (_find_handler_ctr) tty->print_cr("%5u find exception handler", _find_handler_ctr);
2095 if (_rethrow_ctr) tty->print_cr("%5u rethrow handler", _rethrow_ctr);
2096 if (_unsafe_set_memory_ctr) tty->print_cr("%5u unsafe set memorys", _unsafe_set_memory_ctr);
2097
2098 AdapterHandlerLibrary::print_statistics();
2099
2100 if (xtty != nullptr) xtty->tail("statistics");
2101 }
2102
2103 inline double percent(int64_t x, int64_t y) {
2104 return 100.0 * (double)x / (double)MAX2(y, (int64_t)1);
2105 }
2106
2107 class MethodArityHistogram {
2108 public:
2109 enum { MAX_ARITY = 256 };
2110 private:
2111 static uint64_t _arity_histogram[MAX_ARITY]; // histogram of #args
2112 static uint64_t _size_histogram[MAX_ARITY]; // histogram of arg size in words
2113 static uint64_t _total_compiled_calls;
2114 static uint64_t _max_compiled_calls_per_method;
2115 static int _max_arity; // max. arity seen
2116 static int _max_size; // max. arg size seen
2117
2118 static void add_method_to_histogram(nmethod* nm) {
2119 Method* method = (nm == nullptr) ? nullptr : nm->method();
2120 if (method != nullptr) {
2121 ArgumentCount args(method->signature());
2122 int arity = args.size() + (method->is_static() ? 0 : 1);
2167 // Take the Compile_lock to protect against changes in the CodeBlob structures
2168 MutexLocker mu1(Compile_lock, Mutex::_safepoint_check_flag);
2169 // Take the CodeCache_lock to protect against changes in the CodeHeap structure
2170 MutexLocker mu2(CodeCache_lock, Mutex::_no_safepoint_check_flag);
2171 _max_arity = _max_size = 0;
2172 _total_compiled_calls = 0;
2173 _max_compiled_calls_per_method = 0;
2174 for (int i = 0; i < MAX_ARITY; i++) _arity_histogram[i] = _size_histogram[i] = 0;
2175 CodeCache::nmethods_do(add_method_to_histogram);
2176 print_histogram();
2177 }
2178 };
2179
2180 uint64_t MethodArityHistogram::_arity_histogram[MethodArityHistogram::MAX_ARITY];
2181 uint64_t MethodArityHistogram::_size_histogram[MethodArityHistogram::MAX_ARITY];
2182 uint64_t MethodArityHistogram::_total_compiled_calls;
2183 uint64_t MethodArityHistogram::_max_compiled_calls_per_method;
2184 int MethodArityHistogram::_max_arity;
2185 int MethodArityHistogram::_max_size;
2186
2187 void SharedRuntime::print_call_statistics(uint64_t comp_total) {
2188 tty->print_cr("Calls from compiled code:");
2189 int64_t total = _nof_normal_calls + _nof_interface_calls + _nof_static_calls;
2190 int64_t mono_c = _nof_normal_calls - _nof_megamorphic_calls;
2191 int64_t mono_i = _nof_interface_calls;
2192 tty->print_cr("\t" INT64_FORMAT_W(12) " (100%%) total non-inlined ", total);
2193 tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.1f%%) |- virtual calls ", _nof_normal_calls, percent(_nof_normal_calls, total));
2194 tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.0f%%) | |- inlined ", _nof_inlined_calls, percent(_nof_inlined_calls, _nof_normal_calls));
2195 tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.0f%%) | |- monomorphic ", mono_c, percent(mono_c, _nof_normal_calls));
2196 tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.0f%%) | |- megamorphic ", _nof_megamorphic_calls, percent(_nof_megamorphic_calls, _nof_normal_calls));
2197 tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.1f%%) |- interface calls ", _nof_interface_calls, percent(_nof_interface_calls, total));
2198 tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.0f%%) | |- inlined ", _nof_inlined_interface_calls, percent(_nof_inlined_interface_calls, _nof_interface_calls));
2199 tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.0f%%) | |- monomorphic ", mono_i, percent(mono_i, _nof_interface_calls));
2200 tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.1f%%) |- static/special calls", _nof_static_calls, percent(_nof_static_calls, total));
2201 tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.0f%%) | |- inlined ", _nof_inlined_static_calls, percent(_nof_inlined_static_calls, _nof_static_calls));
2202 tty->cr();
2203 tty->print_cr("Note 1: counter updates are not MT-safe.");
2204 tty->print_cr("Note 2: %% in major categories are relative to total non-inlined calls;");
2205 tty->print_cr(" %% in nested categories are relative to their category");
2206 tty->print_cr(" (and thus add up to more than 100%% with inlining)");
2207 tty->cr();
2511 }
2512 #endif // INCLUDE_CDS
2513 if (entry == nullptr) {
2514 assert_lock_strong(AdapterHandlerLibrary_lock);
2515 AdapterHandlerEntry** entry_p = _adapter_handler_table->get(fp);
2516 if (entry_p != nullptr) {
2517 entry = *entry_p;
2518 assert(entry->fingerprint()->equals(fp), "fingerprint mismatch key fp %s %s (hash=%d) != found fp %s %s (hash=%d)",
2519 entry->fingerprint()->as_basic_args_string(), entry->fingerprint()->as_string(), entry->fingerprint()->compute_hash(),
2520 fp->as_basic_args_string(), fp->as_string(), fp->compute_hash());
2521 #ifndef PRODUCT
2522 _runtime_hits++;
2523 #endif
2524 }
2525 }
2526 AdapterFingerPrint::deallocate(fp);
2527 return entry;
2528 }
2529
2530 #ifndef PRODUCT
2531 static void print_table_statistics() {
2532 auto size = [&] (AdapterFingerPrint* key, AdapterHandlerEntry* a) {
2533 return sizeof(*key) + sizeof(*a);
2534 };
2535 TableStatistics ts = _adapter_handler_table->statistics_calculate(size);
2536 ts.print(tty, "AdapterHandlerTable");
2537 tty->print_cr("AdapterHandlerTable (table_size=%d, entries=%d)",
2538 _adapter_handler_table->table_size(), _adapter_handler_table->number_of_entries());
2539 int total_hits = _archived_hits + _runtime_hits;
2540 tty->print_cr("AdapterHandlerTable: lookups %d equals %d hits %d (archived=%d+runtime=%d)",
2541 _lookups, _equals, total_hits, _archived_hits, _runtime_hits);
2542 }
2543 #endif
2544
2545 // ---------------------------------------------------------------------------
2546 // Implementation of AdapterHandlerLibrary
2547 AdapterHandlerEntry* AdapterHandlerLibrary::_no_arg_handler = nullptr;
2548 AdapterHandlerEntry* AdapterHandlerLibrary::_int_arg_handler = nullptr;
2549 AdapterHandlerEntry* AdapterHandlerLibrary::_obj_arg_handler = nullptr;
2550 AdapterHandlerEntry* AdapterHandlerLibrary::_obj_int_arg_handler = nullptr;
2551 AdapterHandlerEntry* AdapterHandlerLibrary::_obj_obj_arg_handler = nullptr;
2552 #if INCLUDE_CDS
2553 ArchivedAdapterTable AdapterHandlerLibrary::_aot_adapter_handler_table;
2554 #endif // INCLUDE_CDS
2555 static const int AdapterHandlerLibrary_size = 16*K;
2556 BufferBlob* AdapterHandlerLibrary::_buffer = nullptr;
2557 volatile uint AdapterHandlerLibrary::_id_counter = 0;
2558
2559 BufferBlob* AdapterHandlerLibrary::buffer_blob() {
2560 assert(_buffer != nullptr, "should be initialized");
2561 return _buffer;
2562 }
2563
3446 };
3447 assert_locked_or_safepoint(AdapterHandlerLibrary_lock);
3448 _adapter_handler_table->iterate(findblob_runtime_table);
3449 }
3450 assert(found, "Should have found handler");
3451 }
3452
3453 void AdapterHandlerEntry::print_adapter_on(outputStream* st) const {
3454 st->print("AHE@" INTPTR_FORMAT ": %s", p2i(this), fingerprint()->as_string());
3455 if (adapter_blob() != nullptr) {
3456 st->print(" i2c: " INTPTR_FORMAT, p2i(get_i2c_entry()));
3457 st->print(" c2i: " INTPTR_FORMAT, p2i(get_c2i_entry()));
3458 st->print(" c2iUV: " INTPTR_FORMAT, p2i(get_c2i_unverified_entry()));
3459 if (get_c2i_no_clinit_check_entry() != nullptr) {
3460 st->print(" c2iNCI: " INTPTR_FORMAT, p2i(get_c2i_no_clinit_check_entry()));
3461 }
3462 }
3463 st->cr();
3464 }
3465
3466 #ifndef PRODUCT
3467
3468 void AdapterHandlerLibrary::print_statistics() {
3469 print_table_statistics();
3470 }
3471
3472 #endif /* PRODUCT */
3473
3474 JRT_LEAF(void, SharedRuntime::enable_stack_reserved_zone(JavaThread* current))
3475 assert(current == JavaThread::current(), "pre-condition");
3476 StackOverflow* overflow_state = current->stack_overflow_state();
3477 overflow_state->enable_stack_reserved_zone(/*check_if_disabled*/true);
3478 overflow_state->set_reserved_stack_activation(current->stack_base());
3479 JRT_END
3480
3481 frame SharedRuntime::look_for_reserved_stack_annotated_method(JavaThread* current, frame fr) {
3482 ResourceMark rm(current);
3483 frame activation;
3484 nmethod* nm = nullptr;
3485 int count = 1;
3486
3487 assert(fr.is_java_frame(), "Must start on Java frame");
3488
3489 RegisterMap map(JavaThread::current(),
3490 RegisterMap::UpdateMap::skip,
3491 RegisterMap::ProcessFrames::skip,
3492 RegisterMap::WalkContinuation::skip); // don't walk continuations
3493 for (; !fr.is_first_frame(); fr = fr.sender(&map)) {
|
51 #include "oops/klass.hpp"
52 #include "oops/method.inline.hpp"
53 #include "oops/objArrayKlass.hpp"
54 #include "oops/oop.inline.hpp"
55 #include "prims/forte.hpp"
56 #include "prims/jvmtiExport.hpp"
57 #include "prims/jvmtiThreadState.hpp"
58 #include "prims/methodHandles.hpp"
59 #include "prims/nativeLookup.hpp"
60 #include "runtime/arguments.hpp"
61 #include "runtime/atomicAccess.hpp"
62 #include "runtime/basicLock.inline.hpp"
63 #include "runtime/frame.inline.hpp"
64 #include "runtime/handles.inline.hpp"
65 #include "runtime/init.hpp"
66 #include "runtime/interfaceSupport.inline.hpp"
67 #include "runtime/java.hpp"
68 #include "runtime/javaCalls.hpp"
69 #include "runtime/jniHandles.inline.hpp"
70 #include "runtime/osThread.hpp"
71 #include "runtime/perfData.inline.hpp"
72 #include "runtime/sharedRuntime.hpp"
73 #include "runtime/stackWatermarkSet.hpp"
74 #include "runtime/stubRoutines.hpp"
75 #include "runtime/synchronizer.hpp"
76 #include "runtime/timerTrace.hpp"
77 #include "runtime/vframe.inline.hpp"
78 #include "runtime/vframeArray.hpp"
79 #include "runtime/vm_version.hpp"
80 #include "services/management.hpp"
81 #include "utilities/copy.hpp"
82 #include "utilities/dtrace.hpp"
83 #include "utilities/events.hpp"
84 #include "utilities/globalDefinitions.hpp"
85 #include "utilities/hashTable.hpp"
86 #include "utilities/macros.hpp"
87 #include "utilities/xmlstream.hpp"
88 #ifdef COMPILER1
89 #include "c1/c1_Runtime1.hpp"
90 #endif
91 #if INCLUDE_JFR
92 #include "jfr/jfr.inline.hpp"
93 #endif
94
95 // Shared runtime stub routines reside in their own unique blob with a
96 // single entry point
97
98
99 #define SHARED_STUB_FIELD_DEFINE(name, type) \
100 type* SharedRuntime::BLOB_FIELD_NAME(name);
101 SHARED_STUBS_DO(SHARED_STUB_FIELD_DEFINE)
102 #undef SHARED_STUB_FIELD_DEFINE
103
104 nmethod* SharedRuntime::_cont_doYield_stub;
105
106 PerfTickCounters* SharedRuntime::_perf_resolve_opt_virtual_total_time = nullptr;
107 PerfTickCounters* SharedRuntime::_perf_resolve_virtual_total_time = nullptr;
108 PerfTickCounters* SharedRuntime::_perf_resolve_static_total_time = nullptr;
109 PerfTickCounters* SharedRuntime::_perf_handle_wrong_method_total_time = nullptr;
110 PerfTickCounters* SharedRuntime::_perf_ic_miss_total_time = nullptr;
111
112 #if 0
113 // TODO tweak global stub name generation to match this
114 #define SHARED_STUB_NAME_DECLARE(name, type) "Shared Runtime " # name "_blob",
115 const char *SharedRuntime::_stub_names[] = {
116 SHARED_STUBS_DO(SHARED_STUB_NAME_DECLARE)
117 };
118 #endif
119
120 //----------------------------generate_stubs-----------------------------------
121 void SharedRuntime::generate_initial_stubs() {
122 // Build this early so it's available for the interpreter.
123 _throw_StackOverflowError_blob =
124 generate_throw_exception(StubId::shared_throw_StackOverflowError_id,
125 CAST_FROM_FN_PTR(address, SharedRuntime::throw_StackOverflowError));
126 }
127
128 void SharedRuntime::generate_stubs() {
129 _wrong_method_blob =
130 generate_resolve_blob(StubId::shared_wrong_method_id,
131 CAST_FROM_FN_PTR(address, SharedRuntime::handle_wrong_method));
161 generate_throw_exception(StubId::shared_throw_NullPointerException_at_call_id,
162 CAST_FROM_FN_PTR(address, SharedRuntime::throw_NullPointerException_at_call));
163
164 #if COMPILER2_OR_JVMCI
165 // Vectors are generated only by C2 and JVMCI.
166 bool support_wide = is_wide_vector(MaxVectorSize);
167 if (support_wide) {
168 _polling_page_vectors_safepoint_handler_blob =
169 generate_handler_blob(StubId::shared_polling_page_vectors_safepoint_handler_id,
170 CAST_FROM_FN_PTR(address, SafepointSynchronize::handle_polling_page_exception));
171 }
172 #endif // COMPILER2_OR_JVMCI
173 _polling_page_safepoint_handler_blob =
174 generate_handler_blob(StubId::shared_polling_page_safepoint_handler_id,
175 CAST_FROM_FN_PTR(address, SafepointSynchronize::handle_polling_page_exception));
176 _polling_page_return_handler_blob =
177 generate_handler_blob(StubId::shared_polling_page_return_handler_id,
178 CAST_FROM_FN_PTR(address, SafepointSynchronize::handle_polling_page_exception));
179
180 generate_deopt_blob();
181
182 if (UsePerfData) {
183 EXCEPTION_MARK;
184 NEWPERFTICKCOUNTERS(_perf_resolve_opt_virtual_total_time, SUN_CI, "resovle_opt_virtual_call");
185 NEWPERFTICKCOUNTERS(_perf_resolve_virtual_total_time, SUN_CI, "resovle_virtual_call");
186 NEWPERFTICKCOUNTERS(_perf_resolve_static_total_time, SUN_CI, "resovle_static_call");
187 NEWPERFTICKCOUNTERS(_perf_handle_wrong_method_total_time, SUN_CI, "handle_wrong_method");
188 NEWPERFTICKCOUNTERS(_perf_ic_miss_total_time , SUN_CI, "ic_miss");
189 if (HAS_PENDING_EXCEPTION) {
190 vm_exit_during_initialization("SharedRuntime::generate_stubs() failed unexpectedly");
191 }
192 }
193 }
194
195 void SharedRuntime::init_adapter_library() {
196 AdapterHandlerLibrary::initialize();
197 }
198
199 static void print_counter_on(outputStream* st, const char* name, PerfTickCounters* counter, uint cnt) {
200 st->print(" %-28s " JLONG_FORMAT_W(6) "us", name, counter->elapsed_counter_value_us());
201 if (TraceThreadTime) {
202 st->print(" (elapsed) " JLONG_FORMAT_W(6) "us (thread)", counter->thread_counter_value_us());
203 }
204 st->print(" / %5d events", cnt);
205 st->cr();
206 }
207
208 void SharedRuntime::print_counters_on(outputStream* st) {
209 st->print_cr("SharedRuntime:");
210 if (UsePerfData) {
211 print_counter_on(st, "resolve_opt_virtual_call:", _perf_resolve_opt_virtual_total_time, _resolve_opt_virtual_ctr);
212 print_counter_on(st, "resolve_virtual_call:", _perf_resolve_virtual_total_time, _resolve_virtual_ctr);
213 print_counter_on(st, "resolve_static_call:", _perf_resolve_static_total_time, _resolve_static_ctr);
214 print_counter_on(st, "handle_wrong_method:", _perf_handle_wrong_method_total_time, _wrong_method_ctr);
215 print_counter_on(st, "ic_miss:", _perf_ic_miss_total_time, _ic_miss_ctr);
216
217 jlong total_elapsed_time_us = Management::ticks_to_us(_perf_resolve_opt_virtual_total_time->elapsed_counter_value() +
218 _perf_resolve_virtual_total_time->elapsed_counter_value() +
219 _perf_resolve_static_total_time->elapsed_counter_value() +
220 _perf_handle_wrong_method_total_time->elapsed_counter_value() +
221 _perf_ic_miss_total_time->elapsed_counter_value());
222 st->print("Total: " JLONG_FORMAT_W(5) "us", total_elapsed_time_us);
223 if (TraceThreadTime) {
224 jlong total_thread_time_us = Management::ticks_to_us(_perf_resolve_opt_virtual_total_time->thread_counter_value() +
225 _perf_resolve_virtual_total_time->thread_counter_value() +
226 _perf_resolve_static_total_time->thread_counter_value() +
227 _perf_handle_wrong_method_total_time->thread_counter_value() +
228 _perf_ic_miss_total_time->thread_counter_value());
229 st->print(" (elapsed) " JLONG_FORMAT_W(5) "us (thread)", total_thread_time_us);
230
231 }
232 st->cr();
233 } else {
234 st->print_cr(" no data (UsePerfData is turned off)");
235 }
236 }
237
238 #if INCLUDE_JFR
239 //------------------------------generate jfr runtime stubs ------
240 void SharedRuntime::generate_jfr_stubs() {
241 ResourceMark rm;
242 const char* timer_msg = "SharedRuntime generate_jfr_stubs";
243 TraceTime timer(timer_msg, TRACETIME_LOG(Info, startuptime));
244
245 _jfr_write_checkpoint_blob = generate_jfr_write_checkpoint();
246 _jfr_return_lease_blob = generate_jfr_return_lease();
247 }
248
249 #endif // INCLUDE_JFR
250
251 #include <math.h>
252
253 // Implementation of SharedRuntime
254
255 // For statistics
256 uint SharedRuntime::_ic_miss_ctr = 0;
257 uint SharedRuntime::_wrong_method_ctr = 0;
258 uint SharedRuntime::_resolve_static_ctr = 0;
259 uint SharedRuntime::_resolve_virtual_ctr = 0;
260 uint SharedRuntime::_resolve_opt_virtual_ctr = 0;
261
262 #ifndef PRODUCT
263 uint SharedRuntime::_implicit_null_throws = 0;
264 uint SharedRuntime::_implicit_div0_throws = 0;
265
266 int64_t SharedRuntime::_nof_normal_calls = 0;
267 int64_t SharedRuntime::_nof_inlined_calls = 0;
268 int64_t SharedRuntime::_nof_megamorphic_calls = 0;
269 int64_t SharedRuntime::_nof_static_calls = 0;
270 int64_t SharedRuntime::_nof_inlined_static_calls = 0;
271 int64_t SharedRuntime::_nof_interface_calls = 0;
272 int64_t SharedRuntime::_nof_inlined_interface_calls = 0;
273
274 uint SharedRuntime::_new_instance_ctr=0;
275 uint SharedRuntime::_new_array_ctr=0;
276 uint SharedRuntime::_multi2_ctr=0;
277 uint SharedRuntime::_multi3_ctr=0;
278 uint SharedRuntime::_multi4_ctr=0;
279 uint SharedRuntime::_multi5_ctr=0;
280 uint SharedRuntime::_mon_enter_stub_ctr=0;
281 uint SharedRuntime::_mon_exit_stub_ctr=0;
282 uint SharedRuntime::_mon_enter_ctr=0;
296 uint SharedRuntime::_unsafe_set_memory_ctr=0;
297
298 int SharedRuntime::_ICmiss_index = 0;
299 int SharedRuntime::_ICmiss_count[SharedRuntime::maxICmiss_count];
300 address SharedRuntime::_ICmiss_at[SharedRuntime::maxICmiss_count];
301
302
303 void SharedRuntime::trace_ic_miss(address at) {
304 for (int i = 0; i < _ICmiss_index; i++) {
305 if (_ICmiss_at[i] == at) {
306 _ICmiss_count[i]++;
307 return;
308 }
309 }
310 int index = _ICmiss_index++;
311 if (_ICmiss_index >= maxICmiss_count) _ICmiss_index = maxICmiss_count - 1;
312 _ICmiss_at[index] = at;
313 _ICmiss_count[index] = 1;
314 }
315
316 void SharedRuntime::print_ic_miss_histogram_on(outputStream* st) {
317 if (ICMissHistogram) {
318 st->print_cr("IC Miss Histogram:");
319 int tot_misses = 0;
320 for (int i = 0; i < _ICmiss_index; i++) {
321 st->print_cr(" at: " INTPTR_FORMAT " nof: %d", p2i(_ICmiss_at[i]), _ICmiss_count[i]);
322 tot_misses += _ICmiss_count[i];
323 }
324 st->print_cr("Total IC misses: %7d", tot_misses);
325 }
326 }
327
328 #ifdef COMPILER2
329 // Runtime methods for printf-style debug nodes (same printing format as fieldDescriptor::print_on_for)
330 void SharedRuntime::debug_print_value(jboolean x) {
331 tty->print_cr("boolean %d", x);
332 }
333
334 void SharedRuntime::debug_print_value(jbyte x) {
335 tty->print_cr("byte %d", x);
336 }
337
338 void SharedRuntime::debug_print_value(jshort x) {
339 tty->print_cr("short %d", x);
340 }
341
342 void SharedRuntime::debug_print_value(jchar x) {
343 tty->print_cr("char %c %d", isprint(x) ? x : ' ', x);
344 }
813 jobject vthread = JNIHandles::make_local(const_cast<oopDesc*>(vt));
814 JvmtiVTMSTransitionDisabler::VTMS_vthread_unmount(vthread, hide);
815 JNIHandles::destroy_local(vthread);
816 JRT_END
817 #endif // INCLUDE_JVMTI
818
819 // The interpreter code to call this tracing function is only
820 // called/generated when UL is on for redefine, class and has the right level
821 // and tags. Since obsolete methods are never compiled, we don't have
822 // to modify the compilers to generate calls to this function.
823 //
824 JRT_LEAF(int, SharedRuntime::rc_trace_method_entry(
825 JavaThread* thread, Method* method))
826 if (method->is_obsolete()) {
827 // We are calling an obsolete method, but this is not necessarily
828 // an error. Our method could have been redefined just after we
829 // fetched the Method* from the constant pool.
830 ResourceMark rm;
831 log_trace(redefine, class, obsolete)("calling obsolete method '%s'", method->name_and_sig_as_C_string());
832 }
833
834 LogStreamHandle(Trace, interpreter, bytecode) log;
835 if (log.is_enabled()) {
836 ResourceMark rm;
837 log.print("method entry: " INTPTR_FORMAT " %s %s%s%s%s",
838 p2i(thread),
839 (method->is_static() ? "static" : "virtual"),
840 method->name_and_sig_as_C_string(),
841 (method->is_native() ? " native" : ""),
842 (thread->class_being_initialized() != nullptr ? " clinit" : ""),
843 (method->method_holder()->is_initialized() ? "" : " being_initialized"));
844 }
845 return 0;
846 JRT_END
847
848 // ret_pc points into caller; we are returning caller's exception handler
849 // for given exception
850 // Note that the implementation of this method assumes it's only called when an exception has actually occured
851 address SharedRuntime::compute_compiled_exc_handler(nmethod* nm, address ret_pc, Handle& exception,
852 bool force_unwind, bool top_frame_only, bool& recursive_exception_occurred) {
853 assert(nm != nullptr, "must exist");
854 ResourceMark rm;
855
856 #if INCLUDE_JVMCI
857 if (nm->is_compiled_by_jvmci()) {
858 // lookup exception handler for this pc
859 int catch_pco = pointer_delta_as_int(ret_pc, nm->code_begin());
860 ExceptionHandlerTable table(nm);
861 HandlerTableEntry *t = table.entry_for(catch_pco, -1, 0);
862 if (t != nullptr) {
863 return nm->code_begin() + t->pco();
864 } else {
1474
1475 // determine call info & receiver
1476 // note: a) receiver is null for static calls
1477 // b) an exception is thrown if receiver is null for non-static calls
1478 CallInfo call_info;
1479 Bytecodes::Code invoke_code = Bytecodes::_illegal;
1480 Handle receiver = find_callee_info(invoke_code, call_info, CHECK_(methodHandle()));
1481
1482 NoSafepointVerifier nsv;
1483
1484 methodHandle callee_method(current, call_info.selected_method());
1485
1486 assert((!is_virtual && invoke_code == Bytecodes::_invokestatic ) ||
1487 (!is_virtual && invoke_code == Bytecodes::_invokespecial) ||
1488 (!is_virtual && invoke_code == Bytecodes::_invokehandle ) ||
1489 (!is_virtual && invoke_code == Bytecodes::_invokedynamic) ||
1490 ( is_virtual && invoke_code != Bytecodes::_invokestatic ), "inconsistent bytecode");
1491
1492 assert(!caller_nm->is_unloading(), "It should not be unloading");
1493
1494 // tracing/debugging/statistics
1495 uint *addr = (is_optimized) ? (&_resolve_opt_virtual_ctr) :
1496 (is_virtual) ? (&_resolve_virtual_ctr) :
1497 (&_resolve_static_ctr);
1498 AtomicAccess::inc(addr);
1499
1500 #ifndef PRODUCT
1501 if (TraceCallFixup) {
1502 ResourceMark rm(current);
1503 tty->print("resolving %s%s (%s) call to",
1504 (is_optimized) ? "optimized " : "", (is_virtual) ? "virtual" : "static",
1505 Bytecodes::name(invoke_code));
1506 callee_method->print_short_name(tty);
1507 tty->print_cr(" at pc: " INTPTR_FORMAT " to code: " INTPTR_FORMAT,
1508 p2i(caller_frame.pc()), p2i(callee_method->code()));
1509 }
1510 #endif
1511
1512 if (invoke_code == Bytecodes::_invokestatic) {
1513 assert(callee_method->method_holder()->is_initialized() ||
1514 callee_method->method_holder()->is_reentrant_initialization(current),
1515 "invalid class initialization state for invoke_static");
1516 if (!VM_Version::supports_fast_class_init_checks() && callee_method->needs_clinit_barrier()) {
1517 // In order to keep class initialization check, do not patch call
1518 // site for static call when the class is not fully initialized.
1519 // Proper check is enforced by call site re-resolution on every invocation.
1520 //
1536
1537 // Make sure the callee nmethod does not get deoptimized and removed before
1538 // we are done patching the code.
1539
1540
1541 CompiledICLocker ml(caller_nm);
1542 if (is_virtual && !is_optimized) {
1543 CompiledIC* inline_cache = CompiledIC_before(caller_nm, caller_frame.pc());
1544 inline_cache->update(&call_info, receiver->klass());
1545 } else {
1546 // Callsite is a direct call - set it to the destination method
1547 CompiledDirectCall* callsite = CompiledDirectCall::before(caller_frame.pc());
1548 callsite->set(callee_method);
1549 }
1550
1551 return callee_method;
1552 }
1553
1554 // Inline caches exist only in compiled code
1555 JRT_BLOCK_ENTRY(address, SharedRuntime::handle_wrong_method_ic_miss(JavaThread* current))
1556 PerfTraceTime timer(_perf_ic_miss_total_time);
1557
1558 #ifdef ASSERT
1559 RegisterMap reg_map(current,
1560 RegisterMap::UpdateMap::skip,
1561 RegisterMap::ProcessFrames::include,
1562 RegisterMap::WalkContinuation::skip);
1563 frame stub_frame = current->last_frame();
1564 assert(stub_frame.is_runtime_frame(), "sanity check");
1565 frame caller_frame = stub_frame.sender(®_map);
1566 assert(!caller_frame.is_interpreted_frame() && !caller_frame.is_entry_frame() && !caller_frame.is_upcall_stub_frame(), "unexpected frame");
1567 #endif /* ASSERT */
1568
1569 methodHandle callee_method;
1570 JRT_BLOCK
1571 callee_method = SharedRuntime::handle_ic_miss_helper(CHECK_NULL);
1572 // Return Method* through TLS
1573 current->set_vm_result_metadata(callee_method());
1574 JRT_BLOCK_END
1575 // return compiled code entry point after potential safepoints
1576 return get_resolved_entry(current, callee_method);
1577 JRT_END
1578
1579
1580 // Handle call site that has been made non-entrant
1581 JRT_BLOCK_ENTRY(address, SharedRuntime::handle_wrong_method(JavaThread* current))
1582 PerfTraceTime timer(_perf_handle_wrong_method_total_time);
1583
1584 // 6243940 We might end up in here if the callee is deoptimized
1585 // as we race to call it. We don't want to take a safepoint if
1586 // the caller was interpreted because the caller frame will look
1587 // interpreted to the stack walkers and arguments are now
1588 // "compiled" so it is much better to make this transition
1589 // invisible to the stack walking code. The i2c path will
1590 // place the callee method in the callee_target. It is stashed
1591 // there because if we try and find the callee by normal means a
1592 // safepoint is possible and have trouble gc'ing the compiled args.
1593 RegisterMap reg_map(current,
1594 RegisterMap::UpdateMap::skip,
1595 RegisterMap::ProcessFrames::include,
1596 RegisterMap::WalkContinuation::skip);
1597 frame stub_frame = current->last_frame();
1598 assert(stub_frame.is_runtime_frame(), "sanity check");
1599 frame caller_frame = stub_frame.sender(®_map);
1600
1601 if (caller_frame.is_interpreted_frame() ||
1602 caller_frame.is_entry_frame() ||
1603 caller_frame.is_upcall_stub_frame()) {
1616 // so bypassing it in c2i adapter is benign.
1617 return callee->get_c2i_no_clinit_check_entry();
1618 } else {
1619 return callee->get_c2i_entry();
1620 }
1621 }
1622
1623 // Must be compiled to compiled path which is safe to stackwalk
1624 methodHandle callee_method;
1625 JRT_BLOCK
1626 // Force resolving of caller (if we called from compiled frame)
1627 callee_method = SharedRuntime::reresolve_call_site(CHECK_NULL);
1628 current->set_vm_result_metadata(callee_method());
1629 JRT_BLOCK_END
1630 // return compiled code entry point after potential safepoints
1631 return get_resolved_entry(current, callee_method);
1632 JRT_END
1633
1634 // Handle abstract method call
1635 JRT_BLOCK_ENTRY(address, SharedRuntime::handle_wrong_method_abstract(JavaThread* current))
1636 PerfTraceTime timer(_perf_handle_wrong_method_total_time);
1637
1638 // Verbose error message for AbstractMethodError.
1639 // Get the called method from the invoke bytecode.
1640 vframeStream vfst(current, true);
1641 assert(!vfst.at_end(), "Java frame must exist");
1642 methodHandle caller(current, vfst.method());
1643 Bytecode_invoke invoke(caller, vfst.bci());
1644 DEBUG_ONLY( invoke.verify(); )
1645
1646 // Find the compiled caller frame.
1647 RegisterMap reg_map(current,
1648 RegisterMap::UpdateMap::include,
1649 RegisterMap::ProcessFrames::include,
1650 RegisterMap::WalkContinuation::skip);
1651 frame stubFrame = current->last_frame();
1652 assert(stubFrame.is_runtime_frame(), "must be");
1653 frame callerFrame = stubFrame.sender(®_map);
1654 assert(callerFrame.is_compiled_frame(), "must be");
1655
1656 // Install exception and return forward entry.
1657 address res = SharedRuntime::throw_AbstractMethodError_entry();
1664 LinkResolver::throw_abstract_method_error(callee, recv_klass, CHECK_(res));
1665 }
1666 JRT_BLOCK_END
1667 return res;
1668 JRT_END
1669
1670 // return verified_code_entry if interp_only_mode is not set for the current thread;
1671 // otherwise return c2i entry.
1672 address SharedRuntime::get_resolved_entry(JavaThread* current, methodHandle callee_method) {
1673 if (current->is_interp_only_mode() && !callee_method->is_special_native_intrinsic()) {
1674 // In interp_only_mode we need to go to the interpreted entry
1675 // The c2i won't patch in this mode -- see fixup_callers_callsite
1676 return callee_method->get_c2i_entry();
1677 }
1678 assert(callee_method->verified_code_entry() != nullptr, " Jump to zero!");
1679 return callee_method->verified_code_entry();
1680 }
1681
1682 // resolve a static call and patch code
1683 JRT_BLOCK_ENTRY(address, SharedRuntime::resolve_static_call_C(JavaThread* current ))
1684 PerfTraceTime timer(_perf_resolve_static_total_time);
1685
1686 methodHandle callee_method;
1687 bool enter_special = false;
1688 JRT_BLOCK
1689 callee_method = SharedRuntime::resolve_helper(false, false, CHECK_NULL);
1690 current->set_vm_result_metadata(callee_method());
1691 JRT_BLOCK_END
1692 // return compiled code entry point after potential safepoints
1693 return get_resolved_entry(current, callee_method);
1694 JRT_END
1695
1696 // resolve virtual call and update inline cache to monomorphic
1697 JRT_BLOCK_ENTRY(address, SharedRuntime::resolve_virtual_call_C(JavaThread* current))
1698 PerfTraceTime timer(_perf_resolve_virtual_total_time);
1699
1700 methodHandle callee_method;
1701 JRT_BLOCK
1702 callee_method = SharedRuntime::resolve_helper(true, false, CHECK_NULL);
1703 current->set_vm_result_metadata(callee_method());
1704 JRT_BLOCK_END
1705 // return compiled code entry point after potential safepoints
1706 return get_resolved_entry(current, callee_method);
1707 JRT_END
1708
1709
1710 // Resolve a virtual call that can be statically bound (e.g., always
1711 // monomorphic, so it has no inline cache). Patch code to resolved target.
1712 JRT_BLOCK_ENTRY(address, SharedRuntime::resolve_opt_virtual_call_C(JavaThread* current))
1713 PerfTraceTime timer(_perf_resolve_opt_virtual_total_time);
1714
1715 methodHandle callee_method;
1716 JRT_BLOCK
1717 callee_method = SharedRuntime::resolve_helper(true, true, CHECK_NULL);
1718 current->set_vm_result_metadata(callee_method());
1719 JRT_BLOCK_END
1720 // return compiled code entry point after potential safepoints
1721 return get_resolved_entry(current, callee_method);
1722 JRT_END
1723
1724 methodHandle SharedRuntime::handle_ic_miss_helper(TRAPS) {
1725 JavaThread* current = THREAD;
1726 ResourceMark rm(current);
1727 CallInfo call_info;
1728 Bytecodes::Code bc;
1729
1730 // receiver is null for static calls. An exception is thrown for null
1731 // receivers for non-static calls
1732 Handle receiver = find_callee_info(bc, call_info, CHECK_(methodHandle()));
1733
1734 methodHandle callee_method(current, call_info.selected_method());
1735
1736 AtomicAccess::inc(&_ic_miss_ctr);
1737
1738 #ifndef PRODUCT
1739 // Statistics & Tracing
1740 if (TraceCallFixup) {
1741 ResourceMark rm(current);
1742 tty->print("IC miss (%s) call to", Bytecodes::name(bc));
1743 callee_method->print_short_name(tty);
1744 tty->print_cr(" code: " INTPTR_FORMAT, p2i(callee_method->code()));
1745 }
1746
1747 if (ICMissHistogram) {
1748 MutexLocker m(VMStatistic_lock);
1749 RegisterMap reg_map(current,
1750 RegisterMap::UpdateMap::skip,
1751 RegisterMap::ProcessFrames::include,
1752 RegisterMap::WalkContinuation::skip);
1753 frame f = current->last_frame().real_sender(®_map);// skip runtime stub
1754 // produce statistics under the lock
1755 trace_ic_miss(f.pc());
1756 }
1757 #endif
1758
1841 CompiledDirectCall* cdc = CompiledDirectCall::at(call_addr);
1842 cdc->set_to_clean();
1843 break;
1844 }
1845
1846 case relocInfo::virtual_call_type: {
1847 // compiled, dispatched call (which used to call an interpreted method)
1848 CompiledIC* inline_cache = CompiledIC_at(caller_nm, call_addr);
1849 inline_cache->set_to_clean();
1850 break;
1851 }
1852 default:
1853 break;
1854 }
1855 }
1856 }
1857 }
1858
1859 methodHandle callee_method = find_callee_method(CHECK_(methodHandle()));
1860
1861 AtomicAccess::inc(&_wrong_method_ctr);
1862
1863 #ifndef PRODUCT
1864 if (TraceCallFixup) {
1865 ResourceMark rm(current);
1866 tty->print("handle_wrong_method reresolving call to");
1867 callee_method->print_short_name(tty);
1868 tty->print_cr(" code: " INTPTR_FORMAT, p2i(callee_method->code()));
1869 }
1870 #endif
1871
1872 return callee_method;
1873 }
1874
1875 address SharedRuntime::handle_unsafe_access(JavaThread* thread, address next_pc) {
1876 // The faulting unsafe accesses should be changed to throw the error
1877 // synchronously instead. Meanwhile the faulting instruction will be
1878 // skipped over (effectively turning it into a no-op) and an
1879 // asynchronous exception will be raised which the thread will
1880 // handle at a later point. If the instruction is a load it will
1881 // return garbage.
1882
1883 // Request an async exception.
2126 if (CheckJNICalls) {
2127 fatal("Object has been unlocked by JNI");
2128 }
2129 return;
2130 }
2131 ObjectSynchronizer::exit(obj, lock, current);
2132 }
2133
2134 // Handles the uncommon cases of monitor unlocking in compiled code
2135 JRT_LEAF(void, SharedRuntime::complete_monitor_unlocking_C(oopDesc* obj, BasicLock* lock, JavaThread* current))
2136 assert(current == JavaThread::current(), "pre-condition");
2137 SharedRuntime::monitor_exit_helper(obj, lock, current);
2138 JRT_END
2139
2140 #ifndef PRODUCT
2141
2142 void SharedRuntime::print_statistics() {
2143 ttyLocker ttyl;
2144 if (xtty != nullptr) xtty->head("statistics type='SharedRuntime'");
2145
2146 SharedRuntime::print_ic_miss_histogram_on(tty);
2147 SharedRuntime::print_counters_on(tty);
2148 AdapterHandlerLibrary::print_statistics_on(tty);
2149
2150 if (xtty != nullptr) xtty->tail("statistics");
2151 }
2152
2153 //void SharedRuntime::print_counters_on(outputStream* st) {
2154 // // Dump the JRT_ENTRY counters
2155 // if (_new_instance_ctr) st->print_cr("%5u new instance requires GC", _new_instance_ctr);
2156 // if (_new_array_ctr) st->print_cr("%5u new array requires GC", _new_array_ctr);
2157 // if (_multi2_ctr) st->print_cr("%5u multianewarray 2 dim", _multi2_ctr);
2158 // if (_multi3_ctr) st->print_cr("%5u multianewarray 3 dim", _multi3_ctr);
2159 // if (_multi4_ctr) st->print_cr("%5u multianewarray 4 dim", _multi4_ctr);
2160 // if (_multi5_ctr) st->print_cr("%5u multianewarray 5 dim", _multi5_ctr);
2161 //
2162 // st->print_cr("%5u inline cache miss in compiled", _ic_miss_ctr);
2163 // st->print_cr("%5u wrong method", _wrong_method_ctr);
2164 // st->print_cr("%5u unresolved static call site", _resolve_static_ctr);
2165 // st->print_cr("%5u unresolved virtual call site", _resolve_virtual_ctr);
2166 // st->print_cr("%5u unresolved opt virtual call site", _resolve_opt_virtual_ctr);
2167 //
2168 // if (_mon_enter_stub_ctr) st->print_cr("%5u monitor enter stub", _mon_enter_stub_ctr);
2169 // if (_mon_exit_stub_ctr) st->print_cr("%5u monitor exit stub", _mon_exit_stub_ctr);
2170 // if (_mon_enter_ctr) st->print_cr("%5u monitor enter slow", _mon_enter_ctr);
2171 // if (_mon_exit_ctr) st->print_cr("%5u monitor exit slow", _mon_exit_ctr);
2172 // if (_partial_subtype_ctr) st->print_cr("%5u slow partial subtype", _partial_subtype_ctr);
2173 // if (_jbyte_array_copy_ctr) st->print_cr("%5u byte array copies", _jbyte_array_copy_ctr);
2174 // if (_jshort_array_copy_ctr) st->print_cr("%5u short array copies", _jshort_array_copy_ctr);
2175 // if (_jint_array_copy_ctr) st->print_cr("%5u int array copies", _jint_array_copy_ctr);
2176 // if (_jlong_array_copy_ctr) st->print_cr("%5u long array copies", _jlong_array_copy_ctr);
2177 // if (_oop_array_copy_ctr) st->print_cr("%5u oop array copies", _oop_array_copy_ctr);
2178 // if (_checkcast_array_copy_ctr) st->print_cr("%5u checkcast array copies", _checkcast_array_copy_ctr);
2179 // if (_unsafe_array_copy_ctr) st->print_cr("%5u unsafe array copies", _unsafe_array_copy_ctr);
2180 // if (_generic_array_copy_ctr) st->print_cr("%5u generic array copies", _generic_array_copy_ctr);
2181 // if (_slow_array_copy_ctr) st->print_cr("%5u slow array copies", _slow_array_copy_ctr);
2182 // if (_find_handler_ctr) st->print_cr("%5u find exception handler", _find_handler_ctr);
2183 // if (_rethrow_ctr) st->print_cr("%5u rethrow handler", _rethrow_ctr);
2184 // if (_unsafe_set_memory_ctr) tty->print_cr("%5u unsafe set memorys", _unsafe_set_memory_ctr);
2185 //}
2186
2187 inline double percent(int64_t x, int64_t y) {
2188 return 100.0 * (double)x / (double)MAX2(y, (int64_t)1);
2189 }
2190
2191 class MethodArityHistogram {
2192 public:
2193 enum { MAX_ARITY = 256 };
2194 private:
2195 static uint64_t _arity_histogram[MAX_ARITY]; // histogram of #args
2196 static uint64_t _size_histogram[MAX_ARITY]; // histogram of arg size in words
2197 static uint64_t _total_compiled_calls;
2198 static uint64_t _max_compiled_calls_per_method;
2199 static int _max_arity; // max. arity seen
2200 static int _max_size; // max. arg size seen
2201
2202 static void add_method_to_histogram(nmethod* nm) {
2203 Method* method = (nm == nullptr) ? nullptr : nm->method();
2204 if (method != nullptr) {
2205 ArgumentCount args(method->signature());
2206 int arity = args.size() + (method->is_static() ? 0 : 1);
2251 // Take the Compile_lock to protect against changes in the CodeBlob structures
2252 MutexLocker mu1(Compile_lock, Mutex::_safepoint_check_flag);
2253 // Take the CodeCache_lock to protect against changes in the CodeHeap structure
2254 MutexLocker mu2(CodeCache_lock, Mutex::_no_safepoint_check_flag);
2255 _max_arity = _max_size = 0;
2256 _total_compiled_calls = 0;
2257 _max_compiled_calls_per_method = 0;
2258 for (int i = 0; i < MAX_ARITY; i++) _arity_histogram[i] = _size_histogram[i] = 0;
2259 CodeCache::nmethods_do(add_method_to_histogram);
2260 print_histogram();
2261 }
2262 };
2263
2264 uint64_t MethodArityHistogram::_arity_histogram[MethodArityHistogram::MAX_ARITY];
2265 uint64_t MethodArityHistogram::_size_histogram[MethodArityHistogram::MAX_ARITY];
2266 uint64_t MethodArityHistogram::_total_compiled_calls;
2267 uint64_t MethodArityHistogram::_max_compiled_calls_per_method;
2268 int MethodArityHistogram::_max_arity;
2269 int MethodArityHistogram::_max_size;
2270
2271 void SharedRuntime::print_call_statistics_on(outputStream* st) {
2272 tty->print_cr("Calls from compiled code:");
2273 int64_t total = _nof_normal_calls + _nof_interface_calls + _nof_static_calls;
2274 int64_t mono_c = _nof_normal_calls - _nof_megamorphic_calls;
2275 int64_t mono_i = _nof_interface_calls;
2276 tty->print_cr("\t" INT64_FORMAT_W(12) " (100%%) total non-inlined ", total);
2277 tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.1f%%) |- virtual calls ", _nof_normal_calls, percent(_nof_normal_calls, total));
2278 tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.0f%%) | |- inlined ", _nof_inlined_calls, percent(_nof_inlined_calls, _nof_normal_calls));
2279 tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.0f%%) | |- monomorphic ", mono_c, percent(mono_c, _nof_normal_calls));
2280 tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.0f%%) | |- megamorphic ", _nof_megamorphic_calls, percent(_nof_megamorphic_calls, _nof_normal_calls));
2281 tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.1f%%) |- interface calls ", _nof_interface_calls, percent(_nof_interface_calls, total));
2282 tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.0f%%) | |- inlined ", _nof_inlined_interface_calls, percent(_nof_inlined_interface_calls, _nof_interface_calls));
2283 tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.0f%%) | |- monomorphic ", mono_i, percent(mono_i, _nof_interface_calls));
2284 tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.1f%%) |- static/special calls", _nof_static_calls, percent(_nof_static_calls, total));
2285 tty->print_cr("\t" INT64_FORMAT_W(12) " (%4.0f%%) | |- inlined ", _nof_inlined_static_calls, percent(_nof_inlined_static_calls, _nof_static_calls));
2286 tty->cr();
2287 tty->print_cr("Note 1: counter updates are not MT-safe.");
2288 tty->print_cr("Note 2: %% in major categories are relative to total non-inlined calls;");
2289 tty->print_cr(" %% in nested categories are relative to their category");
2290 tty->print_cr(" (and thus add up to more than 100%% with inlining)");
2291 tty->cr();
2595 }
2596 #endif // INCLUDE_CDS
2597 if (entry == nullptr) {
2598 assert_lock_strong(AdapterHandlerLibrary_lock);
2599 AdapterHandlerEntry** entry_p = _adapter_handler_table->get(fp);
2600 if (entry_p != nullptr) {
2601 entry = *entry_p;
2602 assert(entry->fingerprint()->equals(fp), "fingerprint mismatch key fp %s %s (hash=%d) != found fp %s %s (hash=%d)",
2603 entry->fingerprint()->as_basic_args_string(), entry->fingerprint()->as_string(), entry->fingerprint()->compute_hash(),
2604 fp->as_basic_args_string(), fp->as_string(), fp->compute_hash());
2605 #ifndef PRODUCT
2606 _runtime_hits++;
2607 #endif
2608 }
2609 }
2610 AdapterFingerPrint::deallocate(fp);
2611 return entry;
2612 }
2613
2614 #ifndef PRODUCT
2615 void AdapterHandlerLibrary::print_statistics_on(outputStream* st) {
2616 auto size = [&] (AdapterFingerPrint* key, AdapterHandlerEntry* a) {
2617 return sizeof(*key) + sizeof(*a);
2618 };
2619 TableStatistics ts = _adapter_handler_table->statistics_calculate(size);
2620 ts.print(st, "AdapterHandlerTable");
2621 st->print_cr("AdapterHandlerTable (table_size=%d, entries=%d)",
2622 _adapter_handler_table->table_size(), _adapter_handler_table->number_of_entries());
2623 int total_hits = _archived_hits + _runtime_hits;
2624 st->print_cr("AdapterHandlerTable: lookups %d equals %d hits %d (archived=%d+runtime=%d)",
2625 _lookups, _equals, total_hits, _archived_hits, _runtime_hits);
2626 }
2627 #endif // !PRODUCT
2628
2629 // ---------------------------------------------------------------------------
2630 // Implementation of AdapterHandlerLibrary
2631 AdapterHandlerEntry* AdapterHandlerLibrary::_no_arg_handler = nullptr;
2632 AdapterHandlerEntry* AdapterHandlerLibrary::_int_arg_handler = nullptr;
2633 AdapterHandlerEntry* AdapterHandlerLibrary::_obj_arg_handler = nullptr;
2634 AdapterHandlerEntry* AdapterHandlerLibrary::_obj_int_arg_handler = nullptr;
2635 AdapterHandlerEntry* AdapterHandlerLibrary::_obj_obj_arg_handler = nullptr;
2636 #if INCLUDE_CDS
2637 ArchivedAdapterTable AdapterHandlerLibrary::_aot_adapter_handler_table;
2638 #endif // INCLUDE_CDS
2639 static const int AdapterHandlerLibrary_size = 16*K;
2640 BufferBlob* AdapterHandlerLibrary::_buffer = nullptr;
2641 volatile uint AdapterHandlerLibrary::_id_counter = 0;
2642
2643 BufferBlob* AdapterHandlerLibrary::buffer_blob() {
2644 assert(_buffer != nullptr, "should be initialized");
2645 return _buffer;
2646 }
2647
3530 };
3531 assert_locked_or_safepoint(AdapterHandlerLibrary_lock);
3532 _adapter_handler_table->iterate(findblob_runtime_table);
3533 }
3534 assert(found, "Should have found handler");
3535 }
3536
3537 void AdapterHandlerEntry::print_adapter_on(outputStream* st) const {
3538 st->print("AHE@" INTPTR_FORMAT ": %s", p2i(this), fingerprint()->as_string());
3539 if (adapter_blob() != nullptr) {
3540 st->print(" i2c: " INTPTR_FORMAT, p2i(get_i2c_entry()));
3541 st->print(" c2i: " INTPTR_FORMAT, p2i(get_c2i_entry()));
3542 st->print(" c2iUV: " INTPTR_FORMAT, p2i(get_c2i_unverified_entry()));
3543 if (get_c2i_no_clinit_check_entry() != nullptr) {
3544 st->print(" c2iNCI: " INTPTR_FORMAT, p2i(get_c2i_no_clinit_check_entry()));
3545 }
3546 }
3547 st->cr();
3548 }
3549
3550 JRT_LEAF(void, SharedRuntime::enable_stack_reserved_zone(JavaThread* current))
3551 assert(current == JavaThread::current(), "pre-condition");
3552 StackOverflow* overflow_state = current->stack_overflow_state();
3553 overflow_state->enable_stack_reserved_zone(/*check_if_disabled*/true);
3554 overflow_state->set_reserved_stack_activation(current->stack_base());
3555 JRT_END
3556
3557 frame SharedRuntime::look_for_reserved_stack_annotated_method(JavaThread* current, frame fr) {
3558 ResourceMark rm(current);
3559 frame activation;
3560 nmethod* nm = nullptr;
3561 int count = 1;
3562
3563 assert(fr.is_java_frame(), "Must start on Java frame");
3564
3565 RegisterMap map(JavaThread::current(),
3566 RegisterMap::UpdateMap::skip,
3567 RegisterMap::ProcessFrames::skip,
3568 RegisterMap::WalkContinuation::skip); // don't walk continuations
3569 for (; !fr.is_first_frame(); fr = fr.sender(&map)) {
|