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

Wed, 18 Apr 2012 07:21:15 -0400

author
tonyp
date
Wed, 18 Apr 2012 07:21:15 -0400
changeset 3713
720b6a76dd9d
parent 3539
a9647476d1a4
child 3714
f7a8920427a6
permissions
-rw-r--r--

7157073: G1: type change size_t -> uint for region counts / indexes
Summary: Change the type of fields / variables / etc. that represent region counts and indeces from size_t to uint.
Reviewed-by: iveresov, brutisso, jmasa, jwilhelm

ysr@777 1 /*
tonyp@3539 2 * Copyright (c) 2001, 2012, 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
stefank@2314 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP
stefank@2314 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP
stefank@2314 27
stefank@2314 28 #include "gc_implementation/g1/heapRegion.hpp"
stefank@2314 29 #include "utilities/growableArray.hpp"
stefank@2314 30
apetrusenko@984 31 class CSetChooserCache VALUE_OBJ_CLASS_SPEC {
ysr@777 32 private:
ysr@777 33 enum {
ysr@777 34 CacheLength = 16
ysr@777 35 } PrivateConstants;
ysr@777 36
ysr@777 37 HeapRegion* _cache[CacheLength];
ysr@3185 38 int _occupancy; // number of regions in cache
ysr@3185 39 int _first; // (index of) "first" region in the cache
ysr@777 40
ysr@777 41 // adding CacheLength to deal with negative values
ysr@777 42 inline int trim_index(int index) {
ysr@777 43 return (index + CacheLength) % CacheLength;
ysr@777 44 }
ysr@777 45
ysr@777 46 inline int get_sort_index(int index) {
ysr@777 47 return -index-2;
ysr@777 48 }
ysr@777 49 inline int get_index(int sort_index) {
ysr@777 50 return -sort_index-2;
ysr@777 51 }
ysr@777 52
ysr@777 53 public:
ysr@777 54 CSetChooserCache(void);
ysr@777 55
ysr@777 56 inline int occupancy(void) { return _occupancy; }
ysr@777 57 inline bool is_full() { return _occupancy == CacheLength; }
ysr@777 58 inline bool is_empty() { return _occupancy == 0; }
ysr@777 59
ysr@777 60 void clear(void);
ysr@777 61 void insert(HeapRegion *hr);
ysr@777 62 HeapRegion *remove_first(void);
ysr@777 63 inline HeapRegion *get_first(void) {
ysr@777 64 return _cache[_first];
ysr@777 65 }
ysr@777 66
ysr@777 67 #ifndef PRODUCT
ysr@777 68 bool verify (void);
ysr@777 69 bool region_in_cache(HeapRegion *hr) {
ysr@777 70 int sort_index = hr->sort_index();
ysr@777 71 if (sort_index < -1) {
ysr@777 72 int index = get_index(sort_index);
ysr@777 73 guarantee(index < CacheLength, "should be within bounds");
ysr@777 74 return _cache[index] == hr;
ysr@777 75 } else
ysr@777 76 return 0;
ysr@777 77 }
ysr@777 78 #endif // PRODUCT
ysr@777 79 };
ysr@777 80
ysr@777 81 class CollectionSetChooser: public CHeapObj {
ysr@777 82
ysr@777 83 GrowableArray<HeapRegion*> _markedRegions;
tonyp@3539 84
tonyp@3539 85 // The index of the next candidate old region to be considered for
tonyp@3539 86 // addition to the CSet.
tonyp@3539 87 int _curr_index;
tonyp@3539 88
tonyp@3539 89 // The number of candidate old regions added to the CSet chooser.
tonyp@3539 90 int _length;
tonyp@3539 91
ysr@777 92 CSetChooserCache _cache;
tonyp@3539 93 jint _first_par_unreserved_idx;
ysr@777 94
tonyp@3539 95 // If a region has more live bytes than this threshold, it will not
tonyp@3539 96 // be added to the CSet chooser and will not be a candidate for
tonyp@3539 97 // collection.
tonyp@3539 98 size_t _regionLiveThresholdBytes;
ysr@777 99
tonyp@3539 100 // The sum of reclaimable bytes over all the regions in the CSet chooser.
tonyp@3539 101 size_t _remainingReclaimableBytes;
ysr@777 102
ysr@777 103 public:
ysr@777 104
tonyp@3539 105 // Return the current candidate region to be considered for
tonyp@3539 106 // collection without removing it from the CSet chooser.
tonyp@3539 107 HeapRegion* peek() {
tonyp@3539 108 HeapRegion* res = NULL;
tonyp@3539 109 if (_curr_index < _length) {
tonyp@3539 110 res = _markedRegions.at(_curr_index);
tonyp@3539 111 assert(res != NULL,
tonyp@3539 112 err_msg("Unexpected NULL hr in _markedRegions at index %d",
tonyp@3539 113 _curr_index));
tonyp@3539 114 }
tonyp@3539 115 return res;
tonyp@3539 116 }
tonyp@3539 117
tonyp@3539 118 // Remove the given region from the CSet chooser and move to the
tonyp@3539 119 // next one. The given region should be the current candidate region
tonyp@3539 120 // in the CSet chooser.
tonyp@3539 121 void remove_and_move_to_next(HeapRegion* hr) {
tonyp@3539 122 assert(hr != NULL, "pre-condition");
tonyp@3539 123 assert(_curr_index < _length, "pre-condition");
tonyp@3539 124 assert(_markedRegions.at(_curr_index) == hr, "pre-condition");
tonyp@3539 125 hr->set_sort_index(-1);
tonyp@3539 126 _markedRegions.at_put(_curr_index, NULL);
tonyp@3539 127 assert(hr->reclaimable_bytes() <= _remainingReclaimableBytes,
tonyp@3539 128 err_msg("remaining reclaimable bytes inconsistent "
tonyp@3539 129 "from region: "SIZE_FORMAT" remaining: "SIZE_FORMAT,
tonyp@3539 130 hr->reclaimable_bytes(), _remainingReclaimableBytes));
tonyp@3539 131 _remainingReclaimableBytes -= hr->reclaimable_bytes();
tonyp@3539 132 _curr_index += 1;
tonyp@3539 133 }
ysr@777 134
ysr@777 135 CollectionSetChooser();
ysr@777 136
ysr@777 137 void sortMarkedHeapRegions();
ysr@777 138 void fillCache();
tonyp@3539 139
tonyp@3539 140 // Determine whether to add the given region to the CSet chooser or
tonyp@3539 141 // not. Currently, we skip humongous regions (we never add them to
tonyp@3539 142 // the CSet, we only reclaim them during cleanup) and regions whose
tonyp@3539 143 // live bytes are over the threshold.
tonyp@3539 144 bool shouldAdd(HeapRegion* hr) {
tonyp@3539 145 assert(hr->is_marked(), "pre-condition");
tonyp@3539 146 assert(!hr->is_young(), "should never consider young regions");
tonyp@3539 147 return !hr->isHumongous() &&
tonyp@3539 148 hr->live_bytes() < _regionLiveThresholdBytes;
tonyp@3539 149 }
tonyp@3539 150
tonyp@3539 151 // Calculate the minimum number of old regions we'll add to the CSet
tonyp@3539 152 // during a mixed GC.
tonyp@3713 153 uint calcMinOldCSetLength();
tonyp@3539 154
tonyp@3539 155 // Calculate the maximum number of old regions we'll add to the CSet
tonyp@3539 156 // during a mixed GC.
tonyp@3713 157 uint calcMaxOldCSetLength();
tonyp@3539 158
tonyp@3539 159 // Serial version.
ysr@777 160 void addMarkedHeapRegion(HeapRegion *hr);
ysr@777 161
ysr@777 162 // Must be called before calls to getParMarkedHeapRegionChunk.
ysr@777 163 // "n_regions" is the number of regions, "chunkSize" the chunk size.
tonyp@3713 164 void prepareForAddMarkedHeapRegionsPar(uint n_regions, uint chunkSize);
ysr@777 165 // Returns the first index in a contiguous chunk of "n_regions" indexes
ysr@777 166 // that the calling thread has reserved. These must be set by the
ysr@777 167 // calling thread using "setMarkedHeapRegion" (to NULL if necessary).
ysr@777 168 jint getParMarkedHeapRegionChunk(jint n_regions);
ysr@777 169 // Set the marked array entry at index to hr. Careful to claim the index
ysr@777 170 // first if in parallel.
ysr@777 171 void setMarkedHeapRegion(jint index, HeapRegion* hr);
tonyp@3539 172 // Atomically increment the number of added regions by region_num
tonyp@3539 173 // and the amount of reclaimable bytes by reclaimable_bytes.
tonyp@3539 174 void updateTotals(jint region_num, size_t reclaimable_bytes);
ysr@777 175
ysr@777 176 void clearMarkedHeapRegions();
ysr@777 177
tonyp@3539 178 // Return the number of candidate regions that remain to be collected.
tonyp@3713 179 uint remainingRegions() { return (uint) (_length - _curr_index); }
ysr@777 180
tonyp@3539 181 // Determine whether the CSet chooser has more candidate regions or not.
tonyp@3539 182 bool isEmpty() { return remainingRegions() == 0; }
tonyp@3539 183
tonyp@3539 184 // Return the reclaimable bytes that remain to be collected on
tonyp@3539 185 // all the candidate regions in the CSet chooser.
tonyp@3539 186 size_t remainingReclaimableBytes () { return _remainingReclaimableBytes; }
ysr@777 187
ysr@777 188 // Returns true if the used portion of "_markedRegions" is properly
ysr@777 189 // sorted, otherwise asserts false.
ysr@777 190 #ifndef PRODUCT
ysr@777 191 bool verify(void);
ysr@777 192 bool regionProperlyOrdered(HeapRegion* r) {
ysr@777 193 int si = r->sort_index();
tonyp@3539 194 if (si > -1) {
tonyp@3539 195 guarantee(_curr_index <= si && si < _length,
tonyp@3539 196 err_msg("curr: %d sort index: %d: length: %d",
tonyp@3539 197 _curr_index, si, _length));
tonyp@3539 198 guarantee(_markedRegions.at(si) == r,
tonyp@3539 199 err_msg("sort index: %d at: "PTR_FORMAT" r: "PTR_FORMAT,
tonyp@3539 200 si, _markedRegions.at(si), r));
tonyp@3539 201 } else {
tonyp@3539 202 guarantee(si == -1, err_msg("sort index: %d", si));
tonyp@3539 203 }
tonyp@3539 204 return true;
ysr@777 205 }
ysr@777 206 #endif
ysr@777 207
ysr@777 208 };
stefank@2314 209
stefank@2314 210 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP

mercurial