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

Tue, 23 Nov 2010 13:22:55 -0800

author
stefank
date
Tue, 23 Nov 2010 13:22:55 -0800
changeset 2314
f95d63e2154a
parent 1907
c18cbe5936b8
child 2717
371bbc844bf1
permissions
-rw-r--r--

6989984: Use standard include model for Hospot
Summary: Replaced MakeDeps and the includeDB files with more standardized solutions.
Reviewed-by: coleenp, kvn, kamg

ysr@777 1 /*
stefank@2314 2 * Copyright (c) 2001, 2010, 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
ysr@777 31 // We need to sort heap regions by collection desirability.
ysr@777 32
apetrusenko@984 33 class CSetChooserCache VALUE_OBJ_CLASS_SPEC {
ysr@777 34 private:
ysr@777 35 enum {
ysr@777 36 CacheLength = 16
ysr@777 37 } PrivateConstants;
ysr@777 38
ysr@777 39 HeapRegion* _cache[CacheLength];
ysr@777 40 int _occupancy; // number of region in cache
ysr@777 41 int _first; // "first" region in the cache
ysr@777 42
ysr@777 43 // adding CacheLength to deal with negative values
ysr@777 44 inline int trim_index(int index) {
ysr@777 45 return (index + CacheLength) % CacheLength;
ysr@777 46 }
ysr@777 47
ysr@777 48 inline int get_sort_index(int index) {
ysr@777 49 return -index-2;
ysr@777 50 }
ysr@777 51 inline int get_index(int sort_index) {
ysr@777 52 return -sort_index-2;
ysr@777 53 }
ysr@777 54
ysr@777 55 public:
ysr@777 56 CSetChooserCache(void);
ysr@777 57
ysr@777 58 inline int occupancy(void) { return _occupancy; }
ysr@777 59 inline bool is_full() { return _occupancy == CacheLength; }
ysr@777 60 inline bool is_empty() { return _occupancy == 0; }
ysr@777 61
ysr@777 62 void clear(void);
ysr@777 63 void insert(HeapRegion *hr);
ysr@777 64 HeapRegion *remove_first(void);
ysr@777 65 void remove (HeapRegion *hr);
ysr@777 66 inline HeapRegion *get_first(void) {
ysr@777 67 return _cache[_first];
ysr@777 68 }
ysr@777 69
ysr@777 70 #ifndef PRODUCT
ysr@777 71 bool verify (void);
ysr@777 72 bool region_in_cache(HeapRegion *hr) {
ysr@777 73 int sort_index = hr->sort_index();
ysr@777 74 if (sort_index < -1) {
ysr@777 75 int index = get_index(sort_index);
ysr@777 76 guarantee(index < CacheLength, "should be within bounds");
ysr@777 77 return _cache[index] == hr;
ysr@777 78 } else
ysr@777 79 return 0;
ysr@777 80 }
ysr@777 81 #endif // PRODUCT
ysr@777 82 };
ysr@777 83
ysr@777 84 class CollectionSetChooser: public CHeapObj {
ysr@777 85
ysr@777 86 GrowableArray<HeapRegion*> _markedRegions;
ysr@777 87 int _curMarkedIndex;
ysr@777 88 int _numMarkedRegions;
ysr@777 89 CSetChooserCache _cache;
ysr@777 90
ysr@777 91 // True iff last collection pause ran of out new "age 0" regions, and
ysr@777 92 // returned an "age 1" region.
ysr@777 93 bool _unmarked_age_1_returned_as_new;
ysr@777 94
ysr@777 95 jint _first_par_unreserved_idx;
ysr@777 96
ysr@777 97 public:
ysr@777 98
ysr@777 99 HeapRegion* getNextMarkedRegion(double time_so_far, double avg_prediction);
ysr@777 100
ysr@777 101 CollectionSetChooser();
ysr@777 102
ysr@777 103 void printSortedHeapRegions();
ysr@777 104
ysr@777 105 void sortMarkedHeapRegions();
ysr@777 106 void fillCache();
ysr@777 107 bool addRegionToCache(void);
ysr@777 108 void addMarkedHeapRegion(HeapRegion *hr);
ysr@777 109
ysr@777 110 // Must be called before calls to getParMarkedHeapRegionChunk.
ysr@777 111 // "n_regions" is the number of regions, "chunkSize" the chunk size.
ysr@777 112 void prepareForAddMarkedHeapRegionsPar(size_t n_regions, size_t chunkSize);
ysr@777 113 // Returns the first index in a contiguous chunk of "n_regions" indexes
ysr@777 114 // that the calling thread has reserved. These must be set by the
ysr@777 115 // calling thread using "setMarkedHeapRegion" (to NULL if necessary).
ysr@777 116 jint getParMarkedHeapRegionChunk(jint n_regions);
ysr@777 117 // Set the marked array entry at index to hr. Careful to claim the index
ysr@777 118 // first if in parallel.
ysr@777 119 void setMarkedHeapRegion(jint index, HeapRegion* hr);
ysr@777 120 // Atomically increment the number of claimed regions by "inc_by".
ysr@777 121 void incNumMarkedHeapRegions(jint inc_by);
ysr@777 122
ysr@777 123 void clearMarkedHeapRegions();
ysr@777 124
ysr@777 125 void updateAfterFullCollection();
ysr@777 126
ysr@777 127 // Ensure that "hr" is not a member of the marked region array or the cache
ysr@777 128 void removeRegion(HeapRegion* hr);
ysr@777 129
ysr@777 130 bool unmarked_age_1_returned_as_new() { return _unmarked_age_1_returned_as_new; }
ysr@777 131
ysr@777 132 // Returns true if the used portion of "_markedRegions" is properly
ysr@777 133 // sorted, otherwise asserts false.
ysr@777 134 #ifndef PRODUCT
ysr@777 135 bool verify(void);
ysr@777 136 bool regionProperlyOrdered(HeapRegion* r) {
ysr@777 137 int si = r->sort_index();
ysr@777 138 return (si == -1) ||
ysr@777 139 (si > -1 && _markedRegions.at(si) == r) ||
ysr@777 140 (si < -1 && _cache.region_in_cache(r));
ysr@777 141 }
ysr@777 142 #endif
ysr@777 143
ysr@777 144 };
stefank@2314 145
stefank@2314 146 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP

mercurial