hotspot/src/share/vm/gc_implementation/shared/vmGCOperations.cpp
changeset 13927 332925e36741
parent 13755 a00f5de57d30
child 15482 470d0b0c09f1
child 15437 eabd4555d072
equal deleted inserted replaced
13925:37f75ba502b1 13927:332925e36741
   196   SvcGCMarker sgcm(SvcGCMarker::FULL);
   196   SvcGCMarker sgcm(SvcGCMarker::FULL);
   197 
   197 
   198   CollectedHeap* heap = Universe::heap();
   198   CollectedHeap* heap = Universe::heap();
   199   GCCauseSetter gccs(heap, _gc_cause);
   199   GCCauseSetter gccs(heap, _gc_cause);
   200 
   200 
   201   bool do_cms_concurrent = false;
       
   202 
       
   203   // Check again if the space is available.  Another thread
   201   // Check again if the space is available.  Another thread
   204   // may have similarly failed a metadata allocation and induced
   202   // may have similarly failed a metadata allocation and induced
   205   // a GC that freed space for the allocation.
   203   // a GC that freed space for the allocation.
   206   if (!MetadataAllocationFailALot) {
   204   if (!MetadataAllocationFailALot) {
   207     _result = _loader_data->metaspace_non_null()->allocate(_size, _mdtype);
   205     _result = _loader_data->metaspace_non_null()->allocate(_size, _mdtype);
   208     }
   206     }
   209 
   207 
   210   if (_result == NULL) {
   208   if (_result == NULL) {
   211     if (!UseConcMarkSweepGC) {
   209     if (UseConcMarkSweepGC) {
   212       // Don't clear the soft refs the first time.
   210       if (CMSClassUnloadingEnabled) {
       
   211         MetaspaceGC::set_should_concurrent_collect(true);
       
   212       }
       
   213       // For CMS expand since the collection is going to be concurrent.
       
   214       _result =
       
   215         _loader_data->metaspace_non_null()->expand_and_allocate(_size, _mdtype);
       
   216     }
       
   217     if (_result == NULL) {
       
   218       // Don't clear the soft refs.  This GC is for reclaiming metadata
       
   219       // and is unrelated to the fullness of the Java heap which should
       
   220       // be the criteria for clearing SoftReferences.
       
   221       if (Verbose && PrintGCDetails && UseConcMarkSweepGC) {
       
   222         gclog_or_tty->print_cr("\nCMS full GC for Metaspace");
       
   223       }
   213       heap->collect_as_vm_thread(GCCause::_metadata_GC_threshold);
   224       heap->collect_as_vm_thread(GCCause::_metadata_GC_threshold);
   214       _result = _loader_data->metaspace_non_null()->allocate(_size, _mdtype);
   225       _result = _loader_data->metaspace_non_null()->allocate(_size, _mdtype);
   215       // Don't do this for now
   226     }
   216       // This seems too costly to do a second full GC
   227     if (_result == NULL && !UseConcMarkSweepGC /* CMS already tried */) {
   217       // Let the metaspace grow instead
       
   218       // if (_result == NULL) {
       
   219       //  // If allocation fails again, clear soft refs
       
   220       //  heap->collect_as_vm_thread(GCCause::_last_ditch_collection);
       
   221       //  _result = _loader_data->metaspace_non_null()->allocate(_size, _mdtype);
       
   222       // }
       
   223     } else {
       
   224       MetaspaceGC::set_should_concurrent_collect(true);
       
   225       do_cms_concurrent = true;
       
   226     }
       
   227     if (_result == NULL) {
       
   228       // If still failing, allow the Metaspace to expand.
   228       // If still failing, allow the Metaspace to expand.
   229       // See delta_capacity_until_GC() for explanation of the
   229       // See delta_capacity_until_GC() for explanation of the
   230       // amount of the expansion.
   230       // amount of the expansion.
   231       // This should work unless there really is no more space
   231       // This should work unless there really is no more space
   232       // or a MaxMetaspaceSize has been specified on the command line.
   232       // or a MaxMetaspaceSize has been specified on the command line.
   233       _result =
   233       _result =
   234         _loader_data->metaspace_non_null()->expand_and_allocate(_size, _mdtype);
   234         _loader_data->metaspace_non_null()->expand_and_allocate(_size, _mdtype);
   235 
   235 
   236       if (do_cms_concurrent && _result == NULL) {
   236     }
   237         // Rather than fail with a metaspace out-of-memory, do a full
   237     if (Verbose && PrintGCDetails && _result == NULL) {
   238         // GC for CMS.
   238       gclog_or_tty->print_cr("\nAfter Metaspace GC failed to allocate size "
   239         heap->collect_as_vm_thread(GCCause::_metadata_GC_threshold);
   239                              SIZE_FORMAT, _size);
   240         _result = _loader_data->metaspace_non_null()->allocate(_size, _mdtype);
       
   241       }
       
   242       if (_result == NULL) {
       
   243         if (PrintGCDetails) {
       
   244           gclog_or_tty->print_cr("\nAfter Metaspace GC failed to allocate size "
       
   245                                  SIZE_FORMAT, _size);
       
   246         }
       
   247       }
       
   248     }
   240     }
   249   }
   241   }
   250 
   242 
   251   if (_result == NULL && GC_locker::is_active_and_needs_gc()) {
   243   if (_result == NULL && GC_locker::is_active_and_needs_gc()) {
   252     set_gc_locked();
   244     set_gc_locked();