Skip to content

Commit

Permalink
8273505: runtime/cds/appcds/loaderConstraints/DynamicLoaderConstraint…
Browse files Browse the repository at this point in the history
…sTest.java#default-cl crashed with SIGSEGV in MetaspaceShared::link_shared_classes

Reviewed-by: iklam, minqi
  • Loading branch information
calvinccheung committed Sep 20, 2021
1 parent 26e5e9a commit a67f0f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/hotspot/share/cds/metaspaceShared.cpp
Expand Up @@ -584,18 +584,19 @@ void VM_PopulateDumpSharedSpace::doit() {

class CollectCLDClosure : public CLDClosure {
GrowableArray<ClassLoaderData*> _loaded_cld;
GrowableArray<Handle> _loaded_cld_handles; // keep the CLDs alive
Thread* _current_thread;
public:
CollectCLDClosure() {}
CollectCLDClosure(Thread* thread) : _current_thread(thread) {}
~CollectCLDClosure() {
for (int i = 0; i < _loaded_cld.length(); i++) {
ClassLoaderData* cld = _loaded_cld.at(i);
cld->dec_keep_alive();
}
}
void do_cld(ClassLoaderData* cld) {
if (!cld->is_unloading()) {
cld->inc_keep_alive();
_loaded_cld.append(cld);
_loaded_cld_handles.append(Handle(_current_thread, cld->holder_phantom()));
}
}

Expand Down Expand Up @@ -641,11 +642,10 @@ bool MetaspaceShared::link_class_for_cds(InstanceKlass* ik, TRAPS) {
}

void MetaspaceShared::link_shared_classes(TRAPS) {
// Collect all loaded ClassLoaderData.
ResourceMark rm;

LambdaFormInvokers::regenerate_holder_classes(CHECK);
CollectCLDClosure collect_cld;

// Collect all loaded ClassLoaderData.
CollectCLDClosure collect_cld(THREAD);
{
// ClassLoaderDataGraph::loaded_cld_do requires ClassLoaderDataGraph_lock.
// We cannot link the classes while holding this lock (or else we may run into deadlock).
Expand Down
4 changes: 1 addition & 3 deletions src/hotspot/share/classfile/classLoaderData.cpp
Expand Up @@ -302,9 +302,7 @@ bool ClassLoaderData::try_claim(int claim) {
// it is being defined, therefore _keep_alive is not volatile or atomic.
void ClassLoaderData::inc_keep_alive() {
if (has_class_mirror_holder()) {
if (!Arguments::is_dumping_archive()) {
assert(_keep_alive > 0, "Invalid keep alive increment count");
}
assert(_keep_alive > 0, "Invalid keep alive increment count");
_keep_alive++;
}
}
Expand Down

1 comment on commit a67f0f9

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.