RFR: 8278602: CDS dynamic dump may access unloaded classes

Ioi Lam iklam at openjdk.java.net
Thu Dec 16 23:54:30 UTC 2021


On Thu, 16 Dec 2021 08:25:44 GMT, Stefan Karlsson <stefank at openjdk.org> wrote:

>> Cause of crash:
>> 
>> When dumping a CDS archive,  while iterating over entries of the `SystemDictionaryShared::_dumptime_table`, we do not check whether the classes are already unloaded. In the crash, we are trying to call `InstanceKlass::signer()` but the class has already been unloaded.
>> 
>> Fix:
>> 
>> Override the  template function `DumpTimeSharedClassTable::iterate` to ensure iteration safety.  Do not iterate over a class if its `class_loader_data` is no longer alive.
>> 
>> The assert in `DumpTimeSharedClassTable::IterationHelper` found another existing bug -- we were calling `SystemDictionaryShared::is_dumptime_table_empty()` without holding the `DumpTimeTable_lock`. I delayed the call until we have grabbed the lock.
>> 
>> Testing:
>> 
>> I have attached a test case into the bug report. Without the fix, it would reproduce the same crash in less than a minute. With the fix, the crash is no longer reproducible.
>> 
>> Unfortunately, the test case requires a ZGC patch (thanks to @stefank) that adds delays to  increase the likelihood of seeing unloaded classes inside the `_dumptime_table`. Therefore, I cannot integrate the test as a jtreg test. I'll mark the bug as **noreg-hard**
>
> src/hotspot/share/classfile/systemDictionaryShared.cpp line 194:
> 
>> 192:   _dump_in_progress = true;
>> 193: }
>> 194: 
> 
> Did you really intend to set _dump_in_progress to true in stop_dumping()? start_dumping() also sets it to true.

Oh, it should be `_dump_in_progress = false;`. I'll fix that.

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

PR: https://git.openjdk.java.net/jdk/pull/6859


More information about the hotspot-dev mailing list