author | jmasa |
Wed, 14 Dec 2011 13:34:57 -0800 | |
changeset 11396 | 917d8673b5ef |
parent 11174 | fccee5238e70 |
child 11756 | 28b6fe22e43d |
permissions | -rw-r--r-- |
1374 | 1 |
/* |
10523
cdb54c167ab0
7050392: G1: Introduce flag to generate a log of the G1 ergonomic decisions
tonyp
parents:
8930
diff
changeset
|
2 |
* Copyright (c) 2001, 2011, 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:
4473
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4473
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:
4473
diff
changeset
|
21 |
* questions. |
1374 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "gc_implementation/g1/collectionSetChooser.hpp" |
|
27 |
#include "gc_implementation/g1/g1CollectedHeap.inline.hpp" |
|
28 |
#include "gc_implementation/g1/g1CollectorPolicy.hpp" |
|
10523
cdb54c167ab0
7050392: G1: Introduce flag to generate a log of the G1 ergonomic decisions
tonyp
parents:
8930
diff
changeset
|
29 |
#include "gc_implementation/g1/g1ErgoVerbose.hpp" |
7397 | 30 |
#include "memory/space.inline.hpp" |
1374 | 31 |
|
32 |
CSetChooserCache::CSetChooserCache() { |
|
33 |
for (int i = 0; i < CacheLength; ++i) |
|
34 |
_cache[i] = NULL; |
|
35 |
clear(); |
|
36 |
} |
|
37 |
||
38 |
void CSetChooserCache::clear() { |
|
39 |
_occupancy = 0; |
|
40 |
_first = 0; |
|
41 |
for (int i = 0; i < CacheLength; ++i) { |
|
42 |
HeapRegion *hr = _cache[i]; |
|
43 |
if (hr != NULL) |
|
44 |
hr->set_sort_index(-1); |
|
45 |
_cache[i] = NULL; |
|
46 |
} |
|
47 |
} |
|
48 |
||
49 |
#ifndef PRODUCT |
|
50 |
bool CSetChooserCache::verify() { |
|
51 |
int index = _first; |
|
52 |
HeapRegion *prev = NULL; |
|
53 |
for (int i = 0; i < _occupancy; ++i) { |
|
54 |
guarantee(_cache[index] != NULL, "cache entry should not be empty"); |
|
55 |
HeapRegion *hr = _cache[index]; |
|
56 |
guarantee(!hr->is_young(), "should not be young!"); |
|
57 |
if (prev != NULL) { |
|
58 |
guarantee(prev->gc_efficiency() >= hr->gc_efficiency(), |
|
59 |
"cache should be correctly ordered"); |
|
60 |
} |
|
61 |
guarantee(hr->sort_index() == get_sort_index(index), |
|
62 |
"sort index should be correct"); |
|
63 |
index = trim_index(index + 1); |
|
64 |
prev = hr; |
|
65 |
} |
|
66 |
||
67 |
for (int i = 0; i < (CacheLength - _occupancy); ++i) { |
|
68 |
guarantee(_cache[index] == NULL, "cache entry should be empty"); |
|
69 |
index = trim_index(index + 1); |
|
70 |
} |
|
71 |
||
72 |
guarantee(index == _first, "we should have reached where we started from"); |
|
73 |
return true; |
|
74 |
} |
|
75 |
#endif // PRODUCT |
|
76 |
||
77 |
void CSetChooserCache::insert(HeapRegion *hr) { |
|
78 |
assert(!is_full(), "cache should not be empty"); |
|
79 |
hr->calc_gc_efficiency(); |
|
80 |
||
81 |
int empty_index; |
|
82 |
if (_occupancy == 0) { |
|
83 |
empty_index = _first; |
|
84 |
} else { |
|
85 |
empty_index = trim_index(_first + _occupancy); |
|
86 |
assert(_cache[empty_index] == NULL, "last slot should be empty"); |
|
87 |
int last_index = trim_index(empty_index - 1); |
|
88 |
HeapRegion *last = _cache[last_index]; |
|
89 |
assert(last != NULL,"as the cache is not empty, last should not be empty"); |
|
90 |
while (empty_index != _first && |
|
91 |
last->gc_efficiency() < hr->gc_efficiency()) { |
|
92 |
_cache[empty_index] = last; |
|
93 |
last->set_sort_index(get_sort_index(empty_index)); |
|
94 |
empty_index = last_index; |
|
95 |
last_index = trim_index(last_index - 1); |
|
96 |
last = _cache[last_index]; |
|
97 |
} |
|
98 |
} |
|
99 |
_cache[empty_index] = hr; |
|
100 |
hr->set_sort_index(get_sort_index(empty_index)); |
|
101 |
||
102 |
++_occupancy; |
|
103 |
assert(verify(), "cache should be consistent"); |
|
104 |
} |
|
105 |
||
106 |
HeapRegion *CSetChooserCache::remove_first() { |
|
107 |
if (_occupancy > 0) { |
|
108 |
assert(_cache[_first] != NULL, "cache should have at least one region"); |
|
109 |
HeapRegion *ret = _cache[_first]; |
|
110 |
_cache[_first] = NULL; |
|
111 |
ret->set_sort_index(-1); |
|
112 |
--_occupancy; |
|
113 |
_first = trim_index(_first + 1); |
|
114 |
assert(verify(), "cache should be consistent"); |
|
115 |
return ret; |
|
116 |
} else { |
|
117 |
return NULL; |
|
118 |
} |
|
119 |
} |
|
120 |
||
121 |
static inline int orderRegions(HeapRegion* hr1, HeapRegion* hr2) { |
|
122 |
if (hr1 == NULL) { |
|
123 |
if (hr2 == NULL) return 0; |
|
124 |
else return 1; |
|
125 |
} else if (hr2 == NULL) { |
|
126 |
return -1; |
|
127 |
} |
|
128 |
if (hr2->gc_efficiency() < hr1->gc_efficiency()) return -1; |
|
129 |
else if (hr1->gc_efficiency() < hr2->gc_efficiency()) return 1; |
|
130 |
else return 0; |
|
131 |
} |
|
132 |
||
133 |
static int orderRegions(HeapRegion** hr1p, HeapRegion** hr2p) { |
|
134 |
return orderRegions(*hr1p, *hr2p); |
|
135 |
} |
|
136 |
||
137 |
CollectionSetChooser::CollectionSetChooser() : |
|
138 |
// The line below is the worst bit of C++ hackery I've ever written |
|
139 |
// (Detlefs, 11/23). You should think of it as equivalent to |
|
140 |
// "_regions(100, true)": initialize the growable array and inform it |
|
6183
4c74cfe14f20
6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents:
5547
diff
changeset
|
141 |
// that it should allocate its elem array(s) on the C heap. |
4c74cfe14f20
6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents:
5547
diff
changeset
|
142 |
// |
4c74cfe14f20
6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents:
5547
diff
changeset
|
143 |
// The first argument, however, is actually a comma expression |
4c74cfe14f20
6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents:
5547
diff
changeset
|
144 |
// (set_allocation_type(this, C_HEAP), 100). The purpose of the |
4c74cfe14f20
6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents:
5547
diff
changeset
|
145 |
// set_allocation_type() call is to replace the default allocation |
4c74cfe14f20
6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents:
5547
diff
changeset
|
146 |
// type for embedded objects STACK_OR_EMBEDDED with C_HEAP. It will |
4c74cfe14f20
6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents:
5547
diff
changeset
|
147 |
// allow to pass the assert in GenericGrowableArray() which checks |
4c74cfe14f20
6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents:
5547
diff
changeset
|
148 |
// that a growable array object must be on C heap if elements are. |
4c74cfe14f20
6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents:
5547
diff
changeset
|
149 |
// |
4c74cfe14f20
6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents:
5547
diff
changeset
|
150 |
// Note: containing object is allocated on C heap since it is CHeapObj. |
4c74cfe14f20
6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents:
5547
diff
changeset
|
151 |
// |
4c74cfe14f20
6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents:
5547
diff
changeset
|
152 |
_markedRegions((ResourceObj::set_allocation_type((address)&_markedRegions, |
1374 | 153 |
ResourceObj::C_HEAP), |
154 |
100), |
|
155 |
true), |
|
156 |
_curMarkedIndex(0), |
|
157 |
_numMarkedRegions(0), |
|
158 |
_unmarked_age_1_returned_as_new(false), |
|
159 |
_first_par_unreserved_idx(0) |
|
160 |
{} |
|
161 |
||
162 |
||
163 |
||
164 |
#ifndef PRODUCT |
|
165 |
bool CollectionSetChooser::verify() { |
|
166 |
int index = 0; |
|
167 |
guarantee(_curMarkedIndex <= _numMarkedRegions, |
|
168 |
"_curMarkedIndex should be within bounds"); |
|
169 |
while (index < _curMarkedIndex) { |
|
170 |
guarantee(_markedRegions.at(index++) == NULL, |
|
171 |
"all entries before _curMarkedIndex should be NULL"); |
|
172 |
} |
|
173 |
HeapRegion *prev = NULL; |
|
174 |
while (index < _numMarkedRegions) { |
|
175 |
HeapRegion *curr = _markedRegions.at(index++); |
|
10680
f7bdba11999b
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
10523
diff
changeset
|
176 |
guarantee(curr != NULL, "Regions in _markedRegions array cannot be NULL"); |
f7bdba11999b
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
10523
diff
changeset
|
177 |
int si = curr->sort_index(); |
f7bdba11999b
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
10523
diff
changeset
|
178 |
guarantee(!curr->is_young(), "should not be young!"); |
f7bdba11999b
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
10523
diff
changeset
|
179 |
guarantee(si > -1 && si == (index-1), "sort index invariant"); |
f7bdba11999b
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
10523
diff
changeset
|
180 |
if (prev != NULL) { |
f7bdba11999b
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
10523
diff
changeset
|
181 |
guarantee(orderRegions(prev, curr) != 1, "regions should be sorted"); |
1374 | 182 |
} |
10680
f7bdba11999b
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
10523
diff
changeset
|
183 |
prev = curr; |
1374 | 184 |
} |
185 |
return _cache.verify(); |
|
186 |
} |
|
187 |
#endif |
|
188 |
||
189 |
void |
|
190 |
CollectionSetChooser::fillCache() { |
|
10680
f7bdba11999b
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
10523
diff
changeset
|
191 |
while (!_cache.is_full() && (_curMarkedIndex < _numMarkedRegions)) { |
f7bdba11999b
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
10523
diff
changeset
|
192 |
HeapRegion* hr = _markedRegions.at(_curMarkedIndex); |
f7bdba11999b
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
10523
diff
changeset
|
193 |
assert(hr != NULL, |
f7bdba11999b
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
10523
diff
changeset
|
194 |
err_msg("Unexpected NULL hr in _markedRegions at index %d", |
f7bdba11999b
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
10523
diff
changeset
|
195 |
_curMarkedIndex)); |
f7bdba11999b
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
10523
diff
changeset
|
196 |
_curMarkedIndex += 1; |
f7bdba11999b
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
10523
diff
changeset
|
197 |
assert(!hr->is_young(), "should not be young!"); |
f7bdba11999b
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
10523
diff
changeset
|
198 |
assert(hr->sort_index() == _curMarkedIndex-1, "sort_index invariant"); |
f7bdba11999b
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
10523
diff
changeset
|
199 |
_markedRegions.at_put(hr->sort_index(), NULL); |
f7bdba11999b
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
10523
diff
changeset
|
200 |
_cache.insert(hr); |
f7bdba11999b
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
10523
diff
changeset
|
201 |
assert(!_cache.is_empty(), "cache should not be empty"); |
1374 | 202 |
} |
10680
f7bdba11999b
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
10523
diff
changeset
|
203 |
assert(verify(), "cache should be consistent"); |
1374 | 204 |
} |
205 |
||
206 |
void |
|
207 |
CollectionSetChooser::sortMarkedHeapRegions() { |
|
208 |
guarantee(_cache.is_empty(), "cache should be empty"); |
|
209 |
// First trim any unused portion of the top in the parallel case. |
|
210 |
if (_first_par_unreserved_idx > 0) { |
|
211 |
if (G1PrintParCleanupStats) { |
|
212 |
gclog_or_tty->print(" Truncating _markedRegions from %d to %d.\n", |
|
213 |
_markedRegions.length(), _first_par_unreserved_idx); |
|
214 |
} |
|
215 |
assert(_first_par_unreserved_idx <= _markedRegions.length(), |
|
216 |
"Or we didn't reserved enough length"); |
|
217 |
_markedRegions.trunc_to(_first_par_unreserved_idx); |
|
218 |
} |
|
219 |
_markedRegions.sort(orderRegions); |
|
220 |
assert(_numMarkedRegions <= _markedRegions.length(), "Requirement"); |
|
221 |
assert(_numMarkedRegions == 0 |
|
222 |
|| _markedRegions.at(_numMarkedRegions-1) != NULL, |
|
223 |
"Testing _numMarkedRegions"); |
|
224 |
assert(_numMarkedRegions == _markedRegions.length() |
|
225 |
|| _markedRegions.at(_numMarkedRegions) == NULL, |
|
226 |
"Testing _numMarkedRegions"); |
|
227 |
if (G1PrintParCleanupStats) { |
|
228 |
gclog_or_tty->print_cr(" Sorted %d marked regions.", _numMarkedRegions); |
|
229 |
} |
|
230 |
for (int i = 0; i < _numMarkedRegions; i++) { |
|
231 |
assert(_markedRegions.at(i) != NULL, "Should be true by sorting!"); |
|
232 |
_markedRegions.at(i)->set_sort_index(i); |
|
8930
52368505ee8e
7027766: G1: introduce flag to dump the liveness information per region at the end of marking
tonyp
parents:
7397
diff
changeset
|
233 |
} |
52368505ee8e
7027766: G1: introduce flag to dump the liveness information per region at the end of marking
tonyp
parents:
7397
diff
changeset
|
234 |
if (G1PrintRegionLivenessInfo) { |
52368505ee8e
7027766: G1: introduce flag to dump the liveness information per region at the end of marking
tonyp
parents:
7397
diff
changeset
|
235 |
G1PrintRegionLivenessInfoClosure cl(gclog_or_tty, "Post-Sorting"); |
52368505ee8e
7027766: G1: introduce flag to dump the liveness information per region at the end of marking
tonyp
parents:
7397
diff
changeset
|
236 |
for (int i = 0; i < _numMarkedRegions; ++i) { |
52368505ee8e
7027766: G1: introduce flag to dump the liveness information per region at the end of marking
tonyp
parents:
7397
diff
changeset
|
237 |
HeapRegion* r = _markedRegions.at(i); |
52368505ee8e
7027766: G1: introduce flag to dump the liveness information per region at the end of marking
tonyp
parents:
7397
diff
changeset
|
238 |
cl.doHeapRegion(r); |
1374 | 239 |
} |
240 |
} |
|
241 |
assert(verify(), "should now be sorted"); |
|
242 |
} |
|
243 |
||
244 |
void |
|
245 |
CollectionSetChooser::addMarkedHeapRegion(HeapRegion* hr) { |
|
246 |
assert(!hr->isHumongous(), |
|
247 |
"Humongous regions shouldn't be added to the collection set"); |
|
248 |
assert(!hr->is_young(), "should not be young!"); |
|
249 |
_markedRegions.append(hr); |
|
250 |
_numMarkedRegions++; |
|
251 |
hr->calc_gc_efficiency(); |
|
252 |
} |
|
253 |
||
254 |
void |
|
255 |
CollectionSetChooser:: |
|
256 |
prepareForAddMarkedHeapRegionsPar(size_t n_regions, size_t chunkSize) { |
|
257 |
_first_par_unreserved_idx = 0; |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
10680
diff
changeset
|
258 |
int n_threads = ParallelGCThreads; |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
10680
diff
changeset
|
259 |
if (UseDynamicNumberOfGCThreads) { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
10680
diff
changeset
|
260 |
assert(G1CollectedHeap::heap()->workers()->active_workers() > 0, |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
10680
diff
changeset
|
261 |
"Should have been set earlier"); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
10680
diff
changeset
|
262 |
// This is defensive code. As the assertion above says, the number |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
10680
diff
changeset
|
263 |
// of active threads should be > 0, but in case there is some path |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
10680
diff
changeset
|
264 |
// or some improperly initialized variable with leads to no |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
10680
diff
changeset
|
265 |
// active threads, protect against that in a product build. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
10680
diff
changeset
|
266 |
n_threads = MAX2(G1CollectedHeap::heap()->workers()->active_workers(), |
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
267 |
1U); |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
10680
diff
changeset
|
268 |
} |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
10680
diff
changeset
|
269 |
size_t max_waste = n_threads * chunkSize; |
1374 | 270 |
// it should be aligned with respect to chunkSize |
271 |
size_t aligned_n_regions = |
|
272 |
(n_regions + (chunkSize - 1)) / chunkSize * chunkSize; |
|
273 |
assert( aligned_n_regions % chunkSize == 0, "should be aligned" ); |
|
274 |
_markedRegions.at_put_grow((int)(aligned_n_regions + max_waste - 1), NULL); |
|
275 |
} |
|
276 |
||
277 |
jint |
|
278 |
CollectionSetChooser::getParMarkedHeapRegionChunk(jint n_regions) { |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
10680
diff
changeset
|
279 |
// Don't do this assert because this can be called at a point |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
10680
diff
changeset
|
280 |
// where the loop up stream will not execute again but might |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
10680
diff
changeset
|
281 |
// try to claim more chunks (loop test has not been done yet). |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
10680
diff
changeset
|
282 |
// assert(_markedRegions.length() > _first_par_unreserved_idx, |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
10680
diff
changeset
|
283 |
// "Striding beyond the marked regions"); |
1374 | 284 |
jint res = Atomic::add(n_regions, &_first_par_unreserved_idx); |
285 |
assert(_markedRegions.length() > res + n_regions - 1, |
|
286 |
"Should already have been expanded"); |
|
287 |
return res - n_regions; |
|
288 |
} |
|
289 |
||
290 |
void |
|
291 |
CollectionSetChooser::setMarkedHeapRegion(jint index, HeapRegion* hr) { |
|
292 |
assert(_markedRegions.at(index) == NULL, "precondition"); |
|
293 |
assert(!hr->is_young(), "should not be young!"); |
|
294 |
_markedRegions.at_put(index, hr); |
|
295 |
hr->calc_gc_efficiency(); |
|
296 |
} |
|
297 |
||
298 |
void |
|
299 |
CollectionSetChooser::incNumMarkedHeapRegions(jint inc_by) { |
|
300 |
(void)Atomic::add(inc_by, &_numMarkedRegions); |
|
301 |
} |
|
302 |
||
303 |
void |
|
304 |
CollectionSetChooser::clearMarkedHeapRegions(){ |
|
305 |
for (int i = 0; i < _markedRegions.length(); i++) { |
|
306 |
HeapRegion* r = _markedRegions.at(i); |
|
307 |
if (r != NULL) r->set_sort_index(-1); |
|
308 |
} |
|
309 |
_markedRegions.clear(); |
|
310 |
_curMarkedIndex = 0; |
|
311 |
_numMarkedRegions = 0; |
|
312 |
_cache.clear(); |
|
313 |
}; |
|
314 |
||
315 |
void |
|
316 |
CollectionSetChooser::updateAfterFullCollection() { |
|
317 |
clearMarkedHeapRegions(); |
|
318 |
} |
|
319 |
||
320 |
// if time_remaining < 0.0, then this method should try to return |
|
321 |
// a region, whether it fits within the remaining time or not |
|
322 |
HeapRegion* |
|
323 |
CollectionSetChooser::getNextMarkedRegion(double time_remaining, |
|
324 |
double avg_prediction) { |
|
325 |
G1CollectedHeap* g1h = G1CollectedHeap::heap(); |
|
326 |
G1CollectorPolicy* g1p = g1h->g1_policy(); |
|
327 |
fillCache(); |
|
328 |
if (_cache.is_empty()) { |
|
329 |
assert(_curMarkedIndex == _numMarkedRegions, |
|
330 |
"if cache is empty, list should also be empty"); |
|
10523
cdb54c167ab0
7050392: G1: Introduce flag to generate a log of the G1 ergonomic decisions
tonyp
parents:
8930
diff
changeset
|
331 |
ergo_verbose0(ErgoCSetConstruction, |
cdb54c167ab0
7050392: G1: Introduce flag to generate a log of the G1 ergonomic decisions
tonyp
parents:
8930
diff
changeset
|
332 |
"stop adding old regions to CSet", |
cdb54c167ab0
7050392: G1: Introduce flag to generate a log of the G1 ergonomic decisions
tonyp
parents:
8930
diff
changeset
|
333 |
ergo_format_reason("cache is empty")); |
1374 | 334 |
return NULL; |
335 |
} |
|
336 |
||
337 |
HeapRegion *hr = _cache.get_first(); |
|
338 |
assert(hr != NULL, "if cache not empty, first entry should be non-null"); |
|
339 |
double predicted_time = g1h->predict_region_elapsed_time_ms(hr, false); |
|
340 |
||
341 |
if (g1p->adaptive_young_list_length()) { |
|
342 |
if (time_remaining - predicted_time < 0.0) { |
|
343 |
g1h->check_if_region_is_too_expensive(predicted_time); |
|
10523
cdb54c167ab0
7050392: G1: Introduce flag to generate a log of the G1 ergonomic decisions
tonyp
parents:
8930
diff
changeset
|
344 |
ergo_verbose2(ErgoCSetConstruction, |
cdb54c167ab0
7050392: G1: Introduce flag to generate a log of the G1 ergonomic decisions
tonyp
parents:
8930
diff
changeset
|
345 |
"stop adding old regions to CSet", |
cdb54c167ab0
7050392: G1: Introduce flag to generate a log of the G1 ergonomic decisions
tonyp
parents:
8930
diff
changeset
|
346 |
ergo_format_reason("predicted old region time higher than remaining time") |
cdb54c167ab0
7050392: G1: Introduce flag to generate a log of the G1 ergonomic decisions
tonyp
parents:
8930
diff
changeset
|
347 |
ergo_format_ms("predicted old region time") |
cdb54c167ab0
7050392: G1: Introduce flag to generate a log of the G1 ergonomic decisions
tonyp
parents:
8930
diff
changeset
|
348 |
ergo_format_ms("remaining time"), |
cdb54c167ab0
7050392: G1: Introduce flag to generate a log of the G1 ergonomic decisions
tonyp
parents:
8930
diff
changeset
|
349 |
predicted_time, time_remaining); |
1374 | 350 |
return NULL; |
351 |
} |
|
352 |
} else { |
|
10523
cdb54c167ab0
7050392: G1: Introduce flag to generate a log of the G1 ergonomic decisions
tonyp
parents:
8930
diff
changeset
|
353 |
double threshold = 2.0 * avg_prediction; |
cdb54c167ab0
7050392: G1: Introduce flag to generate a log of the G1 ergonomic decisions
tonyp
parents:
8930
diff
changeset
|
354 |
if (predicted_time > threshold) { |
cdb54c167ab0
7050392: G1: Introduce flag to generate a log of the G1 ergonomic decisions
tonyp
parents:
8930
diff
changeset
|
355 |
ergo_verbose2(ErgoCSetConstruction, |
cdb54c167ab0
7050392: G1: Introduce flag to generate a log of the G1 ergonomic decisions
tonyp
parents:
8930
diff
changeset
|
356 |
"stop adding old regions to CSet", |
cdb54c167ab0
7050392: G1: Introduce flag to generate a log of the G1 ergonomic decisions
tonyp
parents:
8930
diff
changeset
|
357 |
ergo_format_reason("predicted old region time higher than threshold") |
cdb54c167ab0
7050392: G1: Introduce flag to generate a log of the G1 ergonomic decisions
tonyp
parents:
8930
diff
changeset
|
358 |
ergo_format_ms("predicted old region time") |
cdb54c167ab0
7050392: G1: Introduce flag to generate a log of the G1 ergonomic decisions
tonyp
parents:
8930
diff
changeset
|
359 |
ergo_format_ms("threshold"), |
cdb54c167ab0
7050392: G1: Introduce flag to generate a log of the G1 ergonomic decisions
tonyp
parents:
8930
diff
changeset
|
360 |
predicted_time, threshold); |
1374 | 361 |
return NULL; |
362 |
} |
|
363 |
} |
|
364 |
||
365 |
HeapRegion *hr2 = _cache.remove_first(); |
|
366 |
assert(hr == hr2, "cache contents should not have changed"); |
|
367 |
||
368 |
return hr; |
|
369 |
} |