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

JVM_FindClassFromClass should assert that from class is never null

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • 26
    • None
    • hotspot

      JVM_FindClassFromClass checks if the incoming "from" parameter could be null. This check is unnecessary and confusing, as subsequent code uses "from" without a null check.

      https://github.com/openjdk/jdk/blob/80ab094a75a6474c33214e3347e08ea7b9177ec8/src/hotspot/share/prims/jvm.cpp#L834-L836

        Klass* from_class = (from_class_oop == nullptr)
                                 ? (Klass*)nullptr
                                 : java_lang_Class::as_Klass(from_class_oop);
        oop class_loader = nullptr;
        if (from_class != nullptr) {
           ....

      However, JVM_FindClassFromClass() is called only from load_class_local() with context->class:

      https://github.com/openjdk/jdk/blob/80ab094a75a6474c33214e3347e08ea7b9177ec8/src/java.base/share/native/libverify/check_code.c#L567-L568

      static jclass load_class_local(context_type *context,const char *classname)
      {
          jclass cb = JVM_FindClassFromClass(context->env, classname,
                                       JNI_FALSE, context->class);

      context->class is set only in a single location, VerifyClassForMajorVersion():

      https://github.com/openjdk/jdk/blob/80ab094a75a6474c33214e3347e08ea7b9177ec8/src/java.base/share/native/libverify/check_code.c#L770-L790


      JNIEXPORT jboolean
      VerifyClassForMajorVersion(JNIEnv *env, jclass cb, char *buffer, jint len,
                                 jint major_version)
      {
          [...]
          memset(context, 0, sizeof(context_type));
          [...]
          context->class = cb;


      VerifyClassForMajorVersion() has only a single caller, Verifier::inference_verify(), which never passes a null class in the "cb" parameter:

      https://github.com/openjdk/jdk/blob/80ab094a75a6474c33214e3347e08ea7b9177ec8/src/hotspot/share/classfile/verifier.cpp#L322

      Symbol* Verifier::inference_verify(
          InstanceKlass* klass, char* message, size_t message_len, TRAPS) {
         [...]
        jclass cls = (jclass) JNIHandles::make_local(thread, klass->java_mirror());
         [...]
          result = (*verify_func)(env, cls, message, (int)message_len, klass->major_version());
       




            phubner Paul Hübner
            iklam Ioi Lam
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: