--- old/src/hotspot/share/gc/g1/g1CollectedHeap.cpp 2018-11-19 17:19:11.572376700 -0800 +++ new/src/hotspot/share/gc/g1/g1CollectedHeap.cpp 2018-11-19 17:19:10.639281100 -0800 @@ -1025,6 +1025,8 @@ abandon_collection_set(collection_set()); tear_down_region_sets(false /* free_list_only */); + + hrm()->prepare_for_full_collection_start(); } void G1CollectedHeap::verify_before_full_collection(bool explicit_gc) { @@ -1036,6 +1038,8 @@ } void G1CollectedHeap::prepare_heap_for_mutators() { + hrm()->prepare_for_full_collection_end(); + // Delete metaspaces for unloaded class loaders and clean up loader_data graph ClassLoaderDataGraph::purge(); MetaspaceUtils::verify_metrics(); @@ -1486,7 +1490,7 @@ _bot(NULL), _listener(), _hrm(NULL), - _is_hetero_heap(false), + _is_hetero_heap(AllocateOldGenAt != NULL), _allocator(NULL), _verifier(NULL), _summary_bytes_used(0), @@ -1619,7 +1623,7 @@ guarantee(HeapWordSize == wordSize, "HeapWordSize must equal wordSize"); size_t init_byte_size = collector_policy()->initial_heap_byte_size(); - size_t max_byte_size = collector_policy()->max_heap_byte_size(); + size_t max_byte_size = g1_collector_policy()->heap_reservation_size_bytes(); size_t heap_alignment = collector_policy()->heap_alignment(); // Ensure that the sizes are properly aligned. @@ -1639,10 +1643,6 @@ // address that was requested (i.e. the preferred heap base). // If this happens then we could end up using a non-optimal // compressed oops mode. - if (AllocateOldGenAt != NULL) { - _is_hetero_heap = true; - max_byte_size *= 2; - } ReservedSpace heap_rs = Universe::reserve_heap(max_byte_size, heap_alignment); @@ -1693,6 +1693,11 @@ HeapRegion::GrainBytes, 1, mtJavaHeap); + if(heap_storage == NULL) { + vm_shutdown_during_initialization("Could not initialize G1 heap"); + return JNI_ERR; + } + os::trace_page_sizes("Heap", collector_policy()->min_heap_byte_size(), max_byte_size, @@ -1723,12 +1728,8 @@ G1RegionToSpaceMapper* next_bitmap_storage = create_aux_memory_mapper("Next Bitmap", bitmap_size, G1CMBitMap::heap_map_factor()); - if (is_hetero_heap()) { - _hrm = new HeapRegionManagerForHeteroHeap((uint)((max_byte_size / 2) / HeapRegion::GrainBytes /*heap size as num of regions*/)); - } - else { - _hrm = new HeapRegionManager(); - } + _hrm = HeapRegionManager::create_manager(this, collector_policy()); + _hrm->initialize(heap_storage, prev_bitmap_storage, next_bitmap_storage, bot_storage, cardtable_storage, card_counts_storage); _card_table->initialize(cardtable_storage); // Do later initialization work for concurrent refinement. @@ -1782,6 +1783,11 @@ // Perform any initialization actions delegated to the policy. g1_policy()->init(this, &_collection_set); + // Now we know the target length of young list. So adjust the heap to provision that many regions on dram. + if (is_hetero_heap()) { + static_cast(hrm())->adjust_dram_regions((uint)g1_policy()->young_list_target_length(), workers()); + } + jint ecode = initialize_concurrent_refinement(); if (ecode != JNI_OK) { return ecode; @@ -1920,6 +1926,10 @@ return _collector_policy; } +G1CollectorPolicy* G1CollectedHeap::g1_collector_policy() const { + return _collector_policy; +} + SoftRefPolicy* G1CollectedHeap::soft_ref_policy() { return &_soft_ref_policy; } @@ -2519,6 +2529,10 @@ if (full) { // Update the number of full collections that have been completed. increment_old_marking_cycles_completed(false /* concurrent */); + // Now we know the target length of young list. So adjust the heap to provision that many regions on dram. + if (is_hetero_heap()) { + static_cast(hrm())->adjust_dram_regions((uint)g1_policy()->young_list_target_length(), workers()); + } } // We are at the end of the GC. Total collections has already been increased.