8274753: ZGC: SEGV in MetaspaceShared::link_shared_classes

8274935: dumptime_table has stale entry

Reviewed-by: eosterlund, iklam
This commit is contained in:
Coleen Phillimore 2021-10-11 12:11:11 +00:00
parent b7af890574
commit 110e38ded8
3 changed files with 37 additions and 9 deletions
src/hotspot/share
test/hotspot/jtreg/runtime/cds/appcds/loaderConstraints

@ -584,20 +584,19 @@ void VM_PopulateDumpSharedSpace::doit() {
class CollectCLDClosure : public CLDClosure {
GrowableArray<ClassLoaderData*> _loaded_cld;
GrowableArray<Handle> _loaded_cld_handles; // keep the CLDs alive
GrowableArray<OopHandle> _loaded_cld_handles; // keep the CLDs alive
Thread* _current_thread;
public:
CollectCLDClosure(Thread* thread) : _current_thread(thread) {}
~CollectCLDClosure() {
for (int i = 0; i < _loaded_cld.length(); i++) {
ClassLoaderData* cld = _loaded_cld.at(i);
for (int i = 0; i < _loaded_cld_handles.length(); i++) {
_loaded_cld_handles.at(i).release(Universe::vm_global());
}
}
void do_cld(ClassLoaderData* cld) {
if (!cld->is_unloading()) {
_loaded_cld.append(cld);
_loaded_cld_handles.append(Handle(_current_thread, cld->holder_phantom()));
}
assert(cld->is_alive(), "must be");
_loaded_cld.append(cld);
_loaded_cld_handles.append(OopHandle(Universe::vm_global(), cld->holder_phantom()));
}
int nof_cld() const { return _loaded_cld.length(); }

@ -55,6 +55,7 @@
#include "classfile/packageEntry.hpp"
#include "classfile/symbolTable.hpp"
#include "classfile/systemDictionary.hpp"
#include "classfile/systemDictionaryShared.hpp"
#include "classfile/vmClasses.hpp"
#include "logging/log.hpp"
#include "logging/logStream.hpp"
@ -884,6 +885,8 @@ void ClassLoaderData::free_deallocate_list_C_heap_structures() {
// Remove the class so unloading events aren't triggered for
// this class (scratch or error class) in do_unloading().
remove_class(ik);
// But still have to remove it from the dumptime_table.
SystemDictionaryShared::handle_class_unloading(ik);
}
}
}

@ -52,6 +52,23 @@
* @run main/othervm/timeout=180 -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. DynamicLoaderConstraintsTest custom
*/
/**
* @test id=custom-cl-zgc
* @requires vm.cds.custom.loaders
* @requires vm.gc.Z
* @summary Test dumptime_table entries are removed with zgc eager class unloading
* @bug 8274935
* @library /test/lib
* /test/hotspot/jtreg/runtime/cds/appcds
* /test/hotspot/jtreg/runtime/cds/appcds/test-classes
* /test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive
* @modules java.base/jdk.internal.misc
* jdk.httpserver
* @build sun.hotspot.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm/timeout=180 -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. DynamicLoaderConstraintsTest custom-zgc
*/
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import jdk.test.lib.Asserts;
@ -83,9 +100,11 @@ public class DynamicLoaderConstraintsTest extends DynamicArchiveTestBase {
* if false, LoaderConstraintsApp will be loaded by the built-in AppClassLoader.
*/
static boolean useCustomLoader;
static boolean useZGC;
public static void main(String[] args) throws Exception {
useCustomLoader = (args.length != 0);
useZGC = (args.length != 0 && args[0].equals("custom-zgc"));
runTest(DynamicLoaderConstraintsTest::doTest);
}
@ -124,8 +143,15 @@ public class DynamicLoaderConstraintsTest extends DynamicArchiveTestBase {
};
if (useCustomLoader) {
cmdLine = TestCommon.concat(cmdLine, "-cp", loaderJar,
loaderMainClass, appJar);
if (useZGC) {
// Add options to force eager class unloading.
cmdLine = TestCommon.concat(cmdLine, "-cp", loaderJar,
"-XX:+UseZGC", "-XX:ZCollectionInterval=0.01",
loaderMainClass, appJar);
} else {
cmdLine = TestCommon.concat(cmdLine, "-cp", loaderJar,
loaderMainClass, appJar);
}
} else {
cmdLine = TestCommon.concat(cmdLine, "-cp", appJar);
}