< prev index next >

src/hotspot/share/gc/g1/g1CollectedHeap.cpp

Print this page
rev 60584 : imported patch 8245511-ihop


 860   // We will loop until a) we manage to successfully perform the
 861   // allocation or b) we successfully schedule a collection which
 862   // fails to perform the allocation. b) is the only case when we'll
 863   // return NULL.
 864   HeapWord* result = NULL;
 865   for (uint try_count = 1, gclocker_retry_count = 0; /* we'll return */; try_count += 1) {
 866     bool should_try_gc;
 867     uint gc_count_before;
 868 
 869 
 870     {
 871       MutexLocker x(Heap_lock);
 872 
 873       // Given that humongous objects are not allocated in young
 874       // regions, we'll first try to do the allocation without doing a
 875       // collection hoping that there's enough space in the heap.
 876       result = humongous_obj_allocate(word_size);
 877       if (result != NULL) {
 878         size_t size_in_regions = humongous_obj_size_in_regions(word_size);
 879         policy()->old_gen_alloc_tracker()->
 880           add_allocated_bytes_since_last_gc(size_in_regions * HeapRegion::GrainBytes);
 881         return result;
 882       }
 883 
 884       // Only try a GC if the GCLocker does not signal the need for a GC. Wait until
 885       // the GCLocker initiated GC has been performed and then retry. This includes
 886       // the case when the GC Locker is not active but has not been performed.
 887       should_try_gc = !GCLocker::needs_gc();
 888       // Read the GC count while still holding the Heap_lock.
 889       gc_count_before = total_collections();
 890     }
 891 
 892     if (should_try_gc) {
 893       bool succeeded;
 894       result = do_collection_pause(word_size, gc_count_before, &succeeded,
 895                                    GCCause::_g1_humongous_allocation);
 896       if (result != NULL) {
 897         assert(succeeded, "only way to get back a non-NULL result");
 898         log_trace(gc, alloc)("%s: Successfully scheduled collection returning " PTR_FORMAT,
 899                              Thread::current()->name(), p2i(result));



 900         return result;
 901       }
 902 
 903       if (succeeded) {
 904         // We successfully scheduled a collection which failed to allocate. No
 905         // point in trying to allocate further. We'll just return NULL.
 906         log_trace(gc, alloc)("%s: Successfully scheduled collection failing to allocate "
 907                              SIZE_FORMAT " words", Thread::current()->name(), word_size);
 908         return NULL;
 909       }
 910       log_trace(gc, alloc)("%s: Unsuccessfully scheduled collection allocating " SIZE_FORMAT "",
 911                            Thread::current()->name(), word_size);
 912     } else {
 913       // Failed to schedule a collection.
 914       if (gclocker_retry_count > GCLockerRetryAllocationCount) {
 915         log_warning(gc, alloc)("%s: Retried waiting for GCLocker too often allocating "
 916                                SIZE_FORMAT " words", Thread::current()->name(), word_size);
 917         return NULL;
 918       }
 919       log_trace(gc, alloc)("%s: Stall until clear", Thread::current()->name());




 860   // We will loop until a) we manage to successfully perform the
 861   // allocation or b) we successfully schedule a collection which
 862   // fails to perform the allocation. b) is the only case when we'll
 863   // return NULL.
 864   HeapWord* result = NULL;
 865   for (uint try_count = 1, gclocker_retry_count = 0; /* we'll return */; try_count += 1) {
 866     bool should_try_gc;
 867     uint gc_count_before;
 868 
 869 
 870     {
 871       MutexLocker x(Heap_lock);
 872 
 873       // Given that humongous objects are not allocated in young
 874       // regions, we'll first try to do the allocation without doing a
 875       // collection hoping that there's enough space in the heap.
 876       result = humongous_obj_allocate(word_size);
 877       if (result != NULL) {
 878         size_t size_in_regions = humongous_obj_size_in_regions(word_size);
 879         policy()->old_gen_alloc_tracker()->
 880           add_allocated_humongous_bytes_since_last_gc(size_in_regions * HeapRegion::GrainBytes);
 881         return result;
 882       }
 883 
 884       // Only try a GC if the GCLocker does not signal the need for a GC. Wait until
 885       // the GCLocker initiated GC has been performed and then retry. This includes
 886       // the case when the GC Locker is not active but has not been performed.
 887       should_try_gc = !GCLocker::needs_gc();
 888       // Read the GC count while still holding the Heap_lock.
 889       gc_count_before = total_collections();
 890     }
 891 
 892     if (should_try_gc) {
 893       bool succeeded;
 894       result = do_collection_pause(word_size, gc_count_before, &succeeded,
 895                                    GCCause::_g1_humongous_allocation);
 896       if (result != NULL) {
 897         assert(succeeded, "only way to get back a non-NULL result");
 898         log_trace(gc, alloc)("%s: Successfully scheduled collection returning " PTR_FORMAT,
 899                              Thread::current()->name(), p2i(result));
 900         size_t size_in_regions = humongous_obj_size_in_regions(word_size);
 901         policy()->old_gen_alloc_tracker()->
 902           record_collection_pause_humongous_allocation(size_in_regions * HeapRegion::GrainBytes);
 903         return result;
 904       }
 905 
 906       if (succeeded) {
 907         // We successfully scheduled a collection which failed to allocate. No
 908         // point in trying to allocate further. We'll just return NULL.
 909         log_trace(gc, alloc)("%s: Successfully scheduled collection failing to allocate "
 910                              SIZE_FORMAT " words", Thread::current()->name(), word_size);
 911         return NULL;
 912       }
 913       log_trace(gc, alloc)("%s: Unsuccessfully scheduled collection allocating " SIZE_FORMAT "",
 914                            Thread::current()->name(), word_size);
 915     } else {
 916       // Failed to schedule a collection.
 917       if (gclocker_retry_count > GCLockerRetryAllocationCount) {
 918         log_warning(gc, alloc)("%s: Retried waiting for GCLocker too often allocating "
 919                                SIZE_FORMAT " words", Thread::current()->name(), word_size);
 920         return NULL;
 921       }
 922       log_trace(gc, alloc)("%s: Stall until clear", Thread::current()->name());


< prev index next >