Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/hotspot/share/cds/metaspaceShared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down
3 changes: 3 additions & 0 deletions src/hotspot/share/classfile/classLoaderData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -885,6 +886,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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -124,8 +143,15 @@ static void doTest(boolean errorInDump) throws Exception {
};

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);
}
Expand Down