hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp
changeset 33108 6714a3872d8f
parent 33107 77bf0d2069a3
child 33152 6ad7fe735042
equal deleted inserted replaced
33107:77bf0d2069a3 33108:6714a3872d8f
  1799                   maximum_desired_capacity, (double) MaxHeapFreeRatio);
  1799                   maximum_desired_capacity, (double) MaxHeapFreeRatio);
  1800     shrink(shrink_bytes);
  1800     shrink(shrink_bytes);
  1801   }
  1801   }
  1802 }
  1802 }
  1803 
  1803 
  1804 
  1804 HeapWord* G1CollectedHeap::satisfy_failed_allocation_helper(size_t word_size,
  1805 HeapWord*
  1805                                                             AllocationContext_t context,
  1806 G1CollectedHeap::satisfy_failed_allocation(size_t word_size,
  1806                                                             bool do_gc,
  1807                                            AllocationContext_t context,
  1807                                                             bool clear_all_soft_refs,
  1808                                            bool* succeeded) {
  1808                                                             bool expect_null_mutator_alloc_region,
  1809   assert_at_safepoint(true /* should_be_vm_thread */);
  1809                                                             bool* gc_succeeded) {
  1810 
  1810   *gc_succeeded = true;
  1811   *succeeded = true;
       
  1812   // Let's attempt the allocation first.
  1811   // Let's attempt the allocation first.
  1813   HeapWord* result =
  1812   HeapWord* result =
  1814     attempt_allocation_at_safepoint(word_size,
  1813     attempt_allocation_at_safepoint(word_size,
  1815                                     context,
  1814                                     context,
  1816                                     false /* expect_null_mutator_alloc_region */);
  1815                                     expect_null_mutator_alloc_region);
  1817   if (result != NULL) {
  1816   if (result != NULL) {
  1818     assert(*succeeded, "sanity");
  1817     assert(*gc_succeeded, "sanity");
  1819     return result;
  1818     return result;
  1820   }
  1819   }
  1821 
  1820 
  1822   // In a G1 heap, we're supposed to keep allocation from failing by
  1821   // In a G1 heap, we're supposed to keep allocation from failing by
  1823   // incremental pauses.  Therefore, at least for now, we'll favor
  1822   // incremental pauses.  Therefore, at least for now, we'll favor
  1824   // expansion over collection.  (This might change in the future if we can
  1823   // expansion over collection.  (This might change in the future if we can
  1825   // do something smarter than full collection to satisfy a failed alloc.)
  1824   // do something smarter than full collection to satisfy a failed alloc.)
  1826   result = expand_and_allocate(word_size, context);
  1825   result = expand_and_allocate(word_size, context);
  1827   if (result != NULL) {
  1826   if (result != NULL) {
  1828     assert(*succeeded, "sanity");
  1827     assert(*gc_succeeded, "sanity");
  1829     return result;
  1828     return result;
  1830   }
  1829   }
  1831 
  1830 
  1832   // Expansion didn't work, we'll try to do a Full GC.
  1831   if (do_gc) {
  1833   bool gc_succeeded = do_collection(false, /* explicit_gc */
  1832     // Expansion didn't work, we'll try to do a Full GC.
  1834                                     false, /* clear_all_soft_refs */
  1833     *gc_succeeded = do_collection(false, /* explicit_gc */
  1835                                     word_size);
  1834                                   clear_all_soft_refs,
  1836   if (!gc_succeeded) {
  1835                                   word_size);
  1837     *succeeded = false;
  1836   }
  1838     return NULL;
  1837 
  1839   }
  1838   return NULL;
  1840 
  1839 }
  1841   // Retry the allocation
  1840 
  1842   result = attempt_allocation_at_safepoint(word_size,
  1841 HeapWord* G1CollectedHeap::satisfy_failed_allocation(size_t word_size,
  1843                                            context,
  1842                                                      AllocationContext_t context,
  1844                                            true /* expect_null_mutator_alloc_region */);
  1843                                                      bool* succeeded) {
  1845   if (result != NULL) {
  1844   assert_at_safepoint(true /* should_be_vm_thread */);
  1846     assert(*succeeded, "sanity");
  1845 
       
  1846   // Attempts to allocate followed by Full GC.
       
  1847   HeapWord* result =
       
  1848     satisfy_failed_allocation_helper(word_size,
       
  1849                                      context,
       
  1850                                      true,  /* do_gc */
       
  1851                                      false, /* clear_all_soft_refs */
       
  1852                                      false, /* expect_null_mutator_alloc_region */
       
  1853                                      succeeded);
       
  1854 
       
  1855   if (result != NULL || !*succeeded) {
  1847     return result;
  1856     return result;
  1848   }
  1857   }
  1849 
  1858 
  1850   // Then, try a Full GC that will collect all soft references.
  1859   // Attempts to allocate followed by Full GC that will collect all soft references.
  1851   gc_succeeded = do_collection(false, /* explicit_gc */
  1860   result = satisfy_failed_allocation_helper(word_size,
  1852                                true,  /* clear_all_soft_refs */
  1861                                             context,
  1853                                word_size);
  1862                                             true, /* do_gc */
  1854   if (!gc_succeeded) {
  1863                                             true, /* clear_all_soft_refs */
  1855     *succeeded = false;
  1864                                             true, /* expect_null_mutator_alloc_region */
  1856     return NULL;
  1865                                             succeeded);
  1857   }
  1866 
  1858 
  1867   if (result != NULL || !*succeeded) {
  1859   // Retry the allocation once more
  1868     return result;
  1860   result = attempt_allocation_at_safepoint(word_size,
  1869   }
  1861                                            context,
  1870 
  1862                                            true /* expect_null_mutator_alloc_region */);
  1871   // Attempts to allocate, no GC
       
  1872   result = satisfy_failed_allocation_helper(word_size,
       
  1873                                             context,
       
  1874                                             false, /* do_gc */
       
  1875                                             false, /* clear_all_soft_refs */
       
  1876                                             true,  /* expect_null_mutator_alloc_region */
       
  1877                                             succeeded);
       
  1878 
  1863   if (result != NULL) {
  1879   if (result != NULL) {
  1864     assert(*succeeded, "sanity");
  1880     assert(*succeeded, "sanity");
  1865     return result;
  1881     return result;
  1866   }
  1882   }
  1867 
  1883