1.1 --- a/src/share/vm/classfile/classLoaderData.cpp Mon Feb 10 10:34:52 2014 +0100 1.2 +++ b/src/share/vm/classfile/classLoaderData.cpp Tue Jan 07 13:26:56 2014 -0500 1.3 @@ -648,12 +648,12 @@ 1.4 return array; 1.5 } 1.6 1.7 -#ifndef PRODUCT 1.8 -// for debugging and hsfind(x) 1.9 -bool ClassLoaderDataGraph::contains(address x) { 1.10 - // I think we need the _metaspace_lock taken here because the class loader 1.11 - // data graph could be changing while we are walking it (new entries added, 1.12 - // new entries being unloaded, etc). 1.13 +// For profiling and hsfind() only. Otherwise, this is unsafe (and slow). This 1.14 +// is done lock free to avoid lock inversion problems. It is safe because 1.15 +// new ClassLoaderData are added to the end of the CLDG, and only removed at 1.16 +// safepoint. The _unloading list can be deallocated concurrently with CMS so 1.17 +// this doesn't look in metaspace for classes that have been unloaded. 1.18 +bool ClassLoaderDataGraph::contains(const void* x) { 1.19 if (DumpSharedSpaces) { 1.20 // There are only two metaspaces to worry about. 1.21 ClassLoaderData* ncld = ClassLoaderData::the_null_class_loader_data(); 1.22 @@ -670,16 +670,11 @@ 1.23 } 1.24 } 1.25 1.26 - // Could also be on an unloading list which is okay, ie. still allocated 1.27 - // for a little while. 1.28 - for (ClassLoaderData* ucld = _unloading; ucld != NULL; ucld = ucld->next()) { 1.29 - if (ucld->metaspace_or_null() != NULL && ucld->metaspace_or_null()->contains(x)) { 1.30 - return true; 1.31 - } 1.32 - } 1.33 + // Do not check unloading list because deallocation can be concurrent. 1.34 return false; 1.35 } 1.36 1.37 +#ifndef PRODUCT 1.38 bool ClassLoaderDataGraph::contains_loader_data(ClassLoaderData* loader_data) { 1.39 for (ClassLoaderData* data = _head; data != NULL; data = data->next()) { 1.40 if (loader_data == data) {