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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Not an Issue
    • Affects Version/s: hs20
    • Fix Version/s: None
    • Component/s: hotspot
    • Labels:
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      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.

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: