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

[JNI] Cannot pass global reference as methodId in NewObjectA

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      JRE version: Java(TM) SE Runtime Environment (21.0.1+12) (build 21.0.1+12-LTS-29)

      A DESCRIPTION OF THE PROBLEM :
      When attempting to call NewObjectA using a methodId returned by NewGlobalRef, an access violation occurs.

      By using the OpenJDK code to debug, it was possible to find the root cause of this issue. For explanation purposes, this bug report will reference the OpenJDK GitHub repository [https://github.com/openjdk/jdk/tree/940f67c1a62c6f9462266f3a108649aca114cffa].

      The handler for NewObjectA in jni.cpp creates a new instance of C++ class JNI_ArgumentPusherArray and passes the unmodified methodID that was given to the handler. This constructor directly calls Method::resolve_jmethod_id on the methodID, without first passing it to one of the resolve methods in the JNIHandles class, resulting in the address being unaligned by 2 bytes. Since the resulting object will be invalid, the VM will crash.


      CUSTOMER SUBMITTED WORKAROUND :
      Bitwise AND the jmethod to remove the tag bits by using `x & ~3`

      FREQUENCY : always


            rsurianaraya Rajagopal Surianarayanan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: