RFR: 8368727: CDS custom loader support causes asserts during class unloading

David Holmes dholmes at openjdk.org
Thu Oct 2 05:16:54 UTC 2025


On Fri, 26 Sep 2025 06:11:54 GMT, Ioi Lam <iklam at openjdk.org> wrote:

> When loading a class `k` from the CDS archive on behalf of a custom class loader, we were calling `loader_data->add_class(k)` too early. If the loading of `k` fails, it may be in `loader_data->_klasses`, but `k->init_state()` will remain `allocated`. This causes an assert during class unloading:
> 
> 
> # assert(ik->is_loaded()) failed: class should be loaded 0x000000000b518eb8
> V [libjvm.so+0xfa6bd5] InstanceKlass::unload_class(InstanceKlass*)+0x555 (instanceKlass.cpp:2870)
> V [libjvm.so+0xa790e3] ClassLoaderData::classes_do(void (*)(InstanceKlass*))+0xc3 (classLoaderData.cpp:441
> 
> 
> The fix is to move the  `loader_data->add_class(k)` call to `k->Klass::restore_unshareable_info()`. This is the same location as if `k` were loaded by the 3 built-in class loaders.
> 
> This was discovered when running some JCK tests in AOT mode. I've added a reproducer as a jtreg test case.

Okay.

Thanks

-------------

Marked as reviewed by dholmes (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/27511#pullrequestreview-3292396228


More information about the hotspot-dev mailing list