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

loaded_classes_do may see ArrayKlass before InstanceKlass is loaded

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 19
    • Component/s: hotspot
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b07

      Description

      In the following code, if k is a shared ArrayKlass, it may be passed to klass_closure->do_klass() before its InstanceKlass is in the is_loaded() state.

      void ClassLoaderData::loaded_classes_do(KlassClosure* klass_closure) {
        // Lock-free access requires load_acquire
        for (Klass* k = Atomic::load_acquire(&_klasses); k != NULL; k = k->next_link()) {
          // Do not filter ArrayKlass oops here...
          if (k->is_array_klass() || (k->is_instance_klass() && InstanceKlass::cast(k)->is_loaded())) {
      #ifdef ASSERT
            oop m = k->java_mirror();
            assert(m != NULL, "NULL mirror");
            assert(m->is_a(vmClasses::Class_klass()), "invalid mirror");
      #endif
            klass_closure->do_klass(k);
          }
        }
      }

      Scenario:

      [1] java/lang/Object is restored via InstanceKlass::restore_unshareable_info()
      [2] [Ljava/lang/Object; is restored in when InstanceKlass::restore_unshareable_info() calls array_klasses()->restore_unshareable_info()

      At this point, both Klasses are in the ClassLoaderData::_klasses list. However, java/lang/Object is not yet loaded. If another thread calls ClassLoaderData::loaded_classes_do(), it will see the ArrayKlass but not the InstanceKlass.

      See discussions in https://github.com/openjdk/jdk/pull/5935

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              iklam Ioi Lam
              Reporter:
              iklam Ioi Lam
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: