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

Print this page




1757   }
1758 
1759   // Expansion didn't work, we'll try to do a Full GC.
1760   bool gc_succeeded = do_collection(false, /* explicit_gc */
1761                                     false, /* clear_all_soft_refs */
1762                                     word_size);
1763   if (!gc_succeeded) {
1764     *succeeded = false;
1765     return NULL;
1766   }
1767 
1768   // Retry the allocation
1769   result = attempt_allocation_at_safepoint(word_size,
1770                                            context,
1771                                            true /* expect_null_mutator_alloc_region */);
1772   if (result != NULL) {
1773     assert(*succeeded, "sanity");
1774     return result;
1775   }
1776 








1777   // Then, try a Full GC that will collect all soft references.
1778   gc_succeeded = do_collection(false, /* explicit_gc */
1779                                true,  /* clear_all_soft_refs */
1780                                word_size);
1781   if (!gc_succeeded) {
1782     *succeeded = false;
1783     return NULL;
1784   }
1785 
1786   // Retry the allocation once more
1787   result = attempt_allocation_at_safepoint(word_size,
1788                                            context,
1789                                            true /* expect_null_mutator_alloc_region */);
1790   if (result != NULL) {
1791     assert(*succeeded, "sanity");
1792     return result;
1793   }
1794 
1795   assert(!collector_policy()->should_clear_all_soft_refs(),
1796          "Flag should have been handled and cleared prior to this point");







1797 
1798   // What else?  We might try synchronous finalization later.  If the total
1799   // space available is large enough for the allocation, then a more
1800   // complete compaction phase than we've tried so far might be
1801   // appropriate.
1802   assert(*succeeded, "sanity");
1803   return NULL;
1804 }
1805 
1806 // Attempting to expand the heap sufficiently
1807 // to support an allocation of the given "word_size".  If
1808 // successful, perform the allocation and return the address of the
1809 // allocated block, or else "NULL".
1810 
1811 HeapWord* G1CollectedHeap::expand_and_allocate(size_t word_size, AllocationContext_t context) {
1812   assert_at_safepoint(true /* should_be_vm_thread */);
1813 
1814   verify_region_sets_optional();
1815 
1816   size_t expand_bytes = MAX2(word_size * HeapWordSize, MinHeapDeltaBytes);




1757   }
1758 
1759   // Expansion didn't work, we'll try to do a Full GC.
1760   bool gc_succeeded = do_collection(false, /* explicit_gc */
1761                                     false, /* clear_all_soft_refs */
1762                                     word_size);
1763   if (!gc_succeeded) {
1764     *succeeded = false;
1765     return NULL;
1766   }
1767 
1768   // Retry the allocation
1769   result = attempt_allocation_at_safepoint(word_size,
1770                                            context,
1771                                            true /* expect_null_mutator_alloc_region */);
1772   if (result != NULL) {
1773     assert(*succeeded, "sanity");
1774     return result;
1775   }
1776 
1777   // We may shrink heap too much after full gc.
1778   // Expand heap will help - JDK-8130265
1779   result = expand_and_allocate(word_size, context);
1780   if (result != NULL) {
1781     assert(*succeeded, "sanity");
1782     return result;
1783   }
1784 
1785   // Then, try a Full GC that will collect all soft references.
1786   gc_succeeded = do_collection(false, /* explicit_gc */
1787                                true,  /* clear_all_soft_refs */
1788                                word_size);
1789   if (!gc_succeeded) {
1790     *succeeded = false;
1791     return NULL;
1792   }
1793 
1794   // Retry the allocation once more
1795   result = attempt_allocation_at_safepoint(word_size,
1796                                            context,
1797                                            true /* expect_null_mutator_alloc_region */);
1798   if (result != NULL) {
1799     assert(*succeeded, "sanity");
1800     return result;
1801   }
1802 
1803   assert(!collector_policy()->should_clear_all_soft_refs(),
1804          "Flag should have been handled and cleared prior to this point");
1805 
1806   // Retry expand_and_allocate once more
1807   result = expand_and_allocate(word_size, context);
1808   if (result != NULL) {
1809     assert(*succeeded, "sanity");
1810     return result;
1811   }
1812 
1813   // What else?  We might try synchronous finalization later.  If the total
1814   // space available is large enough for the allocation, then a more
1815   // complete compaction phase than we've tried so far might be
1816   // appropriate.
1817   assert(*succeeded, "sanity");
1818   return NULL;
1819 }
1820 
1821 // Attempting to expand the heap sufficiently
1822 // to support an allocation of the given "word_size".  If
1823 // successful, perform the allocation and return the address of the
1824 // allocated block, or else "NULL".
1825 
1826 HeapWord* G1CollectedHeap::expand_and_allocate(size_t word_size, AllocationContext_t context) {
1827   assert_at_safepoint(true /* should_be_vm_thread */);
1828 
1829   verify_region_sets_optional();
1830 
1831   size_t expand_bytes = MAX2(word_size * HeapWordSize, MinHeapDeltaBytes);