1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_VM_GC_G1_HeterogeneousHeapRegionManager_HPP 26 #define SHARE_VM_GC_G1_HeterogeneousHeapRegionManager_HPP 27 28 // This class manages heap regions on heterogenous memory comprising of dram and nv-dimm. 29 // Regions in dram (dram_set) are used for young objects and archive regions (CDS). 30 // Regions in nv-dimm (nvdimm_set) are used for old objects and humongous objects. 31 // At any point there are some regions committed on dram and some on nv-dimm with the following guarantees: 32 // 1. The total number of regions committed in dram and nv-dimm equals the current size of heap. 33 // 2. Consequently, total number of regions committed is less than or equal to Xmx. 34 // 3. To maintain the guarantee stated by 1., whenever one set grows (new regions committed), the other set shrinks (regions un-committed). 35 // 3a. If more dram regions are needed (young generation expansion), corresponding number of regions in nv-dimm are un-committed. 36 // 3b. When old generation or humongous set grows, and new regions need to be committed to nv-dimm, corresponding number of regions 37 // are un-committed in dram. 38 class HeterogeneousHeapRegionManager : public HeapRegionManager { 39 const uint _max_regions; 40 uint _max_dram_regions; 41 uint _max_nvdimm_regions; 42 uint _total_commited_before_full_gc; 43 uint _start_index_of_nvdimm; 44 45 uint total_regions_committed() const; 46 uint num_committed_dram() const; 47 uint num_committed_nvdimm() const; 48 49 // Similar to find_unavailable_from_idx() function from base class, difference is this function searches in range [start, end]. 50 uint find_unavailable_in_range(uint start_idx, uint end_idx, uint* res_idx) const; 51 52 // Expand into dram. Maintains the invariant that total number of committed regions is less than current heap size. 53 uint expand_dram(uint num_regions, WorkGang* pretouch_workers); 54 55 // Expand into nv-dimm. 56 uint expand_nvdimm(uint num_regions, WorkGang* pretouch_workers); 57 58 // Expand by finding unavailable regions in [start, end] range. 59 uint expand_in_range(uint start, uint end, uint num_regions, WorkGang* pretouch_workers); 60 61 // Shrink dram set of regions. 62 uint shrink_dram(uint num_regions, bool update_free_list = true); 63 64 // Shrink nv-dimm set of regions. 65 uint shrink_nvdimm(uint num_regions, bool update_free_list = true); 66 67 // Shrink regions from [start, end] range. 68 uint shrink_in_range(uint start, uint end, uint num_regions, bool update_free_list = true); 69 70 // Similar to find_empty_from_idx_reverse() in base class. Only here it searches in a range. 71 uint find_empty_in_range_reverse(uint start_idx, uint end_idx, uint* res_idx); 72 73 // Similar to find_contiguous() in base class, with [start, end] range 74 uint find_contiguous(size_t start, size_t end, size_t num, bool empty_only); 75 76 uint free_list_dram_length() const; 77 uint free_list_nvdimm_length() const; 78 79 // is region with given index in nv-dimm? 80 bool is_in_nvdimm(uint index) const; 81 bool is_in_dram(uint index) const; 82 83 public: 84 85 // Empty constructor, we'll initialize it with the initialize() method. 86 HeterogeneousHeapRegionManager(uint num_regions) : _max_regions(num_regions), _max_dram_regions(0), 87 _max_nvdimm_regions(0), _start_index_of_nvdimm(0) 88 {} 89 90 uint start_index_of_nvdimm() const; 91 uint start_index_of_dram() const; 92 uint end_index_of_nvdimm() const; 93 uint end_index_of_dram() const; 94 95 // Override. 96 HeapRegion* get_dummy_region(); 97 98 // Adjust dram_set to provision 'expected_num_regions' regions. 99 void adjust_dram_regions(uint expected_num_regions, WorkGang* pretouch_workers); 100 101 // Prepare heap regions before and after full collection. 102 void prepare_for_full_collection_start(); 103 void prepare_for_full_collection_end(); 104 105 virtual HeapRegion* allocate_free_region(bool is_old); 106 107 // Return maximum number of regions that heap can expand to. 108 uint max_expandable_length() const; 109 110 // Override. Expand in nv-dimm. 111 uint expand_by(uint num_regions, WorkGang* pretouch_workers); 112 113 // Override. 114 uint expand_at(uint start, uint num_regions, WorkGang* pretouch_workers); 115 116 // Override. This function is called for humongous allocation, so we need to find empty regions in nv-dimm. 117 uint find_contiguous_only_empty(size_t num); 118 119 // Override. This function is called for humongous allocation, so we need to find empty or unavailable regions in nv-dimm. 120 uint find_contiguous_empty_or_unavailable(size_t num); 121 122 // Overrides base class implementation to find highest free region in dram. 123 uint find_highest_free(bool* expanded); 124 125 // Override. This fuction is called to shrink the heap, we shrink in dram first then in nv-dimm. 126 uint shrink_by(uint num_regions_to_remove); 127 128 void verify(); 129 }; 130 131 #endif