21 * questions. |
21 * questions. |
22 * |
22 * |
23 */ |
23 */ |
24 |
24 |
25 #include "precompiled.hpp" |
25 #include "precompiled.hpp" |
|
26 #include "aot/aotLoader.hpp" |
26 #include "classfile/stringTable.hpp" |
27 #include "classfile/stringTable.hpp" |
27 #include "classfile/systemDictionary.hpp" |
28 #include "classfile/systemDictionary.hpp" |
28 #include "classfile/vmSymbols.hpp" |
29 #include "classfile/vmSymbols.hpp" |
29 #include "code/codeCache.hpp" |
30 #include "code/codeCache.hpp" |
30 #include "code/compiledIC.hpp" |
31 #include "code/compiledIC.hpp" |
77 RuntimeStub* SharedRuntime::_wrong_method_abstract_blob; |
78 RuntimeStub* SharedRuntime::_wrong_method_abstract_blob; |
78 RuntimeStub* SharedRuntime::_ic_miss_blob; |
79 RuntimeStub* SharedRuntime::_ic_miss_blob; |
79 RuntimeStub* SharedRuntime::_resolve_opt_virtual_call_blob; |
80 RuntimeStub* SharedRuntime::_resolve_opt_virtual_call_blob; |
80 RuntimeStub* SharedRuntime::_resolve_virtual_call_blob; |
81 RuntimeStub* SharedRuntime::_resolve_virtual_call_blob; |
81 RuntimeStub* SharedRuntime::_resolve_static_call_blob; |
82 RuntimeStub* SharedRuntime::_resolve_static_call_blob; |
|
83 address SharedRuntime::_resolve_static_call_entry; |
82 |
84 |
83 DeoptimizationBlob* SharedRuntime::_deopt_blob; |
85 DeoptimizationBlob* SharedRuntime::_deopt_blob; |
84 SafepointBlob* SharedRuntime::_polling_page_vectors_safepoint_handler_blob; |
86 SafepointBlob* SharedRuntime::_polling_page_vectors_safepoint_handler_blob; |
85 SafepointBlob* SharedRuntime::_polling_page_safepoint_handler_blob; |
87 SafepointBlob* SharedRuntime::_polling_page_safepoint_handler_blob; |
86 SafepointBlob* SharedRuntime::_polling_page_return_handler_blob; |
88 SafepointBlob* SharedRuntime::_polling_page_return_handler_blob; |
96 _wrong_method_abstract_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::handle_wrong_method_abstract), "wrong_method_abstract_stub"); |
98 _wrong_method_abstract_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::handle_wrong_method_abstract), "wrong_method_abstract_stub"); |
97 _ic_miss_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::handle_wrong_method_ic_miss), "ic_miss_stub"); |
99 _ic_miss_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::handle_wrong_method_ic_miss), "ic_miss_stub"); |
98 _resolve_opt_virtual_call_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::resolve_opt_virtual_call_C), "resolve_opt_virtual_call"); |
100 _resolve_opt_virtual_call_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::resolve_opt_virtual_call_C), "resolve_opt_virtual_call"); |
99 _resolve_virtual_call_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::resolve_virtual_call_C), "resolve_virtual_call"); |
101 _resolve_virtual_call_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::resolve_virtual_call_C), "resolve_virtual_call"); |
100 _resolve_static_call_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::resolve_static_call_C), "resolve_static_call"); |
102 _resolve_static_call_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::resolve_static_call_C), "resolve_static_call"); |
|
103 _resolve_static_call_entry = _resolve_static_call_blob->entry_point(); |
101 |
104 |
102 #if defined(COMPILER2) || INCLUDE_JVMCI |
105 #if defined(COMPILER2) || INCLUDE_JVMCI |
103 // Vectors are generated only by C2 and JVMCI. |
106 // Vectors are generated only by C2 and JVMCI. |
104 bool support_wide = is_wide_vector(MaxVectorSize); |
107 bool support_wide = is_wide_vector(MaxVectorSize); |
105 if (support_wide) { |
108 if (support_wide) { |
474 |
477 |
475 #if INCLUDE_JVMCI |
478 #if INCLUDE_JVMCI |
476 // JVMCI's ExceptionHandlerStub expects the thread local exception PC to be clear |
479 // JVMCI's ExceptionHandlerStub expects the thread local exception PC to be clear |
477 // and other exception handler continuations do not read it |
480 // and other exception handler continuations do not read it |
478 thread->set_exception_pc(NULL); |
481 thread->set_exception_pc(NULL); |
479 #endif |
482 #endif // INCLUDE_JVMCI |
480 |
483 |
481 // The fastest case first |
484 // The fastest case first |
482 CodeBlob* blob = CodeCache::find_blob(return_address); |
485 CodeBlob* blob = CodeCache::find_blob(return_address); |
483 nmethod* nm = (blob != NULL) ? blob->as_nmethod_or_null() : NULL; |
486 nmethod* nm = (blob != NULL) ? blob->as_nmethod_or_null() : NULL; |
484 if (nm != NULL) { |
487 if (nm != NULL) { |
501 return SharedRuntime::deopt_blob()->unpack_with_exception(); |
504 return SharedRuntime::deopt_blob()->unpack_with_exception(); |
502 } else { |
505 } else { |
503 return nm->exception_begin(); |
506 return nm->exception_begin(); |
504 } |
507 } |
505 } |
508 } |
|
509 |
|
510 #if INCLUDE_AOT |
|
511 if (UseAOT && blob->is_aot()) { |
|
512 // AOT Compiled code |
|
513 return AOTLoader::exception_begin(thread, blob, return_address); |
|
514 } |
|
515 #endif |
506 |
516 |
507 // Entry code |
517 // Entry code |
508 if (StubRoutines::returns_to_call_stub(return_address)) { |
518 if (StubRoutines::returns_to_call_stub(return_address)) { |
509 return StubRoutines::catch_exception_entry(); |
519 return StubRoutines::catch_exception_entry(); |
510 } |
520 } |
987 address SharedRuntime::native_method_throw_unsatisfied_link_error_entry() { |
997 address SharedRuntime::native_method_throw_unsatisfied_link_error_entry() { |
988 return CAST_FROM_FN_PTR(address, &throw_unsatisfied_link_error); |
998 return CAST_FROM_FN_PTR(address, &throw_unsatisfied_link_error); |
989 } |
999 } |
990 |
1000 |
991 JRT_ENTRY_NO_ASYNC(void, SharedRuntime::register_finalizer(JavaThread* thread, oopDesc* obj)) |
1001 JRT_ENTRY_NO_ASYNC(void, SharedRuntime::register_finalizer(JavaThread* thread, oopDesc* obj)) |
992 assert(obj->is_oop(), "must be a valid oop"); |
|
993 #if INCLUDE_JVMCI |
1002 #if INCLUDE_JVMCI |
994 // This removes the requirement for JVMCI compilers to emit code |
|
995 // performing a dynamic check that obj has a finalizer before |
|
996 // calling this routine. There should be no performance impact |
|
997 // for C1 since it emits a dynamic check. C2 and the interpreter |
|
998 // uses other runtime routines for registering finalizers. |
|
999 if (!obj->klass()->has_finalizer()) { |
1003 if (!obj->klass()->has_finalizer()) { |
1000 return; |
1004 return; |
1001 } |
1005 } |
1002 #endif // INCLUDE_JVMCI |
1006 #endif // INCLUDE_JVMCI |
|
1007 assert(obj->is_oop(), "must be a valid oop"); |
1003 assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise"); |
1008 assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise"); |
1004 InstanceKlass::register_finalizer(instanceOop(obj), CHECK); |
1009 InstanceKlass::register_finalizer(instanceOop(obj), CHECK); |
1005 JRT_END |
1010 JRT_END |
1006 |
1011 |
1007 |
1012 |
1224 assert(fr.is_runtime_frame(), "must be a runtimeStub"); |
1229 assert(fr.is_runtime_frame(), "must be a runtimeStub"); |
1225 fr = fr.sender(®_map); |
1230 fr = fr.sender(®_map); |
1226 assert(fr.is_entry_frame(), "must be"); |
1231 assert(fr.is_entry_frame(), "must be"); |
1227 // fr is now pointing to the entry frame. |
1232 // fr is now pointing to the entry frame. |
1228 callee_method = methodHandle(THREAD, fr.entry_frame_call_wrapper()->callee_method()); |
1233 callee_method = methodHandle(THREAD, fr.entry_frame_call_wrapper()->callee_method()); |
1229 assert(fr.entry_frame_call_wrapper()->receiver() == NULL || !callee_method->is_static(), "non-null receiver for static call??"); |
|
1230 } else { |
1234 } else { |
1231 Bytecodes::Code bc; |
1235 Bytecodes::Code bc; |
1232 CallInfo callinfo; |
1236 CallInfo callinfo; |
1233 find_callee_info_helper(thread, vfst, bc, callinfo, CHECK_(methodHandle())); |
1237 find_callee_info_helper(thread, vfst, bc, callinfo, CHECK_(methodHandle())); |
1234 callee_method = callinfo.selected_method(); |
1238 callee_method = callinfo.selected_method(); |
1353 nmethodLocker nl_callee(callee); |
1357 nmethodLocker nl_callee(callee); |
1354 #ifdef ASSERT |
1358 #ifdef ASSERT |
1355 address dest_entry_point = callee == NULL ? 0 : callee->entry_point(); // used below |
1359 address dest_entry_point = callee == NULL ? 0 : callee->entry_point(); // used below |
1356 #endif |
1360 #endif |
1357 |
1361 |
|
1362 bool is_nmethod = caller_nm->is_nmethod(); |
|
1363 |
1358 if (is_virtual) { |
1364 if (is_virtual) { |
1359 assert(receiver.not_null() || invoke_code == Bytecodes::_invokehandle, "sanity check"); |
1365 assert(receiver.not_null() || invoke_code == Bytecodes::_invokehandle, "sanity check"); |
1360 bool static_bound = call_info.resolved_method()->can_be_statically_bound(); |
1366 bool static_bound = call_info.resolved_method()->can_be_statically_bound(); |
1361 KlassHandle h_klass(THREAD, invoke_code == Bytecodes::_invokehandle ? NULL : receiver->klass()); |
1367 KlassHandle h_klass(THREAD, invoke_code == Bytecodes::_invokehandle ? NULL : receiver->klass()); |
1362 CompiledIC::compute_monomorphic_entry(callee_method, h_klass, |
1368 CompiledIC::compute_monomorphic_entry(callee_method, h_klass, |
1363 is_optimized, static_bound, virtual_call_info, |
1369 is_optimized, static_bound, is_nmethod, virtual_call_info, |
1364 CHECK_(methodHandle())); |
1370 CHECK_(methodHandle())); |
1365 } else { |
1371 } else { |
1366 // static call |
1372 // static call |
1367 CompiledStaticCall::compute_entry(callee_method, static_call_info); |
1373 CompiledStaticCall::compute_entry(callee_method, is_nmethod, static_call_info); |
1368 } |
1374 } |
1369 |
1375 |
1370 // grab lock, check for deoptimization and potentially patch caller |
1376 // grab lock, check for deoptimization and potentially patch caller |
1371 { |
1377 { |
1372 MutexLocker ml_patch(CompiledIC_lock); |
1378 MutexLocker ml_patch(CompiledIC_lock); |
1393 CompiledIC* inline_cache = CompiledIC_before(caller_nm, caller_frame.pc()); |
1399 CompiledIC* inline_cache = CompiledIC_before(caller_nm, caller_frame.pc()); |
1394 if (inline_cache->is_clean()) { |
1400 if (inline_cache->is_clean()) { |
1395 inline_cache->set_to_monomorphic(virtual_call_info); |
1401 inline_cache->set_to_monomorphic(virtual_call_info); |
1396 } |
1402 } |
1397 } else { |
1403 } else { |
1398 CompiledStaticCall* ssc = compiledStaticCall_before(caller_frame.pc()); |
1404 CompiledStaticCall* ssc = caller_nm->compiledStaticCall_before(caller_frame.pc()); |
1399 if (ssc->is_clean()) ssc->set(static_call_info); |
1405 if (ssc->is_clean()) ssc->set(static_call_info); |
1400 } |
1406 } |
1401 } |
1407 } |
1402 |
1408 |
1403 } // unlock CompiledIC_lock |
1409 } // unlock CompiledIC_lock |
1507 JRT_BLOCK_END |
1513 JRT_BLOCK_END |
1508 // return compiled code entry point after potential safepoints |
1514 // return compiled code entry point after potential safepoints |
1509 assert(callee_method->verified_code_entry() != NULL, " Jump to zero!"); |
1515 assert(callee_method->verified_code_entry() != NULL, " Jump to zero!"); |
1510 return callee_method->verified_code_entry(); |
1516 return callee_method->verified_code_entry(); |
1511 JRT_END |
1517 JRT_END |
|
1518 |
1512 |
1519 |
1513 |
1520 |
1514 methodHandle SharedRuntime::handle_ic_miss_helper(JavaThread *thread, TRAPS) { |
1521 methodHandle SharedRuntime::handle_ic_miss_helper(JavaThread *thread, TRAPS) { |
1515 ResourceMark rm(thread); |
1522 ResourceMark rm(thread); |
1516 CallInfo call_info; |
1523 CallInfo call_info; |
1621 CompiledICInfo info; |
1628 CompiledICInfo info; |
1622 KlassHandle receiver_klass(THREAD, receiver()->klass()); |
1629 KlassHandle receiver_klass(THREAD, receiver()->klass()); |
1623 inline_cache->compute_monomorphic_entry(callee_method, |
1630 inline_cache->compute_monomorphic_entry(callee_method, |
1624 receiver_klass, |
1631 receiver_klass, |
1625 inline_cache->is_optimized(), |
1632 inline_cache->is_optimized(), |
1626 false, |
1633 false, caller_nm->is_nmethod(), |
1627 info, CHECK_(methodHandle())); |
1634 info, CHECK_(methodHandle())); |
1628 inline_cache->set_to_monomorphic(info); |
1635 inline_cache->set_to_monomorphic(info); |
1629 } else if (!inline_cache->is_megamorphic() && !inline_cache->is_clean()) { |
1636 } else if (!inline_cache->is_megamorphic() && !inline_cache->is_clean()) { |
1630 // Potential change to megamorphic |
1637 // Potential change to megamorphic |
1631 bool successful = inline_cache->set_to_megamorphic(&call_info, bc, CHECK_(methodHandle())); |
1638 bool successful = inline_cache->set_to_megamorphic(&call_info, bc, CHECK_(methodHandle())); |
1690 { |
1697 { |
1691 // Get call instruction under lock because another thread may be |
1698 // Get call instruction under lock because another thread may be |
1692 // busy patching it. |
1699 // busy patching it. |
1693 MutexLockerEx ml_patch(Patching_lock, Mutex::_no_safepoint_check_flag); |
1700 MutexLockerEx ml_patch(Patching_lock, Mutex::_no_safepoint_check_flag); |
1694 // Location of call instruction |
1701 // Location of call instruction |
1695 if (NativeCall::is_call_before(pc)) { |
1702 call_addr = caller_nm->call_instruction_address(pc); |
1696 NativeCall *ncall = nativeCall_before(pc); |
|
1697 call_addr = ncall->instruction_address(); |
|
1698 } |
|
1699 } |
1703 } |
1700 // Make sure nmethod doesn't get deoptimized and removed until |
1704 // Make sure nmethod doesn't get deoptimized and removed until |
1701 // this is done with it. |
1705 // this is done with it. |
1702 // CLEANUP - with lazy deopt shouldn't need this lock |
1706 // CLEANUP - with lazy deopt shouldn't need this lock |
1703 nmethodLocker nmlock(caller_nm); |
1707 nmethodLocker nmlock(caller_nm); |
1723 // is always done through the same code path. (experience shows that it |
1727 // is always done through the same code path. (experience shows that it |
1724 // leads to very hard to track down bugs, if an inline cache gets updated |
1728 // leads to very hard to track down bugs, if an inline cache gets updated |
1725 // to a wrong method). It should not be performance critical, since the |
1729 // to a wrong method). It should not be performance critical, since the |
1726 // resolve is only done once. |
1730 // resolve is only done once. |
1727 |
1731 |
|
1732 bool is_nmethod = caller_nm->is_nmethod(); |
1728 MutexLocker ml(CompiledIC_lock); |
1733 MutexLocker ml(CompiledIC_lock); |
1729 if (is_static_call) { |
1734 if (is_static_call) { |
1730 CompiledStaticCall* ssc= compiledStaticCall_at(call_addr); |
1735 CompiledStaticCall* ssc = caller_nm->compiledStaticCall_at(call_addr); |
1731 ssc->set_to_clean(); |
1736 ssc->set_to_clean(); |
1732 } else { |
1737 } else { |
1733 // compiled, dispatched call (which used to call an interpreted method) |
1738 // compiled, dispatched call (which used to call an interpreted method) |
1734 CompiledIC* inline_cache = CompiledIC_at(caller_nm, call_addr); |
1739 CompiledIC* inline_cache = CompiledIC_at(caller_nm, call_addr); |
1735 inline_cache->set_to_clean(); |
1740 inline_cache->set_to_clean(); |
1791 assert(a->value() == b->value(), "register allocation mismatch: a=" INTX_FORMAT ", b=" INTX_FORMAT, a->value(), b->value()); |
1796 assert(a->value() == b->value(), "register allocation mismatch: a=" INTX_FORMAT ", b=" INTX_FORMAT, a->value(), b->value()); |
1792 } |
1797 } |
1793 assert(regs_with_member_name[member_arg_pos].first()->is_valid(), "bad member arg"); |
1798 assert(regs_with_member_name[member_arg_pos].first()->is_valid(), "bad member arg"); |
1794 } |
1799 } |
1795 #endif |
1800 #endif |
|
1801 |
|
1802 bool SharedRuntime::should_fixup_call_destination(address destination, address entry_point, address caller_pc, Method* moop, CodeBlob* cb) { |
|
1803 if (destination != entry_point) { |
|
1804 CodeBlob* callee = CodeCache::find_blob(destination); |
|
1805 // callee == cb seems weird. It means calling interpreter thru stub. |
|
1806 if (callee == cb || callee->is_adapter_blob()) { |
|
1807 // static call or optimized virtual |
|
1808 if (TraceCallFixup) { |
|
1809 tty->print("fixup callsite at " INTPTR_FORMAT " to compiled code for", p2i(caller_pc)); |
|
1810 moop->print_short_name(tty); |
|
1811 tty->print_cr(" to " INTPTR_FORMAT, p2i(entry_point)); |
|
1812 } |
|
1813 return true; |
|
1814 } else { |
|
1815 if (TraceCallFixup) { |
|
1816 tty->print("failed to fixup callsite at " INTPTR_FORMAT " to compiled code for", p2i(caller_pc)); |
|
1817 moop->print_short_name(tty); |
|
1818 tty->print_cr(" to " INTPTR_FORMAT, p2i(entry_point)); |
|
1819 } |
|
1820 // assert is too strong could also be resolve destinations. |
|
1821 // assert(InlineCacheBuffer::contains(destination) || VtableStubs::contains(destination), "must be"); |
|
1822 } |
|
1823 } else { |
|
1824 if (TraceCallFixup) { |
|
1825 tty->print("already patched callsite at " INTPTR_FORMAT " to compiled code for", p2i(caller_pc)); |
|
1826 moop->print_short_name(tty); |
|
1827 tty->print_cr(" to " INTPTR_FORMAT, p2i(entry_point)); |
|
1828 } |
|
1829 } |
|
1830 return false; |
|
1831 } |
1796 |
1832 |
1797 // --------------------------------------------------------------------------- |
1833 // --------------------------------------------------------------------------- |
1798 // We are calling the interpreter via a c2i. Normally this would mean that |
1834 // We are calling the interpreter via a c2i. Normally this would mean that |
1799 // we were called by a compiled method. However we could have lost a race |
1835 // we were called by a compiled method. However we could have lost a race |
1800 // where we went int -> i2c -> c2i and so the caller could in fact be |
1836 // where we went int -> i2c -> c2i and so the caller could in fact be |
1841 if (nm->is_in_use()) { |
1877 if (nm->is_in_use()) { |
1842 |
1878 |
1843 // Expect to find a native call there (unless it was no-inline cache vtable dispatch) |
1879 // Expect to find a native call there (unless it was no-inline cache vtable dispatch) |
1844 MutexLockerEx ml_patch(Patching_lock, Mutex::_no_safepoint_check_flag); |
1880 MutexLockerEx ml_patch(Patching_lock, Mutex::_no_safepoint_check_flag); |
1845 if (NativeCall::is_call_before(return_pc)) { |
1881 if (NativeCall::is_call_before(return_pc)) { |
1846 NativeCall *call = nativeCall_before(return_pc); |
1882 ResourceMark mark; |
|
1883 NativeCallWrapper* call = nm->call_wrapper_before(return_pc); |
1847 // |
1884 // |
1848 // bug 6281185. We might get here after resolving a call site to a vanilla |
1885 // bug 6281185. We might get here after resolving a call site to a vanilla |
1849 // virtual call. Because the resolvee uses the verified entry it may then |
1886 // virtual call. Because the resolvee uses the verified entry it may then |
1850 // see compiled code and attempt to patch the site by calling us. This would |
1887 // see compiled code and attempt to patch the site by calling us. This would |
1851 // then incorrectly convert the call site to optimized and its downhill from |
1888 // then incorrectly convert the call site to optimized and its downhill from |
1862 typ != relocInfo::opt_virtual_call_type && |
1899 typ != relocInfo::opt_virtual_call_type && |
1863 typ != relocInfo::static_stub_type) { |
1900 typ != relocInfo::static_stub_type) { |
1864 return; |
1901 return; |
1865 } |
1902 } |
1866 address destination = call->destination(); |
1903 address destination = call->destination(); |
1867 if (destination != entry_point) { |
1904 if (should_fixup_call_destination(destination, entry_point, caller_pc, moop, cb)) { |
1868 CodeBlob* callee = CodeCache::find_blob(destination); |
1905 call->set_destination_mt_safe(entry_point); |
1869 // callee == cb seems weird. It means calling interpreter thru stub. |
|
1870 if (callee == cb || callee->is_adapter_blob()) { |
|
1871 // static call or optimized virtual |
|
1872 if (TraceCallFixup) { |
|
1873 tty->print("fixup callsite at " INTPTR_FORMAT " to compiled code for", p2i(caller_pc)); |
|
1874 moop->print_short_name(tty); |
|
1875 tty->print_cr(" to " INTPTR_FORMAT, p2i(entry_point)); |
|
1876 } |
|
1877 call->set_destination_mt_safe(entry_point); |
|
1878 } else { |
|
1879 if (TraceCallFixup) { |
|
1880 tty->print("failed to fixup callsite at " INTPTR_FORMAT " to compiled code for", p2i(caller_pc)); |
|
1881 moop->print_short_name(tty); |
|
1882 tty->print_cr(" to " INTPTR_FORMAT, p2i(entry_point)); |
|
1883 } |
|
1884 // assert is too strong could also be resolve destinations. |
|
1885 // assert(InlineCacheBuffer::contains(destination) || VtableStubs::contains(destination), "must be"); |
|
1886 } |
|
1887 } else { |
|
1888 if (TraceCallFixup) { |
|
1889 tty->print("already patched callsite at " INTPTR_FORMAT " to compiled code for", p2i(caller_pc)); |
|
1890 moop->print_short_name(tty); |
|
1891 tty->print_cr(" to " INTPTR_FORMAT, p2i(entry_point)); |
|
1892 } |
|
1893 } |
1906 } |
1894 } |
1907 } |
1895 } |
1908 } |
1896 IRT_END |
1909 IRT_END |
1897 |
1910 |