--- old/share/gc/g1/g1CollectedHeap.cpp 2018-06-15 09:47:35.906912384 -0700 +++ new/share/gc/g1/g1CollectedHeap.cpp 2018-06-15 09:47:35.854912383 -0700 @@ -1316,8 +1316,7 @@ bool G1CollectedHeap::expand(size_t expand_bytes, WorkGang* pretouch_workers, double* expand_time_ms) { size_t aligned_expand_bytes = ReservedSpace::page_align_size_up(expand_bytes); - aligned_expand_bytes = align_up(aligned_expand_bytes, - HeapRegion::GrainBytes); + aligned_expand_bytes = align_up(aligned_expand_bytes, HeapRegion::GrainBytes); log_debug(gc, ergo, heap)("Expand the heap. requested expansion amount: " SIZE_FORMAT "B expansion amount: " SIZE_FORMAT "B", expand_bytes, aligned_expand_bytes); @@ -1563,7 +1562,7 @@ _hot_card_cache = new G1HotCardCache(this); // Carve out the G1 part of the heap. - ReservedSpace g1_rs = heap_rs.first_part(max_byte_size); + ReservedSpace g1_rs = heap_rs.first_part(heap_rs.size()); size_t page_size = UseLargePages ? os::large_page_size() : os::vm_page_size(); G1RegionToSpaceMapper* heap_storage = G1RegionToSpaceMapper::create_mapper(g1_rs, @@ -1646,12 +1645,36 @@ } _cm_thread = _cm->cm_thread(); + // Expand NVDIMM to maximum old gen size. + if (AllocateOldGenAt != NULL) { + int fd_for_heap = -1; + fd_for_heap = os::create_file_for_heap(AllocateOldGenAt); + if (fd_for_heap== -1) { + vm_exit_during_initialization( + err_msg("Could not create file for Heap at location %s", AllocateOldGenAt)); + } + // Allocate space on device. + os::allocate_file(fd_for_heap, MaxHeapSize); + os::set_nvdimm_fd(fd_for_heap); + os::set_nvdimm_present(true); + os::set_nvdimm_heapbase((address)(heap_rs.base())); + } + size_t aligned_expand_bytes = 0; + if (os::has_nvdimm()) { + aligned_expand_bytes = expand_old_gen_on_nvdimm(max_byte_size); + } // Now expand into the initial heap size. if (!expand(init_byte_size, _workers)) { vm_shutdown_during_initialization("Failed to allocate initial heap."); return JNI_ENOMEM; } + if (os::has_nvdimm()) { + // Show how much memory was committed on NVDIMM and DRAM. + log_info(gc, heap)("NVDIMM Reserved Bytes : %ld DRAM Reserved Bytes : %ld \n", aligned_expand_bytes, init_byte_size); + log_info(gc, heap)("When NVDIMM is present, we always reserve and commit Maximum OldGen Size on NVDIMM"); + log_info(gc, heap)("JVM will have more size reserved and committed than specified by Xmn or Xms options (but never more than Xmx)."); + } // Perform any initialization actions delegated to the policy. g1_policy()->init(this, &_collection_set); @@ -1713,6 +1736,16 @@ return JNI_OK; } +size_t G1CollectedHeap::expand_old_gen_on_nvdimm(size_t max_byte_size) { + size_t nvdimm_bytes = max_byte_size - (size_t)(max_byte_size * G1MaxNewSizePercent)/100; + size_t aligned_expand_bytes = ReservedSpace::page_align_size_up(nvdimm_bytes); + aligned_expand_bytes = align_up(aligned_expand_bytes, HeapRegion::GrainBytes); + uint nvdimm_regions = (uint)(aligned_expand_bytes/HeapRegion::GrainBytes); + os::set_nvdimm_regionlength(nvdimm_regions); + expand(aligned_expand_bytes, _workers); + return aligned_expand_bytes; +} + void G1CollectedHeap::initialize_serviceability() { _eden_pool = new G1EdenPool(this); _survivor_pool = new G1SurvivorPool(this);