RFR: 8368727: CDS custom loader support causes asserts during class unloading
Ioi Lam
iklam at openjdk.org
Fri Sep 26 06:22:55 UTC 2025
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.
-------------
Commit messages:
- fixed whitespaces
- 8368727: CDS custom loader support causes asserts during class unloading
Changes: https://git.openjdk.org/jdk/pull/27511/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=27511&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8368727
Stats: 66 lines in 5 files changed: 54 ins; 5 del; 7 mod
Patch: https://git.openjdk.org/jdk/pull/27511.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/27511/head:pull/27511
PR: https://git.openjdk.org/jdk/pull/27511
More information about the hotspot-dev
mailing list