1778 LinkInfo link_info(pool, index, Bytecodes::_invokeinterface, CHECK);
1779 Klass* recvrKlass = recv.is_null() ? (Klass*)nullptr : recv->klass();
1780 resolve_interface_call(result, recv, recvrKlass, link_info, true, CHECK);
1781 }
1782
1783 bool LinkResolver::resolve_previously_linked_invokehandle(CallInfo& result, const LinkInfo& link_info, const constantPoolHandle& pool, int index, TRAPS) {
1784 ResolvedMethodEntry* method_entry = pool->cache()->resolved_method_entry_at(index);
1785 if (method_entry->method() != nullptr) {
1786 Klass* resolved_klass = link_info.resolved_klass();
1787 methodHandle method(THREAD, method_entry->method());
1788 Handle appendix(THREAD, pool->cache()->appendix_if_resolved(method_entry));
1789 result.set_handle(resolved_klass, method, appendix, CHECK_false);
1790 JFR_ONLY(Jfr::on_resolution(result, CHECK_false);)
1791 return true;
1792 } else {
1793 return false;
1794 }
1795 }
1796
1797 void LinkResolver::resolve_invokehandle(CallInfo& result, const constantPoolHandle& pool, int index, TRAPS) {
1798
1799 PerfTraceTimedEvent timer(ClassLoader::perf_resolve_invokehandle_time(),
1800 ClassLoader::perf_resolve_invokehandle_count());
1801
1802 LinkInfo link_info(pool, index, Bytecodes::_invokehandle, CHECK);
1803 if (log_is_enabled(Info, methodhandles)) {
1804 ResourceMark rm(THREAD);
1805 log_info(methodhandles)("resolve_invokehandle %s %s", link_info.name()->as_C_string(),
1806 link_info.signature()->as_C_string());
1807 }
1808 { // Check if the call site has been bound already, and short circuit:
1809 bool is_done = resolve_previously_linked_invokehandle(result, link_info, pool, index, CHECK);
1810 if (is_done) return;
1811 }
1812 resolve_handle_call(result, link_info, CHECK);
1813 }
1814
1815 void LinkResolver::resolve_handle_call(CallInfo& result,
1816 const LinkInfo& link_info,
1817 TRAPS) {
1818 // JSR 292: this must be an implicitly generated method MethodHandle.invokeExact(*...) or similar
1819 Klass* resolved_klass = link_info.resolved_klass();
1820 assert(resolved_klass == vmClasses::MethodHandle_klass() ||
1821 resolved_klass == vmClasses::VarHandle_klass(), "");
1822 assert(MethodHandles::is_signature_polymorphic_name(link_info.name()), "");
1823 Handle resolved_appendix;
1824 Method* m = lookup_polymorphic_method(link_info, &resolved_appendix, CHECK);
1825 methodHandle resolved_method(THREAD, m);
1826
1827 if (link_info.check_access()) {
1828 Symbol* name = link_info.name();
1829 vmIntrinsics::ID iid = MethodHandles::signature_polymorphic_name_id(name);
1830 if (MethodHandles::is_signature_polymorphic_intrinsic(iid)) {
1831 // Check if method can be accessed by the referring class.
1834
1835 Klass* current_klass = link_info.current_klass();
1836 assert(current_klass != nullptr , "current_klass should not be null");
1837 check_method_accessability(current_klass,
1838 resolved_klass,
1839 resolved_method->method_holder(),
1840 resolved_method,
1841 CHECK);
1842 } else {
1843 // Java code is free to arbitrarily link signature-polymorphic invokers.
1844 assert(iid == vmIntrinsics::_invokeGeneric, "not an invoker: %s", vmIntrinsics::name_at(iid));
1845 assert(MethodHandles::is_signature_polymorphic_public_name(resolved_klass, name), "not public");
1846 }
1847 }
1848 result.set_handle(resolved_klass, resolved_method, resolved_appendix, CHECK);
1849 JFR_ONLY(Jfr::on_resolution(result, CHECK);)
1850 }
1851
1852 void LinkResolver::resolve_invokedynamic(CallInfo& result, const constantPoolHandle& pool, int indy_index, TRAPS) {
1853 PerfTraceTimedEvent timer(ClassLoader::perf_resolve_invokedynamic_time(),
1854 ClassLoader::perf_resolve_invokedynamic_count());
1855
1856 int pool_index = pool->resolved_indy_entry_at(indy_index)->constant_pool_index();
1857
1858 // Resolve the bootstrap specifier (BSM + optional arguments).
1859 BootstrapInfo bootstrap_specifier(pool, pool_index, indy_index);
1860
1861 // Check if CallSite has been bound already or failed already, and short circuit:
1862 {
1863 bool is_done = bootstrap_specifier.resolve_previously_linked_invokedynamic(result, CHECK);
1864 if (is_done) return;
1865 }
1866
1867 // The initial step in Call Site Specifier Resolution is to resolve the symbolic
1868 // reference to a method handle which will be the bootstrap method for a dynamic
1869 // call site. If resolution for the java.lang.invoke.MethodHandle for the bootstrap
1870 // method fails, then a MethodHandleInError is stored at the corresponding bootstrap
1871 // method's CP index for the CONSTANT_MethodHandle_info.
1872 // Any subsequent invokedynamic instruction which shares
1873 // this bootstrap method will encounter the resolution of MethodHandleInError.
1874
1875 resolve_dynamic_call(result, bootstrap_specifier, CHECK);
|
1778 LinkInfo link_info(pool, index, Bytecodes::_invokeinterface, CHECK);
1779 Klass* recvrKlass = recv.is_null() ? (Klass*)nullptr : recv->klass();
1780 resolve_interface_call(result, recv, recvrKlass, link_info, true, CHECK);
1781 }
1782
1783 bool LinkResolver::resolve_previously_linked_invokehandle(CallInfo& result, const LinkInfo& link_info, const constantPoolHandle& pool, int index, TRAPS) {
1784 ResolvedMethodEntry* method_entry = pool->cache()->resolved_method_entry_at(index);
1785 if (method_entry->method() != nullptr) {
1786 Klass* resolved_klass = link_info.resolved_klass();
1787 methodHandle method(THREAD, method_entry->method());
1788 Handle appendix(THREAD, pool->cache()->appendix_if_resolved(method_entry));
1789 result.set_handle(resolved_klass, method, appendix, CHECK_false);
1790 JFR_ONLY(Jfr::on_resolution(result, CHECK_false);)
1791 return true;
1792 } else {
1793 return false;
1794 }
1795 }
1796
1797 void LinkResolver::resolve_invokehandle(CallInfo& result, const constantPoolHandle& pool, int index, TRAPS) {
1798 PerfTraceTimedEvent timer(ClassLoader::perf_resolve_invokehandle_time(),
1799 ClassLoader::perf_resolve_invokehandle_count(),
1800 THREAD->class_being_initialized() == nullptr);
1801
1802 LinkInfo link_info(pool, index, Bytecodes::_invokehandle, CHECK);
1803 { // Check if the call site has been bound already, and short circuit:
1804 bool is_done = resolve_previously_linked_invokehandle(result, link_info, pool, index, CHECK);
1805 if (is_done) return;
1806 }
1807 if (log_is_enabled(Info, methodhandles)) {
1808 ResourceMark rm(THREAD);
1809 log_info(methodhandles)("resolve_invokehandle %s %s", link_info.name()->as_C_string(),
1810 link_info.signature()->as_C_string());
1811 }
1812 resolve_handle_call(result, link_info, CHECK);
1813 }
1814
1815 void LinkResolver::resolve_handle_call(CallInfo& result,
1816 const LinkInfo& link_info,
1817 TRAPS) {
1818 // JSR 292: this must be an implicitly generated method MethodHandle.invokeExact(*...) or similar
1819 Klass* resolved_klass = link_info.resolved_klass();
1820 assert(resolved_klass == vmClasses::MethodHandle_klass() ||
1821 resolved_klass == vmClasses::VarHandle_klass(), "");
1822 assert(MethodHandles::is_signature_polymorphic_name(link_info.name()), "");
1823 Handle resolved_appendix;
1824 Method* m = lookup_polymorphic_method(link_info, &resolved_appendix, CHECK);
1825 methodHandle resolved_method(THREAD, m);
1826
1827 if (link_info.check_access()) {
1828 Symbol* name = link_info.name();
1829 vmIntrinsics::ID iid = MethodHandles::signature_polymorphic_name_id(name);
1830 if (MethodHandles::is_signature_polymorphic_intrinsic(iid)) {
1831 // Check if method can be accessed by the referring class.
1834
1835 Klass* current_klass = link_info.current_klass();
1836 assert(current_klass != nullptr , "current_klass should not be null");
1837 check_method_accessability(current_klass,
1838 resolved_klass,
1839 resolved_method->method_holder(),
1840 resolved_method,
1841 CHECK);
1842 } else {
1843 // Java code is free to arbitrarily link signature-polymorphic invokers.
1844 assert(iid == vmIntrinsics::_invokeGeneric, "not an invoker: %s", vmIntrinsics::name_at(iid));
1845 assert(MethodHandles::is_signature_polymorphic_public_name(resolved_klass, name), "not public");
1846 }
1847 }
1848 result.set_handle(resolved_klass, resolved_method, resolved_appendix, CHECK);
1849 JFR_ONLY(Jfr::on_resolution(result, CHECK);)
1850 }
1851
1852 void LinkResolver::resolve_invokedynamic(CallInfo& result, const constantPoolHandle& pool, int indy_index, TRAPS) {
1853 PerfTraceTimedEvent timer(ClassLoader::perf_resolve_invokedynamic_time(),
1854 ClassLoader::perf_resolve_invokedynamic_count(),
1855 THREAD->class_being_initialized() == nullptr);
1856 int pool_index = pool->resolved_indy_entry_at(indy_index)->constant_pool_index();
1857
1858 // Resolve the bootstrap specifier (BSM + optional arguments).
1859 BootstrapInfo bootstrap_specifier(pool, pool_index, indy_index);
1860
1861 // Check if CallSite has been bound already or failed already, and short circuit:
1862 {
1863 bool is_done = bootstrap_specifier.resolve_previously_linked_invokedynamic(result, CHECK);
1864 if (is_done) return;
1865 }
1866
1867 // The initial step in Call Site Specifier Resolution is to resolve the symbolic
1868 // reference to a method handle which will be the bootstrap method for a dynamic
1869 // call site. If resolution for the java.lang.invoke.MethodHandle for the bootstrap
1870 // method fails, then a MethodHandleInError is stored at the corresponding bootstrap
1871 // method's CP index for the CONSTANT_MethodHandle_info.
1872 // Any subsequent invokedynamic instruction which shares
1873 // this bootstrap method will encounter the resolution of MethodHandleInError.
1874
1875 resolve_dynamic_call(result, bootstrap_specifier, CHECK);
|