603 // Allocate blocks during garbage collection. Will ensure an |
603 // Allocate blocks during garbage collection. Will ensure an |
604 // allocation region, either by picking one or expanding the |
604 // allocation region, either by picking one or expanding the |
605 // heap, and then allocate a block of the given size. The block |
605 // heap, and then allocate a block of the given size. The block |
606 // may not be a humongous - it must fit into a single heap region. |
606 // may not be a humongous - it must fit into a single heap region. |
607 HeapWord* par_allocate_during_gc(GCAllocPurpose purpose, size_t word_size); |
607 HeapWord* par_allocate_during_gc(GCAllocPurpose purpose, size_t word_size); |
|
608 |
|
609 HeapWord* allocate_during_gc_slow(GCAllocPurpose purpose, |
|
610 HeapRegion* alloc_region, |
|
611 bool par, |
|
612 size_t word_size); |
608 |
613 |
609 // Ensure that no further allocations can happen in "r", bearing in mind |
614 // Ensure that no further allocations can happen in "r", bearing in mind |
610 // that parallel threads might be attempting allocations. |
615 // that parallel threads might be attempting allocations. |
611 void par_allocate_remaining_space(HeapRegion* r); |
616 void par_allocate_remaining_space(HeapRegion* r); |
612 |
617 |
1769 if (_retired) |
1774 if (_retired) |
1770 return; |
1775 return; |
1771 ParGCAllocBuffer::retire(end_of_gc, retain); |
1776 ParGCAllocBuffer::retire(end_of_gc, retain); |
1772 _retired = true; |
1777 _retired = true; |
1773 } |
1778 } |
1774 |
|
1775 bool is_retired() { |
|
1776 return _retired; |
|
1777 } |
|
1778 }; |
|
1779 |
|
1780 class G1ParGCAllocBufferContainer { |
|
1781 protected: |
|
1782 static int const _priority_max = 2; |
|
1783 G1ParGCAllocBuffer* _priority_buffer[_priority_max]; |
|
1784 |
|
1785 public: |
|
1786 G1ParGCAllocBufferContainer(size_t gclab_word_size) { |
|
1787 for (int pr = 0; pr < _priority_max; ++pr) { |
|
1788 _priority_buffer[pr] = new G1ParGCAllocBuffer(gclab_word_size); |
|
1789 } |
|
1790 } |
|
1791 |
|
1792 ~G1ParGCAllocBufferContainer() { |
|
1793 for (int pr = 0; pr < _priority_max; ++pr) { |
|
1794 assert(_priority_buffer[pr]->is_retired(), "alloc buffers should all retire at this point."); |
|
1795 delete _priority_buffer[pr]; |
|
1796 } |
|
1797 } |
|
1798 |
|
1799 HeapWord* allocate(size_t word_sz) { |
|
1800 HeapWord* obj; |
|
1801 for (int pr = 0; pr < _priority_max; ++pr) { |
|
1802 obj = _priority_buffer[pr]->allocate(word_sz); |
|
1803 if (obj != NULL) return obj; |
|
1804 } |
|
1805 return obj; |
|
1806 } |
|
1807 |
|
1808 bool contains(void* addr) { |
|
1809 for (int pr = 0; pr < _priority_max; ++pr) { |
|
1810 if (_priority_buffer[pr]->contains(addr)) return true; |
|
1811 } |
|
1812 return false; |
|
1813 } |
|
1814 |
|
1815 void undo_allocation(HeapWord* obj, size_t word_sz) { |
|
1816 bool finish_undo; |
|
1817 for (int pr = 0; pr < _priority_max; ++pr) { |
|
1818 if (_priority_buffer[pr]->contains(obj)) { |
|
1819 _priority_buffer[pr]->undo_allocation(obj, word_sz); |
|
1820 finish_undo = true; |
|
1821 } |
|
1822 } |
|
1823 if (!finish_undo) ShouldNotReachHere(); |
|
1824 } |
|
1825 |
|
1826 size_t words_remaining() { |
|
1827 size_t result = 0; |
|
1828 for (int pr = 0; pr < _priority_max; ++pr) { |
|
1829 result += _priority_buffer[pr]->words_remaining(); |
|
1830 } |
|
1831 return result; |
|
1832 } |
|
1833 |
|
1834 size_t words_remaining_in_retired_buffer() { |
|
1835 G1ParGCAllocBuffer* retired = _priority_buffer[0]; |
|
1836 return retired->words_remaining(); |
|
1837 } |
|
1838 |
|
1839 void flush_stats_and_retire(PLABStats* stats, bool end_of_gc, bool retain) { |
|
1840 for (int pr = 0; pr < _priority_max; ++pr) { |
|
1841 _priority_buffer[pr]->flush_stats_and_retire(stats, end_of_gc, retain); |
|
1842 } |
|
1843 } |
|
1844 |
|
1845 void update(bool end_of_gc, bool retain, HeapWord* buf, size_t word_sz) { |
|
1846 G1ParGCAllocBuffer* retired_and_set = _priority_buffer[0]; |
|
1847 retired_and_set->retire(end_of_gc, retain); |
|
1848 retired_and_set->set_buf(buf); |
|
1849 retired_and_set->set_word_size(word_sz); |
|
1850 adjust_priority_order(); |
|
1851 } |
|
1852 |
|
1853 private: |
|
1854 void adjust_priority_order() { |
|
1855 G1ParGCAllocBuffer* retired_and_set = _priority_buffer[0]; |
|
1856 |
|
1857 int last = _priority_max - 1; |
|
1858 for (int pr = 0; pr < last; ++pr) { |
|
1859 _priority_buffer[pr] = _priority_buffer[pr + 1]; |
|
1860 } |
|
1861 _priority_buffer[last] = retired_and_set; |
|
1862 } |
|
1863 }; |
1779 }; |
1864 |
1780 |
1865 class G1ParScanThreadState : public StackObj { |
1781 class G1ParScanThreadState : public StackObj { |
1866 protected: |
1782 protected: |
1867 G1CollectedHeap* _g1h; |
1783 G1CollectedHeap* _g1h; |
1868 RefToScanQueue* _refs; |
1784 RefToScanQueue* _refs; |
1869 DirtyCardQueue _dcq; |
1785 DirtyCardQueue _dcq; |
1870 G1SATBCardTableModRefBS* _ct_bs; |
1786 G1SATBCardTableModRefBS* _ct_bs; |
1871 G1RemSet* _g1_rem; |
1787 G1RemSet* _g1_rem; |
1872 |
1788 |
1873 G1ParGCAllocBufferContainer _surviving_alloc_buffer; |
1789 G1ParGCAllocBuffer _surviving_alloc_buffer; |
1874 G1ParGCAllocBufferContainer _tenured_alloc_buffer; |
1790 G1ParGCAllocBuffer _tenured_alloc_buffer; |
1875 G1ParGCAllocBufferContainer* _alloc_buffers[GCAllocPurposeCount]; |
1791 G1ParGCAllocBuffer* _alloc_buffers[GCAllocPurposeCount]; |
1876 ageTable _age_table; |
1792 ageTable _age_table; |
1877 |
1793 |
1878 G1ParScanClosure _scanner; |
1794 G1ParScanClosure _scanner; |
1879 |
1795 |
1880 size_t _alloc_buffer_waste; |
1796 size_t _alloc_buffer_waste; |
1966 |
1882 |
1967 HeapWord* allocate_slow(GCAllocPurpose purpose, size_t word_sz) { |
1883 HeapWord* allocate_slow(GCAllocPurpose purpose, size_t word_sz) { |
1968 HeapWord* obj = NULL; |
1884 HeapWord* obj = NULL; |
1969 size_t gclab_word_size = _g1h->desired_plab_sz(purpose); |
1885 size_t gclab_word_size = _g1h->desired_plab_sz(purpose); |
1970 if (word_sz * 100 < gclab_word_size * ParallelGCBufferWastePct) { |
1886 if (word_sz * 100 < gclab_word_size * ParallelGCBufferWastePct) { |
1971 G1ParGCAllocBufferContainer* alloc_buf = alloc_buffer(purpose); |
1887 G1ParGCAllocBuffer* alloc_buf = alloc_buffer(purpose); |
|
1888 add_to_alloc_buffer_waste(alloc_buf->words_remaining()); |
|
1889 alloc_buf->retire(false /* end_of_gc */, false /* retain */); |
1972 |
1890 |
1973 HeapWord* buf = _g1h->par_allocate_during_gc(purpose, gclab_word_size); |
1891 HeapWord* buf = _g1h->par_allocate_during_gc(purpose, gclab_word_size); |
1974 if (buf == NULL) return NULL; // Let caller handle allocation failure. |
1892 if (buf == NULL) return NULL; // Let caller handle allocation failure. |
1975 |
1893 // Otherwise. |
1976 add_to_alloc_buffer_waste(alloc_buf->words_remaining_in_retired_buffer()); |
1894 alloc_buf->set_word_size(gclab_word_size); |
1977 alloc_buf->update(false /* end_of_gc */, false /* retain */, buf, gclab_word_size); |
1895 alloc_buf->set_buf(buf); |
1978 |
1896 |
1979 obj = alloc_buf->allocate(word_sz); |
1897 obj = alloc_buf->allocate(word_sz); |
1980 assert(obj != NULL, "buffer was definitely big enough..."); |
1898 assert(obj != NULL, "buffer was definitely big enough..."); |
1981 } else { |
1899 } else { |
1982 obj = _g1h->par_allocate_during_gc(purpose, word_sz); |
1900 obj = _g1h->par_allocate_during_gc(purpose, word_sz); |