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