On Mon, 24 Oct 2022 12:16:54 GMT, Coleen Phillimore <cole...@openjdk.org> wrote:
> This change adds an option **EnableWaitForParallelLoad** to enable the legacy > behavior where the VM will manage synchronization for multiple threads > loading the same class using a non-parallel capable class loader that have > released the class loader lock. The VM will break the class loader lock for > parallel threads trying to load the class, and wait for the first thread that > initiated loading the class to complete. The subsequent threads will use the > result of the first thread, rather than get a LinkageError: duplicate class > definition for loading the class without synchronization. > Releasing the class loader lock was a common workaround for class loaders > that used a non-hierarchical delegation scheme to avoid deadlock, before > parallel capable class loading was added. > https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/ClassLoader.html#registerAsParallelCapable() > > Tested with tier1-6 and internal applications. Marked as reviewed by mchung (Reviewer). Adding core-libs-dev so that more developers know this behavioral change. *Background:* Prior to JDK 7, custom class loaders using non-hierarchical class delegation model were prone to deadlock (see [1] for details). This workaround was added in the VM in JDK 6 to allow parallel class loading for non-parallel-capable class loaders to avoid deadlocks. The VM also supports a common workaround at the time that some customers explicitly issue a wait() on the class loader lock. Such workaround was kept to allow those customers to migrate to using multi-thread-safe parallel-capable class loaders. It has been 11 years since Java 7 and it's expected that those deadlock-prone custom class loaders should have migrated to the parallel-capable class loaders. If customers have class loaders depending on this legacy behavior, they can set `-XX:+EnableWaitForParallelLoad` flag to enable the legacy behavior and migrate to parallel-capable class loaders as soon as possible. The `EnableWaitForParallelLoad` VM flag will be removed in a future release. Refers to CSR [JDK-8295848](https://bugs.openjdk.org/browse/JDK-8295848) for details. ------------- PR: https://git.openjdk.org/jdk/pull/10832