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

Thu, 22 Sep 2011 10:57:37 -0700

author
johnc
date
Thu, 22 Sep 2011 10:57:37 -0700
changeset 3175
4dfb2df418f2
parent 2717
371bbc844bf1
child 3185
b9390528617c
permissions
-rw-r--r--

6484982: G1: process references during evacuation pauses
Summary: G1 now uses two reference processors - one is used by concurrent marking and the other is used by STW GCs (both full and incremental evacuation pauses). In an evacuation pause, the reference processor is embedded into the closures used to scan objects. Doing so causes causes reference objects to be 'discovered' by the reference processor. At the end of the evacuation pause, these discovered reference objects are processed - preserving (and copying) referent objects (and their reachable graphs) as appropriate.
Reviewed-by: ysr, jwilhelm, brutisso, stefank, tonyp

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 sortMarkedHeapRegions();
ysr@777 104 void fillCache();
ysr@777 105 bool addRegionToCache(void);
ysr@777 106 void addMarkedHeapRegion(HeapRegion *hr);
ysr@777 107
ysr@777 108 // Must be called before calls to getParMarkedHeapRegionChunk.
ysr@777 109 // "n_regions" is the number of regions, "chunkSize" the chunk size.
ysr@777 110 void prepareForAddMarkedHeapRegionsPar(size_t n_regions, size_t chunkSize);
ysr@777 111 // Returns the first index in a contiguous chunk of "n_regions" indexes
ysr@777 112 // that the calling thread has reserved. These must be set by the
ysr@777 113 // calling thread using "setMarkedHeapRegion" (to NULL if necessary).
ysr@777 114 jint getParMarkedHeapRegionChunk(jint n_regions);
ysr@777 115 // Set the marked array entry at index to hr. Careful to claim the index
ysr@777 116 // first if in parallel.
ysr@777 117 void setMarkedHeapRegion(jint index, HeapRegion* hr);
ysr@777 118 // Atomically increment the number of claimed regions by "inc_by".
ysr@777 119 void incNumMarkedHeapRegions(jint inc_by);
ysr@777 120
ysr@777 121 void clearMarkedHeapRegions();
ysr@777 122
ysr@777 123 void updateAfterFullCollection();
ysr@777 124
ysr@777 125 // Ensure that "hr" is not a member of the marked region array or the cache
ysr@777 126 void removeRegion(HeapRegion* hr);
ysr@777 127
ysr@777 128 bool unmarked_age_1_returned_as_new() { return _unmarked_age_1_returned_as_new; }
ysr@777 129
ysr@777 130 // Returns true if the used portion of "_markedRegions" is properly
ysr@777 131 // sorted, otherwise asserts false.
ysr@777 132 #ifndef PRODUCT
ysr@777 133 bool verify(void);
ysr@777 134 bool regionProperlyOrdered(HeapRegion* r) {
ysr@777 135 int si = r->sort_index();
ysr@777 136 return (si == -1) ||
ysr@777 137 (si > -1 && _markedRegions.at(si) == r) ||
ysr@777 138 (si < -1 && _cache.region_in_cache(r));
ysr@777 139 }
ysr@777 140 #endif
ysr@777 141
ysr@777 142 };
stefank@2314 143
stefank@2314 144 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP

mercurial