1.1 --- a/src/share/vm/gc_implementation/shared/vmGCOperations.cpp Wed Oct 03 20:31:41 2012 +0200 1.2 +++ b/src/share/vm/gc_implementation/shared/vmGCOperations.cpp Thu Oct 04 10:40:23 2012 -0700 1.3 @@ -198,8 +198,6 @@ 1.4 CollectedHeap* heap = Universe::heap(); 1.5 GCCauseSetter gccs(heap, _gc_cause); 1.6 1.7 - bool do_cms_concurrent = false; 1.8 - 1.9 // Check again if the space is available. Another thread 1.10 // may have similarly failed a metadata allocation and induced 1.11 // a GC that freed space for the allocation. 1.12 @@ -208,23 +206,25 @@ 1.13 } 1.14 1.15 if (_result == NULL) { 1.16 - if (!UseConcMarkSweepGC) { 1.17 - // Don't clear the soft refs the first time. 1.18 + if (UseConcMarkSweepGC) { 1.19 + if (CMSClassUnloadingEnabled) { 1.20 + MetaspaceGC::set_should_concurrent_collect(true); 1.21 + } 1.22 + // For CMS expand since the collection is going to be concurrent. 1.23 + _result = 1.24 + _loader_data->metaspace_non_null()->expand_and_allocate(_size, _mdtype); 1.25 + } 1.26 + if (_result == NULL) { 1.27 + // Don't clear the soft refs. This GC is for reclaiming metadata 1.28 + // and is unrelated to the fullness of the Java heap which should 1.29 + // be the criteria for clearing SoftReferences. 1.30 + if (Verbose && PrintGCDetails && UseConcMarkSweepGC) { 1.31 + gclog_or_tty->print_cr("\nCMS full GC for Metaspace"); 1.32 + } 1.33 heap->collect_as_vm_thread(GCCause::_metadata_GC_threshold); 1.34 _result = _loader_data->metaspace_non_null()->allocate(_size, _mdtype); 1.35 - // Don't do this for now 1.36 - // This seems too costly to do a second full GC 1.37 - // Let the metaspace grow instead 1.38 - // if (_result == NULL) { 1.39 - // // If allocation fails again, clear soft refs 1.40 - // heap->collect_as_vm_thread(GCCause::_last_ditch_collection); 1.41 - // _result = _loader_data->metaspace_non_null()->allocate(_size, _mdtype); 1.42 - // } 1.43 - } else { 1.44 - MetaspaceGC::set_should_concurrent_collect(true); 1.45 - do_cms_concurrent = true; 1.46 } 1.47 - if (_result == NULL) { 1.48 + if (_result == NULL && !UseConcMarkSweepGC /* CMS already tried */) { 1.49 // If still failing, allow the Metaspace to expand. 1.50 // See delta_capacity_until_GC() for explanation of the 1.51 // amount of the expansion. 1.52 @@ -233,18 +233,10 @@ 1.53 _result = 1.54 _loader_data->metaspace_non_null()->expand_and_allocate(_size, _mdtype); 1.55 1.56 - if (do_cms_concurrent && _result == NULL) { 1.57 - // Rather than fail with a metaspace out-of-memory, do a full 1.58 - // GC for CMS. 1.59 - heap->collect_as_vm_thread(GCCause::_metadata_GC_threshold); 1.60 - _result = _loader_data->metaspace_non_null()->allocate(_size, _mdtype); 1.61 - } 1.62 - if (_result == NULL) { 1.63 - if (PrintGCDetails) { 1.64 - gclog_or_tty->print_cr("\nAfter Metaspace GC failed to allocate size " 1.65 - SIZE_FORMAT, _size); 1.66 - } 1.67 - } 1.68 + } 1.69 + if (Verbose && PrintGCDetails && _result == NULL) { 1.70 + gclog_or_tty->print_cr("\nAfter Metaspace GC failed to allocate size " 1.71 + SIZE_FORMAT, _size); 1.72 } 1.73 } 1.74