1815 assert(n_rem_sets > 0, "Invariant.");
1816
1817 _worker_cset_start_region = NEW_C_HEAP_ARRAY(HeapRegion*, n_queues, mtGC);
1818 _worker_cset_start_region_time_stamp = NEW_C_HEAP_ARRAY(uint, n_queues, mtGC);
1819 _evacuation_failed_info_array = NEW_C_HEAP_ARRAY(EvacuationFailedInfo, n_queues, mtGC);
1820
1821 for (int i = 0; i < n_queues; i++) {
1822 RefToScanQueue* q = new RefToScanQueue();
1823 q->initialize();
1824 _task_queues->register_queue(i, q);
1825 ::new (&_evacuation_failed_info_array[i]) EvacuationFailedInfo();
1826 }
1827 clear_cset_start_regions();
1828
1829 // Initialize the G1EvacuationFailureALot counters and flags.
1830 NOT_PRODUCT(reset_evacuation_should_fail();)
1831
1832 guarantee(_task_queues != NULL, "task_queues allocation failure.");
1833 }
1834
1835 jint G1CollectedHeap::initialize() {
1836 CollectedHeap::pre_initialize();
1837 os::enable_vtime();
1838
1839 G1Log::init();
1840
1841 // Necessary to satisfy locking discipline assertions.
1842
1843 MutexLocker x(Heap_lock);
1844
1845 // We have to initialize the printer before committing the heap, as
1846 // it will be used then.
1847 _hr_printer.set_active(G1PrintHeapRegions);
1848
1849 // While there are no constraints in the GC code that HeapWordSize
1850 // be any particular value, there are multiple other areas in the
1851 // system which believe this to be true (e.g. oop->object_size in some
1852 // cases incorrectly returns the size in wordSize units rather than
1853 // HeapWordSize).
1854 guarantee(HeapWordSize == wordSize, "HeapWordSize must equal wordSize");
1882 ReservedSpace heap_rs = Universe::reserve_heap(max_byte_size,
1883 heap_alignment);
1884
1885 initialize_reserved_region((HeapWord*)heap_rs.base(), (HeapWord*)(heap_rs.base() + heap_rs.size()));
1886
1887 // Create the barrier set for the entire reserved region.
1888 G1SATBCardTableLoggingModRefBS* bs
1889 = new G1SATBCardTableLoggingModRefBS(reserved_region());
1890 bs->initialize();
1891 assert(bs->is_a(BarrierSet::G1SATBCTLogging), "sanity");
1892 set_barrier_set(bs);
1893
1894 // Also create a G1 rem set.
1895 _g1_rem_set = new G1RemSet(this, g1_barrier_set());
1896
1897 // Carve out the G1 part of the heap.
1898
1899 ReservedSpace g1_rs = heap_rs.first_part(max_byte_size);
1900 G1RegionToSpaceMapper* heap_storage =
1901 G1RegionToSpaceMapper::create_mapper(g1_rs,
1902 UseLargePages ? os::large_page_size() : os::vm_page_size(),
1903 HeapRegion::GrainBytes,
1904 1,
1905 mtJavaHeap);
1906 heap_storage->set_mapping_changed_listener(&_listener);
1907
1908 // Reserve space for the block offset table. We do not support automatic uncommit
1909 // for the card table at this time. BOT only.
1910 ReservedSpace bot_rs(G1BlockOffsetSharedArray::compute_size(g1_rs.size() / HeapWordSize));
1911 G1RegionToSpaceMapper* bot_storage =
1912 G1RegionToSpaceMapper::create_mapper(bot_rs,
1913 os::vm_page_size(),
1914 HeapRegion::GrainBytes,
1915 G1BlockOffsetSharedArray::N_bytes,
1916 mtGC);
1917
1918 ReservedSpace cardtable_rs(G1SATBCardTableLoggingModRefBS::compute_size(g1_rs.size() / HeapWordSize));
1919 G1RegionToSpaceMapper* cardtable_storage =
1920 G1RegionToSpaceMapper::create_mapper(cardtable_rs,
1921 os::vm_page_size(),
1922 HeapRegion::GrainBytes,
1923 G1BlockOffsetSharedArray::N_bytes,
1924 mtGC);
1925
1926 // Reserve space for the card counts table.
1927 ReservedSpace card_counts_rs(G1BlockOffsetSharedArray::compute_size(g1_rs.size() / HeapWordSize));
1928 G1RegionToSpaceMapper* card_counts_storage =
1929 G1RegionToSpaceMapper::create_mapper(card_counts_rs,
1930 os::vm_page_size(),
1931 HeapRegion::GrainBytes,
1932 G1BlockOffsetSharedArray::N_bytes,
1933 mtGC);
1934
1935 // Reserve space for prev and next bitmap.
1936 size_t bitmap_size = CMBitMap::compute_size(g1_rs.size());
1937
1938 ReservedSpace prev_bitmap_rs(ReservedSpace::allocation_align_size_up(bitmap_size));
1939 G1RegionToSpaceMapper* prev_bitmap_storage =
1940 G1RegionToSpaceMapper::create_mapper(prev_bitmap_rs,
1941 os::vm_page_size(),
1942 HeapRegion::GrainBytes,
1943 CMBitMap::mark_distance(),
1944 mtGC);
1945
1946 ReservedSpace next_bitmap_rs(ReservedSpace::allocation_align_size_up(bitmap_size));
1947 G1RegionToSpaceMapper* next_bitmap_storage =
1948 G1RegionToSpaceMapper::create_mapper(next_bitmap_rs,
1949 os::vm_page_size(),
1950 HeapRegion::GrainBytes,
1951 CMBitMap::mark_distance(),
1952 mtGC);
1953
1954 _hrm.initialize(heap_storage, prev_bitmap_storage, next_bitmap_storage, bot_storage, cardtable_storage, card_counts_storage);
1955 g1_barrier_set()->initialize(cardtable_storage);
1956 // Do later initialization work for concurrent refinement.
1957 _cg1r->init(card_counts_storage);
1958
1959 // 6843694 - ensure that the maximum region index can fit
1960 // in the remembered set structures.
1961 const uint max_region_idx = (1U << (sizeof(RegionIdx_t)*BitsPerByte-1)) - 1;
1962 guarantee((max_regions() - 1) <= max_region_idx, "too many regions");
1963
1964 size_t max_cards_per_region = ((size_t)1 << (sizeof(CardIdx_t)*BitsPerByte-1)) - 1;
1965 guarantee(HeapRegion::CardsPerRegion > 0, "make sure it's initialized");
1966 guarantee(HeapRegion::CardsPerRegion < max_cards_per_region,
1967 "too many cards per region");
1968
1969 FreeRegionList::set_unrealistically_long_length(max_regions() + 1);
1970
1971 _bot_shared = new G1BlockOffsetSharedArray(reserved_region(), bot_storage);
1972
|
1815 assert(n_rem_sets > 0, "Invariant.");
1816
1817 _worker_cset_start_region = NEW_C_HEAP_ARRAY(HeapRegion*, n_queues, mtGC);
1818 _worker_cset_start_region_time_stamp = NEW_C_HEAP_ARRAY(uint, n_queues, mtGC);
1819 _evacuation_failed_info_array = NEW_C_HEAP_ARRAY(EvacuationFailedInfo, n_queues, mtGC);
1820
1821 for (int i = 0; i < n_queues; i++) {
1822 RefToScanQueue* q = new RefToScanQueue();
1823 q->initialize();
1824 _task_queues->register_queue(i, q);
1825 ::new (&_evacuation_failed_info_array[i]) EvacuationFailedInfo();
1826 }
1827 clear_cset_start_regions();
1828
1829 // Initialize the G1EvacuationFailureALot counters and flags.
1830 NOT_PRODUCT(reset_evacuation_should_fail();)
1831
1832 guarantee(_task_queues != NULL, "task_queues allocation failure.");
1833 }
1834
1835 G1RegionToSpaceMapper* G1CollectedHeap::create_aux_memory_mapper(const char* description,
1836 size_t size,
1837 size_t translation_factor) {
1838 // Determine the preferred page size for the auxiliary data structures. We always
1839 // prefer large pages if the given size allows it for performance reasons.
1840 size_t const commit_size = os::page_size_for_region_unaligned(size, 1);
1841 // The base address reserved space must be aligned to that page. Otherwise we
1842 // would need to split pages (or it would be completely impossible) when
1843 // uncommitting memory within the heap.
1844 // Size need *not* be aligned to above calculated commit size.
1845 size_t const alignment = MAX2(commit_size, (size_t)os::vm_allocation_granularity());
1846 bool const use_large_pages = commit_size != (size_t)os::vm_page_size() ? UseLargePages : false;
1847 ReservedSpace rs(align_size_up(size, alignment), alignment, use_large_pages);
1848 G1RegionToSpaceMapper* result =
1849 G1RegionToSpaceMapper::create_mapper(rs,
1850 size,
1851 commit_size,
1852 HeapRegion::GrainBytes,
1853 translation_factor,
1854 mtGC);
1855 if (TracePageSizes) {
1856 gclog_or_tty->print_cr("G1 '%s': pg_sz=" SIZE_FORMAT" base=" PTR_FORMAT" size=" SIZE_FORMAT" alignment=" SIZE_FORMAT" reqsize=" SIZE_FORMAT,
1857 description, commit_size, p2i(rs.base()), rs.size(), rs.alignment(), size);
1858 }
1859 return result;
1860 }
1861
1862 jint G1CollectedHeap::initialize() {
1863 CollectedHeap::pre_initialize();
1864 os::enable_vtime();
1865
1866 G1Log::init();
1867
1868 // Necessary to satisfy locking discipline assertions.
1869
1870 MutexLocker x(Heap_lock);
1871
1872 // We have to initialize the printer before committing the heap, as
1873 // it will be used then.
1874 _hr_printer.set_active(G1PrintHeapRegions);
1875
1876 // While there are no constraints in the GC code that HeapWordSize
1877 // be any particular value, there are multiple other areas in the
1878 // system which believe this to be true (e.g. oop->object_size in some
1879 // cases incorrectly returns the size in wordSize units rather than
1880 // HeapWordSize).
1881 guarantee(HeapWordSize == wordSize, "HeapWordSize must equal wordSize");
1909 ReservedSpace heap_rs = Universe::reserve_heap(max_byte_size,
1910 heap_alignment);
1911
1912 initialize_reserved_region((HeapWord*)heap_rs.base(), (HeapWord*)(heap_rs.base() + heap_rs.size()));
1913
1914 // Create the barrier set for the entire reserved region.
1915 G1SATBCardTableLoggingModRefBS* bs
1916 = new G1SATBCardTableLoggingModRefBS(reserved_region());
1917 bs->initialize();
1918 assert(bs->is_a(BarrierSet::G1SATBCTLogging), "sanity");
1919 set_barrier_set(bs);
1920
1921 // Also create a G1 rem set.
1922 _g1_rem_set = new G1RemSet(this, g1_barrier_set());
1923
1924 // Carve out the G1 part of the heap.
1925
1926 ReservedSpace g1_rs = heap_rs.first_part(max_byte_size);
1927 G1RegionToSpaceMapper* heap_storage =
1928 G1RegionToSpaceMapper::create_mapper(g1_rs,
1929 g1_rs.size(),
1930 UseLargePages ? os::large_page_size() : os::vm_page_size(),
1931 HeapRegion::GrainBytes,
1932 1,
1933 mtJavaHeap);
1934 heap_storage->set_mapping_changed_listener(&_listener);
1935
1936 // Create storage for the BOT, card table, card counts table (hot card cache) and the bitmaps.
1937 G1RegionToSpaceMapper* bot_storage =
1938 create_aux_memory_mapper("Block offset table",
1939 G1BlockOffsetSharedArray::compute_size(g1_rs.size() / HeapWordSize),
1940 G1BlockOffsetSharedArray::N_bytes);
1941
1942 ReservedSpace cardtable_rs(G1SATBCardTableLoggingModRefBS::compute_size(g1_rs.size() / HeapWordSize));
1943 G1RegionToSpaceMapper* cardtable_storage =
1944 create_aux_memory_mapper("Card table",
1945 G1SATBCardTableLoggingModRefBS::compute_size(g1_rs.size() / HeapWordSize),
1946 G1BlockOffsetSharedArray::N_bytes);
1947
1948 G1RegionToSpaceMapper* card_counts_storage =
1949 create_aux_memory_mapper("Card counts table",
1950 G1BlockOffsetSharedArray::compute_size(g1_rs.size() / HeapWordSize),
1951 G1BlockOffsetSharedArray::N_bytes);
1952
1953 size_t bitmap_size = CMBitMap::compute_size(g1_rs.size());
1954 G1RegionToSpaceMapper* prev_bitmap_storage =
1955 create_aux_memory_mapper("Prev Bitmap", bitmap_size, CMBitMap::mark_distance());
1956 G1RegionToSpaceMapper* next_bitmap_storage =
1957 create_aux_memory_mapper("Next Bitmap", bitmap_size, CMBitMap::mark_distance());
1958
1959 _hrm.initialize(heap_storage, prev_bitmap_storage, next_bitmap_storage, bot_storage, cardtable_storage, card_counts_storage);
1960 g1_barrier_set()->initialize(cardtable_storage);
1961 // Do later initialization work for concurrent refinement.
1962 _cg1r->init(card_counts_storage);
1963
1964 // 6843694 - ensure that the maximum region index can fit
1965 // in the remembered set structures.
1966 const uint max_region_idx = (1U << (sizeof(RegionIdx_t)*BitsPerByte-1)) - 1;
1967 guarantee((max_regions() - 1) <= max_region_idx, "too many regions");
1968
1969 size_t max_cards_per_region = ((size_t)1 << (sizeof(CardIdx_t)*BitsPerByte-1)) - 1;
1970 guarantee(HeapRegion::CardsPerRegion > 0, "make sure it's initialized");
1971 guarantee(HeapRegion::CardsPerRegion < max_cards_per_region,
1972 "too many cards per region");
1973
1974 FreeRegionList::set_unrealistically_long_length(max_regions() + 1);
1975
1976 _bot_shared = new G1BlockOffsetSharedArray(reserved_region(), bot_storage);
1977
|