RFR: 8278131: runtime/cds/appcds/dynamicArchive/* tests failing in loom repo
Ioi Lam
iklam at openjdk.java.net
Wed Dec 15 04:38:04 UTC 2021
On Wed, 15 Dec 2021 01:40:26 GMT, David Holmes <dholmes at openjdk.org> wrote:
> Sorry but this isn't making any sense to me. You can't GC a class until its classloader becomes unreachable - at which point the classloader and all its loaded classes become unreachable together. So you can't keep a class alive by storing a reference to it in a static field of a class loaded by the same classloader - it was already kept alive.
>
> David
Hi David,
URLClassLoader urlClassLoader =
new URLClassLoader("HelloClassLoader", urls, null);
Class c = Class.forName(className, true, urlClassLoader);
+ if (keepAlive) {
+ keptC = c;
+ }
The class `c` is defined by a custom class loader (`urlClassLoader`). Before this patch, when `urlClassLoader` and `c` fall out of scope, this class becomes eligible for garbage collection.
The class that runs the above code (`HelloUnload`) is loaded by the app class loader. By referencing `c` in a static field of `HelloUnload`, we make sure `c` is never unloaded.
-------------
PR: https://git.openjdk.java.net/jdk/pull/6843
More information about the hotspot-runtime-dev
mailing list