[OPenJDK]Classloader leak due to ForkJoinPool
Issue
-
Observe that no classes are unloaded with Java 21 but classes are unloaded with Java 17.
-
We have bisected to this commit, which causes the difference in behavior: GitHub Ref
In memory snapshots, we see that a ProtectionDomain is holding the class loader in question. The ProtectionDomain belongs to a thread of a ForkJoinPool. We tried submitting a task in ForkJoinPool at the start of our application, that didn't help. Possibly the leak is caused by any new thread used in the pool (see the static initializer of ForkJoinWorkerThread).
The structure of our application is roughly, the user changes classes then runs their code in our framework. We have a dedicated classloader for the user classes, we unload previous versions of user classes, then use a new classloader to load the new versions and run the user code. We use the same JDK to do so, we also hot swap when the user is in a debug session, changing their code. We need something to avoid the ProtectionDomain that causes the classloader to be leaked.
Environment
- OpenJDK
- 21
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.