8194963: SystemDictionary::link_method_handle_constant() can't link MethodHandle.invoke()/invokeExact() jdk-10+40
authorvlivanov
Thu, 18 Jan 2018 02:25:18 +0300
changeset 48596 860326263d1f
parent 48595 5d699d81c10c
child 48597 b6bb930cd488
8194963: SystemDictionary::link_method_handle_constant() can't link MethodHandle.invoke()/invokeExact() Reviewed-by: kvn, psandoz
src/hotspot/share/classfile/systemDictionary.cpp
src/hotspot/share/classfile/vmSymbols.hpp
--- a/src/hotspot/share/classfile/systemDictionary.cpp	Wed Jan 17 14:25:47 2018 -0800
+++ b/src/hotspot/share/classfile/systemDictionary.cpp	Thu Jan 18 02:25:18 2018 +0300
@@ -2775,7 +2775,17 @@
   java_lang_invoke_MemberName::set_name (mname(), name_str());
   java_lang_invoke_MemberName::set_type (mname(), signature_str());
   java_lang_invoke_MemberName::set_flags(mname(), MethodHandles::ref_kind_to_flags(ref_kind));
-  MethodHandles::resolve_MemberName(mname, caller, CHECK_(empty));
+
+  if (ref_kind == JVM_REF_invokeVirtual &&
+      callee->name() == vmSymbols::java_lang_invoke_MethodHandle() &&
+      (name == vmSymbols::invoke_name() || name == vmSymbols::invokeExact_name())) {
+    // Skip resolution for j.l.i.MethodHandle.invoke()/invokeExact().
+    // They are public signature polymorphic methods, but require appendix argument
+    // which MemberName resolution doesn't handle. There's special logic on JDK side to handle them
+    // (see MethodHandles.linkMethodHandleConstant() and MethodHandles.findVirtualForMH()).
+  } else {
+    MethodHandles::resolve_MemberName(mname, caller, CHECK_(empty));
+  }
 
   // After method/field resolution succeeded, it's safe to resolve MH signature as well.
   Handle type = MethodHandles::resolve_MemberName_type(mname, caller, CHECK_(empty));
--- a/src/hotspot/share/classfile/vmSymbols.hpp	Wed Jan 17 14:25:47 2018 -0800
+++ b/src/hotspot/share/classfile/vmSymbols.hpp	Thu Jan 18 02:25:18 2018 +0300
@@ -304,6 +304,7 @@
   /* internal up-calls made only by the JVM, via class sun.invoke.MethodHandleNatives: */         \
   template(findMethodHandleType_name,                 "findMethodHandleType")                     \
   template(findMethodHandleType_signature,       "(Ljava/lang/Class;[Ljava/lang/Class;)Ljava/lang/invoke/MethodType;") \
+  template(invokeExact_name,                          "invokeExact")                              \
   template(linkMethodHandleConstant_name,             "linkMethodHandleConstant")                 \
   template(linkMethodHandleConstant_signature, "(Ljava/lang/Class;ILjava/lang/Class;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/invoke/MethodHandle;") \
   template(linkMethod_name,                           "linkMethod")                               \