1826 ergo_verbose0(ErgoHeapSizing, 1827 "did not expand the heap", 1828 ergo_format_reason("heap expansion operation failed")); 1829 // The expansion of the virtual storage space was unsuccessful. 1830 // Let's see if it was because we ran out of swap. 1831 if (G1ExitOnExpansionFailure && 1832 _g1_storage.uncommitted_size() >= aligned_expand_bytes) { 1833 // We had head room... 1834 vm_exit_out_of_memory(aligned_expand_bytes, OOM_MMAP_ERROR, "G1 heap expansion"); 1835 } 1836 } 1837 return successful; 1838 } 1839 1840 void G1CollectedHeap::shrink_helper(size_t shrink_bytes) { 1841 size_t old_mem_size = _g1_storage.committed_size(); 1842 size_t aligned_shrink_bytes = 1843 ReservedSpace::page_align_size_down(shrink_bytes); 1844 aligned_shrink_bytes = align_size_down(aligned_shrink_bytes, 1845 HeapRegion::GrainBytes); 1846 uint num_regions_deleted = 0; 1847 MemRegion mr = _hrs.shrink_by(aligned_shrink_bytes, &num_regions_deleted); 1848 HeapWord* old_end = (HeapWord*) _g1_storage.high(); 1849 assert(mr.end() == old_end, "post-condition"); 1850 1851 ergo_verbose3(ErgoHeapSizing, 1852 "shrink the heap", 1853 ergo_format_byte("requested shrinking amount") 1854 ergo_format_byte("aligned shrinking amount") 1855 ergo_format_byte("attempted shrinking amount"), 1856 shrink_bytes, aligned_shrink_bytes, mr.byte_size()); 1857 if (mr.byte_size() > 0) { 1858 if (_hr_printer.is_active()) { 1859 HeapWord* curr = mr.end(); 1860 while (curr > mr.start()) { 1861 HeapWord* curr_end = curr; 1862 curr -= HeapRegion::GrainWords; 1863 _hr_printer.uncommit(curr, curr_end); 1864 } 1865 assert(curr == mr.start(), "post-condition"); 1866 } 1867 1868 _g1_storage.shrink_by(mr.byte_size()); 1869 HeapWord* new_end = (HeapWord*) _g1_storage.high(); 1870 assert(mr.start() == new_end, "post-condition"); 1871 1872 _expansion_regions += num_regions_deleted; 1873 update_committed_space(old_end, new_end); 1874 HeapRegionRemSet::shrink_heap(n_regions()); 1875 g1_policy()->record_new_heap_size(n_regions()); 1876 } else { 1877 ergo_verbose0(ErgoHeapSizing, 1878 "did not shrink the heap", 1879 ergo_format_reason("heap shrinking operation failed")); 1880 } 1881 } 1882 1883 void G1CollectedHeap::shrink(size_t shrink_bytes) { 1884 verify_region_sets_optional(); 1885 1886 // We should only reach here at the end of a Full GC which means we 1887 // should not not be holding to any GC alloc regions. The method 1888 // below will make sure of that and do any remaining clean up. 1889 abandon_gc_alloc_regions(); 1890 1891 // Instead of tearing down / rebuilding the free lists here, we 1892 // could instead use the remove_all_pending() method on free_list to | 1826 ergo_verbose0(ErgoHeapSizing, 1827 "did not expand the heap", 1828 ergo_format_reason("heap expansion operation failed")); 1829 // The expansion of the virtual storage space was unsuccessful. 1830 // Let's see if it was because we ran out of swap. 1831 if (G1ExitOnExpansionFailure && 1832 _g1_storage.uncommitted_size() >= aligned_expand_bytes) { 1833 // We had head room... 1834 vm_exit_out_of_memory(aligned_expand_bytes, OOM_MMAP_ERROR, "G1 heap expansion"); 1835 } 1836 } 1837 return successful; 1838 } 1839 1840 void G1CollectedHeap::shrink_helper(size_t shrink_bytes) { 1841 size_t old_mem_size = _g1_storage.committed_size(); 1842 size_t aligned_shrink_bytes = 1843 ReservedSpace::page_align_size_down(shrink_bytes); 1844 aligned_shrink_bytes = align_size_down(aligned_shrink_bytes, 1845 HeapRegion::GrainBytes); 1846 uint num_regions_to_remove = (uint)(shrink_bytes / HeapRegion::GrainBytes); 1847 1848 uint num_regions_removed = _hrs.shrink_by(num_regions_to_remove); 1849 HeapWord* old_end = (HeapWord*) _g1_storage.high(); 1850 size_t shrunk_bytes = num_regions_removed * HeapRegion::GrainBytes; 1851 1852 ergo_verbose3(ErgoHeapSizing, 1853 "shrink the heap", 1854 ergo_format_byte("requested shrinking amount") 1855 ergo_format_byte("aligned shrinking amount") 1856 ergo_format_byte("attempted shrinking amount"), 1857 shrink_bytes, aligned_shrink_bytes, shrunk_bytes); 1858 if (num_regions_removed > 0) { 1859 _g1_storage.shrink_by(shrunk_bytes); 1860 HeapWord* new_end = (HeapWord*) _g1_storage.high(); 1861 1862 if (_hr_printer.is_active()) { 1863 HeapWord* curr = old_end; 1864 while (curr > new_end) { 1865 HeapWord* curr_end = curr; 1866 curr -= HeapRegion::GrainWords; 1867 _hr_printer.uncommit(curr, curr_end); 1868 } 1869 } 1870 1871 _expansion_regions += num_regions_removed; 1872 update_committed_space(old_end, new_end); 1873 HeapRegionRemSet::shrink_heap(n_regions()); 1874 g1_policy()->record_new_heap_size(n_regions()); 1875 } else { 1876 ergo_verbose0(ErgoHeapSizing, 1877 "did not shrink the heap", 1878 ergo_format_reason("heap shrinking operation failed")); 1879 } 1880 } 1881 1882 void G1CollectedHeap::shrink(size_t shrink_bytes) { 1883 verify_region_sets_optional(); 1884 1885 // We should only reach here at the end of a Full GC which means we 1886 // should not not be holding to any GC alloc regions. The method 1887 // below will make sure of that and do any remaining clean up. 1888 abandon_gc_alloc_regions(); 1889 1890 // Instead of tearing down / rebuilding the free lists here, we 1891 // could instead use the remove_all_pending() method on free_list to |