RFR: 8278131: runtime/cds/appcds/dynamicArchive/* tests failing in loom repo
Calvin Cheung
ccheung at openjdk.java.net
Thu Dec 16 02:36:00 UTC 2021
On Wed, 15 Dec 2021 04:34:23 GMT, Ioi Lam <iklam 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
>
>> 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.
@iklam, @dholmes-ora, @yminqi Thanks for the review.
-------------
PR: https://git.openjdk.java.net/jdk/pull/6843
More information about the hotspot-runtime-dev
mailing list