Skip to content

Commit 110e38d

Browse files
committedOct 11, 2021
8274753: ZGC: SEGV in MetaspaceShared::link_shared_classes
8274935: dumptime_table has stale entry Reviewed-by: eosterlund, iklam
1 parent b7af890 commit 110e38d

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed
 

‎src/hotspot/share/cds/metaspaceShared.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -584,20 +584,19 @@ void VM_PopulateDumpSharedSpace::doit() {
584584

585585
class CollectCLDClosure : public CLDClosure {
586586
GrowableArray<ClassLoaderData*> _loaded_cld;
587-
GrowableArray<Handle> _loaded_cld_handles; // keep the CLDs alive
587+
GrowableArray<OopHandle> _loaded_cld_handles; // keep the CLDs alive
588588
Thread* _current_thread;
589589
public:
590590
CollectCLDClosure(Thread* thread) : _current_thread(thread) {}
591591
~CollectCLDClosure() {
592-
for (int i = 0; i < _loaded_cld.length(); i++) {
593-
ClassLoaderData* cld = _loaded_cld.at(i);
592+
for (int i = 0; i < _loaded_cld_handles.length(); i++) {
593+
_loaded_cld_handles.at(i).release(Universe::vm_global());
594594
}
595595
}
596596
void do_cld(ClassLoaderData* cld) {
597-
if (!cld->is_unloading()) {
598-
_loaded_cld.append(cld);
599-
_loaded_cld_handles.append(Handle(_current_thread, cld->holder_phantom()));
600-
}
597+
assert(cld->is_alive(), "must be");
598+
_loaded_cld.append(cld);
599+
_loaded_cld_handles.append(OopHandle(Universe::vm_global(), cld->holder_phantom()));
601600
}
602601

603602
int nof_cld() const { return _loaded_cld.length(); }

‎src/hotspot/share/classfile/classLoaderData.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include "classfile/packageEntry.hpp"
5656
#include "classfile/symbolTable.hpp"
5757
#include "classfile/systemDictionary.hpp"
58+
#include "classfile/systemDictionaryShared.hpp"
5859
#include "classfile/vmClasses.hpp"
5960
#include "logging/log.hpp"
6061
#include "logging/logStream.hpp"
@@ -884,6 +885,8 @@ void ClassLoaderData::free_deallocate_list_C_heap_structures() {
884885
// Remove the class so unloading events aren't triggered for
885886
// this class (scratch or error class) in do_unloading().
886887
remove_class(ik);
888+
// But still have to remove it from the dumptime_table.
889+
SystemDictionaryShared::handle_class_unloading(ik);
887890
}
888891
}
889892
}

‎test/hotspot/jtreg/runtime/cds/appcds/loaderConstraints/DynamicLoaderConstraintsTest.java

+28-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,23 @@
5252
* @run main/othervm/timeout=180 -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. DynamicLoaderConstraintsTest custom
5353
*/
5454

55+
/**
56+
* @test id=custom-cl-zgc
57+
* @requires vm.cds.custom.loaders
58+
* @requires vm.gc.Z
59+
* @summary Test dumptime_table entries are removed with zgc eager class unloading
60+
* @bug 8274935
61+
* @library /test/lib
62+
* /test/hotspot/jtreg/runtime/cds/appcds
63+
* /test/hotspot/jtreg/runtime/cds/appcds/test-classes
64+
* /test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive
65+
* @modules java.base/jdk.internal.misc
66+
* jdk.httpserver
67+
* @build sun.hotspot.WhiteBox
68+
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
69+
* @run main/othervm/timeout=180 -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. DynamicLoaderConstraintsTest custom-zgc
70+
*/
71+
5572
import com.sun.net.httpserver.HttpExchange;
5673
import com.sun.net.httpserver.HttpHandler;
5774
import jdk.test.lib.Asserts;
@@ -83,9 +100,11 @@ public class DynamicLoaderConstraintsTest extends DynamicArchiveTestBase {
83100
* if false, LoaderConstraintsApp will be loaded by the built-in AppClassLoader.
84101
*/
85102
static boolean useCustomLoader;
103+
static boolean useZGC;
86104

87105
public static void main(String[] args) throws Exception {
88106
useCustomLoader = (args.length != 0);
107+
useZGC = (args.length != 0 && args[0].equals("custom-zgc"));
89108
runTest(DynamicLoaderConstraintsTest::doTest);
90109
}
91110

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

126145
if (useCustomLoader) {
127-
cmdLine = TestCommon.concat(cmdLine, "-cp", loaderJar,
128-
loaderMainClass, appJar);
146+
if (useZGC) {
147+
// Add options to force eager class unloading.
148+
cmdLine = TestCommon.concat(cmdLine, "-cp", loaderJar,
149+
"-XX:+UseZGC", "-XX:ZCollectionInterval=0.01",
150+
loaderMainClass, appJar);
151+
} else {
152+
cmdLine = TestCommon.concat(cmdLine, "-cp", loaderJar,
153+
loaderMainClass, appJar);
154+
}
129155
} else {
130156
cmdLine = TestCommon.concat(cmdLine, "-cp", appJar);
131157
}

0 commit comments

Comments
 (0)
Please sign in to comment.