733 HeapWord* GenCollectorPolicy::satisfy_failed_allocation(size_t size, 734 bool is_tlab) { 735 GenCollectedHeap *gch = GenCollectedHeap::heap(); 736 GCCauseSetter x(gch, GCCause::_allocation_failure); 737 HeapWord* result = NULL; 738 739 assert(size != 0, "Precondition violated"); 740 if (GC_locker::is_active_and_needs_gc()) { 741 // GC locker is active; instead of a collection we will attempt 742 // to expand the heap, if there's room for expansion. 743 if (!gch->is_maximal_no_gc()) { 744 result = expand_heap_and_allocate(size, is_tlab); 745 } 746 return result; // Could be null if we are out of space. 747 } else if (!gch->incremental_collection_will_fail(false /* don't consult_young */)) { 748 // Do an incremental collection. 749 gch->do_collection(false /* full */, 750 false /* clear_all_soft_refs */, 751 size /* size */, 752 is_tlab /* is_tlab */, 753 number_of_generations() - 1 /* max_level */); 754 } else { 755 if (Verbose && PrintGCDetails) { 756 gclog_or_tty->print(" :: Trying full because partial may fail :: "); 757 } 758 // Try a full collection; see delta for bug id 6266275 759 // for the original code and why this has been simplified 760 // with from-space allocation criteria modified and 761 // such allocation moved out of the safepoint path. 762 gch->do_collection(true /* full */, 763 false /* clear_all_soft_refs */, 764 size /* size */, 765 is_tlab /* is_tlab */, 766 number_of_generations() - 1 /* max_level */); 767 } 768 769 result = gch->attempt_allocation(size, is_tlab, false /*first_only*/); 770 771 if (result != NULL) { 772 assert(gch->is_in_reserved(result), "result not in heap"); 773 return result; 774 } 775 776 // OK, collection failed, try expansion. 777 result = expand_heap_and_allocate(size, is_tlab); 778 if (result != NULL) { 779 return result; 780 } 781 782 // If we reach this point, we're really out of memory. Try every trick 783 // we can to reclaim memory. Force collection of soft references. Force 784 // a complete compaction of the heap. Any additional methods for finding 785 // free memory should be here, especially if they are expensive. If this 786 // attempt fails, an OOM exception will be thrown. 787 { 788 UIntFlagSetting flag_change(MarkSweepAlwaysCompactCount, 1); // Make sure the heap is fully compacted 789 790 gch->do_collection(true /* full */, 791 true /* clear_all_soft_refs */, 792 size /* size */, 793 is_tlab /* is_tlab */, 794 number_of_generations() - 1 /* max_level */); 795 } 796 797 result = gch->attempt_allocation(size, is_tlab, false /* first_only */); 798 if (result != NULL) { 799 assert(gch->is_in_reserved(result), "result not in heap"); 800 return result; 801 } 802 803 assert(!should_clear_all_soft_refs(), 804 "Flag should have been handled and cleared prior to this point"); 805 806 // What else? We might try synchronous finalization later. If the total 807 // space available is large enough for the allocation, then a more 808 // complete compaction phase than we've tried so far might be 809 // appropriate. 810 return NULL; 811 } 812 813 MetaWord* CollectorPolicy::satisfy_failed_metadata_allocation( 814 ClassLoaderData* loader_data, | 733 HeapWord* GenCollectorPolicy::satisfy_failed_allocation(size_t size, 734 bool is_tlab) { 735 GenCollectedHeap *gch = GenCollectedHeap::heap(); 736 GCCauseSetter x(gch, GCCause::_allocation_failure); 737 HeapWord* result = NULL; 738 739 assert(size != 0, "Precondition violated"); 740 if (GC_locker::is_active_and_needs_gc()) { 741 // GC locker is active; instead of a collection we will attempt 742 // to expand the heap, if there's room for expansion. 743 if (!gch->is_maximal_no_gc()) { 744 result = expand_heap_and_allocate(size, is_tlab); 745 } 746 return result; // Could be null if we are out of space. 747 } else if (!gch->incremental_collection_will_fail(false /* don't consult_young */)) { 748 // Do an incremental collection. 749 gch->do_collection(false /* full */, 750 false /* clear_all_soft_refs */, 751 size /* size */, 752 is_tlab /* is_tlab */, 753 Generation::Old /* max_generation */); 754 } else { 755 if (Verbose && PrintGCDetails) { 756 gclog_or_tty->print(" :: Trying full because partial may fail :: "); 757 } 758 // Try a full collection; see delta for bug id 6266275 759 // for the original code and why this has been simplified 760 // with from-space allocation criteria modified and 761 // such allocation moved out of the safepoint path. 762 gch->do_collection(true /* full */, 763 false /* clear_all_soft_refs */, 764 size /* size */, 765 is_tlab /* is_tlab */, 766 Generation::Old /* max_generation */); 767 } 768 769 result = gch->attempt_allocation(size, is_tlab, false /*first_only*/); 770 771 if (result != NULL) { 772 assert(gch->is_in_reserved(result), "result not in heap"); 773 return result; 774 } 775 776 // OK, collection failed, try expansion. 777 result = expand_heap_and_allocate(size, is_tlab); 778 if (result != NULL) { 779 return result; 780 } 781 782 // If we reach this point, we're really out of memory. Try every trick 783 // we can to reclaim memory. Force collection of soft references. Force 784 // a complete compaction of the heap. Any additional methods for finding 785 // free memory should be here, especially if they are expensive. If this 786 // attempt fails, an OOM exception will be thrown. 787 { 788 UIntFlagSetting flag_change(MarkSweepAlwaysCompactCount, 1); // Make sure the heap is fully compacted 789 790 gch->do_collection(true /* full */, 791 true /* clear_all_soft_refs */, 792 size /* size */, 793 is_tlab /* is_tlab */, 794 Generation::Old /* max_generation */); 795 } 796 797 result = gch->attempt_allocation(size, is_tlab, false /* first_only */); 798 if (result != NULL) { 799 assert(gch->is_in_reserved(result), "result not in heap"); 800 return result; 801 } 802 803 assert(!should_clear_all_soft_refs(), 804 "Flag should have been handled and cleared prior to this point"); 805 806 // What else? We might try synchronous finalization later. If the total 807 // space available is large enough for the allocation, then a more 808 // complete compaction phase than we've tried so far might be 809 // appropriate. 810 return NULL; 811 } 812 813 MetaWord* CollectorPolicy::satisfy_failed_metadata_allocation( 814 ClassLoaderData* loader_data, |