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

Provide warnings about the use of JNI RegisterNatives to rebind native methods for boot/platform classes in other classloaders

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P3 P3
    • 15
    • 15
    • hotspot
    • b10

      JNI RegisterNatives provides a mechanism for binding native method implementations to the native methods declared by a Java class, as an alternate mechanism to the usual JNI linking process that occurs. For example, given the following method in java.lang.Thread:

      private native void start0();

      the normal JNI linkage process would look for a native method declared as:

      JNIEXPORT Java_java_lang_Thread_start0(JNIEnv* env, jobject thread);

      whereas RegisterNatives allows start0() to be bound directly to JVM_StartThread in the JVM.

      However, there is nothing to constrain the use of RegisterNatives so that the binding of native methods for the Thread class (for example) can only happen in native code that is itself part of the implementation of the Thread class. Any native code can bind, or rebind, any native method for any class.

      This may initially seem surprising but native agents, for example, can need the ability to intercept any method call, and interception of native methods needs rebinding to the interceptor method, which does its extra work for the agent, then calls the real method. So this is important functionality.

      Nevertheless this ability may be surprising and so we want to highlight its existence by adding additional warning text to the JNI specification, and by providing a runtime warning (which can be disabled if needed) if a native method (of a boot, or platform-loader class) is re-bound by code from a different classloader.

            dholmes David Holmes
            dholmes David Holmes
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: