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

[premain] InstanceKlass::initialize_from_cds() is not thread safe

XMLWordPrintable

      InstanceKlass::initialize_from_cds() assumes that it's running in single-threads mode, and tries to mark a class as initialized without locking.

      https://github.com/openjdk/leyden/blob/603b991fc2a66b2c67857cd989efa12b6da063cd/src/hotspot/share/oops/instanceKlass.cpp#L818-L857

      However, it looks like ClassPrelinker::init_javabase_preloaded_classes() may be called too late, after some Java threads have already started.

      # Internal Error (.../src/hotspot/share/oops/instanceKlass.hpp:1101), pid=90195, tid=8963
      # assert((thread == JavaThread::current() && _init_thread == nullptr) || (thread == nullptr && _init_thread == JavaThread::current())) failed: Only one thread is allowed to own initialization

      V [libjvm.dylib+0x870b44] InstanceKlass::set_init_thread(JavaThread*)+0x110
      V [libjvm.dylib+0x8706e8] InstanceKlass::initialize_from_cds(JavaThread*)+0x304
      V [libjvm.dylib+0x4af024] ClassPrelinker::init_javabase_preloaded_classes(JavaThread*)+0x70
      V [libjvm.dylib+0x10dddf8] Threads::create_vm(JavaVMInitArgs*, bool*)+0x5b0

      ==============
      Suggested fix -- ClassPrelinker::init_javabase_preloaded_classes() should be moved to an earlier phase.

            iklam Ioi Lam
            iklam Ioi Lam
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: