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

Mon, 03 Aug 2009 12:59:30 -0700

author
johnc
date
Mon, 03 Aug 2009 12:59:30 -0700
changeset 1324
15c5903cf9e1
parent 1014
0fbdb4381b99
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6865703: G1: Parallelize hot card cache cleanup
Summary: Have the GC worker threads clear the hot card cache in parallel by having each worker thread claim a chunk of the card cache and process the cards in that chunk. The size of the chunks that each thread will claim is determined at VM initialization from the size of the card cache and the number of worker threads.
Reviewed-by: jmasa, tonyp

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

mercurial