Fri, 29 Apr 2011 14:59:04 -0400
7035144: G1: nightly failure: Non-dirty cards in region that should be dirty (failures still exist...)
Summary: We should only undirty cards after we decide that they are not on a young region, not before. The fix also includes improvements to the verify_dirty_region() method which print out which cards were not found dirty.
Reviewed-by: johnc, brutisso
1 /*
2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP
26 #define SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP
28 #include "gc_implementation/g1/heapRegion.hpp"
29 #include "utilities/growableArray.hpp"
31 // We need to sort heap regions by collection desirability.
33 class CSetChooserCache VALUE_OBJ_CLASS_SPEC {
34 private:
35 enum {
36 CacheLength = 16
37 } PrivateConstants;
39 HeapRegion* _cache[CacheLength];
40 int _occupancy; // number of region in cache
41 int _first; // "first" region in the cache
43 // adding CacheLength to deal with negative values
44 inline int trim_index(int index) {
45 return (index + CacheLength) % CacheLength;
46 }
48 inline int get_sort_index(int index) {
49 return -index-2;
50 }
51 inline int get_index(int sort_index) {
52 return -sort_index-2;
53 }
55 public:
56 CSetChooserCache(void);
58 inline int occupancy(void) { return _occupancy; }
59 inline bool is_full() { return _occupancy == CacheLength; }
60 inline bool is_empty() { return _occupancy == 0; }
62 void clear(void);
63 void insert(HeapRegion *hr);
64 HeapRegion *remove_first(void);
65 void remove (HeapRegion *hr);
66 inline HeapRegion *get_first(void) {
67 return _cache[_first];
68 }
70 #ifndef PRODUCT
71 bool verify (void);
72 bool region_in_cache(HeapRegion *hr) {
73 int sort_index = hr->sort_index();
74 if (sort_index < -1) {
75 int index = get_index(sort_index);
76 guarantee(index < CacheLength, "should be within bounds");
77 return _cache[index] == hr;
78 } else
79 return 0;
80 }
81 #endif // PRODUCT
82 };
84 class CollectionSetChooser: public CHeapObj {
86 GrowableArray<HeapRegion*> _markedRegions;
87 int _curMarkedIndex;
88 int _numMarkedRegions;
89 CSetChooserCache _cache;
91 // True iff last collection pause ran of out new "age 0" regions, and
92 // returned an "age 1" region.
93 bool _unmarked_age_1_returned_as_new;
95 jint _first_par_unreserved_idx;
97 public:
99 HeapRegion* getNextMarkedRegion(double time_so_far, double avg_prediction);
101 CollectionSetChooser();
103 void sortMarkedHeapRegions();
104 void fillCache();
105 bool addRegionToCache(void);
106 void addMarkedHeapRegion(HeapRegion *hr);
108 // Must be called before calls to getParMarkedHeapRegionChunk.
109 // "n_regions" is the number of regions, "chunkSize" the chunk size.
110 void prepareForAddMarkedHeapRegionsPar(size_t n_regions, size_t chunkSize);
111 // Returns the first index in a contiguous chunk of "n_regions" indexes
112 // that the calling thread has reserved. These must be set by the
113 // calling thread using "setMarkedHeapRegion" (to NULL if necessary).
114 jint getParMarkedHeapRegionChunk(jint n_regions);
115 // Set the marked array entry at index to hr. Careful to claim the index
116 // first if in parallel.
117 void setMarkedHeapRegion(jint index, HeapRegion* hr);
118 // Atomically increment the number of claimed regions by "inc_by".
119 void incNumMarkedHeapRegions(jint inc_by);
121 void clearMarkedHeapRegions();
123 void updateAfterFullCollection();
125 // Ensure that "hr" is not a member of the marked region array or the cache
126 void removeRegion(HeapRegion* hr);
128 bool unmarked_age_1_returned_as_new() { return _unmarked_age_1_returned_as_new; }
130 // Returns true if the used portion of "_markedRegions" is properly
131 // sorted, otherwise asserts false.
132 #ifndef PRODUCT
133 bool verify(void);
134 bool regionProperlyOrdered(HeapRegion* r) {
135 int si = r->sort_index();
136 return (si == -1) ||
137 (si > -1 && _markedRegions.at(si) == r) ||
138 (si < -1 && _cache.region_in_cache(r));
139 }
140 #endif
142 };
144 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP