src/share/vm/gc_implementation/g1/heapRegionManager.hpp

Mon, 19 Aug 2019 10:11:31 +0200

author
neugens
date
Mon, 19 Aug 2019 10:11:31 +0200
changeset 9861
a248d0be1309
parent 7835
e5406a79ae90
child 7994
04ff2f6cd0eb
permissions
-rw-r--r--

8229401: Fix JFR code cache test failures
8223689: Add JFR Thread Sampling Support
8223690: Add JFR BiasedLock Event Support
8223691: Add JFR G1 Region Type Change Event Support
8223692: Add JFR G1 Heap Summary Event Support
Summary: Backport JFR from JDK11, additional fixes
Reviewed-by: neugens, apetushkov
Contributed-by: denghui.ddh@alibaba-inc.com

ysr@777 1 /*
azakharov@7835 2 * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
ysr@777 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ysr@777 4 *
ysr@777 5 * This code is free software; you can redistribute it and/or modify it
ysr@777 6 * under the terms of the GNU General Public License version 2 only, as
ysr@777 7 * published by the Free Software Foundation.
ysr@777 8 *
ysr@777 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ysr@777 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ysr@777 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ysr@777 12 * version 2 for more details (a copy is included in the LICENSE file that
ysr@777 13 * accompanied this code).
ysr@777 14 *
ysr@777 15 * You should have received a copy of the GNU General Public License version
ysr@777 16 * 2 along with this work; if not, write to the Free Software Foundation,
ysr@777 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ysr@777 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
ysr@777 22 *
ysr@777 23 */
ysr@777 24
tschatzl@7091 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONMANAGER_HPP
tschatzl@7091 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONMANAGER_HPP
stefank@2314 27
tschatzl@5773 28 #include "gc_implementation/g1/g1BiasedArray.hpp"
tschatzl@7051 29 #include "gc_implementation/g1/g1RegionToSpaceMapper.hpp"
tschatzl@7050 30 #include "gc_implementation/g1/heapRegionSet.hpp"
azakharov@7835 31 #include "services/memoryUsage.hpp"
tschatzl@5773 32
ysr@777 33 class HeapRegion;
ysr@777 34 class HeapRegionClosure;
tonyp@2963 35 class FreeRegionList;
tonyp@2963 36
tschatzl@5773 37 class G1HeapRegionTable : public G1BiasedMappedArray<HeapRegion*> {
tschatzl@5773 38 protected:
tschatzl@7050 39 virtual HeapRegion* default_value() const { return NULL; }
tschatzl@5773 40 };
tschatzl@5773 41
tschatzl@7051 42 // This class keeps track of the actual heap memory, auxiliary data
tschatzl@7051 43 // and its metadata (i.e., HeapRegion instances) and the list of free regions.
tschatzl@7051 44 //
tschatzl@7051 45 // This allows maximum flexibility for deciding what to commit or uncommit given
tschatzl@7051 46 // a request from outside.
tschatzl@7051 47 //
tschatzl@7051 48 // HeapRegions are kept in the _regions array in address order. A region's
tschatzl@7051 49 // index in the array corresponds to its index in the heap (i.e., 0 is the
tschatzl@7051 50 // region at the bottom of the heap, 1 is the one after it, etc.). Two
tschatzl@7051 51 // regions that are consecutive in the array should also be adjacent in the
tschatzl@7051 52 // address space (i.e., region(i).end() == region(i+1).bottom().
tonyp@2963 53 //
tonyp@2963 54 // We create a HeapRegion when we commit the region's address space
tonyp@2963 55 // for the first time. When we uncommit the address space of a
tonyp@2963 56 // region we retain the HeapRegion to be able to re-use it in the
tonyp@2963 57 // future (in case we recommit it).
tonyp@2963 58 //
tonyp@2963 59 // We keep track of three lengths:
tonyp@2963 60 //
tschatzl@7051 61 // * _num_committed (returned by length()) is the number of currently
tschatzl@7051 62 // committed regions. These may not be contiguous.
tschatzl@7051 63 // * _allocated_heapregions_length (not exposed outside this class) is the
tschatzl@7051 64 // number of regions+1 for which we have HeapRegions.
tschatzl@5773 65 // * max_length() returns the maximum number of regions the heap can have.
tonyp@2963 66 //
ysr@777 67
tschatzl@7091 68 class HeapRegionManager: public CHeapObj<mtGC> {
tonyp@3168 69 friend class VMStructs;
ysr@777 70
tschatzl@5773 71 G1HeapRegionTable _regions;
ysr@777 72
tschatzl@7051 73 G1RegionToSpaceMapper* _heap_mapper;
tschatzl@7051 74 G1RegionToSpaceMapper* _prev_bitmap_mapper;
tschatzl@7051 75 G1RegionToSpaceMapper* _next_bitmap_mapper;
tschatzl@7051 76 G1RegionToSpaceMapper* _bot_mapper;
tschatzl@7051 77 G1RegionToSpaceMapper* _cardtable_mapper;
tschatzl@7051 78 G1RegionToSpaceMapper* _card_counts_mapper;
tonyp@2963 79
tschatzl@7050 80 FreeRegionList _free_list;
tonyp@2963 81
tschatzl@7051 82 // Each bit in this bitmap indicates that the corresponding region is available
tschatzl@7051 83 // for allocation.
tschatzl@7051 84 BitMap _available_map;
tschatzl@7051 85
tschatzl@7050 86 // The number of regions committed in the heap.
tschatzl@7050 87 uint _num_committed;
tonyp@2963 88
tschatzl@7050 89 // Internal only. The highest heap region +1 we allocated a HeapRegion instance for.
tschatzl@7050 90 uint _allocated_heapregions_length;
tonyp@2963 91
tschatzl@7050 92 HeapWord* heap_bottom() const { return _regions.bottom_address_mapped(); }
tschatzl@7050 93 HeapWord* heap_end() const {return _regions.end_address_mapped(); }
tonyp@2963 94
tschatzl@7050 95 void make_regions_available(uint index, uint num_regions = 1);
brutisso@5074 96
tschatzl@7050 97 // Pass down commit calls to the VirtualSpace.
tschatzl@7050 98 void commit_regions(uint index, size_t num_regions = 1);
tschatzl@7050 99 void uncommit_regions(uint index, size_t num_regions = 1);
ysr@777 100
tschatzl@7050 101 // Notify other data structures about change in the heap layout.
tschatzl@7050 102 void update_committed_space(HeapWord* old_end, HeapWord* new_end);
tschatzl@7050 103 // Calculate the starting region for each worker during parallel iteration so
tschatzl@7050 104 // that they do not all start from the same region.
tschatzl@7050 105 uint start_region_for_worker(uint worker_i, uint num_workers, uint num_regions) const;
tschatzl@5773 106
tschatzl@7051 107 // Find a contiguous set of empty or uncommitted regions of length num and return
tschatzl@7091 108 // the index of the first region or G1_NO_HRM_INDEX if the search was unsuccessful.
tschatzl@7051 109 // If only_empty is true, only empty regions are considered.
tschatzl@7051 110 // Searches from bottom to top of the heap, doing a first-fit.
tschatzl@7051 111 uint find_contiguous(size_t num, bool only_empty);
tschatzl@7050 112 // Finds the next sequence of unavailable regions starting from start_idx. Returns the
tschatzl@7050 113 // length of the sequence found. If this result is zero, no such sequence could be found,
tschatzl@7050 114 // otherwise res_idx indicates the start index of these regions.
tschatzl@7050 115 uint find_unavailable_from_idx(uint start_idx, uint* res_idx) const;
tschatzl@7050 116 // Finds the next sequence of empty regions starting from start_idx, going backwards in
tschatzl@7050 117 // the heap. Returns the length of the sequence found. If this value is zero, no
tschatzl@7050 118 // sequence could be found, otherwise res_idx contains the start index of this range.
tschatzl@7050 119 uint find_empty_from_idx_reverse(uint start_idx, uint* res_idx) const;
tschatzl@7051 120 // Allocate a new HeapRegion for the given index.
tschatzl@7091 121 HeapRegion* new_heap_region(uint hrm_index);
tschatzl@7050 122 #ifdef ASSERT
tschatzl@7050 123 public:
tschatzl@7050 124 bool is_free(HeapRegion* hr) const;
tschatzl@7050 125 #endif
tschatzl@7050 126 // Returns whether the given region is available for allocation.
tschatzl@7050 127 bool is_available(uint region) const;
ysr@777 128
tschatzl@7091 129 public:
tschatzl@7091 130 // Empty constructor, we'll initialize it with the initialize() method.
tschatzl@7091 131 HeapRegionManager() : _regions(), _heap_mapper(NULL), _num_committed(0),
tschatzl@7051 132 _next_bitmap_mapper(NULL), _prev_bitmap_mapper(NULL), _bot_mapper(NULL),
tschatzl@7051 133 _allocated_heapregions_length(0), _available_map(),
tschatzl@7051 134 _free_list("Free list", new MasterFreeRegionListMtSafeChecker())
tschatzl@7050 135 { }
tschatzl@7050 136
tschatzl@7051 137 void initialize(G1RegionToSpaceMapper* heap_storage,
tschatzl@7051 138 G1RegionToSpaceMapper* prev_bitmap,
tschatzl@7051 139 G1RegionToSpaceMapper* next_bitmap,
tschatzl@7051 140 G1RegionToSpaceMapper* bot,
tschatzl@7051 141 G1RegionToSpaceMapper* cardtable,
tschatzl@7051 142 G1RegionToSpaceMapper* card_counts);
tschatzl@7050 143
tschatzl@7050 144 // Return the "dummy" region used for G1AllocRegion. This is currently a hardwired
tschatzl@7050 145 // new HeapRegion that owns HeapRegion at index 0. Since at the moment we commit
tschatzl@7050 146 // the heap from the lowest address, this region (and its associated data
tschatzl@7050 147 // structures) are available and we do not need to check further.
tschatzl@7050 148 HeapRegion* get_dummy_region() { return new_heap_region(0); }
ysr@777 149
tonyp@2963 150 // Return the HeapRegion at the given index. Assume that the index
tonyp@2963 151 // is valid.
tonyp@3713 152 inline HeapRegion* at(uint index) const;
ysr@777 153
tonyp@2963 154 // If addr is within the committed space return its corresponding
tonyp@2963 155 // HeapRegion, otherwise return NULL.
tonyp@2963 156 inline HeapRegion* addr_to_region(HeapWord* addr) const;
ysr@777 157
tschatzl@7050 158 // Insert the given region into the free region list.
tschatzl@7050 159 inline void insert_into_free_list(HeapRegion* hr);
tschatzl@7050 160
tschatzl@7050 161 // Insert the given region list into the global free region list.
tschatzl@7050 162 void insert_list_into_free_list(FreeRegionList* list) {
tschatzl@7050 163 _free_list.add_ordered(list);
tschatzl@7050 164 }
tschatzl@7050 165
tschatzl@7050 166 HeapRegion* allocate_free_region(bool is_old) {
tschatzl@7050 167 HeapRegion* hr = _free_list.remove_region(is_old);
tschatzl@7050 168
tschatzl@7050 169 if (hr != NULL) {
tschatzl@7050 170 assert(hr->next() == NULL, "Single region should not have next");
tschatzl@7091 171 assert(is_available(hr->hrm_index()), "Must be committed");
tschatzl@7050 172 }
tschatzl@7050 173 return hr;
tschatzl@7050 174 }
tschatzl@7050 175
tschatzl@7050 176 inline void allocate_free_regions_starting_at(uint first, uint num_regions);
tschatzl@7050 177
tschatzl@7050 178 // Remove all regions from the free list.
tschatzl@7050 179 void remove_all_free_regions() {
tschatzl@7050 180 _free_list.remove_all();
tschatzl@7050 181 }
tschatzl@7050 182
tschatzl@7050 183 // Return the number of committed free regions in the heap.
tschatzl@7050 184 uint num_free_regions() const {
tschatzl@7050 185 return _free_list.length();
tschatzl@7050 186 }
tschatzl@7050 187
tschatzl@7050 188 size_t total_capacity_bytes() const {
tschatzl@7050 189 return num_free_regions() * HeapRegion::GrainBytes;
tschatzl@7050 190 }
tschatzl@7050 191
tschatzl@7050 192 // Return the number of available (uncommitted) regions.
tschatzl@7050 193 uint available() const { return max_length() - length(); }
tschatzl@7050 194
tonyp@2963 195 // Return the number of regions that have been committed in the heap.
tschatzl@7050 196 uint length() const { return _num_committed; }
tonyp@2963 197
tonyp@2963 198 // Return the maximum number of regions in the heap.
tschatzl@5773 199 uint max_length() const { return (uint)_regions.length(); }
tonyp@2963 200
azakharov@7835 201 MemoryUsage get_auxiliary_data_memory_usage() const;
azakharov@7835 202
tschatzl@7050 203 MemRegion reserved() const { return MemRegion(heap_bottom(), heap_end()); }
ysr@777 204
tschatzl@7050 205 // Expand the sequence to reflect that the heap has grown. Either create new
tschatzl@7050 206 // HeapRegions, or re-use existing ones. Returns the number of regions the
tschatzl@7050 207 // sequence was expanded by. If a HeapRegion allocation fails, the resulting
tschatzl@7050 208 // number of regions might be smaller than what's desired.
tschatzl@7050 209 uint expand_by(uint num_regions);
tschatzl@7050 210
tschatzl@7050 211 // Makes sure that the regions from start to start+num_regions-1 are available
tschatzl@7050 212 // for allocation. Returns the number of regions that were committed to achieve
tschatzl@7050 213 // this.
tschatzl@7050 214 uint expand_at(uint start, uint num_regions);
tschatzl@7050 215
tschatzl@7051 216 // Find a contiguous set of empty regions of length num. Returns the start index of
tschatzl@7091 217 // that set, or G1_NO_HRM_INDEX.
tschatzl@7051 218 uint find_contiguous_only_empty(size_t num) { return find_contiguous(num, true); }
tschatzl@7051 219 // Find a contiguous set of empty or unavailable regions of length num. Returns the
tschatzl@7091 220 // start index of that set, or G1_NO_HRM_INDEX.
tschatzl@7051 221 uint find_contiguous_empty_or_unavailable(size_t num) { return find_contiguous(num, false); }
tschatzl@7050 222
tschatzl@7050 223 HeapRegion* next_region_in_heap(const HeapRegion* r) const;
ysr@777 224
tonyp@2963 225 // Apply blk->doHeapRegion() on all committed regions in address order,
tonyp@2963 226 // terminating the iteration early if doHeapRegion() returns true.
tonyp@2963 227 void iterate(HeapRegionClosure* blk) const;
ysr@777 228
tschatzl@7050 229 void par_iterate(HeapRegionClosure* blk, uint worker_id, uint no_of_par_workers, jint claim_value) const;
ysr@777 230
tschatzl@7050 231 // Uncommit up to num_regions_to_remove regions that are completely free.
tschatzl@7050 232 // Return the actual number of uncommitted regions.
brutisso@5074 233 uint shrink_by(uint num_regions_to_remove);
ysr@777 234
tschatzl@7050 235 void verify();
tschatzl@7050 236
tonyp@2963 237 // Do some sanity checking.
tonyp@2963 238 void verify_optional() PRODUCT_RETURN;
ysr@777 239 };
stefank@2314 240
tschatzl@7091 241 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONMANAGER_HPP

mercurial