JDK-8293174 : Implement special unlocked parallel class loading handling in Java
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 20
  • Priority: P3
  • Status: Resolved
  • Resolution: Won't Fix
  • Submitted: 2022-08-31
  • Updated: 2022-12-14
  • Resolved: 2022-12-14
Related Reports
Relates :  
Relates :  
Relates :  
Description
There is special case class loading code in the JVM that detects whether another thread is loading a class from a non-parallel capable class loader and waits for that thread to complete.  This is a long-standing behavior in the JVM to handle older class loading code that releases the ClassLoader object lock while loading.  The result of this behavior is that unlocked class loading does not get a LinkageError: duplicate class definition.

This code is implemented in the SystemDictionary double_lock_wait function and surrounding code, and uses internal information about object monitors to release the class loader lock in order to make the second thread wait for the first.  This code can be moved to Java which can then simply wait on the lock with normal Object.wait call.

The proposal is to move this wait to Java and have the JVM class loader call out to that function which will detect the class loading already in progress, and synchronize loading that class to not get LinkageError.

Moving this to Java allows us to remove the code that notifies and reenters the class loader lock using details from our internal implementation.

The linked bug JDK-8295673 proposed to deprecate and remove this behavior since it is not specified in either the JVMS or JLS.
Comments
If the special unlocked parallel class loading is removed via JDK-8298469 there's no need to move it to Java.
14-12-2022