Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7009928

JSR 292: Impossible to get method ID for MH.invokeExact() with correct signature from JNI

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P2 P2
    • None
    • hs20
    • hotspot
    • generic
    • generic

      It's not possible to call MethodHandle.invokeExact() from JNI code.

      When I try to get method ID and pass actual MH signature to JNI function GetMethodID, for example:
       
          mid = GetMethodID(..., methodHandleClass, "invokeExact", "(Ljava/lang/Object;Ljava/lang/Object;IJDF)Ljava/lang/Object;");

      ...NoSuchMethodError is reported by JNI.

      Note that invokeExact calls encoded into classfiles created by JDK7 b123 javac, has actual MH signature, and NOT the signature recorded in MethodHandle.class for invokeExact: ("([Ljava/lang/Object;)Ljava/lang/Object;").
      According to the lastest JSR 292 specification, this is not a defect.

      According to documentation for MethodHandle.invokeExact() method:

      "When this method is observed via the Core Reflection API, it will appear as a single native method, taking an object array and returning an object. If this native method is invoked directly via Method.invoke, via JNI, or indirectly via java.lang.invoke.MethodHandles.Lookup#unreflect, it will throw an UnsupportedOperationException."

      Only MethodHandle.invokeWithArguments() can be used to call MethodHandle target from JNI and Reflection code.

            jrose John Rose
            kshiroko Kirill Shirokov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: