Mercurial > hg > graal-compiler
annotate src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp @ 1489:cff162798819
6888953: some calls to function-like macros are missing semicolons
Reviewed-by: pbk, kvn
author | jcoomes |
---|---|
date | Sun, 11 Oct 2009 16:19:25 -0700 |
parents | 1316cec51b4d |
children | cc387008223e |
rev | line source |
---|---|
342 | 1 /* |
1387
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1360
diff
changeset
|
2 * Copyright 2001-2010 Sun Microsystems, Inc. All Rights Reserved. |
342 | 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 #include "incls/_precompiled.incl" | |
26 #include "incls/_g1CollectedHeap.cpp.incl" | |
27 | |
942
2c79770d1f6e
6819085: G1: use larger and/or user settable region size
tonyp
parents:
941
diff
changeset
|
28 size_t G1CollectedHeap::_humongous_object_threshold_in_words = 0; |
2c79770d1f6e
6819085: G1: use larger and/or user settable region size
tonyp
parents:
941
diff
changeset
|
29 |
342 | 30 // turn it on so that the contents of the young list (scan-only / |
31 // to-be-collected) are printed at "strategic" points before / during | |
32 // / after the collection --- this is useful for debugging | |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
33 #define YOUNG_LIST_VERBOSE 0 |
342 | 34 // CURRENT STATUS |
35 // This file is under construction. Search for "FIXME". | |
36 | |
37 // INVARIANTS/NOTES | |
38 // | |
39 // All allocation activity covered by the G1CollectedHeap interface is | |
40 // serialized by acquiring the HeapLock. This happens in | |
41 // mem_allocate_work, which all such allocation functions call. | |
42 // (Note that this does not apply to TLAB allocation, which is not part | |
43 // of this interface: it is done by clients of this interface.) | |
44 | |
45 // Local to this file. | |
46 | |
47 class RefineCardTableEntryClosure: public CardTableEntryClosure { | |
48 SuspendibleThreadSet* _sts; | |
49 G1RemSet* _g1rs; | |
50 ConcurrentG1Refine* _cg1r; | |
51 bool _concurrent; | |
52 public: | |
53 RefineCardTableEntryClosure(SuspendibleThreadSet* sts, | |
54 G1RemSet* g1rs, | |
55 ConcurrentG1Refine* cg1r) : | |
56 _sts(sts), _g1rs(g1rs), _cg1r(cg1r), _concurrent(true) | |
57 {} | |
58 bool do_card_ptr(jbyte* card_ptr, int worker_i) { | |
59 _g1rs->concurrentRefineOneCard(card_ptr, worker_i); | |
60 if (_concurrent && _sts->should_yield()) { | |
61 // Caller will actually yield. | |
62 return false; | |
63 } | |
64 // Otherwise, we finished successfully; return true. | |
65 return true; | |
66 } | |
67 void set_concurrent(bool b) { _concurrent = b; } | |
68 }; | |
69 | |
70 | |
71 class ClearLoggedCardTableEntryClosure: public CardTableEntryClosure { | |
72 int _calls; | |
73 G1CollectedHeap* _g1h; | |
74 CardTableModRefBS* _ctbs; | |
75 int _histo[256]; | |
76 public: | |
77 ClearLoggedCardTableEntryClosure() : | |
78 _calls(0) | |
79 { | |
80 _g1h = G1CollectedHeap::heap(); | |
81 _ctbs = (CardTableModRefBS*)_g1h->barrier_set(); | |
82 for (int i = 0; i < 256; i++) _histo[i] = 0; | |
83 } | |
84 bool do_card_ptr(jbyte* card_ptr, int worker_i) { | |
85 if (_g1h->is_in_reserved(_ctbs->addr_for(card_ptr))) { | |
86 _calls++; | |
87 unsigned char* ujb = (unsigned char*)card_ptr; | |
88 int ind = (int)(*ujb); | |
89 _histo[ind]++; | |
90 *card_ptr = -1; | |
91 } | |
92 return true; | |
93 } | |
94 int calls() { return _calls; } | |
95 void print_histo() { | |
96 gclog_or_tty->print_cr("Card table value histogram:"); | |
97 for (int i = 0; i < 256; i++) { | |
98 if (_histo[i] != 0) { | |
99 gclog_or_tty->print_cr(" %d: %d", i, _histo[i]); | |
100 } | |
101 } | |
102 } | |
103 }; | |
104 | |
105 class RedirtyLoggedCardTableEntryClosure: public CardTableEntryClosure { | |
106 int _calls; | |
107 G1CollectedHeap* _g1h; | |
108 CardTableModRefBS* _ctbs; | |
109 public: | |
110 RedirtyLoggedCardTableEntryClosure() : | |
111 _calls(0) | |
112 { | |
113 _g1h = G1CollectedHeap::heap(); | |
114 _ctbs = (CardTableModRefBS*)_g1h->barrier_set(); | |
115 } | |
116 bool do_card_ptr(jbyte* card_ptr, int worker_i) { | |
117 if (_g1h->is_in_reserved(_ctbs->addr_for(card_ptr))) { | |
118 _calls++; | |
119 *card_ptr = 0; | |
120 } | |
121 return true; | |
122 } | |
123 int calls() { return _calls; } | |
124 }; | |
125 | |
616
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
126 class RedirtyLoggedCardTableEntryFastClosure : public CardTableEntryClosure { |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
127 public: |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
128 bool do_card_ptr(jbyte* card_ptr, int worker_i) { |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
129 *card_ptr = CardTableModRefBS::dirty_card_val(); |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
130 return true; |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
131 } |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
132 }; |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
133 |
342 | 134 YoungList::YoungList(G1CollectedHeap* g1h) |
135 : _g1h(g1h), _head(NULL), | |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
136 _length(0), |
342 | 137 _last_sampled_rs_lengths(0), |
545 | 138 _survivor_head(NULL), _survivor_tail(NULL), _survivor_length(0) |
342 | 139 { |
140 guarantee( check_list_empty(false), "just making sure..." ); | |
141 } | |
142 | |
143 void YoungList::push_region(HeapRegion *hr) { | |
144 assert(!hr->is_young(), "should not already be young"); | |
145 assert(hr->get_next_young_region() == NULL, "cause it should!"); | |
146 | |
147 hr->set_next_young_region(_head); | |
148 _head = hr; | |
149 | |
150 hr->set_young(); | |
151 double yg_surv_rate = _g1h->g1_policy()->predict_yg_surv_rate((int)_length); | |
152 ++_length; | |
153 } | |
154 | |
155 void YoungList::add_survivor_region(HeapRegion* hr) { | |
545 | 156 assert(hr->is_survivor(), "should be flagged as survivor region"); |
342 | 157 assert(hr->get_next_young_region() == NULL, "cause it should!"); |
158 | |
159 hr->set_next_young_region(_survivor_head); | |
160 if (_survivor_head == NULL) { | |
545 | 161 _survivor_tail = hr; |
342 | 162 } |
163 _survivor_head = hr; | |
164 | |
165 ++_survivor_length; | |
166 } | |
167 | |
168 void YoungList::empty_list(HeapRegion* list) { | |
169 while (list != NULL) { | |
170 HeapRegion* next = list->get_next_young_region(); | |
171 list->set_next_young_region(NULL); | |
172 list->uninstall_surv_rate_group(); | |
173 list->set_not_young(); | |
174 list = next; | |
175 } | |
176 } | |
177 | |
178 void YoungList::empty_list() { | |
179 assert(check_list_well_formed(), "young list should be well formed"); | |
180 | |
181 empty_list(_head); | |
182 _head = NULL; | |
183 _length = 0; | |
184 | |
185 empty_list(_survivor_head); | |
186 _survivor_head = NULL; | |
545 | 187 _survivor_tail = NULL; |
342 | 188 _survivor_length = 0; |
189 | |
190 _last_sampled_rs_lengths = 0; | |
191 | |
192 assert(check_list_empty(false), "just making sure..."); | |
193 } | |
194 | |
195 bool YoungList::check_list_well_formed() { | |
196 bool ret = true; | |
197 | |
198 size_t length = 0; | |
199 HeapRegion* curr = _head; | |
200 HeapRegion* last = NULL; | |
201 while (curr != NULL) { | |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
202 if (!curr->is_young()) { |
342 | 203 gclog_or_tty->print_cr("### YOUNG REGION "PTR_FORMAT"-"PTR_FORMAT" " |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
204 "incorrectly tagged (y: %d, surv: %d)", |
342 | 205 curr->bottom(), curr->end(), |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
206 curr->is_young(), curr->is_survivor()); |
342 | 207 ret = false; |
208 } | |
209 ++length; | |
210 last = curr; | |
211 curr = curr->get_next_young_region(); | |
212 } | |
213 ret = ret && (length == _length); | |
214 | |
215 if (!ret) { | |
216 gclog_or_tty->print_cr("### YOUNG LIST seems not well formed!"); | |
217 gclog_or_tty->print_cr("### list has %d entries, _length is %d", | |
218 length, _length); | |
219 } | |
220 | |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
221 return ret; |
342 | 222 } |
223 | |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
224 bool YoungList::check_list_empty(bool check_sample) { |
342 | 225 bool ret = true; |
226 | |
227 if (_length != 0) { | |
228 gclog_or_tty->print_cr("### YOUNG LIST should have 0 length, not %d", | |
229 _length); | |
230 ret = false; | |
231 } | |
232 if (check_sample && _last_sampled_rs_lengths != 0) { | |
233 gclog_or_tty->print_cr("### YOUNG LIST has non-zero last sampled RS lengths"); | |
234 ret = false; | |
235 } | |
236 if (_head != NULL) { | |
237 gclog_or_tty->print_cr("### YOUNG LIST does not have a NULL head"); | |
238 ret = false; | |
239 } | |
240 if (!ret) { | |
241 gclog_or_tty->print_cr("### YOUNG LIST does not seem empty"); | |
242 } | |
243 | |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
244 return ret; |
342 | 245 } |
246 | |
247 void | |
248 YoungList::rs_length_sampling_init() { | |
249 _sampled_rs_lengths = 0; | |
250 _curr = _head; | |
251 } | |
252 | |
253 bool | |
254 YoungList::rs_length_sampling_more() { | |
255 return _curr != NULL; | |
256 } | |
257 | |
258 void | |
259 YoungList::rs_length_sampling_next() { | |
260 assert( _curr != NULL, "invariant" ); | |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
261 size_t rs_length = _curr->rem_set()->occupied(); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
262 |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
263 _sampled_rs_lengths += rs_length; |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
264 |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
265 // The current region may not yet have been added to the |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
266 // incremental collection set (it gets added when it is |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
267 // retired as the current allocation region). |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
268 if (_curr->in_collection_set()) { |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
269 // Update the collection set policy information for this region |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
270 _g1h->g1_policy()->update_incremental_cset_info(_curr, rs_length); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
271 } |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
272 |
342 | 273 _curr = _curr->get_next_young_region(); |
274 if (_curr == NULL) { | |
275 _last_sampled_rs_lengths = _sampled_rs_lengths; | |
276 // gclog_or_tty->print_cr("last sampled RS lengths = %d", _last_sampled_rs_lengths); | |
277 } | |
278 } | |
279 | |
280 void | |
281 YoungList::reset_auxilary_lists() { | |
282 guarantee( is_empty(), "young list should be empty" ); | |
283 assert(check_list_well_formed(), "young list should be well formed"); | |
284 | |
285 // Add survivor regions to SurvRateGroup. | |
286 _g1h->g1_policy()->note_start_adding_survivor_regions(); | |
545 | 287 _g1h->g1_policy()->finished_recalculating_age_indexes(true /* is_survivors */); |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
288 |
342 | 289 for (HeapRegion* curr = _survivor_head; |
290 curr != NULL; | |
291 curr = curr->get_next_young_region()) { | |
292 _g1h->g1_policy()->set_region_survivors(curr); | |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
293 |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
294 // The region is a non-empty survivor so let's add it to |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
295 // the incremental collection set for the next evacuation |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
296 // pause. |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
297 _g1h->g1_policy()->add_region_to_incremental_cset_rhs(curr); |
342 | 298 } |
299 _g1h->g1_policy()->note_stop_adding_survivor_regions(); | |
300 | |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
301 _head = _survivor_head; |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
302 _length = _survivor_length; |
342 | 303 if (_survivor_head != NULL) { |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
304 assert(_survivor_tail != NULL, "cause it shouldn't be"); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
305 assert(_survivor_length > 0, "invariant"); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
306 _survivor_tail->set_next_young_region(NULL); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
307 } |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
308 |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
309 // Don't clear the survivor list handles until the start of |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
310 // the next evacuation pause - we need it in order to re-tag |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
311 // the survivor regions from this evacuation pause as 'young' |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
312 // at the start of the next. |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
313 |
545 | 314 _g1h->g1_policy()->finished_recalculating_age_indexes(false /* is_survivors */); |
342 | 315 |
316 assert(check_list_well_formed(), "young list should be well formed"); | |
317 } | |
318 | |
319 void YoungList::print() { | |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
320 HeapRegion* lists[] = {_head, _survivor_head}; |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
321 const char* names[] = {"YOUNG", "SURVIVOR"}; |
342 | 322 |
323 for (unsigned int list = 0; list < ARRAY_SIZE(lists); ++list) { | |
324 gclog_or_tty->print_cr("%s LIST CONTENTS", names[list]); | |
325 HeapRegion *curr = lists[list]; | |
326 if (curr == NULL) | |
327 gclog_or_tty->print_cr(" empty"); | |
328 while (curr != NULL) { | |
329 gclog_or_tty->print_cr(" [%08x-%08x], t: %08x, P: %08x, N: %08x, C: %08x, " | |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
330 "age: %4d, y: %d, surv: %d", |
342 | 331 curr->bottom(), curr->end(), |
332 curr->top(), | |
333 curr->prev_top_at_mark_start(), | |
334 curr->next_top_at_mark_start(), | |
335 curr->top_at_conc_mark_count(), | |
336 curr->age_in_surv_rate_group_cond(), | |
337 curr->is_young(), | |
338 curr->is_survivor()); | |
339 curr = curr->get_next_young_region(); | |
340 } | |
341 } | |
342 | |
343 gclog_or_tty->print_cr(""); | |
344 } | |
345 | |
796
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
346 void G1CollectedHeap::push_dirty_cards_region(HeapRegion* hr) |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
347 { |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
348 // Claim the right to put the region on the dirty cards region list |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
349 // by installing a self pointer. |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
350 HeapRegion* next = hr->get_next_dirty_cards_region(); |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
351 if (next == NULL) { |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
352 HeapRegion* res = (HeapRegion*) |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
353 Atomic::cmpxchg_ptr(hr, hr->next_dirty_cards_region_addr(), |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
354 NULL); |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
355 if (res == NULL) { |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
356 HeapRegion* head; |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
357 do { |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
358 // Put the region to the dirty cards region list. |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
359 head = _dirty_cards_region_list; |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
360 next = (HeapRegion*) |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
361 Atomic::cmpxchg_ptr(hr, &_dirty_cards_region_list, head); |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
362 if (next == head) { |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
363 assert(hr->get_next_dirty_cards_region() == hr, |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
364 "hr->get_next_dirty_cards_region() != hr"); |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
365 if (next == NULL) { |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
366 // The last region in the list points to itself. |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
367 hr->set_next_dirty_cards_region(hr); |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
368 } else { |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
369 hr->set_next_dirty_cards_region(next); |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
370 } |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
371 } |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
372 } while (next != head); |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
373 } |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
374 } |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
375 } |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
376 |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
377 HeapRegion* G1CollectedHeap::pop_dirty_cards_region() |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
378 { |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
379 HeapRegion* head; |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
380 HeapRegion* hr; |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
381 do { |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
382 head = _dirty_cards_region_list; |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
383 if (head == NULL) { |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
384 return NULL; |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
385 } |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
386 HeapRegion* new_head = head->get_next_dirty_cards_region(); |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
387 if (head == new_head) { |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
388 // The last region. |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
389 new_head = NULL; |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
390 } |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
391 hr = (HeapRegion*)Atomic::cmpxchg_ptr(new_head, &_dirty_cards_region_list, |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
392 head); |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
393 } while (hr != head); |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
394 assert(hr != NULL, "invariant"); |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
395 hr->set_next_dirty_cards_region(NULL); |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
396 return hr; |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
397 } |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
398 |
342 | 399 void G1CollectedHeap::stop_conc_gc_threads() { |
794 | 400 _cg1r->stop(); |
342 | 401 _czft->stop(); |
402 _cmThread->stop(); | |
403 } | |
404 | |
405 | |
406 void G1CollectedHeap::check_ct_logs_at_safepoint() { | |
407 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); | |
408 CardTableModRefBS* ct_bs = (CardTableModRefBS*)barrier_set(); | |
409 | |
410 // Count the dirty cards at the start. | |
411 CountNonCleanMemRegionClosure count1(this); | |
412 ct_bs->mod_card_iterate(&count1); | |
413 int orig_count = count1.n(); | |
414 | |
415 // First clear the logged cards. | |
416 ClearLoggedCardTableEntryClosure clear; | |
417 dcqs.set_closure(&clear); | |
418 dcqs.apply_closure_to_all_completed_buffers(); | |
419 dcqs.iterate_closure_all_threads(false); | |
420 clear.print_histo(); | |
421 | |
422 // Now ensure that there's no dirty cards. | |
423 CountNonCleanMemRegionClosure count2(this); | |
424 ct_bs->mod_card_iterate(&count2); | |
425 if (count2.n() != 0) { | |
426 gclog_or_tty->print_cr("Card table has %d entries; %d originally", | |
427 count2.n(), orig_count); | |
428 } | |
429 guarantee(count2.n() == 0, "Card table should be clean."); | |
430 | |
431 RedirtyLoggedCardTableEntryClosure redirty; | |
432 JavaThread::dirty_card_queue_set().set_closure(&redirty); | |
433 dcqs.apply_closure_to_all_completed_buffers(); | |
434 dcqs.iterate_closure_all_threads(false); | |
435 gclog_or_tty->print_cr("Log entries = %d, dirty cards = %d.", | |
436 clear.calls(), orig_count); | |
437 guarantee(redirty.calls() == clear.calls(), | |
438 "Or else mechanism is broken."); | |
439 | |
440 CountNonCleanMemRegionClosure count3(this); | |
441 ct_bs->mod_card_iterate(&count3); | |
442 if (count3.n() != orig_count) { | |
443 gclog_or_tty->print_cr("Should have restored them all: orig = %d, final = %d.", | |
444 orig_count, count3.n()); | |
445 guarantee(count3.n() >= orig_count, "Should have restored them all."); | |
446 } | |
447 | |
448 JavaThread::dirty_card_queue_set().set_closure(_refine_cte_cl); | |
449 } | |
450 | |
451 // Private class members. | |
452 | |
453 G1CollectedHeap* G1CollectedHeap::_g1h; | |
454 | |
455 // Private methods. | |
456 | |
457 // Finds a HeapRegion that can be used to allocate a given size of block. | |
458 | |
459 | |
460 HeapRegion* G1CollectedHeap::newAllocRegion_work(size_t word_size, | |
461 bool do_expand, | |
462 bool zero_filled) { | |
463 ConcurrentZFThread::note_region_alloc(); | |
464 HeapRegion* res = alloc_free_region_from_lists(zero_filled); | |
465 if (res == NULL && do_expand) { | |
466 expand(word_size * HeapWordSize); | |
467 res = alloc_free_region_from_lists(zero_filled); | |
468 assert(res == NULL || | |
469 (!res->isHumongous() && | |
470 (!zero_filled || | |
471 res->zero_fill_state() == HeapRegion::Allocated)), | |
472 "Alloc Regions must be zero filled (and non-H)"); | |
473 } | |
474 if (res != NULL && res->is_empty()) _free_regions--; | |
475 assert(res == NULL || | |
476 (!res->isHumongous() && | |
477 (!zero_filled || | |
478 res->zero_fill_state() == HeapRegion::Allocated)), | |
479 "Non-young alloc Regions must be zero filled (and non-H)"); | |
480 | |
1282 | 481 if (G1PrintHeapRegions) { |
342 | 482 if (res != NULL) { |
483 gclog_or_tty->print_cr("new alloc region %d:["PTR_FORMAT", "PTR_FORMAT"], " | |
484 "top "PTR_FORMAT, | |
485 res->hrs_index(), res->bottom(), res->end(), res->top()); | |
486 } | |
487 } | |
488 | |
489 return res; | |
490 } | |
491 | |
492 HeapRegion* G1CollectedHeap::newAllocRegionWithExpansion(int purpose, | |
493 size_t word_size, | |
494 bool zero_filled) { | |
495 HeapRegion* alloc_region = NULL; | |
496 if (_gc_alloc_region_counts[purpose] < g1_policy()->max_regions(purpose)) { | |
497 alloc_region = newAllocRegion_work(word_size, true, zero_filled); | |
498 if (purpose == GCAllocForSurvived && alloc_region != NULL) { | |
545 | 499 alloc_region->set_survivor(); |
342 | 500 } |
501 ++_gc_alloc_region_counts[purpose]; | |
502 } else { | |
503 g1_policy()->note_alloc_region_limit_reached(purpose); | |
504 } | |
505 return alloc_region; | |
506 } | |
507 | |
508 // If could fit into free regions w/o expansion, try. | |
509 // Otherwise, if can expand, do so. | |
510 // Otherwise, if using ex regions might help, try with ex given back. | |
511 HeapWord* G1CollectedHeap::humongousObjAllocate(size_t word_size) { | |
512 assert(regions_accounted_for(), "Region leakage!"); | |
513 | |
514 // We can't allocate H regions while cleanupComplete is running, since | |
515 // some of the regions we find to be empty might not yet be added to the | |
516 // unclean list. (If we're already at a safepoint, this call is | |
517 // unnecessary, not to mention wrong.) | |
518 if (!SafepointSynchronize::is_at_safepoint()) | |
519 wait_for_cleanup_complete(); | |
520 | |
521 size_t num_regions = | |
522 round_to(word_size, HeapRegion::GrainWords) / HeapRegion::GrainWords; | |
523 | |
524 // Special case if < one region??? | |
525 | |
526 // Remember the ft size. | |
527 size_t x_size = expansion_regions(); | |
528 | |
529 HeapWord* res = NULL; | |
530 bool eliminated_allocated_from_lists = false; | |
531 | |
532 // Can the allocation potentially fit in the free regions? | |
533 if (free_regions() >= num_regions) { | |
534 res = _hrs->obj_allocate(word_size); | |
535 } | |
536 if (res == NULL) { | |
537 // Try expansion. | |
538 size_t fs = _hrs->free_suffix(); | |
539 if (fs + x_size >= num_regions) { | |
540 expand((num_regions - fs) * HeapRegion::GrainBytes); | |
541 res = _hrs->obj_allocate(word_size); | |
542 assert(res != NULL, "This should have worked."); | |
543 } else { | |
544 // Expansion won't help. Are there enough free regions if we get rid | |
545 // of reservations? | |
546 size_t avail = free_regions(); | |
547 if (avail >= num_regions) { | |
548 res = _hrs->obj_allocate(word_size); | |
549 if (res != NULL) { | |
550 remove_allocated_regions_from_lists(); | |
551 eliminated_allocated_from_lists = true; | |
552 } | |
553 } | |
554 } | |
555 } | |
556 if (res != NULL) { | |
557 // Increment by the number of regions allocated. | |
558 // FIXME: Assumes regions all of size GrainBytes. | |
559 #ifndef PRODUCT | |
560 mr_bs()->verify_clean_region(MemRegion(res, res + num_regions * | |
561 HeapRegion::GrainWords)); | |
562 #endif | |
563 if (!eliminated_allocated_from_lists) | |
564 remove_allocated_regions_from_lists(); | |
565 _summary_bytes_used += word_size * HeapWordSize; | |
566 _free_regions -= num_regions; | |
567 _num_humongous_regions += (int) num_regions; | |
568 } | |
569 assert(regions_accounted_for(), "Region Leakage"); | |
570 return res; | |
571 } | |
572 | |
573 HeapWord* | |
574 G1CollectedHeap::attempt_allocation_slow(size_t word_size, | |
575 bool permit_collection_pause) { | |
576 HeapWord* res = NULL; | |
577 HeapRegion* allocated_young_region = NULL; | |
578 | |
579 assert( SafepointSynchronize::is_at_safepoint() || | |
580 Heap_lock->owned_by_self(), "pre condition of the call" ); | |
581 | |
582 if (isHumongous(word_size)) { | |
583 // Allocation of a humongous object can, in a sense, complete a | |
584 // partial region, if the previous alloc was also humongous, and | |
585 // caused the test below to succeed. | |
586 if (permit_collection_pause) | |
587 do_collection_pause_if_appropriate(word_size); | |
588 res = humongousObjAllocate(word_size); | |
589 assert(_cur_alloc_region == NULL | |
590 || !_cur_alloc_region->isHumongous(), | |
591 "Prevent a regression of this bug."); | |
592 | |
593 } else { | |
354
c0f8f7790199
6652160: G1: assert(cur_used_bytes == _g1->recalculate_used(),"It should!") at g1CollectorPolicy.cpp:1425
iveresov
parents:
353
diff
changeset
|
594 // We may have concurrent cleanup working at the time. Wait for it |
c0f8f7790199
6652160: G1: assert(cur_used_bytes == _g1->recalculate_used(),"It should!") at g1CollectorPolicy.cpp:1425
iveresov
parents:
353
diff
changeset
|
595 // to complete. In the future we would probably want to make the |
c0f8f7790199
6652160: G1: assert(cur_used_bytes == _g1->recalculate_used(),"It should!") at g1CollectorPolicy.cpp:1425
iveresov
parents:
353
diff
changeset
|
596 // concurrent cleanup truly concurrent by decoupling it from the |
c0f8f7790199
6652160: G1: assert(cur_used_bytes == _g1->recalculate_used(),"It should!") at g1CollectorPolicy.cpp:1425
iveresov
parents:
353
diff
changeset
|
597 // allocation. |
c0f8f7790199
6652160: G1: assert(cur_used_bytes == _g1->recalculate_used(),"It should!") at g1CollectorPolicy.cpp:1425
iveresov
parents:
353
diff
changeset
|
598 if (!SafepointSynchronize::is_at_safepoint()) |
c0f8f7790199
6652160: G1: assert(cur_used_bytes == _g1->recalculate_used(),"It should!") at g1CollectorPolicy.cpp:1425
iveresov
parents:
353
diff
changeset
|
599 wait_for_cleanup_complete(); |
342 | 600 // If we do a collection pause, this will be reset to a non-NULL |
601 // value. If we don't, nulling here ensures that we allocate a new | |
602 // region below. | |
603 if (_cur_alloc_region != NULL) { | |
604 // We're finished with the _cur_alloc_region. | |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
605 // As we're builing (at least the young portion) of the collection |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
606 // set incrementally we'll add the current allocation region to |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
607 // the collection set here. |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
608 if (_cur_alloc_region->is_young()) { |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
609 g1_policy()->add_region_to_incremental_cset_lhs(_cur_alloc_region); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
610 } |
342 | 611 _summary_bytes_used += _cur_alloc_region->used(); |
612 _cur_alloc_region = NULL; | |
613 } | |
614 assert(_cur_alloc_region == NULL, "Invariant."); | |
615 // Completion of a heap region is perhaps a good point at which to do | |
616 // a collection pause. | |
617 if (permit_collection_pause) | |
618 do_collection_pause_if_appropriate(word_size); | |
619 // Make sure we have an allocation region available. | |
620 if (_cur_alloc_region == NULL) { | |
621 if (!SafepointSynchronize::is_at_safepoint()) | |
622 wait_for_cleanup_complete(); | |
623 bool next_is_young = should_set_young_locked(); | |
624 // If the next region is not young, make sure it's zero-filled. | |
625 _cur_alloc_region = newAllocRegion(word_size, !next_is_young); | |
626 if (_cur_alloc_region != NULL) { | |
627 _summary_bytes_used -= _cur_alloc_region->used(); | |
628 if (next_is_young) { | |
629 set_region_short_lived_locked(_cur_alloc_region); | |
630 allocated_young_region = _cur_alloc_region; | |
631 } | |
632 } | |
633 } | |
634 assert(_cur_alloc_region == NULL || !_cur_alloc_region->isHumongous(), | |
635 "Prevent a regression of this bug."); | |
636 | |
637 // Now retry the allocation. | |
638 if (_cur_alloc_region != NULL) { | |
639 res = _cur_alloc_region->allocate(word_size); | |
640 } | |
641 } | |
642 | |
643 // NOTE: fails frequently in PRT | |
644 assert(regions_accounted_for(), "Region leakage!"); | |
645 | |
646 if (res != NULL) { | |
647 if (!SafepointSynchronize::is_at_safepoint()) { | |
648 assert( permit_collection_pause, "invariant" ); | |
649 assert( Heap_lock->owned_by_self(), "invariant" ); | |
650 Heap_lock->unlock(); | |
651 } | |
652 | |
653 if (allocated_young_region != NULL) { | |
654 HeapRegion* hr = allocated_young_region; | |
655 HeapWord* bottom = hr->bottom(); | |
656 HeapWord* end = hr->end(); | |
657 MemRegion mr(bottom, end); | |
658 ((CardTableModRefBS*)_g1h->barrier_set())->dirty(mr); | |
659 } | |
660 } | |
661 | |
662 assert( SafepointSynchronize::is_at_safepoint() || | |
663 (res == NULL && Heap_lock->owned_by_self()) || | |
664 (res != NULL && !Heap_lock->owned_by_self()), | |
665 "post condition of the call" ); | |
666 | |
667 return res; | |
668 } | |
669 | |
670 HeapWord* | |
671 G1CollectedHeap::mem_allocate(size_t word_size, | |
672 bool is_noref, | |
673 bool is_tlab, | |
674 bool* gc_overhead_limit_was_exceeded) { | |
675 debug_only(check_for_valid_allocation_state()); | |
676 assert(no_gc_in_progress(), "Allocation during gc not allowed"); | |
677 HeapWord* result = NULL; | |
678 | |
679 // Loop until the allocation is satisified, | |
680 // or unsatisfied after GC. | |
681 for (int try_count = 1; /* return or throw */; try_count += 1) { | |
682 int gc_count_before; | |
683 { | |
684 Heap_lock->lock(); | |
685 result = attempt_allocation(word_size); | |
686 if (result != NULL) { | |
687 // attempt_allocation should have unlocked the heap lock | |
688 assert(is_in(result), "result not in heap"); | |
689 return result; | |
690 } | |
691 // Read the gc count while the heap lock is held. | |
692 gc_count_before = SharedHeap::heap()->total_collections(); | |
693 Heap_lock->unlock(); | |
694 } | |
695 | |
696 // Create the garbage collection operation... | |
697 VM_G1CollectForAllocation op(word_size, | |
698 gc_count_before); | |
699 | |
700 // ...and get the VM thread to execute it. | |
701 VMThread::execute(&op); | |
702 if (op.prologue_succeeded()) { | |
703 result = op.result(); | |
704 assert(result == NULL || is_in(result), "result not in heap"); | |
705 return result; | |
706 } | |
707 | |
708 // Give a warning if we seem to be looping forever. | |
709 if ((QueuedAllocationWarningCount > 0) && | |
710 (try_count % QueuedAllocationWarningCount == 0)) { | |
711 warning("G1CollectedHeap::mem_allocate_work retries %d times", | |
712 try_count); | |
713 } | |
714 } | |
715 } | |
716 | |
717 void G1CollectedHeap::abandon_cur_alloc_region() { | |
718 if (_cur_alloc_region != NULL) { | |
719 // We're finished with the _cur_alloc_region. | |
720 if (_cur_alloc_region->is_empty()) { | |
721 _free_regions++; | |
722 free_region(_cur_alloc_region); | |
723 } else { | |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
724 // As we're builing (at least the young portion) of the collection |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
725 // set incrementally we'll add the current allocation region to |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
726 // the collection set here. |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
727 if (_cur_alloc_region->is_young()) { |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
728 g1_policy()->add_region_to_incremental_cset_lhs(_cur_alloc_region); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
729 } |
342 | 730 _summary_bytes_used += _cur_alloc_region->used(); |
731 } | |
732 _cur_alloc_region = NULL; | |
733 } | |
734 } | |
735 | |
636 | 736 void G1CollectedHeap::abandon_gc_alloc_regions() { |
737 // first, make sure that the GC alloc region list is empty (it should!) | |
738 assert(_gc_alloc_region_list == NULL, "invariant"); | |
739 release_gc_alloc_regions(true /* totally */); | |
740 } | |
741 | |
342 | 742 class PostMCRemSetClearClosure: public HeapRegionClosure { |
743 ModRefBarrierSet* _mr_bs; | |
744 public: | |
745 PostMCRemSetClearClosure(ModRefBarrierSet* mr_bs) : _mr_bs(mr_bs) {} | |
746 bool doHeapRegion(HeapRegion* r) { | |
747 r->reset_gc_time_stamp(); | |
748 if (r->continuesHumongous()) | |
749 return false; | |
750 HeapRegionRemSet* hrrs = r->rem_set(); | |
751 if (hrrs != NULL) hrrs->clear(); | |
752 // You might think here that we could clear just the cards | |
753 // corresponding to the used region. But no: if we leave a dirty card | |
754 // in a region we might allocate into, then it would prevent that card | |
755 // from being enqueued, and cause it to be missed. | |
756 // Re: the performance cost: we shouldn't be doing full GC anyway! | |
757 _mr_bs->clear(MemRegion(r->bottom(), r->end())); | |
758 return false; | |
759 } | |
760 }; | |
761 | |
762 | |
763 class PostMCRemSetInvalidateClosure: public HeapRegionClosure { | |
764 ModRefBarrierSet* _mr_bs; | |
765 public: | |
766 PostMCRemSetInvalidateClosure(ModRefBarrierSet* mr_bs) : _mr_bs(mr_bs) {} | |
767 bool doHeapRegion(HeapRegion* r) { | |
768 if (r->continuesHumongous()) return false; | |
769 if (r->used_region().word_size() != 0) { | |
770 _mr_bs->invalidate(r->used_region(), true /*whole heap*/); | |
771 } | |
772 return false; | |
773 } | |
774 }; | |
775 | |
626
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
776 class RebuildRSOutOfRegionClosure: public HeapRegionClosure { |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
777 G1CollectedHeap* _g1h; |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
778 UpdateRSOopClosure _cl; |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
779 int _worker_i; |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
780 public: |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
781 RebuildRSOutOfRegionClosure(G1CollectedHeap* g1, int worker_i = 0) : |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
782 _cl(g1->g1_rem_set()->as_HRInto_G1RemSet(), worker_i), |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
783 _worker_i(worker_i), |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
784 _g1h(g1) |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
785 { } |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
786 bool doHeapRegion(HeapRegion* r) { |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
787 if (!r->continuesHumongous()) { |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
788 _cl.set_from(r); |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
789 r->oop_iterate(&_cl); |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
790 } |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
791 return false; |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
792 } |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
793 }; |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
794 |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
795 class ParRebuildRSTask: public AbstractGangTask { |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
796 G1CollectedHeap* _g1; |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
797 public: |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
798 ParRebuildRSTask(G1CollectedHeap* g1) |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
799 : AbstractGangTask("ParRebuildRSTask"), |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
800 _g1(g1) |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
801 { } |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
802 |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
803 void work(int i) { |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
804 RebuildRSOutOfRegionClosure rebuild_rs(_g1, i); |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
805 _g1->heap_region_par_iterate_chunked(&rebuild_rs, i, |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
806 HeapRegion::RebuildRSClaimValue); |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
807 } |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
808 }; |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
809 |
342 | 810 void G1CollectedHeap::do_collection(bool full, bool clear_all_soft_refs, |
811 size_t word_size) { | |
1359
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1313
diff
changeset
|
812 if (GC_locker::check_active_before_gc()) { |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1313
diff
changeset
|
813 return; // GC is disabled (e.g. JNI GetXXXCritical operation) |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1313
diff
changeset
|
814 } |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1313
diff
changeset
|
815 |
342 | 816 ResourceMark rm; |
817 | |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
818 if (PrintHeapAtGC) { |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
819 Universe::print_heap_before_gc(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
820 } |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
821 |
342 | 822 if (full && DisableExplicitGC) { |
823 return; | |
824 } | |
825 | |
826 assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint"); | |
827 assert(Thread::current() == VMThread::vm_thread(), "should be in vm thread"); | |
828 | |
1387
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1360
diff
changeset
|
829 const bool do_clear_all_soft_refs = clear_all_soft_refs || |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1360
diff
changeset
|
830 collector_policy()->should_clear_all_soft_refs(); |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1360
diff
changeset
|
831 |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1360
diff
changeset
|
832 ClearedAllSoftRefs casr(do_clear_all_soft_refs, collector_policy()); |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1360
diff
changeset
|
833 |
342 | 834 { |
835 IsGCActiveMark x; | |
836 | |
837 // Timing | |
838 gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps); | |
839 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); | |
1387
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1360
diff
changeset
|
840 TraceTime t(full ? "Full GC (System.gc())" : "Full GC", |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1360
diff
changeset
|
841 PrintGC, true, gclog_or_tty); |
342 | 842 |
1089
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1088
diff
changeset
|
843 TraceMemoryManagerStats tms(true /* fullGC */); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1088
diff
changeset
|
844 |
342 | 845 double start = os::elapsedTime(); |
846 g1_policy()->record_full_collection_start(); | |
847 | |
848 gc_prologue(true); | |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
849 increment_total_collections(true /* full gc */); |
342 | 850 |
851 size_t g1h_prev_used = used(); | |
852 assert(used() == recalculate_used(), "Should be equal"); | |
853 | |
854 if (VerifyBeforeGC && total_collections() >= VerifyGCStartAt) { | |
855 HandleMark hm; // Discard invalid handles created during verification | |
856 prepare_for_verify(); | |
857 gclog_or_tty->print(" VerifyBeforeGC:"); | |
858 Universe::verify(true); | |
859 } | |
860 assert(regions_accounted_for(), "Region leakage!"); | |
861 | |
862 COMPILER2_PRESENT(DerivedPointerTable::clear()); | |
863 | |
864 // We want to discover references, but not process them yet. | |
865 // This mode is disabled in | |
866 // instanceRefKlass::process_discovered_references if the | |
867 // generation does some collection work, or | |
868 // instanceRefKlass::enqueue_discovered_references if the | |
869 // generation returns without doing any work. | |
870 ref_processor()->disable_discovery(); | |
871 ref_processor()->abandon_partial_discovery(); | |
872 ref_processor()->verify_no_references_recorded(); | |
873 | |
874 // Abandon current iterations of concurrent marking and concurrent | |
875 // refinement, if any are in progress. | |
876 concurrent_mark()->abort(); | |
877 | |
878 // Make sure we'll choose a new allocation region afterwards. | |
879 abandon_cur_alloc_region(); | |
636 | 880 abandon_gc_alloc_regions(); |
342 | 881 assert(_cur_alloc_region == NULL, "Invariant."); |
882 g1_rem_set()->as_HRInto_G1RemSet()->cleanupHRRS(); | |
883 tear_down_region_lists(); | |
884 set_used_regions_to_need_zero_fill(); | |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
885 |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
886 // We may have added regions to the current incremental collection |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
887 // set between the last GC or pause and now. We need to clear the |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
888 // incremental collection set and then start rebuilding it afresh |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
889 // after this full GC. |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
890 abandon_collection_set(g1_policy()->inc_cset_head()); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
891 g1_policy()->clear_incremental_cset(); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
892 g1_policy()->stop_incremental_cset_building(); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
893 |
342 | 894 if (g1_policy()->in_young_gc_mode()) { |
895 empty_young_list(); | |
896 g1_policy()->set_full_young_gcs(true); | |
897 } | |
898 | |
899 // Temporarily make reference _discovery_ single threaded (non-MT). | |
900 ReferenceProcessorMTMutator rp_disc_ser(ref_processor(), false); | |
901 | |
902 // Temporarily make refs discovery atomic | |
903 ReferenceProcessorAtomicMutator rp_disc_atomic(ref_processor(), true); | |
904 | |
905 // Temporarily clear _is_alive_non_header | |
906 ReferenceProcessorIsAliveMutator rp_is_alive_null(ref_processor(), NULL); | |
907 | |
908 ref_processor()->enable_discovery(); | |
1387
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1360
diff
changeset
|
909 ref_processor()->setup_policy(do_clear_all_soft_refs); |
342 | 910 |
911 // Do collection work | |
912 { | |
913 HandleMark hm; // Discard invalid handles created during gc | |
1387
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1360
diff
changeset
|
914 G1MarkSweep::invoke_at_safepoint(ref_processor(), do_clear_all_soft_refs); |
342 | 915 } |
916 // Because freeing humongous regions may have added some unclean | |
917 // regions, it is necessary to tear down again before rebuilding. | |
918 tear_down_region_lists(); | |
919 rebuild_region_lists(); | |
920 | |
921 _summary_bytes_used = recalculate_used(); | |
922 | |
923 ref_processor()->enqueue_discovered_references(); | |
924 | |
925 COMPILER2_PRESENT(DerivedPointerTable::update_pointers()); | |
926 | |
1089
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1088
diff
changeset
|
927 MemoryService::track_memory_usage(); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1088
diff
changeset
|
928 |
342 | 929 if (VerifyAfterGC && total_collections() >= VerifyGCStartAt) { |
930 HandleMark hm; // Discard invalid handles created during verification | |
931 gclog_or_tty->print(" VerifyAfterGC:"); | |
637
25e146966e7c
6817419: G1: Enable extensive verification for humongous regions
iveresov
parents:
636
diff
changeset
|
932 prepare_for_verify(); |
342 | 933 Universe::verify(false); |
934 } | |
935 NOT_PRODUCT(ref_processor()->verify_no_references_recorded()); | |
936 | |
937 reset_gc_time_stamp(); | |
938 // Since everything potentially moved, we will clear all remembered | |
626
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
939 // sets, and clear all cards. Later we will rebuild remebered |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
940 // sets. We will also reset the GC time stamps of the regions. |
342 | 941 PostMCRemSetClearClosure rs_clear(mr_bs()); |
942 heap_region_iterate(&rs_clear); | |
943 | |
944 // Resize the heap if necessary. | |
945 resize_if_necessary_after_full_collection(full ? 0 : word_size); | |
946 | |
947 if (_cg1r->use_cache()) { | |
948 _cg1r->clear_and_record_card_counts(); | |
949 _cg1r->clear_hot_cache(); | |
950 } | |
951 | |
626
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
952 // Rebuild remembered sets of all regions. |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
953 if (ParallelGCThreads > 0) { |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
954 ParRebuildRSTask rebuild_rs_task(this); |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
955 assert(check_heap_region_claim_values( |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
956 HeapRegion::InitialClaimValue), "sanity check"); |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
957 set_par_threads(workers()->total_workers()); |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
958 workers()->run_task(&rebuild_rs_task); |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
959 set_par_threads(0); |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
960 assert(check_heap_region_claim_values( |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
961 HeapRegion::RebuildRSClaimValue), "sanity check"); |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
962 reset_heap_region_claim_values(); |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
963 } else { |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
964 RebuildRSOutOfRegionClosure rebuild_rs(this); |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
965 heap_region_iterate(&rebuild_rs); |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
966 } |
87fa6e083d82
6760309: G1: update remembered sets during Full GCs
apetrusenko
parents:
620
diff
changeset
|
967 |
342 | 968 if (PrintGC) { |
969 print_size_transition(gclog_or_tty, g1h_prev_used, used(), capacity()); | |
970 } | |
971 | |
972 if (true) { // FIXME | |
973 // Ask the permanent generation to adjust size for full collections | |
974 perm()->compute_new_size(); | |
975 } | |
976 | |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
977 // Start a new incremental collection set for the next pause |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
978 assert(g1_policy()->collection_set() == NULL, "must be"); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
979 g1_policy()->start_incremental_cset_building(); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
980 |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
981 // Clear the _cset_fast_test bitmap in anticipation of adding |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
982 // regions to the incremental collection set for the next |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
983 // evacuation pause. |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
984 clear_cset_fast_test(); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
985 |
342 | 986 double end = os::elapsedTime(); |
987 g1_policy()->record_full_collection_end(); | |
988 | |
546
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
545
diff
changeset
|
989 #ifdef TRACESPINNING |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
545
diff
changeset
|
990 ParallelTaskTerminator::print_termination_counts(); |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
545
diff
changeset
|
991 #endif |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
545
diff
changeset
|
992 |
342 | 993 gc_epilogue(true); |
994 | |
794 | 995 // Discard all rset updates |
996 JavaThread::dirty_card_queue_set().abandon_logs(); | |
616
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
997 assert(!G1DeferredRSUpdate |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
998 || (G1DeferredRSUpdate && (dirty_card_queue_set().completed_buffers_num() == 0)), "Should not be any"); |
342 | 999 assert(regions_accounted_for(), "Region leakage!"); |
1000 } | |
1001 | |
1002 if (g1_policy()->in_young_gc_mode()) { | |
1003 _young_list->reset_sampled_info(); | |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
1004 // At this point there should be no regions in the |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
1005 // entire heap tagged as young. |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
1006 assert( check_young_list_empty(true /* check_heap */), |
342 | 1007 "young list should be empty at this point"); |
1008 } | |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
1009 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
1010 if (PrintHeapAtGC) { |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
1011 Universe::print_heap_after_gc(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
1012 } |
342 | 1013 } |
1014 | |
1015 void G1CollectedHeap::do_full_collection(bool clear_all_soft_refs) { | |
1016 do_collection(true, clear_all_soft_refs, 0); | |
1017 } | |
1018 | |
1019 // This code is mostly copied from TenuredGeneration. | |
1020 void | |
1021 G1CollectedHeap:: | |
1022 resize_if_necessary_after_full_collection(size_t word_size) { | |
1023 assert(MinHeapFreeRatio <= MaxHeapFreeRatio, "sanity check"); | |
1024 | |
1025 // Include the current allocation, if any, and bytes that will be | |
1026 // pre-allocated to support collections, as "used". | |
1027 const size_t used_after_gc = used(); | |
1028 const size_t capacity_after_gc = capacity(); | |
1029 const size_t free_after_gc = capacity_after_gc - used_after_gc; | |
1030 | |
1031 // We don't have floating point command-line arguments | |
1032 const double minimum_free_percentage = (double) MinHeapFreeRatio / 100; | |
1033 const double maximum_used_percentage = 1.0 - minimum_free_percentage; | |
1034 const double maximum_free_percentage = (double) MaxHeapFreeRatio / 100; | |
1035 const double minimum_used_percentage = 1.0 - maximum_free_percentage; | |
1036 | |
1037 size_t minimum_desired_capacity = (size_t) (used_after_gc / maximum_used_percentage); | |
1038 size_t maximum_desired_capacity = (size_t) (used_after_gc / minimum_used_percentage); | |
1039 | |
1040 // Don't shrink less than the initial size. | |
1041 minimum_desired_capacity = | |
1042 MAX2(minimum_desired_capacity, | |
1043 collector_policy()->initial_heap_byte_size()); | |
1044 maximum_desired_capacity = | |
1045 MAX2(maximum_desired_capacity, | |
1046 collector_policy()->initial_heap_byte_size()); | |
1047 | |
1048 // We are failing here because minimum_desired_capacity is | |
1049 assert(used_after_gc <= minimum_desired_capacity, "sanity check"); | |
1050 assert(minimum_desired_capacity <= maximum_desired_capacity, "sanity check"); | |
1051 | |
1052 if (PrintGC && Verbose) { | |
1053 const double free_percentage = ((double)free_after_gc) / capacity(); | |
1054 gclog_or_tty->print_cr("Computing new size after full GC "); | |
1055 gclog_or_tty->print_cr(" " | |
1056 " minimum_free_percentage: %6.2f", | |
1057 minimum_free_percentage); | |
1058 gclog_or_tty->print_cr(" " | |
1059 " maximum_free_percentage: %6.2f", | |
1060 maximum_free_percentage); | |
1061 gclog_or_tty->print_cr(" " | |
1062 " capacity: %6.1fK" | |
1063 " minimum_desired_capacity: %6.1fK" | |
1064 " maximum_desired_capacity: %6.1fK", | |
1065 capacity() / (double) K, | |
1066 minimum_desired_capacity / (double) K, | |
1067 maximum_desired_capacity / (double) K); | |
1068 gclog_or_tty->print_cr(" " | |
1069 " free_after_gc : %6.1fK" | |
1070 " used_after_gc : %6.1fK", | |
1071 free_after_gc / (double) K, | |
1072 used_after_gc / (double) K); | |
1073 gclog_or_tty->print_cr(" " | |
1074 " free_percentage: %6.2f", | |
1075 free_percentage); | |
1076 } | |
1077 if (capacity() < minimum_desired_capacity) { | |
1078 // Don't expand unless it's significant | |
1079 size_t expand_bytes = minimum_desired_capacity - capacity_after_gc; | |
1080 expand(expand_bytes); | |
1081 if (PrintGC && Verbose) { | |
1082 gclog_or_tty->print_cr(" expanding:" | |
1083 " minimum_desired_capacity: %6.1fK" | |
1084 " expand_bytes: %6.1fK", | |
1085 minimum_desired_capacity / (double) K, | |
1086 expand_bytes / (double) K); | |
1087 } | |
1088 | |
1089 // No expansion, now see if we want to shrink | |
1090 } else if (capacity() > maximum_desired_capacity) { | |
1091 // Capacity too large, compute shrinking size | |
1092 size_t shrink_bytes = capacity_after_gc - maximum_desired_capacity; | |
1093 shrink(shrink_bytes); | |
1094 if (PrintGC && Verbose) { | |
1095 gclog_or_tty->print_cr(" " | |
1096 " shrinking:" | |
1097 " initSize: %.1fK" | |
1098 " maximum_desired_capacity: %.1fK", | |
1099 collector_policy()->initial_heap_byte_size() / (double) K, | |
1100 maximum_desired_capacity / (double) K); | |
1101 gclog_or_tty->print_cr(" " | |
1102 " shrink_bytes: %.1fK", | |
1103 shrink_bytes / (double) K); | |
1104 } | |
1105 } | |
1106 } | |
1107 | |
1108 | |
1109 HeapWord* | |
1110 G1CollectedHeap::satisfy_failed_allocation(size_t word_size) { | |
1111 HeapWord* result = NULL; | |
1112 | |
1113 // In a G1 heap, we're supposed to keep allocation from failing by | |
1114 // incremental pauses. Therefore, at least for now, we'll favor | |
1115 // expansion over collection. (This might change in the future if we can | |
1116 // do something smarter than full collection to satisfy a failed alloc.) | |
1117 | |
1118 result = expand_and_allocate(word_size); | |
1119 if (result != NULL) { | |
1120 assert(is_in(result), "result not in heap"); | |
1121 return result; | |
1122 } | |
1123 | |
1124 // OK, I guess we have to try collection. | |
1125 | |
1126 do_collection(false, false, word_size); | |
1127 | |
1128 result = attempt_allocation(word_size, /*permit_collection_pause*/false); | |
1129 | |
1130 if (result != NULL) { | |
1131 assert(is_in(result), "result not in heap"); | |
1132 return result; | |
1133 } | |
1134 | |
1135 // Try collecting soft references. | |
1136 do_collection(false, true, word_size); | |
1137 result = attempt_allocation(word_size, /*permit_collection_pause*/false); | |
1138 if (result != NULL) { | |
1139 assert(is_in(result), "result not in heap"); | |
1140 return result; | |
1141 } | |
1142 | |
1387
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1360
diff
changeset
|
1143 assert(!collector_policy()->should_clear_all_soft_refs(), |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1360
diff
changeset
|
1144 "Flag should have been handled and cleared prior to this point"); |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1360
diff
changeset
|
1145 |
342 | 1146 // What else? We might try synchronous finalization later. If the total |
1147 // space available is large enough for the allocation, then a more | |
1148 // complete compaction phase than we've tried so far might be | |
1149 // appropriate. | |
1150 return NULL; | |
1151 } | |
1152 | |
1153 // Attempting to expand the heap sufficiently | |
1154 // to support an allocation of the given "word_size". If | |
1155 // successful, perform the allocation and return the address of the | |
1156 // allocated block, or else "NULL". | |
1157 | |
1158 HeapWord* G1CollectedHeap::expand_and_allocate(size_t word_size) { | |
1159 size_t expand_bytes = word_size * HeapWordSize; | |
1160 if (expand_bytes < MinHeapDeltaBytes) { | |
1161 expand_bytes = MinHeapDeltaBytes; | |
1162 } | |
1163 expand(expand_bytes); | |
1164 assert(regions_accounted_for(), "Region leakage!"); | |
1165 HeapWord* result = attempt_allocation(word_size, false /* permit_collection_pause */); | |
1166 return result; | |
1167 } | |
1168 | |
1169 size_t G1CollectedHeap::free_region_if_totally_empty(HeapRegion* hr) { | |
1170 size_t pre_used = 0; | |
1171 size_t cleared_h_regions = 0; | |
1172 size_t freed_regions = 0; | |
1173 UncleanRegionList local_list; | |
1174 free_region_if_totally_empty_work(hr, pre_used, cleared_h_regions, | |
1175 freed_regions, &local_list); | |
1176 | |
1177 finish_free_region_work(pre_used, cleared_h_regions, freed_regions, | |
1178 &local_list); | |
1179 return pre_used; | |
1180 } | |
1181 | |
1182 void | |
1183 G1CollectedHeap::free_region_if_totally_empty_work(HeapRegion* hr, | |
1184 size_t& pre_used, | |
1185 size_t& cleared_h, | |
1186 size_t& freed_regions, | |
1187 UncleanRegionList* list, | |
1188 bool par) { | |
1189 assert(!hr->continuesHumongous(), "should have filtered these out"); | |
1190 size_t res = 0; | |
677 | 1191 if (hr->used() > 0 && hr->garbage_bytes() == hr->used() && |
1192 !hr->is_young()) { | |
1193 if (G1PolicyVerbose > 0) | |
1194 gclog_or_tty->print_cr("Freeing empty region "PTR_FORMAT "(" SIZE_FORMAT " bytes)" | |
1195 " during cleanup", hr, hr->used()); | |
1196 free_region_work(hr, pre_used, cleared_h, freed_regions, list, par); | |
342 | 1197 } |
1198 } | |
1199 | |
1200 // FIXME: both this and shrink could probably be more efficient by | |
1201 // doing one "VirtualSpace::expand_by" call rather than several. | |
1202 void G1CollectedHeap::expand(size_t expand_bytes) { | |
1203 size_t old_mem_size = _g1_storage.committed_size(); | |
1204 // We expand by a minimum of 1K. | |
1205 expand_bytes = MAX2(expand_bytes, (size_t)K); | |
1206 size_t aligned_expand_bytes = | |
1207 ReservedSpace::page_align_size_up(expand_bytes); | |
1208 aligned_expand_bytes = align_size_up(aligned_expand_bytes, | |
1209 HeapRegion::GrainBytes); | |
1210 expand_bytes = aligned_expand_bytes; | |
1211 while (expand_bytes > 0) { | |
1212 HeapWord* base = (HeapWord*)_g1_storage.high(); | |
1213 // Commit more storage. | |
1214 bool successful = _g1_storage.expand_by(HeapRegion::GrainBytes); | |
1215 if (!successful) { | |
1216 expand_bytes = 0; | |
1217 } else { | |
1218 expand_bytes -= HeapRegion::GrainBytes; | |
1219 // Expand the committed region. | |
1220 HeapWord* high = (HeapWord*) _g1_storage.high(); | |
1221 _g1_committed.set_end(high); | |
1222 // Create a new HeapRegion. | |
1223 MemRegion mr(base, high); | |
1224 bool is_zeroed = !_g1_max_committed.contains(base); | |
1225 HeapRegion* hr = new HeapRegion(_bot_shared, mr, is_zeroed); | |
1226 | |
1227 // Now update max_committed if necessary. | |
1228 _g1_max_committed.set_end(MAX2(_g1_max_committed.end(), high)); | |
1229 | |
1230 // Add it to the HeapRegionSeq. | |
1231 _hrs->insert(hr); | |
1232 // Set the zero-fill state, according to whether it's already | |
1233 // zeroed. | |
1234 { | |
1235 MutexLockerEx x(ZF_mon, Mutex::_no_safepoint_check_flag); | |
1236 if (is_zeroed) { | |
1237 hr->set_zero_fill_complete(); | |
1238 put_free_region_on_list_locked(hr); | |
1239 } else { | |
1240 hr->set_zero_fill_needed(); | |
1241 put_region_on_unclean_list_locked(hr); | |
1242 } | |
1243 } | |
1244 _free_regions++; | |
1245 // And we used up an expansion region to create it. | |
1246 _expansion_regions--; | |
1247 // Tell the cardtable about it. | |
1248 Universe::heap()->barrier_set()->resize_covered_region(_g1_committed); | |
1249 // And the offset table as well. | |
1250 _bot_shared->resize(_g1_committed.word_size()); | |
1251 } | |
1252 } | |
1253 if (Verbose && PrintGC) { | |
1254 size_t new_mem_size = _g1_storage.committed_size(); | |
1255 gclog_or_tty->print_cr("Expanding garbage-first heap from %ldK by %ldK to %ldK", | |
1256 old_mem_size/K, aligned_expand_bytes/K, | |
1257 new_mem_size/K); | |
1258 } | |
1259 } | |
1260 | |
1261 void G1CollectedHeap::shrink_helper(size_t shrink_bytes) | |
1262 { | |
1263 size_t old_mem_size = _g1_storage.committed_size(); | |
1264 size_t aligned_shrink_bytes = | |
1265 ReservedSpace::page_align_size_down(shrink_bytes); | |
1266 aligned_shrink_bytes = align_size_down(aligned_shrink_bytes, | |
1267 HeapRegion::GrainBytes); | |
1268 size_t num_regions_deleted = 0; | |
1269 MemRegion mr = _hrs->shrink_by(aligned_shrink_bytes, num_regions_deleted); | |
1270 | |
1271 assert(mr.end() == (HeapWord*)_g1_storage.high(), "Bad shrink!"); | |
1272 if (mr.byte_size() > 0) | |
1273 _g1_storage.shrink_by(mr.byte_size()); | |
1274 assert(mr.start() == (HeapWord*)_g1_storage.high(), "Bad shrink!"); | |
1275 | |
1276 _g1_committed.set_end(mr.start()); | |
1277 _free_regions -= num_regions_deleted; | |
1278 _expansion_regions += num_regions_deleted; | |
1279 | |
1280 // Tell the cardtable about it. | |
1281 Universe::heap()->barrier_set()->resize_covered_region(_g1_committed); | |
1282 | |
1283 // And the offset table as well. | |
1284 _bot_shared->resize(_g1_committed.word_size()); | |
1285 | |
1286 HeapRegionRemSet::shrink_heap(n_regions()); | |
1287 | |
1288 if (Verbose && PrintGC) { | |
1289 size_t new_mem_size = _g1_storage.committed_size(); | |
1290 gclog_or_tty->print_cr("Shrinking garbage-first heap from %ldK by %ldK to %ldK", | |
1291 old_mem_size/K, aligned_shrink_bytes/K, | |
1292 new_mem_size/K); | |
1293 } | |
1294 } | |
1295 | |
1296 void G1CollectedHeap::shrink(size_t shrink_bytes) { | |
636 | 1297 release_gc_alloc_regions(true /* totally */); |
342 | 1298 tear_down_region_lists(); // We will rebuild them in a moment. |
1299 shrink_helper(shrink_bytes); | |
1300 rebuild_region_lists(); | |
1301 } | |
1302 | |
1303 // Public methods. | |
1304 | |
1305 #ifdef _MSC_VER // the use of 'this' below gets a warning, make it go away | |
1306 #pragma warning( disable:4355 ) // 'this' : used in base member initializer list | |
1307 #endif // _MSC_VER | |
1308 | |
1309 | |
1310 G1CollectedHeap::G1CollectedHeap(G1CollectorPolicy* policy_) : | |
1311 SharedHeap(policy_), | |
1312 _g1_policy(policy_), | |
1111 | 1313 _dirty_card_queue_set(false), |
342 | 1314 _ref_processor(NULL), |
1315 _process_strong_tasks(new SubTasksDone(G1H_PS_NumElements)), | |
1316 _bot_shared(NULL), | |
1317 _par_alloc_during_gc_lock(Mutex::leaf, "par alloc during GC lock"), | |
1318 _objs_with_preserved_marks(NULL), _preserved_marks_of_objs(NULL), | |
1319 _evac_failure_scan_stack(NULL) , | |
1320 _mark_in_progress(false), | |
1321 _cg1r(NULL), _czft(NULL), _summary_bytes_used(0), | |
1322 _cur_alloc_region(NULL), | |
1323 _refine_cte_cl(NULL), | |
1324 _free_region_list(NULL), _free_region_list_size(0), | |
1325 _free_regions(0), | |
1326 _full_collection(false), | |
1327 _unclean_region_list(), | |
1328 _unclean_regions_coming(false), | |
1329 _young_list(new YoungList(this)), | |
1330 _gc_time_stamp(0), | |
526 | 1331 _surviving_young_words(NULL), |
1332 _in_cset_fast_test(NULL), | |
796
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
1333 _in_cset_fast_test_base(NULL), |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
1334 _dirty_cards_region_list(NULL) { |
342 | 1335 _g1h = this; // To catch bugs. |
1336 if (_process_strong_tasks == NULL || !_process_strong_tasks->valid()) { | |
1337 vm_exit_during_initialization("Failed necessary allocation."); | |
1338 } | |
942
2c79770d1f6e
6819085: G1: use larger and/or user settable region size
tonyp
parents:
941
diff
changeset
|
1339 |
2c79770d1f6e
6819085: G1: use larger and/or user settable region size
tonyp
parents:
941
diff
changeset
|
1340 _humongous_object_threshold_in_words = HeapRegion::GrainWords / 2; |
2c79770d1f6e
6819085: G1: use larger and/or user settable region size
tonyp
parents:
941
diff
changeset
|
1341 |
342 | 1342 int n_queues = MAX2((int)ParallelGCThreads, 1); |
1343 _task_queues = new RefToScanQueueSet(n_queues); | |
1344 | |
1345 int n_rem_sets = HeapRegionRemSet::num_par_rem_sets(); | |
1346 assert(n_rem_sets > 0, "Invariant."); | |
1347 | |
1348 HeapRegionRemSetIterator** iter_arr = | |
1349 NEW_C_HEAP_ARRAY(HeapRegionRemSetIterator*, n_queues); | |
1350 for (int i = 0; i < n_queues; i++) { | |
1351 iter_arr[i] = new HeapRegionRemSetIterator(); | |
1352 } | |
1353 _rem_set_iterator = iter_arr; | |
1354 | |
1355 for (int i = 0; i < n_queues; i++) { | |
1356 RefToScanQueue* q = new RefToScanQueue(); | |
1357 q->initialize(); | |
1358 _task_queues->register_queue(i, q); | |
1359 } | |
1360 | |
1361 for (int ap = 0; ap < GCAllocPurposeCount; ++ap) { | |
636 | 1362 _gc_alloc_regions[ap] = NULL; |
1363 _gc_alloc_region_counts[ap] = 0; | |
1364 _retained_gc_alloc_regions[ap] = NULL; | |
1365 // by default, we do not retain a GC alloc region for each ap; | |
1366 // we'll override this, when appropriate, below | |
1367 _retain_gc_alloc_region[ap] = false; | |
1368 } | |
1369 | |
1370 // We will try to remember the last half-full tenured region we | |
1371 // allocated to at the end of a collection so that we can re-use it | |
1372 // during the next collection. | |
1373 _retain_gc_alloc_region[GCAllocForTenured] = true; | |
1374 | |
342 | 1375 guarantee(_task_queues != NULL, "task_queues allocation failure."); |
1376 } | |
1377 | |
1378 jint G1CollectedHeap::initialize() { | |
1166 | 1379 CollectedHeap::pre_initialize(); |
342 | 1380 os::enable_vtime(); |
1381 | |
1382 // Necessary to satisfy locking discipline assertions. | |
1383 | |
1384 MutexLocker x(Heap_lock); | |
1385 | |
1386 // While there are no constraints in the GC code that HeapWordSize | |
1387 // be any particular value, there are multiple other areas in the | |
1388 // system which believe this to be true (e.g. oop->object_size in some | |
1389 // cases incorrectly returns the size in wordSize units rather than | |
1390 // HeapWordSize). | |
1391 guarantee(HeapWordSize == wordSize, "HeapWordSize must equal wordSize"); | |
1392 | |
1393 size_t init_byte_size = collector_policy()->initial_heap_byte_size(); | |
1394 size_t max_byte_size = collector_policy()->max_heap_byte_size(); | |
1395 | |
1396 // Ensure that the sizes are properly aligned. | |
1397 Universe::check_alignment(init_byte_size, HeapRegion::GrainBytes, "g1 heap"); | |
1398 Universe::check_alignment(max_byte_size, HeapRegion::GrainBytes, "g1 heap"); | |
1399 | |
1400 _cg1r = new ConcurrentG1Refine(); | |
1401 | |
1402 // Reserve the maximum. | |
1403 PermanentGenerationSpec* pgs = collector_policy()->permanent_generation(); | |
1404 // Includes the perm-gen. | |
642
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1405 |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1406 const size_t total_reserved = max_byte_size + pgs->max_size(); |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1407 char* addr = Universe::preferred_heap_base(total_reserved, Universe::UnscaledNarrowOop); |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1408 |
342 | 1409 ReservedSpace heap_rs(max_byte_size + pgs->max_size(), |
1410 HeapRegion::GrainBytes, | |
642
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1411 false /*ism*/, addr); |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1412 |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1413 if (UseCompressedOops) { |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1414 if (addr != NULL && !heap_rs.is_reserved()) { |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1415 // Failed to reserve at specified address - the requested memory |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1416 // region is taken already, for example, by 'java' launcher. |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1417 // Try again to reserver heap higher. |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1418 addr = Universe::preferred_heap_base(total_reserved, Universe::ZeroBasedNarrowOop); |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1419 ReservedSpace heap_rs0(total_reserved, HeapRegion::GrainBytes, |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1420 false /*ism*/, addr); |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1421 if (addr != NULL && !heap_rs0.is_reserved()) { |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1422 // Failed to reserve at specified address again - give up. |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1423 addr = Universe::preferred_heap_base(total_reserved, Universe::HeapBasedNarrowOop); |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1424 assert(addr == NULL, ""); |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1425 ReservedSpace heap_rs1(total_reserved, HeapRegion::GrainBytes, |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1426 false /*ism*/, addr); |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1427 heap_rs = heap_rs1; |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1428 } else { |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1429 heap_rs = heap_rs0; |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1430 } |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1431 } |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
620
diff
changeset
|
1432 } |
342 | 1433 |
1434 if (!heap_rs.is_reserved()) { | |
1435 vm_exit_during_initialization("Could not reserve enough space for object heap"); | |
1436 return JNI_ENOMEM; | |
1437 } | |
1438 | |
1439 // It is important to do this in a way such that concurrent readers can't | |
1440 // temporarily think somethings in the heap. (I've actually seen this | |
1441 // happen in asserts: DLD.) | |
1442 _reserved.set_word_size(0); | |
1443 _reserved.set_start((HeapWord*)heap_rs.base()); | |
1444 _reserved.set_end((HeapWord*)(heap_rs.base() + heap_rs.size())); | |
1445 | |
1446 _expansion_regions = max_byte_size/HeapRegion::GrainBytes; | |
1447 | |
1448 _num_humongous_regions = 0; | |
1449 | |
1450 // Create the gen rem set (and barrier set) for the entire reserved region. | |
1451 _rem_set = collector_policy()->create_rem_set(_reserved, 2); | |
1452 set_barrier_set(rem_set()->bs()); | |
1453 if (barrier_set()->is_a(BarrierSet::ModRef)) { | |
1454 _mr_bs = (ModRefBarrierSet*)_barrier_set; | |
1455 } else { | |
1456 vm_exit_during_initialization("G1 requires a mod ref bs."); | |
1457 return JNI_ENOMEM; | |
1458 } | |
1459 | |
1460 // Also create a G1 rem set. | |
1461 if (G1UseHRIntoRS) { | |
1462 if (mr_bs()->is_a(BarrierSet::CardTableModRef)) { | |
1463 _g1_rem_set = new HRInto_G1RemSet(this, (CardTableModRefBS*)mr_bs()); | |
1464 } else { | |
1465 vm_exit_during_initialization("G1 requires a cardtable mod ref bs."); | |
1466 return JNI_ENOMEM; | |
1467 } | |
1468 } else { | |
1469 _g1_rem_set = new StupidG1RemSet(this); | |
1470 } | |
1471 | |
1472 // Carve out the G1 part of the heap. | |
1473 | |
1474 ReservedSpace g1_rs = heap_rs.first_part(max_byte_size); | |
1475 _g1_reserved = MemRegion((HeapWord*)g1_rs.base(), | |
1476 g1_rs.size()/HeapWordSize); | |
1477 ReservedSpace perm_gen_rs = heap_rs.last_part(max_byte_size); | |
1478 | |
1479 _perm_gen = pgs->init(perm_gen_rs, pgs->init_size(), rem_set()); | |
1480 | |
1481 _g1_storage.initialize(g1_rs, 0); | |
1482 _g1_committed = MemRegion((HeapWord*)_g1_storage.low(), (size_t) 0); | |
1483 _g1_max_committed = _g1_committed; | |
393 | 1484 _hrs = new HeapRegionSeq(_expansion_regions); |
342 | 1485 guarantee(_hrs != NULL, "Couldn't allocate HeapRegionSeq"); |
1486 guarantee(_cur_alloc_region == NULL, "from constructor"); | |
1487 | |
807
d44bdab1c03d
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
796
diff
changeset
|
1488 // 6843694 - ensure that the maximum region index can fit |
d44bdab1c03d
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
796
diff
changeset
|
1489 // in the remembered set structures. |
d44bdab1c03d
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
796
diff
changeset
|
1490 const size_t max_region_idx = ((size_t)1 << (sizeof(RegionIdx_t)*BitsPerByte-1)) - 1; |
d44bdab1c03d
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
796
diff
changeset
|
1491 guarantee((max_regions() - 1) <= max_region_idx, "too many regions"); |
d44bdab1c03d
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
796
diff
changeset
|
1492 |
d44bdab1c03d
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
796
diff
changeset
|
1493 size_t max_cards_per_region = ((size_t)1 << (sizeof(CardIdx_t)*BitsPerByte-1)) - 1; |
942
2c79770d1f6e
6819085: G1: use larger and/or user settable region size
tonyp
parents:
941
diff
changeset
|
1494 guarantee(HeapRegion::CardsPerRegion > 0, "make sure it's initialized"); |
2c79770d1f6e
6819085: G1: use larger and/or user settable region size
tonyp
parents:
941
diff
changeset
|
1495 guarantee((size_t) HeapRegion::CardsPerRegion < max_cards_per_region, |
2c79770d1f6e
6819085: G1: use larger and/or user settable region size
tonyp
parents:
941
diff
changeset
|
1496 "too many cards per region"); |
807
d44bdab1c03d
6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents:
796
diff
changeset
|
1497 |
342 | 1498 _bot_shared = new G1BlockOffsetSharedArray(_reserved, |
1499 heap_word_size(init_byte_size)); | |
1500 | |
1501 _g1h = this; | |
1502 | |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
1503 _in_cset_fast_test_length = max_regions(); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
1504 _in_cset_fast_test_base = NEW_C_HEAP_ARRAY(bool, _in_cset_fast_test_length); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
1505 |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
1506 // We're biasing _in_cset_fast_test to avoid subtracting the |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
1507 // beginning of the heap every time we want to index; basically |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
1508 // it's the same with what we do with the card table. |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
1509 _in_cset_fast_test = _in_cset_fast_test_base - |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
1510 ((size_t) _g1_reserved.start() >> HeapRegion::LogOfHRGrainBytes); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
1511 |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
1512 // Clear the _cset_fast_test bitmap in anticipation of adding |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
1513 // regions to the incremental collection set for the first |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
1514 // evacuation pause. |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
1515 clear_cset_fast_test(); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
1516 |
342 | 1517 // Create the ConcurrentMark data structure and thread. |
1518 // (Must do this late, so that "max_regions" is defined.) | |
1519 _cm = new ConcurrentMark(heap_rs, (int) max_regions()); | |
1520 _cmThread = _cm->cmThread(); | |
1521 | |
1522 // ...and the concurrent zero-fill thread, if necessary. | |
1523 if (G1ConcZeroFill) { | |
1524 _czft = new ConcurrentZFThread(); | |
1525 } | |
1526 | |
1527 // Initialize the from_card cache structure of HeapRegionRemSet. | |
1528 HeapRegionRemSet::init_heap(max_regions()); | |
1529 | |
677 | 1530 // Now expand into the initial heap size. |
1531 expand(init_byte_size); | |
342 | 1532 |
1533 // Perform any initialization actions delegated to the policy. | |
1534 g1_policy()->init(); | |
1535 | |
1536 g1_policy()->note_start_of_mark_thread(); | |
1537 | |
1538 _refine_cte_cl = | |
1539 new RefineCardTableEntryClosure(ConcurrentG1RefineThread::sts(), | |
1540 g1_rem_set(), | |
1541 concurrent_g1_refine()); | |
1542 JavaThread::dirty_card_queue_set().set_closure(_refine_cte_cl); | |
1543 | |
1544 JavaThread::satb_mark_queue_set().initialize(SATB_Q_CBL_mon, | |
1545 SATB_Q_FL_lock, | |
1111 | 1546 G1SATBProcessCompletedThreshold, |
342 | 1547 Shared_SATB_Q_lock); |
794 | 1548 |
1549 JavaThread::dirty_card_queue_set().initialize(DirtyCardQ_CBL_mon, | |
1550 DirtyCardQ_FL_lock, | |
1111 | 1551 concurrent_g1_refine()->yellow_zone(), |
1552 concurrent_g1_refine()->red_zone(), | |
794 | 1553 Shared_DirtyCardQ_lock); |
1554 | |
616
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
1555 if (G1DeferredRSUpdate) { |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
1556 dirty_card_queue_set().initialize(DirtyCardQ_CBL_mon, |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
1557 DirtyCardQ_FL_lock, |
1111 | 1558 -1, // never trigger processing |
1559 -1, // no limit on length | |
616
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
1560 Shared_DirtyCardQ_lock, |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
1561 &JavaThread::dirty_card_queue_set()); |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
1562 } |
342 | 1563 // In case we're keeping closure specialization stats, initialize those |
1564 // counts and that mechanism. | |
1565 SpecializationStats::clear(); | |
1566 | |
1567 _gc_alloc_region_list = NULL; | |
1568 | |
1569 // Do later initialization work for concurrent refinement. | |
1570 _cg1r->init(); | |
1571 | |
1572 return JNI_OK; | |
1573 } | |
1574 | |
1575 void G1CollectedHeap::ref_processing_init() { | |
1576 SharedHeap::ref_processing_init(); | |
1577 MemRegion mr = reserved_region(); | |
1578 _ref_processor = ReferenceProcessor::create_ref_processor( | |
1579 mr, // span | |
1580 false, // Reference discovery is not atomic | |
1581 // (though it shouldn't matter here.) | |
1582 true, // mt_discovery | |
1583 NULL, // is alive closure: need to fill this in for efficiency | |
1584 ParallelGCThreads, | |
1585 ParallelRefProcEnabled, | |
1586 true); // Setting next fields of discovered | |
1587 // lists requires a barrier. | |
1588 } | |
1589 | |
1590 size_t G1CollectedHeap::capacity() const { | |
1591 return _g1_committed.byte_size(); | |
1592 } | |
1593 | |
1594 void G1CollectedHeap::iterate_dirty_card_closure(bool concurrent, | |
1595 int worker_i) { | |
889 | 1596 // Clean cards in the hot card cache |
1597 concurrent_g1_refine()->clean_up_cache(worker_i, g1_rem_set()); | |
1598 | |
342 | 1599 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
1600 int n_completed_buffers = 0; | |
1601 while (dcqs.apply_closure_to_completed_buffer(worker_i, 0, true)) { | |
1602 n_completed_buffers++; | |
1603 } | |
1604 g1_policy()->record_update_rs_processed_buffers(worker_i, | |
1605 (double) n_completed_buffers); | |
1606 dcqs.clear_n_completed_buffers(); | |
1607 assert(!dcqs.completed_buffers_exist_dirty(), "Completed buffers exist!"); | |
1608 } | |
1609 | |
1610 | |
1611 // Computes the sum of the storage used by the various regions. | |
1612 | |
1613 size_t G1CollectedHeap::used() const { | |
862
36b5611220a7
6863216: Clean up debugging debris inadvertently pushed with 6700789
ysr
parents:
861
diff
changeset
|
1614 assert(Heap_lock->owner() != NULL, |
36b5611220a7
6863216: Clean up debugging debris inadvertently pushed with 6700789
ysr
parents:
861
diff
changeset
|
1615 "Should be owned on this thread's behalf."); |
342 | 1616 size_t result = _summary_bytes_used; |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
1617 // Read only once in case it is set to NULL concurrently |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
1618 HeapRegion* hr = _cur_alloc_region; |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
1619 if (hr != NULL) |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
1620 result += hr->used(); |
342 | 1621 return result; |
1622 } | |
1623 | |
846
42d84bbbecf4
6859911: G1: assert(Heap_lock->owner() = NULL, "Should be owned on this thread's behalf")
tonyp
parents:
845
diff
changeset
|
1624 size_t G1CollectedHeap::used_unlocked() const { |
42d84bbbecf4
6859911: G1: assert(Heap_lock->owner() = NULL, "Should be owned on this thread's behalf")
tonyp
parents:
845
diff
changeset
|
1625 size_t result = _summary_bytes_used; |
42d84bbbecf4
6859911: G1: assert(Heap_lock->owner() = NULL, "Should be owned on this thread's behalf")
tonyp
parents:
845
diff
changeset
|
1626 return result; |
42d84bbbecf4
6859911: G1: assert(Heap_lock->owner() = NULL, "Should be owned on this thread's behalf")
tonyp
parents:
845
diff
changeset
|
1627 } |
42d84bbbecf4
6859911: G1: assert(Heap_lock->owner() = NULL, "Should be owned on this thread's behalf")
tonyp
parents:
845
diff
changeset
|
1628 |
342 | 1629 class SumUsedClosure: public HeapRegionClosure { |
1630 size_t _used; | |
1631 public: | |
1632 SumUsedClosure() : _used(0) {} | |
1633 bool doHeapRegion(HeapRegion* r) { | |
1634 if (!r->continuesHumongous()) { | |
1635 _used += r->used(); | |
1636 } | |
1637 return false; | |
1638 } | |
1639 size_t result() { return _used; } | |
1640 }; | |
1641 | |
1642 size_t G1CollectedHeap::recalculate_used() const { | |
1643 SumUsedClosure blk; | |
1644 _hrs->iterate(&blk); | |
1645 return blk.result(); | |
1646 } | |
1647 | |
1648 #ifndef PRODUCT | |
1649 class SumUsedRegionsClosure: public HeapRegionClosure { | |
1650 size_t _num; | |
1651 public: | |
677 | 1652 SumUsedRegionsClosure() : _num(0) {} |
342 | 1653 bool doHeapRegion(HeapRegion* r) { |
1654 if (r->continuesHumongous() || r->used() > 0 || r->is_gc_alloc_region()) { | |
1655 _num += 1; | |
1656 } | |
1657 return false; | |
1658 } | |
1659 size_t result() { return _num; } | |
1660 }; | |
1661 | |
1662 size_t G1CollectedHeap::recalculate_used_regions() const { | |
1663 SumUsedRegionsClosure blk; | |
1664 _hrs->iterate(&blk); | |
1665 return blk.result(); | |
1666 } | |
1667 #endif // PRODUCT | |
1668 | |
1669 size_t G1CollectedHeap::unsafe_max_alloc() { | |
1670 if (_free_regions > 0) return HeapRegion::GrainBytes; | |
1671 // otherwise, is there space in the current allocation region? | |
1672 | |
1673 // We need to store the current allocation region in a local variable | |
1674 // here. The problem is that this method doesn't take any locks and | |
1675 // there may be other threads which overwrite the current allocation | |
1676 // region field. attempt_allocation(), for example, sets it to NULL | |
1677 // and this can happen *after* the NULL check here but before the call | |
1678 // to free(), resulting in a SIGSEGV. Note that this doesn't appear | |
1679 // to be a problem in the optimized build, since the two loads of the | |
1680 // current allocation region field are optimized away. | |
1681 HeapRegion* car = _cur_alloc_region; | |
1682 | |
1683 // FIXME: should iterate over all regions? | |
1684 if (car == NULL) { | |
1685 return 0; | |
1686 } | |
1687 return car->free(); | |
1688 } | |
1689 | |
1690 void G1CollectedHeap::collect_as_vm_thread(GCCause::Cause cause) { | |
1691 assert(Thread::current()->is_VM_thread(), "Precondition#1"); | |
1692 assert(Heap_lock->is_locked(), "Precondition#2"); | |
1693 GCCauseSetter gcs(this, cause); | |
1694 switch (cause) { | |
1695 case GCCause::_heap_inspection: | |
1696 case GCCause::_heap_dump: { | |
1697 HandleMark hm; | |
1698 do_full_collection(false); // don't clear all soft refs | |
1699 break; | |
1700 } | |
1701 default: // XXX FIX ME | |
1702 ShouldNotReachHere(); // Unexpected use of this function | |
1703 } | |
1704 } | |
1705 | |
1088
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
1706 void G1CollectedHeap::collect(GCCause::Cause cause) { |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
1707 // The caller doesn't have the Heap_lock |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
1708 assert(!Heap_lock->owned_by_self(), "this thread should not own the Heap_lock"); |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
1709 |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
1710 int gc_count_before; |
342 | 1711 { |
1088
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
1712 MutexLocker ml(Heap_lock); |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
1713 // Read the GC count while holding the Heap_lock |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
1714 gc_count_before = SharedHeap::heap()->total_collections(); |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
1715 |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
1716 // Don't want to do a GC until cleanup is completed. |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
1717 wait_for_cleanup_complete(); |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
1718 } // We give up heap lock; VMThread::execute gets it back below |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
1719 switch (cause) { |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
1720 case GCCause::_scavenge_alot: { |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
1721 // Do an incremental pause, which might sometimes be abandoned. |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
1722 VM_G1IncCollectionPause op(gc_count_before, cause); |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
1723 VMThread::execute(&op); |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
1724 break; |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
1725 } |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
1726 default: { |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
1727 // In all other cases, we currently do a full gc. |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
1728 VM_G1CollectFull op(gc_count_before, cause); |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
1729 VMThread::execute(&op); |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
1730 } |
342 | 1731 } |
1732 } | |
1733 | |
1734 bool G1CollectedHeap::is_in(const void* p) const { | |
1735 if (_g1_committed.contains(p)) { | |
1736 HeapRegion* hr = _hrs->addr_to_region(p); | |
1737 return hr->is_in(p); | |
1738 } else { | |
1739 return _perm_gen->as_gen()->is_in(p); | |
1740 } | |
1741 } | |
1742 | |
1743 // Iteration functions. | |
1744 | |
1745 // Iterates an OopClosure over all ref-containing fields of objects | |
1746 // within a HeapRegion. | |
1747 | |
1748 class IterateOopClosureRegionClosure: public HeapRegionClosure { | |
1749 MemRegion _mr; | |
1750 OopClosure* _cl; | |
1751 public: | |
1752 IterateOopClosureRegionClosure(MemRegion mr, OopClosure* cl) | |
1753 : _mr(mr), _cl(cl) {} | |
1754 bool doHeapRegion(HeapRegion* r) { | |
1755 if (! r->continuesHumongous()) { | |
1756 r->oop_iterate(_cl); | |
1757 } | |
1758 return false; | |
1759 } | |
1760 }; | |
1761 | |
678 | 1762 void G1CollectedHeap::oop_iterate(OopClosure* cl, bool do_perm) { |
342 | 1763 IterateOopClosureRegionClosure blk(_g1_committed, cl); |
1764 _hrs->iterate(&blk); | |
678 | 1765 if (do_perm) { |
1766 perm_gen()->oop_iterate(cl); | |
1767 } | |
342 | 1768 } |
1769 | |
678 | 1770 void G1CollectedHeap::oop_iterate(MemRegion mr, OopClosure* cl, bool do_perm) { |
342 | 1771 IterateOopClosureRegionClosure blk(mr, cl); |
1772 _hrs->iterate(&blk); | |
678 | 1773 if (do_perm) { |
1774 perm_gen()->oop_iterate(cl); | |
1775 } | |
342 | 1776 } |
1777 | |
1778 // Iterates an ObjectClosure over all objects within a HeapRegion. | |
1779 | |
1780 class IterateObjectClosureRegionClosure: public HeapRegionClosure { | |
1781 ObjectClosure* _cl; | |
1782 public: | |
1783 IterateObjectClosureRegionClosure(ObjectClosure* cl) : _cl(cl) {} | |
1784 bool doHeapRegion(HeapRegion* r) { | |
1785 if (! r->continuesHumongous()) { | |
1786 r->object_iterate(_cl); | |
1787 } | |
1788 return false; | |
1789 } | |
1790 }; | |
1791 | |
678 | 1792 void G1CollectedHeap::object_iterate(ObjectClosure* cl, bool do_perm) { |
342 | 1793 IterateObjectClosureRegionClosure blk(cl); |
1794 _hrs->iterate(&blk); | |
678 | 1795 if (do_perm) { |
1796 perm_gen()->object_iterate(cl); | |
1797 } | |
342 | 1798 } |
1799 | |
1800 void G1CollectedHeap::object_iterate_since_last_GC(ObjectClosure* cl) { | |
1801 // FIXME: is this right? | |
1802 guarantee(false, "object_iterate_since_last_GC not supported by G1 heap"); | |
1803 } | |
1804 | |
1805 // Calls a SpaceClosure on a HeapRegion. | |
1806 | |
1807 class SpaceClosureRegionClosure: public HeapRegionClosure { | |
1808 SpaceClosure* _cl; | |
1809 public: | |
1810 SpaceClosureRegionClosure(SpaceClosure* cl) : _cl(cl) {} | |
1811 bool doHeapRegion(HeapRegion* r) { | |
1812 _cl->do_space(r); | |
1813 return false; | |
1814 } | |
1815 }; | |
1816 | |
1817 void G1CollectedHeap::space_iterate(SpaceClosure* cl) { | |
1818 SpaceClosureRegionClosure blk(cl); | |
1819 _hrs->iterate(&blk); | |
1820 } | |
1821 | |
1822 void G1CollectedHeap::heap_region_iterate(HeapRegionClosure* cl) { | |
1823 _hrs->iterate(cl); | |
1824 } | |
1825 | |
1826 void G1CollectedHeap::heap_region_iterate_from(HeapRegion* r, | |
1827 HeapRegionClosure* cl) { | |
1828 _hrs->iterate_from(r, cl); | |
1829 } | |
1830 | |
1831 void | |
1832 G1CollectedHeap::heap_region_iterate_from(int idx, HeapRegionClosure* cl) { | |
1833 _hrs->iterate_from(idx, cl); | |
1834 } | |
1835 | |
1836 HeapRegion* G1CollectedHeap::region_at(size_t idx) { return _hrs->at(idx); } | |
1837 | |
1838 void | |
1839 G1CollectedHeap::heap_region_par_iterate_chunked(HeapRegionClosure* cl, | |
1840 int worker, | |
1841 jint claim_value) { | |
355 | 1842 const size_t regions = n_regions(); |
1843 const size_t worker_num = (ParallelGCThreads > 0 ? ParallelGCThreads : 1); | |
1844 // try to spread out the starting points of the workers | |
1845 const size_t start_index = regions / worker_num * (size_t) worker; | |
1846 | |
1847 // each worker will actually look at all regions | |
1848 for (size_t count = 0; count < regions; ++count) { | |
1849 const size_t index = (start_index + count) % regions; | |
1850 assert(0 <= index && index < regions, "sanity"); | |
1851 HeapRegion* r = region_at(index); | |
1852 // we'll ignore "continues humongous" regions (we'll process them | |
1853 // when we come across their corresponding "start humongous" | |
1854 // region) and regions already claimed | |
1855 if (r->claim_value() == claim_value || r->continuesHumongous()) { | |
1856 continue; | |
1857 } | |
1858 // OK, try to claim it | |
342 | 1859 if (r->claimHeapRegion(claim_value)) { |
355 | 1860 // success! |
1861 assert(!r->continuesHumongous(), "sanity"); | |
1862 if (r->startsHumongous()) { | |
1863 // If the region is "starts humongous" we'll iterate over its | |
1864 // "continues humongous" first; in fact we'll do them | |
1865 // first. The order is important. In on case, calling the | |
1866 // closure on the "starts humongous" region might de-allocate | |
1867 // and clear all its "continues humongous" regions and, as a | |
1868 // result, we might end up processing them twice. So, we'll do | |
1869 // them first (notice: most closures will ignore them anyway) and | |
1870 // then we'll do the "starts humongous" region. | |
1871 for (size_t ch_index = index + 1; ch_index < regions; ++ch_index) { | |
1872 HeapRegion* chr = region_at(ch_index); | |
1873 | |
1874 // if the region has already been claimed or it's not | |
1875 // "continues humongous" we're done | |
1876 if (chr->claim_value() == claim_value || | |
1877 !chr->continuesHumongous()) { | |
1878 break; | |
1879 } | |
1880 | |
1881 // Noone should have claimed it directly. We can given | |
1882 // that we claimed its "starts humongous" region. | |
1883 assert(chr->claim_value() != claim_value, "sanity"); | |
1884 assert(chr->humongous_start_region() == r, "sanity"); | |
1885 | |
1886 if (chr->claimHeapRegion(claim_value)) { | |
1887 // we should always be able to claim it; noone else should | |
1888 // be trying to claim this region | |
1889 | |
1890 bool res2 = cl->doHeapRegion(chr); | |
1891 assert(!res2, "Should not abort"); | |
1892 | |
1893 // Right now, this holds (i.e., no closure that actually | |
1894 // does something with "continues humongous" regions | |
1895 // clears them). We might have to weaken it in the future, | |
1896 // but let's leave these two asserts here for extra safety. | |
1897 assert(chr->continuesHumongous(), "should still be the case"); | |
1898 assert(chr->humongous_start_region() == r, "sanity"); | |
1899 } else { | |
1900 guarantee(false, "we should not reach here"); | |
1901 } | |
1902 } | |
1903 } | |
1904 | |
1905 assert(!r->continuesHumongous(), "sanity"); | |
1906 bool res = cl->doHeapRegion(r); | |
1907 assert(!res, "Should not abort"); | |
1908 } | |
1909 } | |
1910 } | |
1911 | |
390 | 1912 class ResetClaimValuesClosure: public HeapRegionClosure { |
1913 public: | |
1914 bool doHeapRegion(HeapRegion* r) { | |
1915 r->set_claim_value(HeapRegion::InitialClaimValue); | |
1916 return false; | |
1917 } | |
1918 }; | |
1919 | |
1920 void | |
1921 G1CollectedHeap::reset_heap_region_claim_values() { | |
1922 ResetClaimValuesClosure blk; | |
1923 heap_region_iterate(&blk); | |
1924 } | |
1925 | |
355 | 1926 #ifdef ASSERT |
1927 // This checks whether all regions in the heap have the correct claim | |
1928 // value. I also piggy-backed on this a check to ensure that the | |
1929 // humongous_start_region() information on "continues humongous" | |
1930 // regions is correct. | |
1931 | |
1932 class CheckClaimValuesClosure : public HeapRegionClosure { | |
1933 private: | |
1934 jint _claim_value; | |
1935 size_t _failures; | |
1936 HeapRegion* _sh_region; | |
1937 public: | |
1938 CheckClaimValuesClosure(jint claim_value) : | |
1939 _claim_value(claim_value), _failures(0), _sh_region(NULL) { } | |
1940 bool doHeapRegion(HeapRegion* r) { | |
1941 if (r->claim_value() != _claim_value) { | |
1942 gclog_or_tty->print_cr("Region ["PTR_FORMAT","PTR_FORMAT"), " | |
1943 "claim value = %d, should be %d", | |
1944 r->bottom(), r->end(), r->claim_value(), | |
1945 _claim_value); | |
1946 ++_failures; | |
1947 } | |
1948 if (!r->isHumongous()) { | |
1949 _sh_region = NULL; | |
1950 } else if (r->startsHumongous()) { | |
1951 _sh_region = r; | |
1952 } else if (r->continuesHumongous()) { | |
1953 if (r->humongous_start_region() != _sh_region) { | |
1954 gclog_or_tty->print_cr("Region ["PTR_FORMAT","PTR_FORMAT"), " | |
1955 "HS = "PTR_FORMAT", should be "PTR_FORMAT, | |
1956 r->bottom(), r->end(), | |
1957 r->humongous_start_region(), | |
1958 _sh_region); | |
1959 ++_failures; | |
342 | 1960 } |
1961 } | |
355 | 1962 return false; |
1963 } | |
1964 size_t failures() { | |
1965 return _failures; | |
1966 } | |
1967 }; | |
1968 | |
1969 bool G1CollectedHeap::check_heap_region_claim_values(jint claim_value) { | |
1970 CheckClaimValuesClosure cl(claim_value); | |
1971 heap_region_iterate(&cl); | |
1972 return cl.failures() == 0; | |
1973 } | |
1974 #endif // ASSERT | |
342 | 1975 |
1976 void G1CollectedHeap::collection_set_iterate(HeapRegionClosure* cl) { | |
1977 HeapRegion* r = g1_policy()->collection_set(); | |
1978 while (r != NULL) { | |
1979 HeapRegion* next = r->next_in_collection_set(); | |
1980 if (cl->doHeapRegion(r)) { | |
1981 cl->incomplete(); | |
1982 return; | |
1983 } | |
1984 r = next; | |
1985 } | |
1986 } | |
1987 | |
1988 void G1CollectedHeap::collection_set_iterate_from(HeapRegion* r, | |
1989 HeapRegionClosure *cl) { | |
1990 assert(r->in_collection_set(), | |
1991 "Start region must be a member of the collection set."); | |
1992 HeapRegion* cur = r; | |
1993 while (cur != NULL) { | |
1994 HeapRegion* next = cur->next_in_collection_set(); | |
1995 if (cl->doHeapRegion(cur) && false) { | |
1996 cl->incomplete(); | |
1997 return; | |
1998 } | |
1999 cur = next; | |
2000 } | |
2001 cur = g1_policy()->collection_set(); | |
2002 while (cur != r) { | |
2003 HeapRegion* next = cur->next_in_collection_set(); | |
2004 if (cl->doHeapRegion(cur) && false) { | |
2005 cl->incomplete(); | |
2006 return; | |
2007 } | |
2008 cur = next; | |
2009 } | |
2010 } | |
2011 | |
2012 CompactibleSpace* G1CollectedHeap::first_compactible_space() { | |
2013 return _hrs->length() > 0 ? _hrs->at(0) : NULL; | |
2014 } | |
2015 | |
2016 | |
2017 Space* G1CollectedHeap::space_containing(const void* addr) const { | |
2018 Space* res = heap_region_containing(addr); | |
2019 if (res == NULL) | |
2020 res = perm_gen()->space_containing(addr); | |
2021 return res; | |
2022 } | |
2023 | |
2024 HeapWord* G1CollectedHeap::block_start(const void* addr) const { | |
2025 Space* sp = space_containing(addr); | |
2026 if (sp != NULL) { | |
2027 return sp->block_start(addr); | |
2028 } | |
2029 return NULL; | |
2030 } | |
2031 | |
2032 size_t G1CollectedHeap::block_size(const HeapWord* addr) const { | |
2033 Space* sp = space_containing(addr); | |
2034 assert(sp != NULL, "block_size of address outside of heap"); | |
2035 return sp->block_size(addr); | |
2036 } | |
2037 | |
2038 bool G1CollectedHeap::block_is_obj(const HeapWord* addr) const { | |
2039 Space* sp = space_containing(addr); | |
2040 return sp->block_is_obj(addr); | |
2041 } | |
2042 | |
2043 bool G1CollectedHeap::supports_tlab_allocation() const { | |
2044 return true; | |
2045 } | |
2046 | |
2047 size_t G1CollectedHeap::tlab_capacity(Thread* ignored) const { | |
2048 return HeapRegion::GrainBytes; | |
2049 } | |
2050 | |
2051 size_t G1CollectedHeap::unsafe_max_tlab_alloc(Thread* ignored) const { | |
2052 // Return the remaining space in the cur alloc region, but not less than | |
2053 // the min TLAB size. | |
1313
664ae0c5e0e5
6755988: G1: assert(new_obj != 0 || ... "should be forwarded")
johnc
parents:
1282
diff
changeset
|
2054 |
664ae0c5e0e5
6755988: G1: assert(new_obj != 0 || ... "should be forwarded")
johnc
parents:
1282
diff
changeset
|
2055 // Also, this value can be at most the humongous object threshold, |
664ae0c5e0e5
6755988: G1: assert(new_obj != 0 || ... "should be forwarded")
johnc
parents:
1282
diff
changeset
|
2056 // since we can't allow tlabs to grow big enough to accomodate |
664ae0c5e0e5
6755988: G1: assert(new_obj != 0 || ... "should be forwarded")
johnc
parents:
1282
diff
changeset
|
2057 // humongous objects. |
664ae0c5e0e5
6755988: G1: assert(new_obj != 0 || ... "should be forwarded")
johnc
parents:
1282
diff
changeset
|
2058 |
664ae0c5e0e5
6755988: G1: assert(new_obj != 0 || ... "should be forwarded")
johnc
parents:
1282
diff
changeset
|
2059 // We need to store the cur alloc region locally, since it might change |
664ae0c5e0e5
6755988: G1: assert(new_obj != 0 || ... "should be forwarded")
johnc
parents:
1282
diff
changeset
|
2060 // between when we test for NULL and when we use it later. |
342 | 2061 ContiguousSpace* cur_alloc_space = _cur_alloc_region; |
1313
664ae0c5e0e5
6755988: G1: assert(new_obj != 0 || ... "should be forwarded")
johnc
parents:
1282
diff
changeset
|
2062 size_t max_tlab_size = _humongous_object_threshold_in_words * wordSize; |
664ae0c5e0e5
6755988: G1: assert(new_obj != 0 || ... "should be forwarded")
johnc
parents:
1282
diff
changeset
|
2063 |
342 | 2064 if (cur_alloc_space == NULL) { |
1313
664ae0c5e0e5
6755988: G1: assert(new_obj != 0 || ... "should be forwarded")
johnc
parents:
1282
diff
changeset
|
2065 return max_tlab_size; |
342 | 2066 } else { |
1313
664ae0c5e0e5
6755988: G1: assert(new_obj != 0 || ... "should be forwarded")
johnc
parents:
1282
diff
changeset
|
2067 return MIN2(MAX2(cur_alloc_space->free(), (size_t)MinTLABSize), |
664ae0c5e0e5
6755988: G1: assert(new_obj != 0 || ... "should be forwarded")
johnc
parents:
1282
diff
changeset
|
2068 max_tlab_size); |
342 | 2069 } |
2070 } | |
2071 | |
2072 HeapWord* G1CollectedHeap::allocate_new_tlab(size_t size) { | |
2073 bool dummy; | |
2074 return G1CollectedHeap::mem_allocate(size, false, true, &dummy); | |
2075 } | |
2076 | |
2077 bool G1CollectedHeap::allocs_are_zero_filled() { | |
2078 return false; | |
2079 } | |
2080 | |
2081 size_t G1CollectedHeap::large_typearray_limit() { | |
2082 // FIXME | |
2083 return HeapRegion::GrainBytes/HeapWordSize; | |
2084 } | |
2085 | |
2086 size_t G1CollectedHeap::max_capacity() const { | |
1092
ed52bcc32739
6880903: G1: G1 reports incorrect Runtime.maxMemory()
tonyp
parents:
1089
diff
changeset
|
2087 return g1_reserved_obj_bytes(); |
342 | 2088 } |
2089 | |
2090 jlong G1CollectedHeap::millis_since_last_gc() { | |
2091 // assert(false, "NYI"); | |
2092 return 0; | |
2093 } | |
2094 | |
2095 | |
2096 void G1CollectedHeap::prepare_for_verify() { | |
2097 if (SafepointSynchronize::is_at_safepoint() || ! UseTLAB) { | |
2098 ensure_parsability(false); | |
2099 } | |
2100 g1_rem_set()->prepare_for_verify(); | |
2101 } | |
2102 | |
2103 class VerifyLivenessOopClosure: public OopClosure { | |
2104 G1CollectedHeap* g1h; | |
2105 public: | |
2106 VerifyLivenessOopClosure(G1CollectedHeap* _g1h) { | |
2107 g1h = _g1h; | |
2108 } | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2109 void do_oop(narrowOop *p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2110 void do_oop( oop *p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2111 |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2112 template <class T> void do_oop_work(T *p) { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2113 oop obj = oopDesc::load_decode_heap_oop(p); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2114 guarantee(obj == NULL || !g1h->is_obj_dead(obj), |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2115 "Dead object referenced by a not dead object"); |
342 | 2116 } |
2117 }; | |
2118 | |
2119 class VerifyObjsInRegionClosure: public ObjectClosure { | |
811 | 2120 private: |
342 | 2121 G1CollectedHeap* _g1h; |
2122 size_t _live_bytes; | |
2123 HeapRegion *_hr; | |
811 | 2124 bool _use_prev_marking; |
342 | 2125 public: |
811 | 2126 // use_prev_marking == true -> use "prev" marking information, |
2127 // use_prev_marking == false -> use "next" marking information | |
2128 VerifyObjsInRegionClosure(HeapRegion *hr, bool use_prev_marking) | |
2129 : _live_bytes(0), _hr(hr), _use_prev_marking(use_prev_marking) { | |
342 | 2130 _g1h = G1CollectedHeap::heap(); |
2131 } | |
2132 void do_object(oop o) { | |
2133 VerifyLivenessOopClosure isLive(_g1h); | |
2134 assert(o != NULL, "Huh?"); | |
811 | 2135 if (!_g1h->is_obj_dead_cond(o, _use_prev_marking)) { |
342 | 2136 o->oop_iterate(&isLive); |
1389
5dbd9300cf9c
6943926: G1: Integer overflow during heap region verification
johnc
parents:
1388
diff
changeset
|
2137 if (!_hr->obj_allocated_since_prev_marking(o)) { |
5dbd9300cf9c
6943926: G1: Integer overflow during heap region verification
johnc
parents:
1388
diff
changeset
|
2138 size_t obj_size = o->size(); // Make sure we don't overflow |
5dbd9300cf9c
6943926: G1: Integer overflow during heap region verification
johnc
parents:
1388
diff
changeset
|
2139 _live_bytes += (obj_size * HeapWordSize); |
5dbd9300cf9c
6943926: G1: Integer overflow during heap region verification
johnc
parents:
1388
diff
changeset
|
2140 } |
342 | 2141 } |
2142 } | |
2143 size_t live_bytes() { return _live_bytes; } | |
2144 }; | |
2145 | |
2146 class PrintObjsInRegionClosure : public ObjectClosure { | |
2147 HeapRegion *_hr; | |
2148 G1CollectedHeap *_g1; | |
2149 public: | |
2150 PrintObjsInRegionClosure(HeapRegion *hr) : _hr(hr) { | |
2151 _g1 = G1CollectedHeap::heap(); | |
2152 }; | |
2153 | |
2154 void do_object(oop o) { | |
2155 if (o != NULL) { | |
2156 HeapWord *start = (HeapWord *) o; | |
2157 size_t word_sz = o->size(); | |
2158 gclog_or_tty->print("\nPrinting obj "PTR_FORMAT" of size " SIZE_FORMAT | |
2159 " isMarkedPrev %d isMarkedNext %d isAllocSince %d\n", | |
2160 (void*) o, word_sz, | |
2161 _g1->isMarkedPrev(o), | |
2162 _g1->isMarkedNext(o), | |
2163 _hr->obj_allocated_since_prev_marking(o)); | |
2164 HeapWord *end = start + word_sz; | |
2165 HeapWord *cur; | |
2166 int *val; | |
2167 for (cur = start; cur < end; cur++) { | |
2168 val = (int *) cur; | |
2169 gclog_or_tty->print("\t "PTR_FORMAT":"PTR_FORMAT"\n", val, *val); | |
2170 } | |
2171 } | |
2172 } | |
2173 }; | |
2174 | |
2175 class VerifyRegionClosure: public HeapRegionClosure { | |
811 | 2176 private: |
342 | 2177 bool _allow_dirty; |
390 | 2178 bool _par; |
811 | 2179 bool _use_prev_marking; |
1020
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2180 bool _failures; |
811 | 2181 public: |
2182 // use_prev_marking == true -> use "prev" marking information, | |
2183 // use_prev_marking == false -> use "next" marking information | |
2184 VerifyRegionClosure(bool allow_dirty, bool par, bool use_prev_marking) | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2185 : _allow_dirty(allow_dirty), |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2186 _par(par), |
1020
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2187 _use_prev_marking(use_prev_marking), |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2188 _failures(false) {} |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2189 |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2190 bool failures() { |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2191 return _failures; |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2192 } |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2193 |
342 | 2194 bool doHeapRegion(HeapRegion* r) { |
390 | 2195 guarantee(_par || r->claim_value() == HeapRegion::InitialClaimValue, |
2196 "Should be unclaimed at verify points."); | |
637
25e146966e7c
6817419: G1: Enable extensive verification for humongous regions
iveresov
parents:
636
diff
changeset
|
2197 if (!r->continuesHumongous()) { |
1020
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2198 bool failures = false; |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2199 r->verify(_allow_dirty, _use_prev_marking, &failures); |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2200 if (failures) { |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2201 _failures = true; |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2202 } else { |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2203 VerifyObjsInRegionClosure not_dead_yet_cl(r, _use_prev_marking); |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2204 r->object_iterate(¬_dead_yet_cl); |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2205 if (r->max_live_bytes() < not_dead_yet_cl.live_bytes()) { |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2206 gclog_or_tty->print_cr("["PTR_FORMAT","PTR_FORMAT"] " |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2207 "max_live_bytes "SIZE_FORMAT" " |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2208 "< calculated "SIZE_FORMAT, |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2209 r->bottom(), r->end(), |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2210 r->max_live_bytes(), |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2211 not_dead_yet_cl.live_bytes()); |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2212 _failures = true; |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2213 } |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2214 } |
342 | 2215 } |
1020
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2216 return false; // stop the region iteration if we hit a failure |
342 | 2217 } |
2218 }; | |
2219 | |
2220 class VerifyRootsClosure: public OopsInGenClosure { | |
2221 private: | |
2222 G1CollectedHeap* _g1h; | |
1020
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2223 bool _use_prev_marking; |
342 | 2224 bool _failures; |
2225 public: | |
811 | 2226 // use_prev_marking == true -> use "prev" marking information, |
2227 // use_prev_marking == false -> use "next" marking information | |
2228 VerifyRootsClosure(bool use_prev_marking) : | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2229 _g1h(G1CollectedHeap::heap()), |
1020
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2230 _use_prev_marking(use_prev_marking), |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2231 _failures(false) { } |
342 | 2232 |
2233 bool failures() { return _failures; } | |
2234 | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2235 template <class T> void do_oop_nv(T* p) { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2236 T heap_oop = oopDesc::load_heap_oop(p); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2237 if (!oopDesc::is_null(heap_oop)) { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2238 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); |
811 | 2239 if (_g1h->is_obj_dead_cond(obj, _use_prev_marking)) { |
342 | 2240 gclog_or_tty->print_cr("Root location "PTR_FORMAT" " |
1020
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2241 "points to dead obj "PTR_FORMAT, p, (void*) obj); |
342 | 2242 obj->print_on(gclog_or_tty); |
2243 _failures = true; | |
2244 } | |
2245 } | |
2246 } | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2247 |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2248 void do_oop(oop* p) { do_oop_nv(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2249 void do_oop(narrowOop* p) { do_oop_nv(p); } |
342 | 2250 }; |
2251 | |
390 | 2252 // This is the task used for parallel heap verification. |
2253 | |
2254 class G1ParVerifyTask: public AbstractGangTask { | |
2255 private: | |
2256 G1CollectedHeap* _g1h; | |
2257 bool _allow_dirty; | |
811 | 2258 bool _use_prev_marking; |
1020
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2259 bool _failures; |
390 | 2260 |
2261 public: | |
811 | 2262 // use_prev_marking == true -> use "prev" marking information, |
2263 // use_prev_marking == false -> use "next" marking information | |
2264 G1ParVerifyTask(G1CollectedHeap* g1h, bool allow_dirty, | |
2265 bool use_prev_marking) : | |
390 | 2266 AbstractGangTask("Parallel verify task"), |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2267 _g1h(g1h), |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2268 _allow_dirty(allow_dirty), |
1020
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2269 _use_prev_marking(use_prev_marking), |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2270 _failures(false) { } |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2271 |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2272 bool failures() { |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2273 return _failures; |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2274 } |
390 | 2275 |
2276 void work(int worker_i) { | |
637
25e146966e7c
6817419: G1: Enable extensive verification for humongous regions
iveresov
parents:
636
diff
changeset
|
2277 HandleMark hm; |
811 | 2278 VerifyRegionClosure blk(_allow_dirty, true, _use_prev_marking); |
390 | 2279 _g1h->heap_region_par_iterate_chunked(&blk, worker_i, |
2280 HeapRegion::ParVerifyClaimValue); | |
1020
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2281 if (blk.failures()) { |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2282 _failures = true; |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2283 } |
390 | 2284 } |
2285 }; | |
2286 | |
342 | 2287 void G1CollectedHeap::verify(bool allow_dirty, bool silent) { |
811 | 2288 verify(allow_dirty, silent, /* use_prev_marking */ true); |
2289 } | |
2290 | |
2291 void G1CollectedHeap::verify(bool allow_dirty, | |
2292 bool silent, | |
2293 bool use_prev_marking) { | |
342 | 2294 if (SafepointSynchronize::is_at_safepoint() || ! UseTLAB) { |
2295 if (!silent) { gclog_or_tty->print("roots "); } | |
811 | 2296 VerifyRootsClosure rootsCl(use_prev_marking); |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
890
diff
changeset
|
2297 CodeBlobToOopClosure blobsCl(&rootsCl, /*do_marking=*/ false); |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
890
diff
changeset
|
2298 process_strong_roots(true, // activate StrongRootsScope |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
890
diff
changeset
|
2299 false, |
342 | 2300 SharedHeap::SO_AllClasses, |
2301 &rootsCl, | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
890
diff
changeset
|
2302 &blobsCl, |
342 | 2303 &rootsCl); |
1020
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2304 bool failures = rootsCl.failures(); |
342 | 2305 rem_set()->invalidate(perm_gen()->used_region(), false); |
2306 if (!silent) { gclog_or_tty->print("heapRegions "); } | |
390 | 2307 if (GCParallelVerificationEnabled && ParallelGCThreads > 1) { |
2308 assert(check_heap_region_claim_values(HeapRegion::InitialClaimValue), | |
2309 "sanity check"); | |
2310 | |
811 | 2311 G1ParVerifyTask task(this, allow_dirty, use_prev_marking); |
390 | 2312 int n_workers = workers()->total_workers(); |
2313 set_par_threads(n_workers); | |
2314 workers()->run_task(&task); | |
2315 set_par_threads(0); | |
1020
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2316 if (task.failures()) { |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2317 failures = true; |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2318 } |
390 | 2319 |
2320 assert(check_heap_region_claim_values(HeapRegion::ParVerifyClaimValue), | |
2321 "sanity check"); | |
2322 | |
2323 reset_heap_region_claim_values(); | |
2324 | |
2325 assert(check_heap_region_claim_values(HeapRegion::InitialClaimValue), | |
2326 "sanity check"); | |
2327 } else { | |
811 | 2328 VerifyRegionClosure blk(allow_dirty, false, use_prev_marking); |
390 | 2329 _hrs->iterate(&blk); |
1020
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2330 if (blk.failures()) { |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2331 failures = true; |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2332 } |
390 | 2333 } |
342 | 2334 if (!silent) gclog_or_tty->print("remset "); |
2335 rem_set()->verify(); | |
1020
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2336 |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2337 if (failures) { |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2338 gclog_or_tty->print_cr("Heap:"); |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2339 print_on(gclog_or_tty, true /* extended */); |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2340 gclog_or_tty->print_cr(""); |
1044 | 2341 if (VerifyDuringGC && G1VerifyDuringGCPrintReachable) { |
1388 | 2342 concurrent_mark()->print_reachable("at-verification-failure", |
2343 use_prev_marking, false /* all */); | |
1020
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2344 } |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2345 gclog_or_tty->flush(); |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2346 } |
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2347 guarantee(!failures, "there should not have been any failures"); |
342 | 2348 } else { |
2349 if (!silent) gclog_or_tty->print("(SKIPPING roots, heapRegions, remset) "); | |
2350 } | |
2351 } | |
2352 | |
2353 class PrintRegionClosure: public HeapRegionClosure { | |
2354 outputStream* _st; | |
2355 public: | |
2356 PrintRegionClosure(outputStream* st) : _st(st) {} | |
2357 bool doHeapRegion(HeapRegion* r) { | |
2358 r->print_on(_st); | |
2359 return false; | |
2360 } | |
2361 }; | |
2362 | |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2363 void G1CollectedHeap::print() const { print_on(tty); } |
342 | 2364 |
2365 void G1CollectedHeap::print_on(outputStream* st) const { | |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2366 print_on(st, PrintHeapAtGCExtended); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2367 } |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2368 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2369 void G1CollectedHeap::print_on(outputStream* st, bool extended) const { |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2370 st->print(" %-20s", "garbage-first heap"); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2371 st->print(" total " SIZE_FORMAT "K, used " SIZE_FORMAT "K", |
846
42d84bbbecf4
6859911: G1: assert(Heap_lock->owner() = NULL, "Should be owned on this thread's behalf")
tonyp
parents:
845
diff
changeset
|
2372 capacity()/K, used_unlocked()/K); |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2373 st->print(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")", |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2374 _g1_storage.low_boundary(), |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2375 _g1_storage.high(), |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2376 _g1_storage.high_boundary()); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2377 st->cr(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2378 st->print(" region size " SIZE_FORMAT "K, ", |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2379 HeapRegion::GrainBytes/K); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2380 size_t young_regions = _young_list->length(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2381 st->print(SIZE_FORMAT " young (" SIZE_FORMAT "K), ", |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2382 young_regions, young_regions * HeapRegion::GrainBytes / K); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2383 size_t survivor_regions = g1_policy()->recorded_survivor_regions(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2384 st->print(SIZE_FORMAT " survivors (" SIZE_FORMAT "K)", |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2385 survivor_regions, survivor_regions * HeapRegion::GrainBytes / K); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2386 st->cr(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2387 perm()->as_gen()->print_on(st); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2388 if (extended) { |
1020
ff2402f6a50b
6882730: G1: parallel heap verification messes up region dump
tonyp
parents:
1019
diff
changeset
|
2389 st->cr(); |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2390 print_on_extended(st); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2391 } |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2392 } |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2393 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2394 void G1CollectedHeap::print_on_extended(outputStream* st) const { |
342 | 2395 PrintRegionClosure blk(st); |
2396 _hrs->iterate(&blk); | |
2397 } | |
2398 | |
2399 void G1CollectedHeap::print_gc_threads_on(outputStream* st) const { | |
2400 if (ParallelGCThreads > 0) { | |
1019 | 2401 workers()->print_worker_threads_on(st); |
2402 } | |
2403 | |
2404 _cmThread->print_on(st); | |
342 | 2405 st->cr(); |
1019 | 2406 |
2407 _cm->print_worker_threads_on(st); | |
2408 | |
2409 _cg1r->print_worker_threads_on(st); | |
2410 | |
342 | 2411 _czft->print_on(st); |
2412 st->cr(); | |
2413 } | |
2414 | |
2415 void G1CollectedHeap::gc_threads_do(ThreadClosure* tc) const { | |
2416 if (ParallelGCThreads > 0) { | |
2417 workers()->threads_do(tc); | |
2418 } | |
2419 tc->do_thread(_cmThread); | |
794 | 2420 _cg1r->threads_do(tc); |
342 | 2421 tc->do_thread(_czft); |
2422 } | |
2423 | |
2424 void G1CollectedHeap::print_tracing_info() const { | |
2425 // We'll overload this to mean "trace GC pause statistics." | |
2426 if (TraceGen0Time || TraceGen1Time) { | |
2427 // The "G1CollectorPolicy" is keeping track of these stats, so delegate | |
2428 // to that. | |
2429 g1_policy()->print_tracing_info(); | |
2430 } | |
751 | 2431 if (G1SummarizeRSetStats) { |
342 | 2432 g1_rem_set()->print_summary_info(); |
2433 } | |
1282 | 2434 if (G1SummarizeConcMark) { |
342 | 2435 concurrent_mark()->print_summary_info(); |
2436 } | |
751 | 2437 if (G1SummarizeZFStats) { |
342 | 2438 ConcurrentZFThread::print_summary_info(); |
2439 } | |
2440 g1_policy()->print_yg_surv_rate_info(); | |
2441 | |
2442 SpecializationStats::print(); | |
2443 } | |
2444 | |
2445 | |
2446 int G1CollectedHeap::addr_to_arena_id(void* addr) const { | |
2447 HeapRegion* hr = heap_region_containing(addr); | |
2448 if (hr == NULL) { | |
2449 return 0; | |
2450 } else { | |
2451 return 1; | |
2452 } | |
2453 } | |
2454 | |
2455 G1CollectedHeap* G1CollectedHeap::heap() { | |
2456 assert(_sh->kind() == CollectedHeap::G1CollectedHeap, | |
2457 "not a garbage-first heap"); | |
2458 return _g1h; | |
2459 } | |
2460 | |
2461 void G1CollectedHeap::gc_prologue(bool full /* Ignored */) { | |
1245
6484c4ee11cb
6904516: More object array barrier fixes, following up on 6906727
ysr
parents:
1166
diff
changeset
|
2462 // always_do_update_barrier = false; |
342 | 2463 assert(InlineCacheBuffer::is_empty(), "should have cleaned up ICBuffer"); |
2464 // Call allocation profiler | |
2465 AllocationProfiler::iterate_since_last_gc(); | |
2466 // Fill TLAB's and such | |
2467 ensure_parsability(true); | |
2468 } | |
2469 | |
2470 void G1CollectedHeap::gc_epilogue(bool full /* Ignored */) { | |
2471 // FIXME: what is this about? | |
2472 // I'm ignoring the "fill_newgen()" call if "alloc_event_enabled" | |
2473 // is set. | |
2474 COMPILER2_PRESENT(assert(DerivedPointerTable::is_empty(), | |
2475 "derived pointer present")); | |
1245
6484c4ee11cb
6904516: More object array barrier fixes, following up on 6906727
ysr
parents:
1166
diff
changeset
|
2476 // always_do_update_barrier = true; |
342 | 2477 } |
2478 | |
2479 void G1CollectedHeap::do_collection_pause() { | |
2480 // Read the GC count while holding the Heap_lock | |
2481 // we need to do this _before_ wait_for_cleanup_complete(), to | |
2482 // ensure that we do not give up the heap lock and potentially | |
2483 // pick up the wrong count | |
2484 int gc_count_before = SharedHeap::heap()->total_collections(); | |
2485 | |
2486 // Don't want to do a GC pause while cleanup is being completed! | |
2487 wait_for_cleanup_complete(); | |
2488 | |
2489 g1_policy()->record_stop_world_start(); | |
2490 { | |
2491 MutexUnlocker mu(Heap_lock); // give up heap lock, execute gets it back | |
2492 VM_G1IncCollectionPause op(gc_count_before); | |
2493 VMThread::execute(&op); | |
2494 } | |
2495 } | |
2496 | |
2497 void | |
2498 G1CollectedHeap::doConcurrentMark() { | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2499 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2500 if (!_cmThread->in_progress()) { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2501 _cmThread->set_started(); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2502 CGC_lock->notify(); |
342 | 2503 } |
2504 } | |
2505 | |
2506 class VerifyMarkedObjsClosure: public ObjectClosure { | |
2507 G1CollectedHeap* _g1h; | |
2508 public: | |
2509 VerifyMarkedObjsClosure(G1CollectedHeap* g1h) : _g1h(g1h) {} | |
2510 void do_object(oop obj) { | |
2511 assert(obj->mark()->is_marked() ? !_g1h->is_obj_dead(obj) : true, | |
2512 "markandsweep mark should agree with concurrent deadness"); | |
2513 } | |
2514 }; | |
2515 | |
2516 void | |
2517 G1CollectedHeap::checkConcurrentMark() { | |
2518 VerifyMarkedObjsClosure verifycl(this); | |
2519 // MutexLockerEx x(getMarkBitMapLock(), | |
2520 // Mutex::_no_safepoint_check_flag); | |
678 | 2521 object_iterate(&verifycl, false); |
342 | 2522 } |
2523 | |
2524 void G1CollectedHeap::do_sync_mark() { | |
2525 _cm->checkpointRootsInitial(); | |
2526 _cm->markFromRoots(); | |
2527 _cm->checkpointRootsFinal(false); | |
2528 } | |
2529 | |
2530 // <NEW PREDICTION> | |
2531 | |
2532 double G1CollectedHeap::predict_region_elapsed_time_ms(HeapRegion *hr, | |
2533 bool young) { | |
2534 return _g1_policy->predict_region_elapsed_time_ms(hr, young); | |
2535 } | |
2536 | |
2537 void G1CollectedHeap::check_if_region_is_too_expensive(double | |
2538 predicted_time_ms) { | |
2539 _g1_policy->check_if_region_is_too_expensive(predicted_time_ms); | |
2540 } | |
2541 | |
2542 size_t G1CollectedHeap::pending_card_num() { | |
2543 size_t extra_cards = 0; | |
2544 JavaThread *curr = Threads::first(); | |
2545 while (curr != NULL) { | |
2546 DirtyCardQueue& dcq = curr->dirty_card_queue(); | |
2547 extra_cards += dcq.size(); | |
2548 curr = curr->next(); | |
2549 } | |
2550 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); | |
2551 size_t buffer_size = dcqs.buffer_size(); | |
2552 size_t buffer_num = dcqs.completed_buffers_num(); | |
2553 return buffer_size * buffer_num + extra_cards; | |
2554 } | |
2555 | |
2556 size_t G1CollectedHeap::max_pending_card_num() { | |
2557 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); | |
2558 size_t buffer_size = dcqs.buffer_size(); | |
2559 size_t buffer_num = dcqs.completed_buffers_num(); | |
2560 int thread_num = Threads::number_of_threads(); | |
2561 return (buffer_num + thread_num) * buffer_size; | |
2562 } | |
2563 | |
2564 size_t G1CollectedHeap::cards_scanned() { | |
2565 HRInto_G1RemSet* g1_rset = (HRInto_G1RemSet*) g1_rem_set(); | |
2566 return g1_rset->cardsScanned(); | |
2567 } | |
2568 | |
2569 void | |
2570 G1CollectedHeap::setup_surviving_young_words() { | |
2571 guarantee( _surviving_young_words == NULL, "pre-condition" ); | |
2572 size_t array_length = g1_policy()->young_cset_length(); | |
2573 _surviving_young_words = NEW_C_HEAP_ARRAY(size_t, array_length); | |
2574 if (_surviving_young_words == NULL) { | |
2575 vm_exit_out_of_memory(sizeof(size_t) * array_length, | |
2576 "Not enough space for young surv words summary."); | |
2577 } | |
2578 memset(_surviving_young_words, 0, array_length * sizeof(size_t)); | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2579 #ifdef ASSERT |
342 | 2580 for (size_t i = 0; i < array_length; ++i) { |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2581 assert( _surviving_young_words[i] == 0, "memset above" ); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2582 } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2583 #endif // !ASSERT |
342 | 2584 } |
2585 | |
2586 void | |
2587 G1CollectedHeap::update_surviving_young_words(size_t* surv_young_words) { | |
2588 MutexLockerEx x(ParGCRareEvent_lock, Mutex::_no_safepoint_check_flag); | |
2589 size_t array_length = g1_policy()->young_cset_length(); | |
2590 for (size_t i = 0; i < array_length; ++i) | |
2591 _surviving_young_words[i] += surv_young_words[i]; | |
2592 } | |
2593 | |
2594 void | |
2595 G1CollectedHeap::cleanup_surviving_young_words() { | |
2596 guarantee( _surviving_young_words != NULL, "pre-condition" ); | |
2597 FREE_C_HEAP_ARRAY(size_t, _surviving_young_words); | |
2598 _surviving_young_words = NULL; | |
2599 } | |
2600 | |
2601 // </NEW PREDICTION> | |
2602 | |
1261
0414c1049f15
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
1245
diff
changeset
|
2603 struct PrepareForRSScanningClosure : public HeapRegionClosure { |
0414c1049f15
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
1245
diff
changeset
|
2604 bool doHeapRegion(HeapRegion *r) { |
0414c1049f15
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
1245
diff
changeset
|
2605 r->rem_set()->set_iter_claimed(0); |
0414c1049f15
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
1245
diff
changeset
|
2606 return false; |
0414c1049f15
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
1245
diff
changeset
|
2607 } |
0414c1049f15
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
1245
diff
changeset
|
2608 }; |
0414c1049f15
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
1245
diff
changeset
|
2609 |
342 | 2610 void |
677 | 2611 G1CollectedHeap::do_collection_pause_at_safepoint() { |
1359
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1313
diff
changeset
|
2612 if (GC_locker::check_active_before_gc()) { |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1313
diff
changeset
|
2613 return; // GC is disabled (e.g. JNI GetXXXCritical operation) |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1313
diff
changeset
|
2614 } |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1313
diff
changeset
|
2615 |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2616 if (PrintHeapAtGC) { |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2617 Universe::print_heap_before_gc(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2618 } |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2619 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2620 { |
1089
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1088
diff
changeset
|
2621 ResourceMark rm; |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1088
diff
changeset
|
2622 |
1359
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1313
diff
changeset
|
2623 // This call will decide whether this pause is an initial-mark |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1313
diff
changeset
|
2624 // pause. If it is, during_initial_mark_pause() will return true |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1313
diff
changeset
|
2625 // for the duration of this pause. |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1313
diff
changeset
|
2626 g1_policy()->decide_on_conc_mark_initiation(); |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1313
diff
changeset
|
2627 |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2628 char verbose_str[128]; |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2629 sprintf(verbose_str, "GC pause "); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2630 if (g1_policy()->in_young_gc_mode()) { |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2631 if (g1_policy()->full_young_gcs()) |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2632 strcat(verbose_str, "(young)"); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2633 else |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2634 strcat(verbose_str, "(partial)"); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2635 } |
1359
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1313
diff
changeset
|
2636 if (g1_policy()->during_initial_mark_pause()) |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2637 strcat(verbose_str, " (initial-mark)"); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2638 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2639 // if PrintGCDetails is on, we'll print long statistics information |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2640 // in the collector policy code, so let's not print this as the output |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2641 // is messy if we do. |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2642 gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2643 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2644 TraceTime t(verbose_str, PrintGC && !PrintGCDetails, true, gclog_or_tty); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2645 |
1089
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1088
diff
changeset
|
2646 TraceMemoryManagerStats tms(false /* fullGC */); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1088
diff
changeset
|
2647 |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2648 assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint"); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2649 assert(Thread::current() == VMThread::vm_thread(), "should be in vm thread"); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2650 guarantee(!is_gc_active(), "collection is not reentrant"); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2651 assert(regions_accounted_for(), "Region leakage!"); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2652 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2653 increment_gc_time_stamp(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2654 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2655 if (g1_policy()->in_young_gc_mode()) { |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2656 assert(check_young_list_well_formed(), |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2657 "young list should be well formed"); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2658 } |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2659 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2660 bool abandoned = false; |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2661 { // Call to jvmpi::post_class_unload_events must occur outside of active GC |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2662 IsGCActiveMark x; |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2663 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2664 gc_prologue(false); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2665 increment_total_collections(false /* full gc */); |
342 | 2666 |
2667 #if G1_REM_SET_LOGGING | |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2668 gclog_or_tty->print_cr("\nJust chose CS, heap:"); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2669 print(); |
342 | 2670 #endif |
2671 | |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2672 if (VerifyBeforeGC && total_collections() >= VerifyGCStartAt) { |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2673 HandleMark hm; // Discard invalid handles created during verification |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2674 prepare_for_verify(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2675 gclog_or_tty->print(" VerifyBeforeGC:"); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2676 Universe::verify(false); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2677 } |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2678 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2679 COMPILER2_PRESENT(DerivedPointerTable::clear()); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2680 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2681 // We want to turn off ref discovery, if necessary, and turn it back on |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2682 // on again later if we do. XXX Dubious: why is discovery disabled? |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2683 bool was_enabled = ref_processor()->discovery_enabled(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2684 if (was_enabled) ref_processor()->disable_discovery(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2685 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2686 // Forget the current alloc region (we might even choose it to be part |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2687 // of the collection set!). |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2688 abandon_cur_alloc_region(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2689 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2690 // The elapsed time induced by the start time below deliberately elides |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2691 // the possible verification above. |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2692 double start_time_sec = os::elapsedTime(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2693 size_t start_used_bytes = used(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2694 |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2695 #if YOUNG_LIST_VERBOSE |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2696 gclog_or_tty->print_cr("\nBefore recording pause start.\nYoung_list:"); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2697 _young_list->print(); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2698 g1_policy()->print_collection_set(g1_policy()->inc_cset_head(), gclog_or_tty); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2699 #endif // YOUNG_LIST_VERBOSE |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2700 |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2701 g1_policy()->record_collection_pause_start(start_time_sec, |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2702 start_used_bytes); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2703 |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2704 #if YOUNG_LIST_VERBOSE |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2705 gclog_or_tty->print_cr("\nAfter recording pause start.\nYoung_list:"); |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2706 _young_list->print(); |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2707 #endif // YOUNG_LIST_VERBOSE |
342 | 2708 |
1359
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1313
diff
changeset
|
2709 if (g1_policy()->during_initial_mark_pause()) { |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2710 concurrent_mark()->checkpointRootsInitialPre(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2711 } |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2712 save_marks(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2713 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2714 // We must do this before any possible evacuation that should propagate |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2715 // marks. |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2716 if (mark_in_progress()) { |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2717 double start_time_sec = os::elapsedTime(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2718 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2719 _cm->drainAllSATBBuffers(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2720 double finish_mark_ms = (os::elapsedTime() - start_time_sec) * 1000.0; |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2721 g1_policy()->record_satb_drain_time(finish_mark_ms); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2722 } |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2723 // Record the number of elements currently on the mark stack, so we |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2724 // only iterate over these. (Since evacuation may add to the mark |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2725 // stack, doing more exposes race conditions.) If no mark is in |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2726 // progress, this will be zero. |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2727 _cm->set_oops_do_bound(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2728 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2729 assert(regions_accounted_for(), "Region leakage."); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2730 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2731 if (mark_in_progress()) |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2732 concurrent_mark()->newCSet(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2733 |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2734 #if YOUNG_LIST_VERBOSE |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2735 gclog_or_tty->print_cr("\nBefore choosing collection set.\nYoung_list:"); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2736 _young_list->print(); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2737 g1_policy()->print_collection_set(g1_policy()->inc_cset_head(), gclog_or_tty); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2738 #endif // YOUNG_LIST_VERBOSE |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2739 |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2740 // Now choose the CS. We may abandon a pause if we find no |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2741 // region that will fit in the MMU pause. |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2742 bool abandoned = g1_policy()->choose_collection_set(); |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2743 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2744 // Nothing to do if we were unable to choose a collection set. |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2745 if (!abandoned) { |
342 | 2746 #if G1_REM_SET_LOGGING |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2747 gclog_or_tty->print_cr("\nAfter pause, heap:"); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2748 print(); |
342 | 2749 #endif |
1261
0414c1049f15
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
1245
diff
changeset
|
2750 PrepareForRSScanningClosure prepare_for_rs_scan; |
0414c1049f15
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
1245
diff
changeset
|
2751 collection_set_iterate(&prepare_for_rs_scan); |
342 | 2752 |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2753 setup_surviving_young_words(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2754 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2755 // Set up the gc allocation regions. |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2756 get_gc_alloc_regions(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2757 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2758 // Actually do the work... |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2759 evacuate_collection_set(); |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2760 |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2761 free_collection_set(g1_policy()->collection_set()); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2762 g1_policy()->clear_collection_set(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2763 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2764 cleanup_surviving_young_words(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2765 |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2766 // Start a new incremental collection set for the next pause. |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2767 g1_policy()->start_incremental_cset_building(); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2768 |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2769 // Clear the _cset_fast_test bitmap in anticipation of adding |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2770 // regions to the incremental collection set for the next |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2771 // evacuation pause. |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2772 clear_cset_fast_test(); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2773 |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2774 if (g1_policy()->in_young_gc_mode()) { |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2775 _young_list->reset_sampled_info(); |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2776 |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2777 // Don't check the whole heap at this point as the |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2778 // GC alloc regions from this pause have been tagged |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2779 // as survivors and moved on to the survivor list. |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2780 // Survivor regions will fail the !is_young() check. |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2781 assert(check_young_list_empty(false /* check_heap */), |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2782 "young list should be empty"); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2783 |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2784 #if YOUNG_LIST_VERBOSE |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2785 gclog_or_tty->print_cr("Before recording survivors.\nYoung List:"); |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2786 _young_list->print(); |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2787 #endif // YOUNG_LIST_VERBOSE |
342 | 2788 |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2789 g1_policy()->record_survivor_regions(_young_list->survivor_length(), |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2790 _young_list->first_survivor_region(), |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2791 _young_list->last_survivor_region()); |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2792 |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2793 _young_list->reset_auxilary_lists(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2794 } |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2795 } else { |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2796 // We have abandoned the current collection. This can only happen |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2797 // if we're not doing young or partially young collections, and |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2798 // we didn't find an old region that we're able to collect within |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2799 // the allowed time. |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2800 |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2801 assert(g1_policy()->collection_set() == NULL, "should be"); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2802 assert(_young_list->length() == 0, "because it should be"); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2803 |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2804 // This should be a no-op. |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2805 abandon_collection_set(g1_policy()->inc_cset_head()); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2806 |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2807 g1_policy()->clear_incremental_cset(); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2808 g1_policy()->stop_incremental_cset_building(); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2809 |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2810 // Start a new incremental collection set for the next pause. |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2811 g1_policy()->start_incremental_cset_building(); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2812 |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2813 // Clear the _cset_fast_test bitmap in anticipation of adding |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2814 // regions to the incremental collection set for the next |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2815 // evacuation pause. |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2816 clear_cset_fast_test(); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2817 |
1088
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
2818 // This looks confusing, because the DPT should really be empty |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
2819 // at this point -- since we have not done any collection work, |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
2820 // there should not be any derived pointers in the table to update; |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
2821 // however, there is some additional state in the DPT which is |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
2822 // reset at the end of the (null) "gc" here via the following call. |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
2823 // A better approach might be to split off that state resetting work |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
2824 // into a separate method that asserts that the DPT is empty and call |
3fc996d4edd2
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
1045
diff
changeset
|
2825 // that here. That is deferred for now. |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2826 COMPILER2_PRESENT(DerivedPointerTable::update_pointers()); |
342 | 2827 } |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2828 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2829 if (evacuation_failed()) { |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2830 _summary_bytes_used = recalculate_used(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2831 } else { |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2832 // The "used" of the the collection set have already been subtracted |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2833 // when they were freed. Add in the bytes evacuated. |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2834 _summary_bytes_used += g1_policy()->bytes_in_to_space(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2835 } |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2836 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2837 if (g1_policy()->in_young_gc_mode() && |
1359
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1313
diff
changeset
|
2838 g1_policy()->during_initial_mark_pause()) { |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2839 concurrent_mark()->checkpointRootsInitialPost(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2840 set_marking_started(); |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2841 // CAUTION: after the doConcurrentMark() call below, |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2842 // the concurrent marking thread(s) could be running |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2843 // concurrently with us. Make sure that anything after |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2844 // this point does not assume that we are the only GC thread |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2845 // running. Note: of course, the actual marking work will |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2846 // not start until the safepoint itself is released in |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
2847 // ConcurrentGCThread::safepoint_desynchronize(). |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2848 doConcurrentMark(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2849 } |
342 | 2850 |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2851 #if YOUNG_LIST_VERBOSE |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2852 gclog_or_tty->print_cr("\nEnd of the pause.\nYoung_list:"); |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2853 _young_list->print(); |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2854 g1_policy()->print_collection_set(g1_policy()->inc_cset_head(), gclog_or_tty); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
2855 #endif // YOUNG_LIST_VERBOSE |
342 | 2856 |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2857 double end_time_sec = os::elapsedTime(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2858 double pause_time_ms = (end_time_sec - start_time_sec) * MILLIUNITS; |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2859 g1_policy()->record_pause_time_ms(pause_time_ms); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2860 g1_policy()->record_collection_pause_end(abandoned); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2861 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2862 assert(regions_accounted_for(), "Region leakage."); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2863 |
1089
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1088
diff
changeset
|
2864 MemoryService::track_memory_usage(); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1088
diff
changeset
|
2865 |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2866 if (VerifyAfterGC && total_collections() >= VerifyGCStartAt) { |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2867 HandleMark hm; // Discard invalid handles created during verification |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2868 gclog_or_tty->print(" VerifyAfterGC:"); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2869 prepare_for_verify(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2870 Universe::verify(false); |
342 | 2871 } |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2872 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2873 if (was_enabled) ref_processor()->enable_discovery(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2874 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2875 { |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2876 size_t expand_bytes = g1_policy()->expansion_amount(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2877 if (expand_bytes > 0) { |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2878 size_t bytes_before = capacity(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2879 expand(expand_bytes); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2880 } |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2881 } |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2882 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2883 if (mark_in_progress()) { |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2884 concurrent_mark()->update_g1_committed(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2885 } |
546
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
545
diff
changeset
|
2886 |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
545
diff
changeset
|
2887 #ifdef TRACESPINNING |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2888 ParallelTaskTerminator::print_termination_counts(); |
546
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
545
diff
changeset
|
2889 #endif |
342 | 2890 |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2891 gc_epilogue(false); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2892 } |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2893 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2894 assert(verify_region_lists(), "Bad region lists."); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2895 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2896 if (ExitAfterGCNum > 0 && total_collections() == ExitAfterGCNum) { |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2897 gclog_or_tty->print_cr("Stopping after GC #%d", ExitAfterGCNum); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2898 print_tracing_info(); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2899 vm_exit(-1); |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2900 } |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2901 } |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2902 |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2903 if (PrintHeapAtGC) { |
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
2904 Universe::print_heap_after_gc(); |
342 | 2905 } |
884
83b687ce3090
6866591: G1: print update buffer processing stats more often
tonyp
parents:
883
diff
changeset
|
2906 if (G1SummarizeRSetStats && |
83b687ce3090
6866591: G1: print update buffer processing stats more often
tonyp
parents:
883
diff
changeset
|
2907 (G1SummarizeRSetStatsPeriod > 0) && |
83b687ce3090
6866591: G1: print update buffer processing stats more often
tonyp
parents:
883
diff
changeset
|
2908 (total_collections() % G1SummarizeRSetStatsPeriod == 0)) { |
83b687ce3090
6866591: G1: print update buffer processing stats more often
tonyp
parents:
883
diff
changeset
|
2909 g1_rem_set()->print_summary_info(); |
83b687ce3090
6866591: G1: print update buffer processing stats more often
tonyp
parents:
883
diff
changeset
|
2910 } |
342 | 2911 } |
2912 | |
1391
79e419e5ea3b
6942253: G1: replace G1ParallelGCAllocBufferSize with YoungPLABSize and OldPLABSize
apetrusenko
parents:
1390
diff
changeset
|
2913 size_t G1CollectedHeap::desired_plab_sz(GCAllocPurpose purpose) |
79e419e5ea3b
6942253: G1: replace G1ParallelGCAllocBufferSize with YoungPLABSize and OldPLABSize
apetrusenko
parents:
1390
diff
changeset
|
2914 { |
79e419e5ea3b
6942253: G1: replace G1ParallelGCAllocBufferSize with YoungPLABSize and OldPLABSize
apetrusenko
parents:
1390
diff
changeset
|
2915 size_t gclab_word_size; |
79e419e5ea3b
6942253: G1: replace G1ParallelGCAllocBufferSize with YoungPLABSize and OldPLABSize
apetrusenko
parents:
1390
diff
changeset
|
2916 switch (purpose) { |
79e419e5ea3b
6942253: G1: replace G1ParallelGCAllocBufferSize with YoungPLABSize and OldPLABSize
apetrusenko
parents:
1390
diff
changeset
|
2917 case GCAllocForSurvived: |
79e419e5ea3b
6942253: G1: replace G1ParallelGCAllocBufferSize with YoungPLABSize and OldPLABSize
apetrusenko
parents:
1390
diff
changeset
|
2918 gclab_word_size = YoungPLABSize; |
79e419e5ea3b
6942253: G1: replace G1ParallelGCAllocBufferSize with YoungPLABSize and OldPLABSize
apetrusenko
parents:
1390
diff
changeset
|
2919 break; |
79e419e5ea3b
6942253: G1: replace G1ParallelGCAllocBufferSize with YoungPLABSize and OldPLABSize
apetrusenko
parents:
1390
diff
changeset
|
2920 case GCAllocForTenured: |
79e419e5ea3b
6942253: G1: replace G1ParallelGCAllocBufferSize with YoungPLABSize and OldPLABSize
apetrusenko
parents:
1390
diff
changeset
|
2921 gclab_word_size = OldPLABSize; |
79e419e5ea3b
6942253: G1: replace G1ParallelGCAllocBufferSize with YoungPLABSize and OldPLABSize
apetrusenko
parents:
1390
diff
changeset
|
2922 break; |
79e419e5ea3b
6942253: G1: replace G1ParallelGCAllocBufferSize with YoungPLABSize and OldPLABSize
apetrusenko
parents:
1390
diff
changeset
|
2923 default: |
79e419e5ea3b
6942253: G1: replace G1ParallelGCAllocBufferSize with YoungPLABSize and OldPLABSize
apetrusenko
parents:
1390
diff
changeset
|
2924 assert(false, "unknown GCAllocPurpose"); |
79e419e5ea3b
6942253: G1: replace G1ParallelGCAllocBufferSize with YoungPLABSize and OldPLABSize
apetrusenko
parents:
1390
diff
changeset
|
2925 gclab_word_size = OldPLABSize; |
79e419e5ea3b
6942253: G1: replace G1ParallelGCAllocBufferSize with YoungPLABSize and OldPLABSize
apetrusenko
parents:
1390
diff
changeset
|
2926 break; |
79e419e5ea3b
6942253: G1: replace G1ParallelGCAllocBufferSize with YoungPLABSize and OldPLABSize
apetrusenko
parents:
1390
diff
changeset
|
2927 } |
79e419e5ea3b
6942253: G1: replace G1ParallelGCAllocBufferSize with YoungPLABSize and OldPLABSize
apetrusenko
parents:
1390
diff
changeset
|
2928 return gclab_word_size; |
79e419e5ea3b
6942253: G1: replace G1ParallelGCAllocBufferSize with YoungPLABSize and OldPLABSize
apetrusenko
parents:
1390
diff
changeset
|
2929 } |
79e419e5ea3b
6942253: G1: replace G1ParallelGCAllocBufferSize with YoungPLABSize and OldPLABSize
apetrusenko
parents:
1390
diff
changeset
|
2930 |
79e419e5ea3b
6942253: G1: replace G1ParallelGCAllocBufferSize with YoungPLABSize and OldPLABSize
apetrusenko
parents:
1390
diff
changeset
|
2931 |
342 | 2932 void G1CollectedHeap::set_gc_alloc_region(int purpose, HeapRegion* r) { |
2933 assert(purpose >= 0 && purpose < GCAllocPurposeCount, "invalid purpose"); | |
636 | 2934 // make sure we don't call set_gc_alloc_region() multiple times on |
2935 // the same region | |
2936 assert(r == NULL || !r->is_gc_alloc_region(), | |
2937 "shouldn't already be a GC alloc region"); | |
1360
bda703475ded
6940894: G1: assert(new_obj != 0 || ... "should be forwarded") for compaction tests
johnc
parents:
1359
diff
changeset
|
2938 assert(r == NULL || !r->isHumongous(), |
bda703475ded
6940894: G1: assert(new_obj != 0 || ... "should be forwarded") for compaction tests
johnc
parents:
1359
diff
changeset
|
2939 "humongous regions shouldn't be used as GC alloc regions"); |
bda703475ded
6940894: G1: assert(new_obj != 0 || ... "should be forwarded") for compaction tests
johnc
parents:
1359
diff
changeset
|
2940 |
342 | 2941 HeapWord* original_top = NULL; |
2942 if (r != NULL) | |
2943 original_top = r->top(); | |
2944 | |
2945 // We will want to record the used space in r as being there before gc. | |
2946 // One we install it as a GC alloc region it's eligible for allocation. | |
2947 // So record it now and use it later. | |
2948 size_t r_used = 0; | |
2949 if (r != NULL) { | |
2950 r_used = r->used(); | |
2951 | |
2952 if (ParallelGCThreads > 0) { | |
2953 // need to take the lock to guard against two threads calling | |
2954 // get_gc_alloc_region concurrently (very unlikely but...) | |
2955 MutexLockerEx x(ParGCRareEvent_lock, Mutex::_no_safepoint_check_flag); | |
2956 r->save_marks(); | |
2957 } | |
2958 } | |
2959 HeapRegion* old_alloc_region = _gc_alloc_regions[purpose]; | |
2960 _gc_alloc_regions[purpose] = r; | |
2961 if (old_alloc_region != NULL) { | |
2962 // Replace aliases too. | |
2963 for (int ap = 0; ap < GCAllocPurposeCount; ++ap) { | |
2964 if (_gc_alloc_regions[ap] == old_alloc_region) { | |
2965 _gc_alloc_regions[ap] = r; | |
2966 } | |
2967 } | |
2968 } | |
2969 if (r != NULL) { | |
2970 push_gc_alloc_region(r); | |
2971 if (mark_in_progress() && original_top != r->next_top_at_mark_start()) { | |
2972 // We are using a region as a GC alloc region after it has been used | |
2973 // as a mutator allocation region during the current marking cycle. | |
2974 // The mutator-allocated objects are currently implicitly marked, but | |
2975 // when we move hr->next_top_at_mark_start() forward at the the end | |
2976 // of the GC pause, they won't be. We therefore mark all objects in | |
2977 // the "gap". We do this object-by-object, since marking densely | |
2978 // does not currently work right with marking bitmap iteration. This | |
2979 // means we rely on TLAB filling at the start of pauses, and no | |
2980 // "resuscitation" of filled TLAB's. If we want to do this, we need | |
2981 // to fix the marking bitmap iteration. | |
2982 HeapWord* curhw = r->next_top_at_mark_start(); | |
2983 HeapWord* t = original_top; | |
2984 | |
2985 while (curhw < t) { | |
2986 oop cur = (oop)curhw; | |
2987 // We'll assume parallel for generality. This is rare code. | |
2988 concurrent_mark()->markAndGrayObjectIfNecessary(cur); // can't we just mark them? | |
2989 curhw = curhw + cur->size(); | |
2990 } | |
2991 assert(curhw == t, "Should have parsed correctly."); | |
2992 } | |
2993 if (G1PolicyVerbose > 1) { | |
2994 gclog_or_tty->print("New alloc region ["PTR_FORMAT", "PTR_FORMAT", " PTR_FORMAT") " | |
2995 "for survivors:", r->bottom(), original_top, r->end()); | |
2996 r->print(); | |
2997 } | |
2998 g1_policy()->record_before_bytes(r_used); | |
2999 } | |
3000 } | |
3001 | |
3002 void G1CollectedHeap::push_gc_alloc_region(HeapRegion* hr) { | |
3003 assert(Thread::current()->is_VM_thread() || | |
3004 par_alloc_during_gc_lock()->owned_by_self(), "Precondition"); | |
3005 assert(!hr->is_gc_alloc_region() && !hr->in_collection_set(), | |
3006 "Precondition."); | |
3007 hr->set_is_gc_alloc_region(true); | |
3008 hr->set_next_gc_alloc_region(_gc_alloc_region_list); | |
3009 _gc_alloc_region_list = hr; | |
3010 } | |
3011 | |
3012 #ifdef G1_DEBUG | |
3013 class FindGCAllocRegion: public HeapRegionClosure { | |
3014 public: | |
3015 bool doHeapRegion(HeapRegion* r) { | |
3016 if (r->is_gc_alloc_region()) { | |
3017 gclog_or_tty->print_cr("Region %d ["PTR_FORMAT"...] is still a gc_alloc_region.", | |
3018 r->hrs_index(), r->bottom()); | |
3019 } | |
3020 return false; | |
3021 } | |
3022 }; | |
3023 #endif // G1_DEBUG | |
3024 | |
3025 void G1CollectedHeap::forget_alloc_region_list() { | |
3026 assert(Thread::current()->is_VM_thread(), "Precondition"); | |
3027 while (_gc_alloc_region_list != NULL) { | |
3028 HeapRegion* r = _gc_alloc_region_list; | |
3029 assert(r->is_gc_alloc_region(), "Invariant."); | |
637
25e146966e7c
6817419: G1: Enable extensive verification for humongous regions
iveresov
parents:
636
diff
changeset
|
3030 // We need HeapRegion::oops_on_card_seq_iterate_careful() to work on |
25e146966e7c
6817419: G1: Enable extensive verification for humongous regions
iveresov
parents:
636
diff
changeset
|
3031 // newly allocated data in order to be able to apply deferred updates |
25e146966e7c
6817419: G1: Enable extensive verification for humongous regions
iveresov
parents:
636
diff
changeset
|
3032 // before the GC is done for verification purposes (i.e to allow |
25e146966e7c
6817419: G1: Enable extensive verification for humongous regions
iveresov
parents:
636
diff
changeset
|
3033 // G1HRRSFlushLogBuffersOnVerify). It's safe thing to do after the |
25e146966e7c
6817419: G1: Enable extensive verification for humongous regions
iveresov
parents:
636
diff
changeset
|
3034 // collection. |
25e146966e7c
6817419: G1: Enable extensive verification for humongous regions
iveresov
parents:
636
diff
changeset
|
3035 r->ContiguousSpace::set_saved_mark(); |
342 | 3036 _gc_alloc_region_list = r->next_gc_alloc_region(); |
3037 r->set_next_gc_alloc_region(NULL); | |
3038 r->set_is_gc_alloc_region(false); | |
545 | 3039 if (r->is_survivor()) { |
3040 if (r->is_empty()) { | |
3041 r->set_not_young(); | |
3042 } else { | |
3043 _young_list->add_survivor_region(r); | |
3044 } | |
3045 } | |
342 | 3046 if (r->is_empty()) { |
3047 ++_free_regions; | |
3048 } | |
3049 } | |
3050 #ifdef G1_DEBUG | |
3051 FindGCAllocRegion fa; | |
3052 heap_region_iterate(&fa); | |
3053 #endif // G1_DEBUG | |
3054 } | |
3055 | |
3056 | |
3057 bool G1CollectedHeap::check_gc_alloc_regions() { | |
3058 // TODO: allocation regions check | |
3059 return true; | |
3060 } | |
3061 | |
3062 void G1CollectedHeap::get_gc_alloc_regions() { | |
636 | 3063 // First, let's check that the GC alloc region list is empty (it should) |
3064 assert(_gc_alloc_region_list == NULL, "invariant"); | |
3065 | |
342 | 3066 for (int ap = 0; ap < GCAllocPurposeCount; ++ap) { |
636 | 3067 assert(_gc_alloc_regions[ap] == NULL, "invariant"); |
861
45d97a99715b
6862661: G1: _gc_alloc_region_counts is not updated properly after 6604422
apetrusenko
parents:
846
diff
changeset
|
3068 assert(_gc_alloc_region_counts[ap] == 0, "invariant"); |
636 | 3069 |
342 | 3070 // Create new GC alloc regions. |
636 | 3071 HeapRegion* alloc_region = _retained_gc_alloc_regions[ap]; |
3072 _retained_gc_alloc_regions[ap] = NULL; | |
3073 | |
3074 if (alloc_region != NULL) { | |
3075 assert(_retain_gc_alloc_region[ap], "only way to retain a GC region"); | |
3076 | |
3077 // let's make sure that the GC alloc region is not tagged as such | |
3078 // outside a GC operation | |
3079 assert(!alloc_region->is_gc_alloc_region(), "sanity"); | |
3080 | |
3081 if (alloc_region->in_collection_set() || | |
3082 alloc_region->top() == alloc_region->end() || | |
1360
bda703475ded
6940894: G1: assert(new_obj != 0 || ... "should be forwarded") for compaction tests
johnc
parents:
1359
diff
changeset
|
3083 alloc_region->top() == alloc_region->bottom() || |
bda703475ded
6940894: G1: assert(new_obj != 0 || ... "should be forwarded") for compaction tests
johnc
parents:
1359
diff
changeset
|
3084 alloc_region->isHumongous()) { |
bda703475ded
6940894: G1: assert(new_obj != 0 || ... "should be forwarded") for compaction tests
johnc
parents:
1359
diff
changeset
|
3085 // we will discard the current GC alloc region if |
bda703475ded
6940894: G1: assert(new_obj != 0 || ... "should be forwarded") for compaction tests
johnc
parents:
1359
diff
changeset
|
3086 // * it's in the collection set (it can happen!), |
bda703475ded
6940894: G1: assert(new_obj != 0 || ... "should be forwarded") for compaction tests
johnc
parents:
1359
diff
changeset
|
3087 // * it's already full (no point in using it), |
bda703475ded
6940894: G1: assert(new_obj != 0 || ... "should be forwarded") for compaction tests
johnc
parents:
1359
diff
changeset
|
3088 // * it's empty (this means that it was emptied during |
bda703475ded
6940894: G1: assert(new_obj != 0 || ... "should be forwarded") for compaction tests
johnc
parents:
1359
diff
changeset
|
3089 // a cleanup and it should be on the free list now), or |
bda703475ded
6940894: G1: assert(new_obj != 0 || ... "should be forwarded") for compaction tests
johnc
parents:
1359
diff
changeset
|
3090 // * it's humongous (this means that it was emptied |
bda703475ded
6940894: G1: assert(new_obj != 0 || ... "should be forwarded") for compaction tests
johnc
parents:
1359
diff
changeset
|
3091 // during a cleanup and was added to the free list, but |
bda703475ded
6940894: G1: assert(new_obj != 0 || ... "should be forwarded") for compaction tests
johnc
parents:
1359
diff
changeset
|
3092 // has been subseqently used to allocate a humongous |
bda703475ded
6940894: G1: assert(new_obj != 0 || ... "should be forwarded") for compaction tests
johnc
parents:
1359
diff
changeset
|
3093 // object that may be less than the region size). |
636 | 3094 |
3095 alloc_region = NULL; | |
3096 } | |
3097 } | |
3098 | |
3099 if (alloc_region == NULL) { | |
3100 // we will get a new GC alloc region | |
342 | 3101 alloc_region = newAllocRegionWithExpansion(ap, 0); |
861
45d97a99715b
6862661: G1: _gc_alloc_region_counts is not updated properly after 6604422
apetrusenko
parents:
846
diff
changeset
|
3102 } else { |
45d97a99715b
6862661: G1: _gc_alloc_region_counts is not updated properly after 6604422
apetrusenko
parents:
846
diff
changeset
|
3103 // the region was retained from the last collection |
45d97a99715b
6862661: G1: _gc_alloc_region_counts is not updated properly after 6604422
apetrusenko
parents:
846
diff
changeset
|
3104 ++_gc_alloc_region_counts[ap]; |
1388 | 3105 if (G1PrintHeapRegions) { |
3106 gclog_or_tty->print_cr("new alloc region %d:["PTR_FORMAT", "PTR_FORMAT"], " | |
3107 "top "PTR_FORMAT, | |
3108 alloc_region->hrs_index(), alloc_region->bottom(), alloc_region->end(), alloc_region->top()); | |
3109 } | |
342 | 3110 } |
636 | 3111 |
342 | 3112 if (alloc_region != NULL) { |
636 | 3113 assert(_gc_alloc_regions[ap] == NULL, "pre-condition"); |
342 | 3114 set_gc_alloc_region(ap, alloc_region); |
3115 } | |
636 | 3116 |
3117 assert(_gc_alloc_regions[ap] == NULL || | |
3118 _gc_alloc_regions[ap]->is_gc_alloc_region(), | |
3119 "the GC alloc region should be tagged as such"); | |
3120 assert(_gc_alloc_regions[ap] == NULL || | |
3121 _gc_alloc_regions[ap] == _gc_alloc_region_list, | |
3122 "the GC alloc region should be the same as the GC alloc list head"); | |
342 | 3123 } |
3124 // Set alternative regions for allocation purposes that have reached | |
636 | 3125 // their limit. |
342 | 3126 for (int ap = 0; ap < GCAllocPurposeCount; ++ap) { |
3127 GCAllocPurpose alt_purpose = g1_policy()->alternative_purpose(ap); | |
3128 if (_gc_alloc_regions[ap] == NULL && alt_purpose != ap) { | |
3129 _gc_alloc_regions[ap] = _gc_alloc_regions[alt_purpose]; | |
3130 } | |
3131 } | |
3132 assert(check_gc_alloc_regions(), "alloc regions messed up"); | |
3133 } | |
3134 | |
636 | 3135 void G1CollectedHeap::release_gc_alloc_regions(bool totally) { |
342 | 3136 // We keep a separate list of all regions that have been alloc regions in |
636 | 3137 // the current collection pause. Forget that now. This method will |
3138 // untag the GC alloc regions and tear down the GC alloc region | |
3139 // list. It's desirable that no regions are tagged as GC alloc | |
3140 // outside GCs. | |
342 | 3141 forget_alloc_region_list(); |
3142 | |
3143 // The current alloc regions contain objs that have survived | |
3144 // collection. Make them no longer GC alloc regions. | |
3145 for (int ap = 0; ap < GCAllocPurposeCount; ++ap) { | |
3146 HeapRegion* r = _gc_alloc_regions[ap]; | |
636 | 3147 _retained_gc_alloc_regions[ap] = NULL; |
861
45d97a99715b
6862661: G1: _gc_alloc_region_counts is not updated properly after 6604422
apetrusenko
parents:
846
diff
changeset
|
3148 _gc_alloc_region_counts[ap] = 0; |
636 | 3149 |
3150 if (r != NULL) { | |
3151 // we retain nothing on _gc_alloc_regions between GCs | |
3152 set_gc_alloc_region(ap, NULL); | |
3153 | |
3154 if (r->is_empty()) { | |
3155 // we didn't actually allocate anything in it; let's just put | |
3156 // it on the free list | |
342 | 3157 MutexLockerEx x(ZF_mon, Mutex::_no_safepoint_check_flag); |
3158 r->set_zero_fill_complete(); | |
3159 put_free_region_on_list_locked(r); | |
636 | 3160 } else if (_retain_gc_alloc_region[ap] && !totally) { |
3161 // retain it so that we can use it at the beginning of the next GC | |
3162 _retained_gc_alloc_regions[ap] = r; | |
342 | 3163 } |
3164 } | |
636 | 3165 } |
3166 } | |
3167 | |
3168 #ifndef PRODUCT | |
3169 // Useful for debugging | |
3170 | |
3171 void G1CollectedHeap::print_gc_alloc_regions() { | |
3172 gclog_or_tty->print_cr("GC alloc regions"); | |
3173 for (int ap = 0; ap < GCAllocPurposeCount; ++ap) { | |
3174 HeapRegion* r = _gc_alloc_regions[ap]; | |
3175 if (r == NULL) { | |
3176 gclog_or_tty->print_cr(" %2d : "PTR_FORMAT, ap, NULL); | |
3177 } else { | |
3178 gclog_or_tty->print_cr(" %2d : "PTR_FORMAT" "SIZE_FORMAT, | |
3179 ap, r->bottom(), r->used()); | |
3180 } | |
3181 } | |
3182 } | |
3183 #endif // PRODUCT | |
342 | 3184 |
3185 void G1CollectedHeap::init_for_evac_failure(OopsInHeapRegionClosure* cl) { | |
3186 _drain_in_progress = false; | |
3187 set_evac_failure_closure(cl); | |
3188 _evac_failure_scan_stack = new (ResourceObj::C_HEAP) GrowableArray<oop>(40, true); | |
3189 } | |
3190 | |
3191 void G1CollectedHeap::finalize_for_evac_failure() { | |
3192 assert(_evac_failure_scan_stack != NULL && | |
3193 _evac_failure_scan_stack->length() == 0, | |
3194 "Postcondition"); | |
3195 assert(!_drain_in_progress, "Postcondition"); | |
1045 | 3196 delete _evac_failure_scan_stack; |
342 | 3197 _evac_failure_scan_stack = NULL; |
3198 } | |
3199 | |
3200 | |
3201 | |
3202 // *** Sequential G1 Evacuation | |
3203 | |
3204 HeapWord* G1CollectedHeap::allocate_during_gc(GCAllocPurpose purpose, size_t word_size) { | |
3205 HeapRegion* alloc_region = _gc_alloc_regions[purpose]; | |
3206 // let the caller handle alloc failure | |
3207 if (alloc_region == NULL) return NULL; | |
3208 assert(isHumongous(word_size) || !alloc_region->isHumongous(), | |
3209 "Either the object is humongous or the region isn't"); | |
3210 HeapWord* block = alloc_region->allocate(word_size); | |
3211 if (block == NULL) { | |
3212 block = allocate_during_gc_slow(purpose, alloc_region, false, word_size); | |
3213 } | |
3214 return block; | |
3215 } | |
3216 | |
3217 class G1IsAliveClosure: public BoolObjectClosure { | |
3218 G1CollectedHeap* _g1; | |
3219 public: | |
3220 G1IsAliveClosure(G1CollectedHeap* g1) : _g1(g1) {} | |
3221 void do_object(oop p) { assert(false, "Do not call."); } | |
3222 bool do_object_b(oop p) { | |
3223 // It is reachable if it is outside the collection set, or is inside | |
3224 // and forwarded. | |
3225 | |
3226 #ifdef G1_DEBUG | |
3227 gclog_or_tty->print_cr("is alive "PTR_FORMAT" in CS %d forwarded %d overall %d", | |
3228 (void*) p, _g1->obj_in_cs(p), p->is_forwarded(), | |
3229 !_g1->obj_in_cs(p) || p->is_forwarded()); | |
3230 #endif // G1_DEBUG | |
3231 | |
3232 return !_g1->obj_in_cs(p) || p->is_forwarded(); | |
3233 } | |
3234 }; | |
3235 | |
3236 class G1KeepAliveClosure: public OopClosure { | |
3237 G1CollectedHeap* _g1; | |
3238 public: | |
3239 G1KeepAliveClosure(G1CollectedHeap* g1) : _g1(g1) {} | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3240 void do_oop(narrowOop* p) { guarantee(false, "Not needed"); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3241 void do_oop( oop* p) { |
342 | 3242 oop obj = *p; |
3243 #ifdef G1_DEBUG | |
3244 if (PrintGC && Verbose) { | |
3245 gclog_or_tty->print_cr("keep alive *"PTR_FORMAT" = "PTR_FORMAT" "PTR_FORMAT, | |
3246 p, (void*) obj, (void*) *p); | |
3247 } | |
3248 #endif // G1_DEBUG | |
3249 | |
3250 if (_g1->obj_in_cs(obj)) { | |
3251 assert( obj->is_forwarded(), "invariant" ); | |
3252 *p = obj->forwardee(); | |
3253 #ifdef G1_DEBUG | |
3254 gclog_or_tty->print_cr(" in CSet: moved "PTR_FORMAT" -> "PTR_FORMAT, | |
3255 (void*) obj, (void*) *p); | |
3256 #endif // G1_DEBUG | |
3257 } | |
3258 } | |
3259 }; | |
3260 | |
616
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3261 class UpdateRSetImmediate : public OopsInHeapRegionClosure { |
342 | 3262 private: |
3263 G1CollectedHeap* _g1; | |
3264 G1RemSet* _g1_rem_set; | |
3265 public: | |
616
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3266 UpdateRSetImmediate(G1CollectedHeap* g1) : |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3267 _g1(g1), _g1_rem_set(g1->g1_rem_set()) {} |
342 | 3268 |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3269 virtual void do_oop(narrowOop* p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3270 virtual void do_oop( oop* p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3271 template <class T> void do_oop_work(T* p) { |
342 | 3272 assert(_from->is_in_reserved(p), "paranoia"); |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3273 T heap_oop = oopDesc::load_heap_oop(p); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3274 if (!oopDesc::is_null(heap_oop) && !_from->is_survivor()) { |
616
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3275 _g1_rem_set->par_write_ref(_from, p, 0); |
342 | 3276 } |
3277 } | |
3278 }; | |
3279 | |
616
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3280 class UpdateRSetDeferred : public OopsInHeapRegionClosure { |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3281 private: |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3282 G1CollectedHeap* _g1; |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3283 DirtyCardQueue *_dcq; |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3284 CardTableModRefBS* _ct_bs; |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3285 |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3286 public: |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3287 UpdateRSetDeferred(G1CollectedHeap* g1, DirtyCardQueue* dcq) : |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3288 _g1(g1), _ct_bs((CardTableModRefBS*)_g1->barrier_set()), _dcq(dcq) {} |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3289 |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3290 virtual void do_oop(narrowOop* p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3291 virtual void do_oop( oop* p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3292 template <class T> void do_oop_work(T* p) { |
616
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3293 assert(_from->is_in_reserved(p), "paranoia"); |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3294 if (!_from->is_in_reserved(oopDesc::load_decode_heap_oop(p)) && |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3295 !_from->is_survivor()) { |
616
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3296 size_t card_index = _ct_bs->index_for(p); |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3297 if (_ct_bs->mark_card_deferred(card_index)) { |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3298 _dcq->enqueue((jbyte*)_ct_bs->byte_for_index(card_index)); |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3299 } |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3300 } |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3301 } |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3302 }; |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3303 |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3304 |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3305 |
342 | 3306 class RemoveSelfPointerClosure: public ObjectClosure { |
3307 private: | |
3308 G1CollectedHeap* _g1; | |
3309 ConcurrentMark* _cm; | |
3310 HeapRegion* _hr; | |
3311 size_t _prev_marked_bytes; | |
3312 size_t _next_marked_bytes; | |
616
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3313 OopsInHeapRegionClosure *_cl; |
342 | 3314 public: |
616
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3315 RemoveSelfPointerClosure(G1CollectedHeap* g1, OopsInHeapRegionClosure* cl) : |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3316 _g1(g1), _cm(_g1->concurrent_mark()), _prev_marked_bytes(0), |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3317 _next_marked_bytes(0), _cl(cl) {} |
342 | 3318 |
3319 size_t prev_marked_bytes() { return _prev_marked_bytes; } | |
3320 size_t next_marked_bytes() { return _next_marked_bytes; } | |
3321 | |
352
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3322 // The original idea here was to coalesce evacuated and dead objects. |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3323 // However that caused complications with the block offset table (BOT). |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3324 // In particular if there were two TLABs, one of them partially refined. |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3325 // |----- TLAB_1--------|----TLAB_2-~~~(partially refined part)~~~| |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3326 // The BOT entries of the unrefined part of TLAB_2 point to the start |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3327 // of TLAB_2. If the last object of the TLAB_1 and the first object |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3328 // of TLAB_2 are coalesced, then the cards of the unrefined part |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3329 // would point into middle of the filler object. |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3330 // |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3331 // The current approach is to not coalesce and leave the BOT contents intact. |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3332 void do_object(oop obj) { |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3333 if (obj->is_forwarded() && obj->forwardee() == obj) { |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3334 // The object failed to move. |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3335 assert(!_g1->is_obj_dead(obj), "We should not be preserving dead objs."); |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3336 _cm->markPrev(obj); |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3337 assert(_cm->isPrevMarked(obj), "Should be marked!"); |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3338 _prev_marked_bytes += (obj->size() * HeapWordSize); |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3339 if (_g1->mark_in_progress() && !_g1->is_obj_ill(obj)) { |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3340 _cm->markAndGrayObjectIfNecessary(obj); |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3341 } |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3342 obj->set_mark(markOopDesc::prototype()); |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3343 // While we were processing RSet buffers during the |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3344 // collection, we actually didn't scan any cards on the |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3345 // collection set, since we didn't want to update remebered |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3346 // sets with entries that point into the collection set, given |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3347 // that live objects fromthe collection set are about to move |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3348 // and such entries will be stale very soon. This change also |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3349 // dealt with a reliability issue which involved scanning a |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3350 // card in the collection set and coming across an array that |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3351 // was being chunked and looking malformed. The problem is |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3352 // that, if evacuation fails, we might have remembered set |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3353 // entries missing given that we skipped cards on the |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3354 // collection set. So, we'll recreate such entries now. |
616
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3355 obj->oop_iterate(_cl); |
352
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3356 assert(_cm->isPrevMarked(obj), "Should be marked!"); |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3357 } else { |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3358 // The object has been either evacuated or is dead. Fill it with a |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3359 // dummy object. |
e0c09f7ec5c4
6702387: G1: assertion failure: assert(p == current_top || oop(p)->is_oop(),"p is not a block start")
iveresov
parents:
342
diff
changeset
|
3360 MemRegion mr((HeapWord*)obj, obj->size()); |
481
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
457
diff
changeset
|
3361 CollectedHeap::fill_with_object(mr); |
342 | 3362 _cm->clearRangeBothMaps(mr); |
3363 } | |
3364 } | |
3365 }; | |
3366 | |
3367 void G1CollectedHeap::remove_self_forwarding_pointers() { | |
616
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3368 UpdateRSetImmediate immediate_update(_g1h); |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3369 DirtyCardQueue dcq(&_g1h->dirty_card_queue_set()); |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3370 UpdateRSetDeferred deferred_update(_g1h, &dcq); |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3371 OopsInHeapRegionClosure *cl; |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3372 if (G1DeferredRSUpdate) { |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3373 cl = &deferred_update; |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3374 } else { |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3375 cl = &immediate_update; |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3376 } |
342 | 3377 HeapRegion* cur = g1_policy()->collection_set(); |
3378 while (cur != NULL) { | |
3379 assert(g1_policy()->assertMarkedBytesDataOK(), "Should be!"); | |
3380 | |
616
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3381 RemoveSelfPointerClosure rspc(_g1h, cl); |
342 | 3382 if (cur->evacuation_failed()) { |
3383 assert(cur->in_collection_set(), "bad CS"); | |
616
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3384 cl->set_region(cur); |
342 | 3385 cur->object_iterate(&rspc); |
3386 | |
3387 // A number of manipulations to make the TAMS be the current top, | |
3388 // and the marked bytes be the ones observed in the iteration. | |
3389 if (_g1h->concurrent_mark()->at_least_one_mark_complete()) { | |
3390 // The comments below are the postconditions achieved by the | |
3391 // calls. Note especially the last such condition, which says that | |
3392 // the count of marked bytes has been properly restored. | |
3393 cur->note_start_of_marking(false); | |
3394 // _next_top_at_mark_start == top, _next_marked_bytes == 0 | |
3395 cur->add_to_marked_bytes(rspc.prev_marked_bytes()); | |
3396 // _next_marked_bytes == prev_marked_bytes. | |
3397 cur->note_end_of_marking(); | |
3398 // _prev_top_at_mark_start == top(), | |
3399 // _prev_marked_bytes == prev_marked_bytes | |
3400 } | |
3401 // If there is no mark in progress, we modified the _next variables | |
3402 // above needlessly, but harmlessly. | |
3403 if (_g1h->mark_in_progress()) { | |
3404 cur->note_start_of_marking(false); | |
3405 // _next_top_at_mark_start == top, _next_marked_bytes == 0 | |
3406 // _next_marked_bytes == next_marked_bytes. | |
3407 } | |
3408 | |
3409 // Now make sure the region has the right index in the sorted array. | |
3410 g1_policy()->note_change_in_marked_bytes(cur); | |
3411 } | |
3412 cur = cur->next_in_collection_set(); | |
3413 } | |
3414 assert(g1_policy()->assertMarkedBytesDataOK(), "Should be!"); | |
3415 | |
3416 // Now restore saved marks, if any. | |
3417 if (_objs_with_preserved_marks != NULL) { | |
3418 assert(_preserved_marks_of_objs != NULL, "Both or none."); | |
3419 assert(_objs_with_preserved_marks->length() == | |
3420 _preserved_marks_of_objs->length(), "Both or none."); | |
3421 guarantee(_objs_with_preserved_marks->length() == | |
3422 _preserved_marks_of_objs->length(), "Both or none."); | |
3423 for (int i = 0; i < _objs_with_preserved_marks->length(); i++) { | |
3424 oop obj = _objs_with_preserved_marks->at(i); | |
3425 markOop m = _preserved_marks_of_objs->at(i); | |
3426 obj->set_mark(m); | |
3427 } | |
3428 // Delete the preserved marks growable arrays (allocated on the C heap). | |
3429 delete _objs_with_preserved_marks; | |
3430 delete _preserved_marks_of_objs; | |
3431 _objs_with_preserved_marks = NULL; | |
3432 _preserved_marks_of_objs = NULL; | |
3433 } | |
3434 } | |
3435 | |
3436 void G1CollectedHeap::push_on_evac_failure_scan_stack(oop obj) { | |
3437 _evac_failure_scan_stack->push(obj); | |
3438 } | |
3439 | |
3440 void G1CollectedHeap::drain_evac_failure_scan_stack() { | |
3441 assert(_evac_failure_scan_stack != NULL, "precondition"); | |
3442 | |
3443 while (_evac_failure_scan_stack->length() > 0) { | |
3444 oop obj = _evac_failure_scan_stack->pop(); | |
3445 _evac_failure_closure->set_region(heap_region_containing(obj)); | |
3446 obj->oop_iterate_backwards(_evac_failure_closure); | |
3447 } | |
3448 } | |
3449 | |
3450 void G1CollectedHeap::handle_evacuation_failure(oop old) { | |
3451 markOop m = old->mark(); | |
3452 // forward to self | |
3453 assert(!old->is_forwarded(), "precondition"); | |
3454 | |
3455 old->forward_to(old); | |
3456 handle_evacuation_failure_common(old, m); | |
3457 } | |
3458 | |
3459 oop | |
3460 G1CollectedHeap::handle_evacuation_failure_par(OopsInHeapRegionClosure* cl, | |
3461 oop old) { | |
3462 markOop m = old->mark(); | |
3463 oop forward_ptr = old->forward_to_atomic(old); | |
3464 if (forward_ptr == NULL) { | |
3465 // Forward-to-self succeeded. | |
3466 if (_evac_failure_closure != cl) { | |
3467 MutexLockerEx x(EvacFailureStack_lock, Mutex::_no_safepoint_check_flag); | |
3468 assert(!_drain_in_progress, | |
3469 "Should only be true while someone holds the lock."); | |
3470 // Set the global evac-failure closure to the current thread's. | |
3471 assert(_evac_failure_closure == NULL, "Or locking has failed."); | |
3472 set_evac_failure_closure(cl); | |
3473 // Now do the common part. | |
3474 handle_evacuation_failure_common(old, m); | |
3475 // Reset to NULL. | |
3476 set_evac_failure_closure(NULL); | |
3477 } else { | |
3478 // The lock is already held, and this is recursive. | |
3479 assert(_drain_in_progress, "This should only be the recursive case."); | |
3480 handle_evacuation_failure_common(old, m); | |
3481 } | |
3482 return old; | |
3483 } else { | |
3484 // Someone else had a place to copy it. | |
3485 return forward_ptr; | |
3486 } | |
3487 } | |
3488 | |
3489 void G1CollectedHeap::handle_evacuation_failure_common(oop old, markOop m) { | |
3490 set_evacuation_failed(true); | |
3491 | |
3492 preserve_mark_if_necessary(old, m); | |
3493 | |
3494 HeapRegion* r = heap_region_containing(old); | |
3495 if (!r->evacuation_failed()) { | |
3496 r->set_evacuation_failed(true); | |
1282 | 3497 if (G1PrintHeapRegions) { |
342 | 3498 gclog_or_tty->print("evacuation failed in heap region "PTR_FORMAT" " |
3499 "["PTR_FORMAT","PTR_FORMAT")\n", | |
3500 r, r->bottom(), r->end()); | |
3501 } | |
3502 } | |
3503 | |
3504 push_on_evac_failure_scan_stack(old); | |
3505 | |
3506 if (!_drain_in_progress) { | |
3507 // prevent recursion in copy_to_survivor_space() | |
3508 _drain_in_progress = true; | |
3509 drain_evac_failure_scan_stack(); | |
3510 _drain_in_progress = false; | |
3511 } | |
3512 } | |
3513 | |
3514 void G1CollectedHeap::preserve_mark_if_necessary(oop obj, markOop m) { | |
3515 if (m != markOopDesc::prototype()) { | |
3516 if (_objs_with_preserved_marks == NULL) { | |
3517 assert(_preserved_marks_of_objs == NULL, "Both or none."); | |
3518 _objs_with_preserved_marks = | |
3519 new (ResourceObj::C_HEAP) GrowableArray<oop>(40, true); | |
3520 _preserved_marks_of_objs = | |
3521 new (ResourceObj::C_HEAP) GrowableArray<markOop>(40, true); | |
3522 } | |
3523 _objs_with_preserved_marks->push(obj); | |
3524 _preserved_marks_of_objs->push(m); | |
3525 } | |
3526 } | |
3527 | |
3528 // *** Parallel G1 Evacuation | |
3529 | |
3530 HeapWord* G1CollectedHeap::par_allocate_during_gc(GCAllocPurpose purpose, | |
3531 size_t word_size) { | |
3532 HeapRegion* alloc_region = _gc_alloc_regions[purpose]; | |
3533 // let the caller handle alloc failure | |
3534 if (alloc_region == NULL) return NULL; | |
3535 | |
3536 HeapWord* block = alloc_region->par_allocate(word_size); | |
3537 if (block == NULL) { | |
3538 MutexLockerEx x(par_alloc_during_gc_lock(), | |
3539 Mutex::_no_safepoint_check_flag); | |
3540 block = allocate_during_gc_slow(purpose, alloc_region, true, word_size); | |
3541 } | |
3542 return block; | |
3543 } | |
3544 | |
545 | 3545 void G1CollectedHeap::retire_alloc_region(HeapRegion* alloc_region, |
3546 bool par) { | |
3547 // Another thread might have obtained alloc_region for the given | |
3548 // purpose, and might be attempting to allocate in it, and might | |
3549 // succeed. Therefore, we can't do the "finalization" stuff on the | |
3550 // region below until we're sure the last allocation has happened. | |
3551 // We ensure this by allocating the remaining space with a garbage | |
3552 // object. | |
3553 if (par) par_allocate_remaining_space(alloc_region); | |
3554 // Now we can do the post-GC stuff on the region. | |
3555 alloc_region->note_end_of_copying(); | |
3556 g1_policy()->record_after_bytes(alloc_region->used()); | |
3557 } | |
3558 | |
342 | 3559 HeapWord* |
3560 G1CollectedHeap::allocate_during_gc_slow(GCAllocPurpose purpose, | |
3561 HeapRegion* alloc_region, | |
3562 bool par, | |
3563 size_t word_size) { | |
3564 HeapWord* block = NULL; | |
3565 // In the parallel case, a previous thread to obtain the lock may have | |
3566 // already assigned a new gc_alloc_region. | |
3567 if (alloc_region != _gc_alloc_regions[purpose]) { | |
3568 assert(par, "But should only happen in parallel case."); | |
3569 alloc_region = _gc_alloc_regions[purpose]; | |
3570 if (alloc_region == NULL) return NULL; | |
3571 block = alloc_region->par_allocate(word_size); | |
3572 if (block != NULL) return block; | |
3573 // Otherwise, continue; this new region is empty, too. | |
3574 } | |
3575 assert(alloc_region != NULL, "We better have an allocation region"); | |
545 | 3576 retire_alloc_region(alloc_region, par); |
342 | 3577 |
3578 if (_gc_alloc_region_counts[purpose] >= g1_policy()->max_regions(purpose)) { | |
3579 // Cannot allocate more regions for the given purpose. | |
3580 GCAllocPurpose alt_purpose = g1_policy()->alternative_purpose(purpose); | |
3581 // Is there an alternative? | |
3582 if (purpose != alt_purpose) { | |
3583 HeapRegion* alt_region = _gc_alloc_regions[alt_purpose]; | |
3584 // Has not the alternative region been aliased? | |
545 | 3585 if (alloc_region != alt_region && alt_region != NULL) { |
342 | 3586 // Try to allocate in the alternative region. |
3587 if (par) { | |
3588 block = alt_region->par_allocate(word_size); | |
3589 } else { | |
3590 block = alt_region->allocate(word_size); | |
3591 } | |
3592 // Make an alias. | |
3593 _gc_alloc_regions[purpose] = _gc_alloc_regions[alt_purpose]; | |
545 | 3594 if (block != NULL) { |
3595 return block; | |
3596 } | |
3597 retire_alloc_region(alt_region, par); | |
342 | 3598 } |
3599 // Both the allocation region and the alternative one are full | |
3600 // and aliased, replace them with a new allocation region. | |
3601 purpose = alt_purpose; | |
3602 } else { | |
3603 set_gc_alloc_region(purpose, NULL); | |
3604 return NULL; | |
3605 } | |
3606 } | |
3607 | |
3608 // Now allocate a new region for allocation. | |
3609 alloc_region = newAllocRegionWithExpansion(purpose, word_size, false /*zero_filled*/); | |
3610 | |
3611 // let the caller handle alloc failure | |
3612 if (alloc_region != NULL) { | |
3613 | |
3614 assert(check_gc_alloc_regions(), "alloc regions messed up"); | |
3615 assert(alloc_region->saved_mark_at_top(), | |
3616 "Mark should have been saved already."); | |
3617 // We used to assert that the region was zero-filled here, but no | |
3618 // longer. | |
3619 | |
3620 // This must be done last: once it's installed, other regions may | |
3621 // allocate in it (without holding the lock.) | |
3622 set_gc_alloc_region(purpose, alloc_region); | |
3623 | |
3624 if (par) { | |
3625 block = alloc_region->par_allocate(word_size); | |
3626 } else { | |
3627 block = alloc_region->allocate(word_size); | |
3628 } | |
3629 // Caller handles alloc failure. | |
3630 } else { | |
3631 // This sets other apis using the same old alloc region to NULL, also. | |
3632 set_gc_alloc_region(purpose, NULL); | |
3633 } | |
3634 return block; // May be NULL. | |
3635 } | |
3636 | |
3637 void G1CollectedHeap::par_allocate_remaining_space(HeapRegion* r) { | |
3638 HeapWord* block = NULL; | |
3639 size_t free_words; | |
3640 do { | |
3641 free_words = r->free()/HeapWordSize; | |
3642 // If there's too little space, no one can allocate, so we're done. | |
3643 if (free_words < (size_t)oopDesc::header_size()) return; | |
3644 // Otherwise, try to claim it. | |
3645 block = r->par_allocate(free_words); | |
3646 } while (block == NULL); | |
481
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
457
diff
changeset
|
3647 fill_with_object(block, free_words); |
342 | 3648 } |
3649 | |
3650 #ifndef PRODUCT | |
3651 bool GCLabBitMapClosure::do_bit(size_t offset) { | |
3652 HeapWord* addr = _bitmap->offsetToHeapWord(offset); | |
3653 guarantee(_cm->isMarked(oop(addr)), "it should be!"); | |
3654 return true; | |
3655 } | |
3656 #endif // PRODUCT | |
3657 | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3658 G1ParScanThreadState::G1ParScanThreadState(G1CollectedHeap* g1h, int queue_num) |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3659 : _g1h(g1h), |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3660 _refs(g1h->task_queue(queue_num)), |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3661 _dcq(&g1h->dirty_card_queue_set()), |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3662 _ct_bs((CardTableModRefBS*)_g1h->barrier_set()), |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3663 _g1_rem(g1h->g1_rem_set()), |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3664 _hash_seed(17), _queue_num(queue_num), |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3665 _term_attempts(0), |
1391
79e419e5ea3b
6942253: G1: replace G1ParallelGCAllocBufferSize with YoungPLABSize and OldPLABSize
apetrusenko
parents:
1390
diff
changeset
|
3666 _surviving_alloc_buffer(g1h->desired_plab_sz(GCAllocForSurvived)), |
79e419e5ea3b
6942253: G1: replace G1ParallelGCAllocBufferSize with YoungPLABSize and OldPLABSize
apetrusenko
parents:
1390
diff
changeset
|
3667 _tenured_alloc_buffer(g1h->desired_plab_sz(GCAllocForTenured)), |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3668 _age_table(false), |
342 | 3669 #if G1_DETAILED_STATS |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3670 _pushes(0), _pops(0), _steals(0), |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3671 _steal_attempts(0), _overflow_pushes(0), |
342 | 3672 #endif |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3673 _strong_roots_time(0), _term_time(0), |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3674 _alloc_buffer_waste(0), _undo_waste(0) |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3675 { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3676 // we allocate G1YoungSurvRateNumRegions plus one entries, since |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3677 // we "sacrifice" entry 0 to keep track of surviving bytes for |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3678 // non-young regions (where the age is -1) |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3679 // We also add a few elements at the beginning and at the end in |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3680 // an attempt to eliminate cache contention |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3681 size_t real_length = 1 + _g1h->g1_policy()->young_cset_length(); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3682 size_t array_length = PADDING_ELEM_NUM + |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3683 real_length + |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3684 PADDING_ELEM_NUM; |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3685 _surviving_young_words_base = NEW_C_HEAP_ARRAY(size_t, array_length); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3686 if (_surviving_young_words_base == NULL) |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3687 vm_exit_out_of_memory(array_length * sizeof(size_t), |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3688 "Not enough space for young surv histo."); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3689 _surviving_young_words = _surviving_young_words_base + PADDING_ELEM_NUM; |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3690 memset(_surviving_young_words, 0, real_length * sizeof(size_t)); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3691 |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3692 _overflowed_refs = new OverflowQueue(10); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3693 |
1391
79e419e5ea3b
6942253: G1: replace G1ParallelGCAllocBufferSize with YoungPLABSize and OldPLABSize
apetrusenko
parents:
1390
diff
changeset
|
3694 _alloc_buffers[GCAllocForSurvived] = &_surviving_alloc_buffer; |
79e419e5ea3b
6942253: G1: replace G1ParallelGCAllocBufferSize with YoungPLABSize and OldPLABSize
apetrusenko
parents:
1390
diff
changeset
|
3695 _alloc_buffers[GCAllocForTenured] = &_tenured_alloc_buffer; |
79e419e5ea3b
6942253: G1: replace G1ParallelGCAllocBufferSize with YoungPLABSize and OldPLABSize
apetrusenko
parents:
1390
diff
changeset
|
3696 |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3697 _start = os::elapsedTime(); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3698 } |
342 | 3699 |
3700 G1ParClosureSuper::G1ParClosureSuper(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state) : | |
3701 _g1(g1), _g1_rem(_g1->g1_rem_set()), _cm(_g1->concurrent_mark()), | |
3702 _par_scan_state(par_scan_state) { } | |
3703 | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3704 template <class T> void G1ParCopyHelper::mark_forwardee(T* p) { |
342 | 3705 // This is called _after_ do_oop_work has been called, hence after |
3706 // the object has been relocated to its new location and *p points | |
3707 // to its new location. | |
3708 | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3709 T heap_oop = oopDesc::load_heap_oop(p); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3710 if (!oopDesc::is_null(heap_oop)) { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3711 oop obj = oopDesc::decode_heap_oop(heap_oop); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3712 assert((_g1->evacuation_failed()) || (!_g1->obj_in_cs(obj)), |
342 | 3713 "shouldn't still be in the CSet if evacuation didn't fail."); |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3714 HeapWord* addr = (HeapWord*)obj; |
342 | 3715 if (_g1->is_in_g1_reserved(addr)) |
3716 _cm->grayRoot(oop(addr)); | |
3717 } | |
3718 } | |
3719 | |
3720 oop G1ParCopyHelper::copy_to_survivor_space(oop old) { | |
3721 size_t word_sz = old->size(); | |
3722 HeapRegion* from_region = _g1->heap_region_containing_raw(old); | |
3723 // +1 to make the -1 indexes valid... | |
3724 int young_index = from_region->young_index_in_cset()+1; | |
3725 assert( (from_region->is_young() && young_index > 0) || | |
3726 (!from_region->is_young() && young_index == 0), "invariant" ); | |
3727 G1CollectorPolicy* g1p = _g1->g1_policy(); | |
3728 markOop m = old->mark(); | |
545 | 3729 int age = m->has_displaced_mark_helper() ? m->displaced_mark_helper()->age() |
3730 : m->age(); | |
3731 GCAllocPurpose alloc_purpose = g1p->evacuation_destination(from_region, age, | |
342 | 3732 word_sz); |
3733 HeapWord* obj_ptr = _par_scan_state->allocate(alloc_purpose, word_sz); | |
3734 oop obj = oop(obj_ptr); | |
3735 | |
3736 if (obj_ptr == NULL) { | |
3737 // This will either forward-to-self, or detect that someone else has | |
3738 // installed a forwarding pointer. | |
3739 OopsInHeapRegionClosure* cl = _par_scan_state->evac_failure_closure(); | |
3740 return _g1->handle_evacuation_failure_par(cl, old); | |
3741 } | |
3742 | |
526 | 3743 // We're going to allocate linearly, so might as well prefetch ahead. |
3744 Prefetch::write(obj_ptr, PrefetchCopyIntervalInBytes); | |
3745 | |
342 | 3746 oop forward_ptr = old->forward_to_atomic(obj); |
3747 if (forward_ptr == NULL) { | |
3748 Copy::aligned_disjoint_words((HeapWord*) old, obj_ptr, word_sz); | |
526 | 3749 if (g1p->track_object_age(alloc_purpose)) { |
3750 // We could simply do obj->incr_age(). However, this causes a | |
3751 // performance issue. obj->incr_age() will first check whether | |
3752 // the object has a displaced mark by checking its mark word; | |
3753 // getting the mark word from the new location of the object | |
3754 // stalls. So, given that we already have the mark word and we | |
3755 // are about to install it anyway, it's better to increase the | |
3756 // age on the mark word, when the object does not have a | |
3757 // displaced mark word. We're not expecting many objects to have | |
3758 // a displaced marked word, so that case is not optimized | |
3759 // further (it could be...) and we simply call obj->incr_age(). | |
3760 | |
3761 if (m->has_displaced_mark_helper()) { | |
3762 // in this case, we have to install the mark word first, | |
3763 // otherwise obj looks to be forwarded (the old mark word, | |
3764 // which contains the forward pointer, was copied) | |
3765 obj->set_mark(m); | |
3766 obj->incr_age(); | |
3767 } else { | |
3768 m = m->incr_age(); | |
545 | 3769 obj->set_mark(m); |
526 | 3770 } |
545 | 3771 _par_scan_state->age_table()->add(obj, word_sz); |
3772 } else { | |
3773 obj->set_mark(m); | |
526 | 3774 } |
3775 | |
342 | 3776 // preserve "next" mark bit |
3777 if (_g1->mark_in_progress() && !_g1->is_obj_ill(old)) { | |
3778 if (!use_local_bitmaps || | |
3779 !_par_scan_state->alloc_buffer(alloc_purpose)->mark(obj_ptr)) { | |
3780 // if we couldn't mark it on the local bitmap (this happens when | |
3781 // the object was not allocated in the GCLab), we have to bite | |
3782 // the bullet and do the standard parallel mark | |
3783 _cm->markAndGrayObjectIfNecessary(obj); | |
3784 } | |
3785 #if 1 | |
3786 if (_g1->isMarkedNext(old)) { | |
3787 _cm->nextMarkBitMap()->parClear((HeapWord*)old); | |
3788 } | |
3789 #endif | |
3790 } | |
3791 | |
3792 size_t* surv_young_words = _par_scan_state->surviving_young_words(); | |
3793 surv_young_words[young_index] += word_sz; | |
3794 | |
3795 if (obj->is_objArray() && arrayOop(obj)->length() >= ParGCArrayScanChunk) { | |
3796 arrayOop(old)->set_length(0); | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3797 oop* old_p = set_partial_array_mask(old); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3798 _par_scan_state->push_on_queue(old_p); |
342 | 3799 } else { |
526 | 3800 // No point in using the slower heap_region_containing() method, |
3801 // given that we know obj is in the heap. | |
3802 _scanner->set_region(_g1->heap_region_containing_raw(obj)); | |
342 | 3803 obj->oop_iterate_backwards(_scanner); |
3804 } | |
3805 } else { | |
3806 _par_scan_state->undo_allocation(alloc_purpose, obj_ptr, word_sz); | |
3807 obj = forward_ptr; | |
3808 } | |
3809 return obj; | |
3810 } | |
3811 | |
1261
0414c1049f15
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
1245
diff
changeset
|
3812 template <bool do_gen_barrier, G1Barrier barrier, bool do_mark_forwardee> |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3813 template <class T> |
1261
0414c1049f15
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
1245
diff
changeset
|
3814 void G1ParCopyClosure <do_gen_barrier, barrier, do_mark_forwardee> |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3815 ::do_oop_work(T* p) { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3816 oop obj = oopDesc::load_decode_heap_oop(p); |
342 | 3817 assert(barrier != G1BarrierRS || obj != NULL, |
3818 "Precondition: G1BarrierRS implies obj is nonNull"); | |
3819 | |
526 | 3820 // here the null check is implicit in the cset_fast_test() test |
1261
0414c1049f15
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
1245
diff
changeset
|
3821 if (_g1->in_cset_fast_test(obj)) { |
342 | 3822 #if G1_REM_SET_LOGGING |
526 | 3823 gclog_or_tty->print_cr("Loc "PTR_FORMAT" contains pointer "PTR_FORMAT" " |
3824 "into CS.", p, (void*) obj); | |
342 | 3825 #endif |
526 | 3826 if (obj->is_forwarded()) { |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3827 oopDesc::encode_store_heap_oop(p, obj->forwardee()); |
526 | 3828 } else { |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3829 oop copy_oop = copy_to_survivor_space(obj); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3830 oopDesc::encode_store_heap_oop(p, copy_oop); |
342 | 3831 } |
526 | 3832 // When scanning the RS, we only care about objs in CS. |
3833 if (barrier == G1BarrierRS) { | |
616
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3834 _par_scan_state->update_rs(_from, p, _par_scan_state->queue_num()); |
342 | 3835 } |
526 | 3836 } |
3837 | |
3838 if (barrier == G1BarrierEvac && obj != NULL) { | |
616
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3839 _par_scan_state->update_rs(_from, p, _par_scan_state->queue_num()); |
526 | 3840 } |
3841 | |
3842 if (do_gen_barrier && obj != NULL) { | |
3843 par_do_barrier(p); | |
3844 } | |
3845 } | |
3846 | |
1261
0414c1049f15
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
1245
diff
changeset
|
3847 template void G1ParCopyClosure<false, G1BarrierEvac, false>::do_oop_work(oop* p); |
0414c1049f15
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
1245
diff
changeset
|
3848 template void G1ParCopyClosure<false, G1BarrierEvac, false>::do_oop_work(narrowOop* p); |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3849 |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3850 template <class T> void G1ParScanPartialArrayClosure::do_oop_nv(T* p) { |
526 | 3851 assert(has_partial_array_mask(p), "invariant"); |
3852 oop old = clear_partial_array_mask(p); | |
342 | 3853 assert(old->is_objArray(), "must be obj array"); |
3854 assert(old->is_forwarded(), "must be forwarded"); | |
3855 assert(Universe::heap()->is_in_reserved(old), "must be in heap."); | |
3856 | |
3857 objArrayOop obj = objArrayOop(old->forwardee()); | |
3858 assert((void*)old != (void*)old->forwardee(), "self forwarding here?"); | |
3859 // Process ParGCArrayScanChunk elements now | |
3860 // and push the remainder back onto queue | |
3861 int start = arrayOop(old)->length(); | |
3862 int end = obj->length(); | |
3863 int remainder = end - start; | |
3864 assert(start <= end, "just checking"); | |
3865 if (remainder > 2 * ParGCArrayScanChunk) { | |
3866 // Test above combines last partial chunk with a full chunk | |
3867 end = start + ParGCArrayScanChunk; | |
3868 arrayOop(old)->set_length(end); | |
3869 // Push remainder. | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3870 oop* old_p = set_partial_array_mask(old); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3871 assert(arrayOop(old)->length() < obj->length(), "Empty push?"); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3872 _par_scan_state->push_on_queue(old_p); |
342 | 3873 } else { |
3874 // Restore length so that the heap remains parsable in | |
3875 // case of evacuation failure. | |
3876 arrayOop(old)->set_length(end); | |
3877 } | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3878 _scanner.set_region(_g1->heap_region_containing_raw(obj)); |
342 | 3879 // process our set of indices (include header in first chunk) |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3880 obj->oop_iterate_range(&_scanner, start, end); |
342 | 3881 } |
3882 | |
3883 class G1ParEvacuateFollowersClosure : public VoidClosure { | |
3884 protected: | |
3885 G1CollectedHeap* _g1h; | |
3886 G1ParScanThreadState* _par_scan_state; | |
3887 RefToScanQueueSet* _queues; | |
3888 ParallelTaskTerminator* _terminator; | |
3889 | |
3890 G1ParScanThreadState* par_scan_state() { return _par_scan_state; } | |
3891 RefToScanQueueSet* queues() { return _queues; } | |
3892 ParallelTaskTerminator* terminator() { return _terminator; } | |
3893 | |
3894 public: | |
3895 G1ParEvacuateFollowersClosure(G1CollectedHeap* g1h, | |
3896 G1ParScanThreadState* par_scan_state, | |
3897 RefToScanQueueSet* queues, | |
3898 ParallelTaskTerminator* terminator) | |
3899 : _g1h(g1h), _par_scan_state(par_scan_state), | |
3900 _queues(queues), _terminator(terminator) {} | |
3901 | |
3902 void do_void() { | |
3903 G1ParScanThreadState* pss = par_scan_state(); | |
3904 while (true) { | |
3905 pss->trim_queue(); | |
3906 IF_G1_DETAILED_STATS(pss->note_steal_attempt()); | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3907 |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3908 StarTask stolen_task; |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3909 if (queues()->steal(pss->queue_num(), pss->hash_seed(), stolen_task)) { |
342 | 3910 IF_G1_DETAILED_STATS(pss->note_steal()); |
526 | 3911 |
3912 // slightly paranoid tests; I'm trying to catch potential | |
3913 // problems before we go into push_on_queue to know where the | |
3914 // problem is coming from | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3915 assert((oop*)stolen_task != NULL, "Error"); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3916 if (stolen_task.is_narrow()) { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3917 assert(UseCompressedOops, "Error"); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3918 narrowOop* p = (narrowOop*) stolen_task; |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3919 assert(has_partial_array_mask(p) || |
1261
0414c1049f15
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
1245
diff
changeset
|
3920 _g1h->is_in_g1_reserved(oopDesc::load_decode_heap_oop(p)), "Error"); |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3921 pss->push_on_queue(p); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3922 } else { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3923 oop* p = (oop*) stolen_task; |
1261
0414c1049f15
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
1245
diff
changeset
|
3924 assert(has_partial_array_mask(p) || _g1h->is_in_g1_reserved(*p), "Error"); |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3925 pss->push_on_queue(p); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3926 } |
342 | 3927 continue; |
3928 } | |
3929 pss->start_term_time(); | |
3930 if (terminator()->offer_termination()) break; | |
3931 pss->end_term_time(); | |
3932 } | |
3933 pss->end_term_time(); | |
3934 pss->retire_alloc_buffers(); | |
3935 } | |
3936 }; | |
3937 | |
3938 class G1ParTask : public AbstractGangTask { | |
3939 protected: | |
3940 G1CollectedHeap* _g1h; | |
3941 RefToScanQueueSet *_queues; | |
3942 ParallelTaskTerminator _terminator; | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3943 int _n_workers; |
342 | 3944 |
3945 Mutex _stats_lock; | |
3946 Mutex* stats_lock() { return &_stats_lock; } | |
3947 | |
3948 size_t getNCards() { | |
3949 return (_g1h->capacity() + G1BlockOffsetSharedArray::N_bytes - 1) | |
3950 / G1BlockOffsetSharedArray::N_bytes; | |
3951 } | |
3952 | |
3953 public: | |
3954 G1ParTask(G1CollectedHeap* g1h, int workers, RefToScanQueueSet *task_queues) | |
3955 : AbstractGangTask("G1 collection"), | |
3956 _g1h(g1h), | |
3957 _queues(task_queues), | |
3958 _terminator(workers, _queues), | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3959 _stats_lock(Mutex::leaf, "parallel G1 stats lock", true), |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3960 _n_workers(workers) |
342 | 3961 {} |
3962 | |
3963 RefToScanQueueSet* queues() { return _queues; } | |
3964 | |
3965 RefToScanQueue *work_queue(int i) { | |
3966 return queues()->queue(i); | |
3967 } | |
3968 | |
3969 void work(int i) { | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
838
diff
changeset
|
3970 if (i >= _n_workers) return; // no work needed this round |
342 | 3971 ResourceMark rm; |
3972 HandleMark hm; | |
3973 | |
526 | 3974 G1ParScanThreadState pss(_g1h, i); |
3975 G1ParScanHeapEvacClosure scan_evac_cl(_g1h, &pss); | |
3976 G1ParScanHeapEvacFailureClosure evac_failure_cl(_g1h, &pss); | |
3977 G1ParScanPartialArrayClosure partial_scan_cl(_g1h, &pss); | |
342 | 3978 |
3979 pss.set_evac_closure(&scan_evac_cl); | |
3980 pss.set_evac_failure_closure(&evac_failure_cl); | |
3981 pss.set_partial_scan_closure(&partial_scan_cl); | |
3982 | |
3983 G1ParScanExtRootClosure only_scan_root_cl(_g1h, &pss); | |
3984 G1ParScanPermClosure only_scan_perm_cl(_g1h, &pss); | |
3985 G1ParScanHeapRSClosure only_scan_heap_rs_cl(_g1h, &pss); | |
1261
0414c1049f15
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
1245
diff
changeset
|
3986 G1ParPushHeapRSClosure push_heap_rs_cl(_g1h, &pss); |
616
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
3987 |
342 | 3988 G1ParScanAndMarkExtRootClosure scan_mark_root_cl(_g1h, &pss); |
3989 G1ParScanAndMarkPermClosure scan_mark_perm_cl(_g1h, &pss); | |
3990 G1ParScanAndMarkHeapRSClosure scan_mark_heap_rs_cl(_g1h, &pss); | |
3991 | |
3992 OopsInHeapRegionClosure *scan_root_cl; | |
3993 OopsInHeapRegionClosure *scan_perm_cl; | |
3994 | |
1359
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1313
diff
changeset
|
3995 if (_g1h->g1_policy()->during_initial_mark_pause()) { |
342 | 3996 scan_root_cl = &scan_mark_root_cl; |
3997 scan_perm_cl = &scan_mark_perm_cl; | |
3998 } else { | |
3999 scan_root_cl = &only_scan_root_cl; | |
4000 scan_perm_cl = &only_scan_perm_cl; | |
4001 } | |
4002 | |
4003 pss.start_strong_roots(); | |
4004 _g1h->g1_process_strong_roots(/* not collecting perm */ false, | |
4005 SharedHeap::SO_AllClasses, | |
4006 scan_root_cl, | |
1261
0414c1049f15
6923991: G1: improve scalability of RSet scanning
iveresov
parents:
1245
diff
changeset
|
4007 &push_heap_rs_cl, |
342 | 4008 scan_perm_cl, |
4009 i); | |
4010 pss.end_strong_roots(); | |
4011 { | |
4012 double start = os::elapsedTime(); | |
4013 G1ParEvacuateFollowersClosure evac(_g1h, &pss, _queues, &_terminator); | |
4014 evac.do_void(); | |
4015 double elapsed_ms = (os::elapsedTime()-start)*1000.0; | |
4016 double term_ms = pss.term_time()*1000.0; | |
4017 _g1h->g1_policy()->record_obj_copy_time(i, elapsed_ms-term_ms); | |
4018 _g1h->g1_policy()->record_termination_time(i, term_ms); | |
4019 } | |
1282 | 4020 _g1h->g1_policy()->record_thread_age_table(pss.age_table()); |
342 | 4021 _g1h->update_surviving_young_words(pss.surviving_young_words()+1); |
4022 | |
4023 // Clean up any par-expanded rem sets. | |
4024 HeapRegionRemSet::par_cleanup(); | |
4025 | |
4026 MutexLocker x(stats_lock()); | |
4027 if (ParallelGCVerbose) { | |
4028 gclog_or_tty->print("Thread %d complete:\n", i); | |
4029 #if G1_DETAILED_STATS | |
4030 gclog_or_tty->print(" Pushes: %7d Pops: %7d Overflows: %7d Steals %7d (in %d attempts)\n", | |
4031 pss.pushes(), | |
4032 pss.pops(), | |
4033 pss.overflow_pushes(), | |
4034 pss.steals(), | |
4035 pss.steal_attempts()); | |
4036 #endif | |
4037 double elapsed = pss.elapsed(); | |
4038 double strong_roots = pss.strong_roots_time(); | |
4039 double term = pss.term_time(); | |
4040 gclog_or_tty->print(" Elapsed: %7.2f ms.\n" | |
4041 " Strong roots: %7.2f ms (%6.2f%%)\n" | |
4042 " Termination: %7.2f ms (%6.2f%%) (in %d entries)\n", | |
4043 elapsed * 1000.0, | |
4044 strong_roots * 1000.0, (strong_roots*100.0/elapsed), | |
4045 term * 1000.0, (term*100.0/elapsed), | |
4046 pss.term_attempts()); | |
4047 size_t total_waste = pss.alloc_buffer_waste() + pss.undo_waste(); | |
4048 gclog_or_tty->print(" Waste: %8dK\n" | |
4049 " Alloc Buffer: %8dK\n" | |
4050 " Undo: %8dK\n", | |
4051 (total_waste * HeapWordSize) / K, | |
4052 (pss.alloc_buffer_waste() * HeapWordSize) / K, | |
4053 (pss.undo_waste() * HeapWordSize) / K); | |
4054 } | |
4055 | |
4056 assert(pss.refs_to_scan() == 0, "Task queue should be empty"); | |
4057 assert(pss.overflowed_refs_to_scan() == 0, "Overflow queue should be empty"); | |
4058 } | |
4059 }; | |
4060 | |
4061 // *** Common G1 Evacuation Stuff | |
4062 | |
4063 void | |
4064 G1CollectedHeap:: | |
4065 g1_process_strong_roots(bool collecting_perm_gen, | |
4066 SharedHeap::ScanningOption so, | |
4067 OopClosure* scan_non_heap_roots, | |
4068 OopsInHeapRegionClosure* scan_rs, | |
4069 OopsInGenClosure* scan_perm, | |
4070 int worker_i) { | |
4071 // First scan the strong roots, including the perm gen. | |
4072 double ext_roots_start = os::elapsedTime(); | |
4073 double closure_app_time_sec = 0.0; | |
4074 | |
4075 BufferingOopClosure buf_scan_non_heap_roots(scan_non_heap_roots); | |
4076 BufferingOopsInGenClosure buf_scan_perm(scan_perm); | |
4077 buf_scan_perm.set_generation(perm_gen()); | |
4078 | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
890
diff
changeset
|
4079 // Walk the code cache w/o buffering, because StarTask cannot handle |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
890
diff
changeset
|
4080 // unaligned oop locations. |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
890
diff
changeset
|
4081 CodeBlobToOopClosure eager_scan_code_roots(scan_non_heap_roots, /*do_marking=*/ true); |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
890
diff
changeset
|
4082 |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
890
diff
changeset
|
4083 process_strong_roots(false, // no scoping; this is parallel code |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
890
diff
changeset
|
4084 collecting_perm_gen, so, |
342 | 4085 &buf_scan_non_heap_roots, |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
890
diff
changeset
|
4086 &eager_scan_code_roots, |
342 | 4087 &buf_scan_perm); |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4088 |
342 | 4089 // Finish up any enqueued closure apps. |
4090 buf_scan_non_heap_roots.done(); | |
4091 buf_scan_perm.done(); | |
4092 double ext_roots_end = os::elapsedTime(); | |
4093 g1_policy()->reset_obj_copy_time(worker_i); | |
4094 double obj_copy_time_sec = | |
4095 buf_scan_non_heap_roots.closure_app_seconds() + | |
4096 buf_scan_perm.closure_app_seconds(); | |
4097 g1_policy()->record_obj_copy_time(worker_i, obj_copy_time_sec * 1000.0); | |
4098 double ext_root_time_ms = | |
4099 ((ext_roots_end - ext_roots_start) - obj_copy_time_sec) * 1000.0; | |
4100 g1_policy()->record_ext_root_scan_time(worker_i, ext_root_time_ms); | |
4101 | |
4102 // Scan strong roots in mark stack. | |
4103 if (!_process_strong_tasks->is_task_claimed(G1H_PS_mark_stack_oops_do)) { | |
4104 concurrent_mark()->oops_do(scan_non_heap_roots); | |
4105 } | |
4106 double mark_stack_scan_ms = (os::elapsedTime() - ext_roots_end) * 1000.0; | |
4107 g1_policy()->record_mark_stack_scan_time(worker_i, mark_stack_scan_ms); | |
4108 | |
4109 // XXX What should this be doing in the parallel case? | |
4110 g1_policy()->record_collection_pause_end_CH_strong_roots(); | |
4111 // Now scan the complement of the collection set. | |
4112 if (scan_rs != NULL) { | |
4113 g1_rem_set()->oops_into_collection_set_do(scan_rs, worker_i); | |
4114 } | |
4115 // Finish with the ref_processor roots. | |
4116 if (!_process_strong_tasks->is_task_claimed(G1H_PS_refProcessor_oops_do)) { | |
4117 ref_processor()->oops_do(scan_non_heap_roots); | |
4118 } | |
4119 g1_policy()->record_collection_pause_end_G1_strong_roots(); | |
4120 _process_strong_tasks->all_tasks_completed(); | |
4121 } | |
4122 | |
4123 void | |
4124 G1CollectedHeap::g1_process_weak_roots(OopClosure* root_closure, | |
4125 OopClosure* non_root_closure) { | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
890
diff
changeset
|
4126 CodeBlobToOopClosure roots_in_blobs(root_closure, /*do_marking=*/ false); |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
890
diff
changeset
|
4127 SharedHeap::process_weak_roots(root_closure, &roots_in_blobs, non_root_closure); |
342 | 4128 } |
4129 | |
4130 | |
4131 class SaveMarksClosure: public HeapRegionClosure { | |
4132 public: | |
4133 bool doHeapRegion(HeapRegion* r) { | |
4134 r->save_marks(); | |
4135 return false; | |
4136 } | |
4137 }; | |
4138 | |
4139 void G1CollectedHeap::save_marks() { | |
4140 if (ParallelGCThreads == 0) { | |
4141 SaveMarksClosure sm; | |
4142 heap_region_iterate(&sm); | |
4143 } | |
4144 // We do this even in the parallel case | |
4145 perm_gen()->save_marks(); | |
4146 } | |
4147 | |
4148 void G1CollectedHeap::evacuate_collection_set() { | |
4149 set_evacuation_failed(false); | |
4150 | |
4151 g1_rem_set()->prepare_for_oops_into_collection_set_do(); | |
4152 concurrent_g1_refine()->set_use_cache(false); | |
889 | 4153 concurrent_g1_refine()->clear_hot_cache_claimed_index(); |
4154 | |
342 | 4155 int n_workers = (ParallelGCThreads > 0 ? workers()->total_workers() : 1); |
4156 set_par_threads(n_workers); | |
4157 G1ParTask g1_par_task(this, n_workers, _task_queues); | |
4158 | |
4159 init_for_evac_failure(NULL); | |
4160 | |
4161 rem_set()->prepare_for_younger_refs_iterate(true); | |
616
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
4162 |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
4163 assert(dirty_card_queue_set().completed_buffers_num() == 0, "Should be empty"); |
342 | 4164 double start_par = os::elapsedTime(); |
4165 if (ParallelGCThreads > 0) { | |
4166 // The individual threads will set their evac-failure closures. | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
890
diff
changeset
|
4167 StrongRootsScope srs(this); |
342 | 4168 workers()->run_task(&g1_par_task); |
4169 } else { | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
890
diff
changeset
|
4170 StrongRootsScope srs(this); |
342 | 4171 g1_par_task.work(0); |
4172 } | |
4173 | |
4174 double par_time = (os::elapsedTime() - start_par) * 1000.0; | |
4175 g1_policy()->record_par_time(par_time); | |
4176 set_par_threads(0); | |
4177 // Is this the right thing to do here? We don't save marks | |
4178 // on individual heap regions when we allocate from | |
4179 // them in parallel, so this seems like the correct place for this. | |
545 | 4180 retire_all_alloc_regions(); |
342 | 4181 { |
4182 G1IsAliveClosure is_alive(this); | |
4183 G1KeepAliveClosure keep_alive(this); | |
4184 JNIHandles::weak_oops_do(&is_alive, &keep_alive); | |
4185 } | |
940
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4186 release_gc_alloc_regions(false /* totally */); |
342 | 4187 g1_rem_set()->cleanup_after_oops_into_collection_set_do(); |
616
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
4188 |
889 | 4189 concurrent_g1_refine()->clear_hot_cache(); |
342 | 4190 concurrent_g1_refine()->set_use_cache(true); |
4191 | |
4192 finalize_for_evac_failure(); | |
4193 | |
4194 // Must do this before removing self-forwarding pointers, which clears | |
4195 // the per-region evac-failure flags. | |
4196 concurrent_mark()->complete_marking_in_collection_set(); | |
4197 | |
4198 if (evacuation_failed()) { | |
4199 remove_self_forwarding_pointers(); | |
4200 if (PrintGCDetails) { | |
4201 gclog_or_tty->print(" (evacuation failed)"); | |
4202 } else if (PrintGC) { | |
4203 gclog_or_tty->print("--"); | |
4204 } | |
4205 } | |
4206 | |
616
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
4207 if (G1DeferredRSUpdate) { |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
4208 RedirtyLoggedCardTableEntryFastClosure redirty; |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
4209 dirty_card_queue_set().set_closure(&redirty); |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
4210 dirty_card_queue_set().apply_closure_to_all_completed_buffers(); |
1111 | 4211 |
4212 DirtyCardQueueSet& dcq = JavaThread::dirty_card_queue_set(); | |
4213 dcq.merge_bufferlists(&dirty_card_queue_set()); | |
616
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
4214 assert(dirty_card_queue_set().completed_buffers_num() == 0, "All should be consumed"); |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
595
diff
changeset
|
4215 } |
342 | 4216 COMPILER2_PRESENT(DerivedPointerTable::update_pointers()); |
4217 } | |
4218 | |
4219 void G1CollectedHeap::free_region(HeapRegion* hr) { | |
4220 size_t pre_used = 0; | |
4221 size_t cleared_h_regions = 0; | |
4222 size_t freed_regions = 0; | |
4223 UncleanRegionList local_list; | |
4224 | |
4225 HeapWord* start = hr->bottom(); | |
4226 HeapWord* end = hr->prev_top_at_mark_start(); | |
4227 size_t used_bytes = hr->used(); | |
4228 size_t live_bytes = hr->max_live_bytes(); | |
4229 if (used_bytes > 0) { | |
4230 guarantee( live_bytes <= used_bytes, "invariant" ); | |
4231 } else { | |
4232 guarantee( live_bytes == 0, "invariant" ); | |
4233 } | |
4234 | |
4235 size_t garbage_bytes = used_bytes - live_bytes; | |
4236 if (garbage_bytes > 0) | |
4237 g1_policy()->decrease_known_garbage_bytes(garbage_bytes); | |
4238 | |
4239 free_region_work(hr, pre_used, cleared_h_regions, freed_regions, | |
4240 &local_list); | |
4241 finish_free_region_work(pre_used, cleared_h_regions, freed_regions, | |
4242 &local_list); | |
4243 } | |
4244 | |
4245 void | |
4246 G1CollectedHeap::free_region_work(HeapRegion* hr, | |
4247 size_t& pre_used, | |
4248 size_t& cleared_h_regions, | |
4249 size_t& freed_regions, | |
4250 UncleanRegionList* list, | |
4251 bool par) { | |
4252 pre_used += hr->used(); | |
4253 if (hr->isHumongous()) { | |
4254 assert(hr->startsHumongous(), | |
4255 "Only the start of a humongous region should be freed."); | |
4256 int ind = _hrs->find(hr); | |
4257 assert(ind != -1, "Should have an index."); | |
4258 // Clear the start region. | |
4259 hr->hr_clear(par, true /*clear_space*/); | |
4260 list->insert_before_head(hr); | |
4261 cleared_h_regions++; | |
4262 freed_regions++; | |
4263 // Clear any continued regions. | |
4264 ind++; | |
4265 while ((size_t)ind < n_regions()) { | |
4266 HeapRegion* hrc = _hrs->at(ind); | |
4267 if (!hrc->continuesHumongous()) break; | |
4268 // Otherwise, does continue the H region. | |
4269 assert(hrc->humongous_start_region() == hr, "Huh?"); | |
4270 hrc->hr_clear(par, true /*clear_space*/); | |
4271 cleared_h_regions++; | |
4272 freed_regions++; | |
4273 list->insert_before_head(hrc); | |
4274 ind++; | |
4275 } | |
4276 } else { | |
4277 hr->hr_clear(par, true /*clear_space*/); | |
4278 list->insert_before_head(hr); | |
4279 freed_regions++; | |
4280 // If we're using clear2, this should not be enabled. | |
4281 // assert(!hr->in_cohort(), "Can't be both free and in a cohort."); | |
4282 } | |
4283 } | |
4284 | |
4285 void G1CollectedHeap::finish_free_region_work(size_t pre_used, | |
4286 size_t cleared_h_regions, | |
4287 size_t freed_regions, | |
4288 UncleanRegionList* list) { | |
4289 if (list != NULL && list->sz() > 0) { | |
4290 prepend_region_list_on_unclean_list(list); | |
4291 } | |
4292 // Acquire a lock, if we're parallel, to update possibly-shared | |
4293 // variables. | |
4294 Mutex* lock = (n_par_threads() > 0) ? ParGCRareEvent_lock : NULL; | |
4295 { | |
4296 MutexLockerEx x(lock, Mutex::_no_safepoint_check_flag); | |
4297 _summary_bytes_used -= pre_used; | |
4298 _num_humongous_regions -= (int) cleared_h_regions; | |
4299 _free_regions += freed_regions; | |
4300 } | |
4301 } | |
4302 | |
4303 | |
4304 void G1CollectedHeap::dirtyCardsForYoungRegions(CardTableModRefBS* ct_bs, HeapRegion* list) { | |
4305 while (list != NULL) { | |
4306 guarantee( list->is_young(), "invariant" ); | |
4307 | |
4308 HeapWord* bottom = list->bottom(); | |
4309 HeapWord* end = list->end(); | |
4310 MemRegion mr(bottom, end); | |
4311 ct_bs->dirty(mr); | |
4312 | |
4313 list = list->get_next_young_region(); | |
4314 } | |
4315 } | |
4316 | |
796
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4317 |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4318 class G1ParCleanupCTTask : public AbstractGangTask { |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4319 CardTableModRefBS* _ct_bs; |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4320 G1CollectedHeap* _g1h; |
940
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4321 HeapRegion* volatile _su_head; |
796
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4322 public: |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4323 G1ParCleanupCTTask(CardTableModRefBS* ct_bs, |
940
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4324 G1CollectedHeap* g1h, |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4325 HeapRegion* survivor_list) : |
796
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4326 AbstractGangTask("G1 Par Cleanup CT Task"), |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4327 _ct_bs(ct_bs), |
940
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4328 _g1h(g1h), |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4329 _su_head(survivor_list) |
796
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4330 { } |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4331 |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4332 void work(int i) { |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4333 HeapRegion* r; |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4334 while (r = _g1h->pop_dirty_cards_region()) { |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4335 clear_cards(r); |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4336 } |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4337 // Redirty the cards of the survivor regions. |
940
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4338 dirty_list(&this->_su_head); |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4339 } |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4340 |
796
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4341 void clear_cards(HeapRegion* r) { |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4342 // Cards for Survivor regions will be dirtied later. |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4343 if (!r->is_survivor()) { |
796
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4344 _ct_bs->clear(MemRegion(r->bottom(), r->end())); |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4345 } |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4346 } |
940
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4347 |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4348 void dirty_list(HeapRegion* volatile * head_ptr) { |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4349 HeapRegion* head; |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4350 do { |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4351 // Pop region off the list. |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4352 head = *head_ptr; |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4353 if (head != NULL) { |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4354 HeapRegion* r = (HeapRegion*) |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4355 Atomic::cmpxchg_ptr(head->get_next_young_region(), head_ptr, head); |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4356 if (r == head) { |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4357 assert(!r->isHumongous(), "Humongous regions shouldn't be on survivor list"); |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4358 _ct_bs->dirty(MemRegion(r->bottom(), r->end())); |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4359 } |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4360 } |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4361 } while (*head_ptr != NULL); |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4362 } |
796
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4363 }; |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4364 |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4365 |
940
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4366 #ifndef PRODUCT |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4367 class G1VerifyCardTableCleanup: public HeapRegionClosure { |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4368 CardTableModRefBS* _ct_bs; |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4369 public: |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4370 G1VerifyCardTableCleanup(CardTableModRefBS* ct_bs) |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4371 : _ct_bs(ct_bs) |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4372 { } |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4373 virtual bool doHeapRegion(HeapRegion* r) |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4374 { |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4375 MemRegion mr(r->bottom(), r->end()); |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4376 if (r->is_survivor()) { |
940
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4377 _ct_bs->verify_dirty_region(mr); |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4378 } else { |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4379 _ct_bs->verify_clean_region(mr); |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4380 } |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4381 return false; |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4382 } |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4383 }; |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4384 #endif |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4385 |
342 | 4386 void G1CollectedHeap::cleanUpCardTable() { |
4387 CardTableModRefBS* ct_bs = (CardTableModRefBS*) (barrier_set()); | |
4388 double start = os::elapsedTime(); | |
4389 | |
796
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4390 // Iterate over the dirty cards region list. |
940
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4391 G1ParCleanupCTTask cleanup_task(ct_bs, this, |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4392 _young_list->first_survivor_region()); |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4393 |
796
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4394 if (ParallelGCThreads > 0) { |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4395 set_par_threads(workers()->total_workers()); |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4396 workers()->run_task(&cleanup_task); |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4397 set_par_threads(0); |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4398 } else { |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4399 while (_dirty_cards_region_list) { |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4400 HeapRegion* r = _dirty_cards_region_list; |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4401 cleanup_task.clear_cards(r); |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4402 _dirty_cards_region_list = r->get_next_dirty_cards_region(); |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4403 if (_dirty_cards_region_list == r) { |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4404 // The last region. |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4405 _dirty_cards_region_list = NULL; |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4406 } |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4407 r->set_next_dirty_cards_region(NULL); |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
794
diff
changeset
|
4408 } |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4409 // now, redirty the cards of the survivor regions |
940
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4410 // (it seemed faster to do it this way, instead of iterating over |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4411 // all regions and then clearing / dirtying as appropriate) |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4412 dirtyCardsForYoungRegions(ct_bs, _young_list->first_survivor_region()); |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4413 } |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4414 |
342 | 4415 double elapsed = os::elapsedTime() - start; |
4416 g1_policy()->record_clear_ct_time( elapsed * 1000.0); | |
940
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4417 #ifndef PRODUCT |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4418 if (G1VerifyCTCleanup || VerifyAfterGC) { |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4419 G1VerifyCardTableCleanup cleanup_verifier(ct_bs); |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4420 heap_region_iterate(&cleanup_verifier); |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4421 } |
8624da129f0b
6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents:
936
diff
changeset
|
4422 #endif |
342 | 4423 } |
4424 | |
4425 void G1CollectedHeap::do_collection_pause_if_appropriate(size_t word_size) { | |
4426 if (g1_policy()->should_do_collection_pause(word_size)) { | |
4427 do_collection_pause(); | |
4428 } | |
4429 } | |
4430 | |
4431 void G1CollectedHeap::free_collection_set(HeapRegion* cs_head) { | |
4432 double young_time_ms = 0.0; | |
4433 double non_young_time_ms = 0.0; | |
4434 | |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4435 // Since the collection set is a superset of the the young list, |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4436 // all we need to do to clear the young list is clear its |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4437 // head and length, and unlink any young regions in the code below |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4438 _young_list->clear(); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4439 |
342 | 4440 G1CollectorPolicy* policy = g1_policy(); |
4441 | |
4442 double start_sec = os::elapsedTime(); | |
4443 bool non_young = true; | |
4444 | |
4445 HeapRegion* cur = cs_head; | |
4446 int age_bound = -1; | |
4447 size_t rs_lengths = 0; | |
4448 | |
4449 while (cur != NULL) { | |
4450 if (non_young) { | |
4451 if (cur->is_young()) { | |
4452 double end_sec = os::elapsedTime(); | |
4453 double elapsed_ms = (end_sec - start_sec) * 1000.0; | |
4454 non_young_time_ms += elapsed_ms; | |
4455 | |
4456 start_sec = os::elapsedTime(); | |
4457 non_young = false; | |
4458 } | |
4459 } else { | |
4460 if (!cur->is_on_free_list()) { | |
4461 double end_sec = os::elapsedTime(); | |
4462 double elapsed_ms = (end_sec - start_sec) * 1000.0; | |
4463 young_time_ms += elapsed_ms; | |
4464 | |
4465 start_sec = os::elapsedTime(); | |
4466 non_young = true; | |
4467 } | |
4468 } | |
4469 | |
4470 rs_lengths += cur->rem_set()->occupied(); | |
4471 | |
4472 HeapRegion* next = cur->next_in_collection_set(); | |
4473 assert(cur->in_collection_set(), "bad CS"); | |
4474 cur->set_next_in_collection_set(NULL); | |
4475 cur->set_in_collection_set(false); | |
4476 | |
4477 if (cur->is_young()) { | |
4478 int index = cur->young_index_in_cset(); | |
4479 guarantee( index != -1, "invariant" ); | |
4480 guarantee( (size_t)index < policy->young_cset_length(), "invariant" ); | |
4481 size_t words_survived = _surviving_young_words[index]; | |
4482 cur->record_surv_words_in_group(words_survived); | |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4483 |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4484 // At this point the we have 'popped' cur from the collection set |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4485 // (linked via next_in_collection_set()) but it is still in the |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4486 // young list (linked via next_young_region()). Clear the |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4487 // _next_young_region field. |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4488 cur->set_next_young_region(NULL); |
342 | 4489 } else { |
4490 int index = cur->young_index_in_cset(); | |
4491 guarantee( index == -1, "invariant" ); | |
4492 } | |
4493 | |
4494 assert( (cur->is_young() && cur->young_index_in_cset() > -1) || | |
4495 (!cur->is_young() && cur->young_index_in_cset() == -1), | |
4496 "invariant" ); | |
4497 | |
4498 if (!cur->evacuation_failed()) { | |
4499 // And the region is empty. | |
4500 assert(!cur->is_empty(), | |
4501 "Should not have empty regions in a CS."); | |
4502 free_region(cur); | |
4503 } else { | |
4504 cur->uninstall_surv_rate_group(); | |
4505 if (cur->is_young()) | |
4506 cur->set_young_index_in_cset(-1); | |
4507 cur->set_not_young(); | |
4508 cur->set_evacuation_failed(false); | |
4509 } | |
4510 cur = next; | |
4511 } | |
4512 | |
4513 policy->record_max_rs_lengths(rs_lengths); | |
4514 policy->cset_regions_freed(); | |
4515 | |
4516 double end_sec = os::elapsedTime(); | |
4517 double elapsed_ms = (end_sec - start_sec) * 1000.0; | |
4518 if (non_young) | |
4519 non_young_time_ms += elapsed_ms; | |
4520 else | |
4521 young_time_ms += elapsed_ms; | |
4522 | |
4523 policy->record_young_free_cset_time_ms(young_time_ms); | |
4524 policy->record_non_young_free_cset_time_ms(non_young_time_ms); | |
4525 } | |
4526 | |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4527 // This routine is similar to the above but does not record |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4528 // any policy statistics or update free lists; we are abandoning |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4529 // the current incremental collection set in preparation of a |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4530 // full collection. After the full GC we will start to build up |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4531 // the incremental collection set again. |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4532 // This is only called when we're doing a full collection |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4533 // and is immediately followed by the tearing down of the young list. |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4534 |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4535 void G1CollectedHeap::abandon_collection_set(HeapRegion* cs_head) { |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4536 HeapRegion* cur = cs_head; |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4537 |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4538 while (cur != NULL) { |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4539 HeapRegion* next = cur->next_in_collection_set(); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4540 assert(cur->in_collection_set(), "bad CS"); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4541 cur->set_next_in_collection_set(NULL); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4542 cur->set_in_collection_set(false); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4543 cur->set_young_index_in_cset(-1); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4544 cur = next; |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4545 } |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4546 } |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4547 |
342 | 4548 HeapRegion* |
4549 G1CollectedHeap::alloc_region_from_unclean_list_locked(bool zero_filled) { | |
4550 assert(ZF_mon->owned_by_self(), "Precondition"); | |
4551 HeapRegion* res = pop_unclean_region_list_locked(); | |
4552 if (res != NULL) { | |
4553 assert(!res->continuesHumongous() && | |
4554 res->zero_fill_state() != HeapRegion::Allocated, | |
4555 "Only free regions on unclean list."); | |
4556 if (zero_filled) { | |
4557 res->ensure_zero_filled_locked(); | |
4558 res->set_zero_fill_allocated(); | |
4559 } | |
4560 } | |
4561 return res; | |
4562 } | |
4563 | |
4564 HeapRegion* G1CollectedHeap::alloc_region_from_unclean_list(bool zero_filled) { | |
4565 MutexLockerEx zx(ZF_mon, Mutex::_no_safepoint_check_flag); | |
4566 return alloc_region_from_unclean_list_locked(zero_filled); | |
4567 } | |
4568 | |
4569 void G1CollectedHeap::put_region_on_unclean_list(HeapRegion* r) { | |
4570 MutexLockerEx x(ZF_mon, Mutex::_no_safepoint_check_flag); | |
4571 put_region_on_unclean_list_locked(r); | |
4572 if (should_zf()) ZF_mon->notify_all(); // Wake up ZF thread. | |
4573 } | |
4574 | |
4575 void G1CollectedHeap::set_unclean_regions_coming(bool b) { | |
4576 MutexLockerEx x(Cleanup_mon); | |
4577 set_unclean_regions_coming_locked(b); | |
4578 } | |
4579 | |
4580 void G1CollectedHeap::set_unclean_regions_coming_locked(bool b) { | |
4581 assert(Cleanup_mon->owned_by_self(), "Precondition"); | |
4582 _unclean_regions_coming = b; | |
4583 // Wake up mutator threads that might be waiting for completeCleanup to | |
4584 // finish. | |
4585 if (!b) Cleanup_mon->notify_all(); | |
4586 } | |
4587 | |
4588 void G1CollectedHeap::wait_for_cleanup_complete() { | |
4589 MutexLockerEx x(Cleanup_mon); | |
4590 wait_for_cleanup_complete_locked(); | |
4591 } | |
4592 | |
4593 void G1CollectedHeap::wait_for_cleanup_complete_locked() { | |
4594 assert(Cleanup_mon->owned_by_self(), "precondition"); | |
4595 while (_unclean_regions_coming) { | |
4596 Cleanup_mon->wait(); | |
4597 } | |
4598 } | |
4599 | |
4600 void | |
4601 G1CollectedHeap::put_region_on_unclean_list_locked(HeapRegion* r) { | |
4602 assert(ZF_mon->owned_by_self(), "precondition."); | |
4603 _unclean_region_list.insert_before_head(r); | |
4604 } | |
4605 | |
4606 void | |
4607 G1CollectedHeap::prepend_region_list_on_unclean_list(UncleanRegionList* list) { | |
4608 MutexLockerEx x(ZF_mon, Mutex::_no_safepoint_check_flag); | |
4609 prepend_region_list_on_unclean_list_locked(list); | |
4610 if (should_zf()) ZF_mon->notify_all(); // Wake up ZF thread. | |
4611 } | |
4612 | |
4613 void | |
4614 G1CollectedHeap:: | |
4615 prepend_region_list_on_unclean_list_locked(UncleanRegionList* list) { | |
4616 assert(ZF_mon->owned_by_self(), "precondition."); | |
4617 _unclean_region_list.prepend_list(list); | |
4618 } | |
4619 | |
4620 HeapRegion* G1CollectedHeap::pop_unclean_region_list_locked() { | |
4621 assert(ZF_mon->owned_by_self(), "precondition."); | |
4622 HeapRegion* res = _unclean_region_list.pop(); | |
4623 if (res != NULL) { | |
4624 // Inform ZF thread that there's a new unclean head. | |
4625 if (_unclean_region_list.hd() != NULL && should_zf()) | |
4626 ZF_mon->notify_all(); | |
4627 } | |
4628 return res; | |
4629 } | |
4630 | |
4631 HeapRegion* G1CollectedHeap::peek_unclean_region_list_locked() { | |
4632 assert(ZF_mon->owned_by_self(), "precondition."); | |
4633 return _unclean_region_list.hd(); | |
4634 } | |
4635 | |
4636 | |
4637 bool G1CollectedHeap::move_cleaned_region_to_free_list_locked() { | |
4638 assert(ZF_mon->owned_by_self(), "Precondition"); | |
4639 HeapRegion* r = peek_unclean_region_list_locked(); | |
4640 if (r != NULL && r->zero_fill_state() == HeapRegion::ZeroFilled) { | |
4641 // Result of below must be equal to "r", since we hold the lock. | |
4642 (void)pop_unclean_region_list_locked(); | |
4643 put_free_region_on_list_locked(r); | |
4644 return true; | |
4645 } else { | |
4646 return false; | |
4647 } | |
4648 } | |
4649 | |
4650 bool G1CollectedHeap::move_cleaned_region_to_free_list() { | |
4651 MutexLockerEx x(ZF_mon, Mutex::_no_safepoint_check_flag); | |
4652 return move_cleaned_region_to_free_list_locked(); | |
4653 } | |
4654 | |
4655 | |
4656 void G1CollectedHeap::put_free_region_on_list_locked(HeapRegion* r) { | |
4657 assert(ZF_mon->owned_by_self(), "precondition."); | |
4658 assert(_free_region_list_size == free_region_list_length(), "Inv"); | |
4659 assert(r->zero_fill_state() == HeapRegion::ZeroFilled, | |
4660 "Regions on free list must be zero filled"); | |
4661 assert(!r->isHumongous(), "Must not be humongous."); | |
4662 assert(r->is_empty(), "Better be empty"); | |
4663 assert(!r->is_on_free_list(), | |
4664 "Better not already be on free list"); | |
4665 assert(!r->is_on_unclean_list(), | |
4666 "Better not already be on unclean list"); | |
4667 r->set_on_free_list(true); | |
4668 r->set_next_on_free_list(_free_region_list); | |
4669 _free_region_list = r; | |
4670 _free_region_list_size++; | |
4671 assert(_free_region_list_size == free_region_list_length(), "Inv"); | |
4672 } | |
4673 | |
4674 void G1CollectedHeap::put_free_region_on_list(HeapRegion* r) { | |
4675 MutexLockerEx x(ZF_mon, Mutex::_no_safepoint_check_flag); | |
4676 put_free_region_on_list_locked(r); | |
4677 } | |
4678 | |
4679 HeapRegion* G1CollectedHeap::pop_free_region_list_locked() { | |
4680 assert(ZF_mon->owned_by_self(), "precondition."); | |
4681 assert(_free_region_list_size == free_region_list_length(), "Inv"); | |
4682 HeapRegion* res = _free_region_list; | |
4683 if (res != NULL) { | |
4684 _free_region_list = res->next_from_free_list(); | |
4685 _free_region_list_size--; | |
4686 res->set_on_free_list(false); | |
4687 res->set_next_on_free_list(NULL); | |
4688 assert(_free_region_list_size == free_region_list_length(), "Inv"); | |
4689 } | |
4690 return res; | |
4691 } | |
4692 | |
4693 | |
4694 HeapRegion* G1CollectedHeap::alloc_free_region_from_lists(bool zero_filled) { | |
4695 // By self, or on behalf of self. | |
4696 assert(Heap_lock->is_locked(), "Precondition"); | |
4697 HeapRegion* res = NULL; | |
4698 bool first = true; | |
4699 while (res == NULL) { | |
4700 if (zero_filled || !first) { | |
4701 MutexLockerEx x(ZF_mon, Mutex::_no_safepoint_check_flag); | |
4702 res = pop_free_region_list_locked(); | |
4703 if (res != NULL) { | |
4704 assert(!res->zero_fill_is_allocated(), | |
4705 "No allocated regions on free list."); | |
4706 res->set_zero_fill_allocated(); | |
4707 } else if (!first) { | |
4708 break; // We tried both, time to return NULL. | |
4709 } | |
4710 } | |
4711 | |
4712 if (res == NULL) { | |
4713 res = alloc_region_from_unclean_list(zero_filled); | |
4714 } | |
4715 assert(res == NULL || | |
4716 !zero_filled || | |
4717 res->zero_fill_is_allocated(), | |
4718 "We must have allocated the region we're returning"); | |
4719 first = false; | |
4720 } | |
4721 return res; | |
4722 } | |
4723 | |
4724 void G1CollectedHeap::remove_allocated_regions_from_lists() { | |
4725 MutexLockerEx x(ZF_mon, Mutex::_no_safepoint_check_flag); | |
4726 { | |
4727 HeapRegion* prev = NULL; | |
4728 HeapRegion* cur = _unclean_region_list.hd(); | |
4729 while (cur != NULL) { | |
4730 HeapRegion* next = cur->next_from_unclean_list(); | |
4731 if (cur->zero_fill_is_allocated()) { | |
4732 // Remove from the list. | |
4733 if (prev == NULL) { | |
4734 (void)_unclean_region_list.pop(); | |
4735 } else { | |
4736 _unclean_region_list.delete_after(prev); | |
4737 } | |
4738 cur->set_on_unclean_list(false); | |
4739 cur->set_next_on_unclean_list(NULL); | |
4740 } else { | |
4741 prev = cur; | |
4742 } | |
4743 cur = next; | |
4744 } | |
4745 assert(_unclean_region_list.sz() == unclean_region_list_length(), | |
4746 "Inv"); | |
4747 } | |
4748 | |
4749 { | |
4750 HeapRegion* prev = NULL; | |
4751 HeapRegion* cur = _free_region_list; | |
4752 while (cur != NULL) { | |
4753 HeapRegion* next = cur->next_from_free_list(); | |
4754 if (cur->zero_fill_is_allocated()) { | |
4755 // Remove from the list. | |
4756 if (prev == NULL) { | |
4757 _free_region_list = cur->next_from_free_list(); | |
4758 } else { | |
4759 prev->set_next_on_free_list(cur->next_from_free_list()); | |
4760 } | |
4761 cur->set_on_free_list(false); | |
4762 cur->set_next_on_free_list(NULL); | |
4763 _free_region_list_size--; | |
4764 } else { | |
4765 prev = cur; | |
4766 } | |
4767 cur = next; | |
4768 } | |
4769 assert(_free_region_list_size == free_region_list_length(), "Inv"); | |
4770 } | |
4771 } | |
4772 | |
4773 bool G1CollectedHeap::verify_region_lists() { | |
4774 MutexLockerEx x(ZF_mon, Mutex::_no_safepoint_check_flag); | |
4775 return verify_region_lists_locked(); | |
4776 } | |
4777 | |
4778 bool G1CollectedHeap::verify_region_lists_locked() { | |
4779 HeapRegion* unclean = _unclean_region_list.hd(); | |
4780 while (unclean != NULL) { | |
4781 guarantee(unclean->is_on_unclean_list(), "Well, it is!"); | |
4782 guarantee(!unclean->is_on_free_list(), "Well, it shouldn't be!"); | |
4783 guarantee(unclean->zero_fill_state() != HeapRegion::Allocated, | |
4784 "Everything else is possible."); | |
4785 unclean = unclean->next_from_unclean_list(); | |
4786 } | |
4787 guarantee(_unclean_region_list.sz() == unclean_region_list_length(), "Inv"); | |
4788 | |
4789 HeapRegion* free_r = _free_region_list; | |
4790 while (free_r != NULL) { | |
4791 assert(free_r->is_on_free_list(), "Well, it is!"); | |
4792 assert(!free_r->is_on_unclean_list(), "Well, it shouldn't be!"); | |
4793 switch (free_r->zero_fill_state()) { | |
4794 case HeapRegion::NotZeroFilled: | |
4795 case HeapRegion::ZeroFilling: | |
4796 guarantee(false, "Should not be on free list."); | |
4797 break; | |
4798 default: | |
4799 // Everything else is possible. | |
4800 break; | |
4801 } | |
4802 free_r = free_r->next_from_free_list(); | |
4803 } | |
4804 guarantee(_free_region_list_size == free_region_list_length(), "Inv"); | |
4805 // If we didn't do an assertion... | |
4806 return true; | |
4807 } | |
4808 | |
4809 size_t G1CollectedHeap::free_region_list_length() { | |
4810 assert(ZF_mon->owned_by_self(), "precondition."); | |
4811 size_t len = 0; | |
4812 HeapRegion* cur = _free_region_list; | |
4813 while (cur != NULL) { | |
4814 len++; | |
4815 cur = cur->next_from_free_list(); | |
4816 } | |
4817 return len; | |
4818 } | |
4819 | |
4820 size_t G1CollectedHeap::unclean_region_list_length() { | |
4821 assert(ZF_mon->owned_by_self(), "precondition."); | |
4822 return _unclean_region_list.length(); | |
4823 } | |
4824 | |
4825 size_t G1CollectedHeap::n_regions() { | |
4826 return _hrs->length(); | |
4827 } | |
4828 | |
4829 size_t G1CollectedHeap::max_regions() { | |
4830 return | |
4831 (size_t)align_size_up(g1_reserved_obj_bytes(), HeapRegion::GrainBytes) / | |
4832 HeapRegion::GrainBytes; | |
4833 } | |
4834 | |
4835 size_t G1CollectedHeap::free_regions() { | |
4836 /* Possibly-expensive assert. | |
4837 assert(_free_regions == count_free_regions(), | |
4838 "_free_regions is off."); | |
4839 */ | |
4840 return _free_regions; | |
4841 } | |
4842 | |
4843 bool G1CollectedHeap::should_zf() { | |
4844 return _free_region_list_size < (size_t) G1ConcZFMaxRegions; | |
4845 } | |
4846 | |
4847 class RegionCounter: public HeapRegionClosure { | |
4848 size_t _n; | |
4849 public: | |
4850 RegionCounter() : _n(0) {} | |
4851 bool doHeapRegion(HeapRegion* r) { | |
677 | 4852 if (r->is_empty()) { |
342 | 4853 assert(!r->isHumongous(), "H regions should not be empty."); |
4854 _n++; | |
4855 } | |
4856 return false; | |
4857 } | |
4858 int res() { return (int) _n; } | |
4859 }; | |
4860 | |
4861 size_t G1CollectedHeap::count_free_regions() { | |
4862 RegionCounter rc; | |
4863 heap_region_iterate(&rc); | |
4864 size_t n = rc.res(); | |
4865 if (_cur_alloc_region != NULL && _cur_alloc_region->is_empty()) | |
4866 n--; | |
4867 return n; | |
4868 } | |
4869 | |
4870 size_t G1CollectedHeap::count_free_regions_list() { | |
4871 size_t n = 0; | |
4872 size_t o = 0; | |
4873 ZF_mon->lock_without_safepoint_check(); | |
4874 HeapRegion* cur = _free_region_list; | |
4875 while (cur != NULL) { | |
4876 cur = cur->next_from_free_list(); | |
4877 n++; | |
4878 } | |
4879 size_t m = unclean_region_list_length(); | |
4880 ZF_mon->unlock(); | |
4881 return n + m; | |
4882 } | |
4883 | |
4884 bool G1CollectedHeap::should_set_young_locked() { | |
4885 assert(heap_lock_held_for_gc(), | |
4886 "the heap lock should already be held by or for this thread"); | |
4887 return (g1_policy()->in_young_gc_mode() && | |
4888 g1_policy()->should_add_next_region_to_young_list()); | |
4889 } | |
4890 | |
4891 void G1CollectedHeap::set_region_short_lived_locked(HeapRegion* hr) { | |
4892 assert(heap_lock_held_for_gc(), | |
4893 "the heap lock should already be held by or for this thread"); | |
4894 _young_list->push_region(hr); | |
4895 g1_policy()->set_region_short_lived(hr); | |
4896 } | |
4897 | |
4898 class NoYoungRegionsClosure: public HeapRegionClosure { | |
4899 private: | |
4900 bool _success; | |
4901 public: | |
4902 NoYoungRegionsClosure() : _success(true) { } | |
4903 bool doHeapRegion(HeapRegion* r) { | |
4904 if (r->is_young()) { | |
4905 gclog_or_tty->print_cr("Region ["PTR_FORMAT", "PTR_FORMAT") tagged as young", | |
4906 r->bottom(), r->end()); | |
4907 _success = false; | |
4908 } | |
4909 return false; | |
4910 } | |
4911 bool success() { return _success; } | |
4912 }; | |
4913 | |
1394
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4914 bool G1CollectedHeap::check_young_list_empty(bool check_heap, bool check_sample) { |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4915 bool ret = _young_list->check_list_empty(check_sample); |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4916 |
1316cec51b4d
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
1391
diff
changeset
|
4917 if (check_heap) { |
342 | 4918 NoYoungRegionsClosure closure; |
4919 heap_region_iterate(&closure); | |
4920 ret = ret && closure.success(); | |
4921 } | |
4922 | |
4923 return ret; | |
4924 } | |
4925 | |
4926 void G1CollectedHeap::empty_young_list() { | |
4927 assert(heap_lock_held_for_gc(), | |
4928 "the heap lock should already be held by or for this thread"); | |
4929 assert(g1_policy()->in_young_gc_mode(), "should be in young GC mode"); | |
4930 | |
4931 _young_list->empty_list(); | |
4932 } | |
4933 | |
4934 bool G1CollectedHeap::all_alloc_regions_no_allocs_since_save_marks() { | |
4935 bool no_allocs = true; | |
4936 for (int ap = 0; ap < GCAllocPurposeCount && no_allocs; ++ap) { | |
4937 HeapRegion* r = _gc_alloc_regions[ap]; | |
4938 no_allocs = r == NULL || r->saved_mark_at_top(); | |
4939 } | |
4940 return no_allocs; | |
4941 } | |
4942 | |
545 | 4943 void G1CollectedHeap::retire_all_alloc_regions() { |
342 | 4944 for (int ap = 0; ap < GCAllocPurposeCount; ++ap) { |
4945 HeapRegion* r = _gc_alloc_regions[ap]; | |
4946 if (r != NULL) { | |
4947 // Check for aliases. | |
4948 bool has_processed_alias = false; | |
4949 for (int i = 0; i < ap; ++i) { | |
4950 if (_gc_alloc_regions[i] == r) { | |
4951 has_processed_alias = true; | |
4952 break; | |
4953 } | |
4954 } | |
4955 if (!has_processed_alias) { | |
545 | 4956 retire_alloc_region(r, false /* par */); |
342 | 4957 } |
4958 } | |
4959 } | |
4960 } | |
4961 | |
4962 | |
4963 // Done at the start of full GC. | |
4964 void G1CollectedHeap::tear_down_region_lists() { | |
4965 MutexLockerEx x(ZF_mon, Mutex::_no_safepoint_check_flag); | |
4966 while (pop_unclean_region_list_locked() != NULL) ; | |
4967 assert(_unclean_region_list.hd() == NULL && _unclean_region_list.sz() == 0, | |
1489
cff162798819
6888953: some calls to function-like macros are missing semicolons
jcoomes
parents:
1394
diff
changeset
|
4968 "Postconditions of loop."); |
342 | 4969 while (pop_free_region_list_locked() != NULL) ; |
4970 assert(_free_region_list == NULL, "Postcondition of loop."); | |
4971 if (_free_region_list_size != 0) { | |
4972 gclog_or_tty->print_cr("Size is %d.", _free_region_list_size); | |
838
0316eac49d5a
6855834: G1: minimize the output when -XX:+PrintHeapAtGC is set
tonyp
parents:
811
diff
changeset
|
4973 print_on(gclog_or_tty, true /* extended */); |
342 | 4974 } |
4975 assert(_free_region_list_size == 0, "Postconditions of loop."); | |
4976 } | |
4977 | |
4978 | |
4979 class RegionResetter: public HeapRegionClosure { | |
4980 G1CollectedHeap* _g1; | |
4981 int _n; | |
4982 public: | |
4983 RegionResetter() : _g1(G1CollectedHeap::heap()), _n(0) {} | |
4984 bool doHeapRegion(HeapRegion* r) { | |
4985 if (r->continuesHumongous()) return false; | |
4986 if (r->top() > r->bottom()) { | |
4987 if (r->top() < r->end()) { | |
4988 Copy::fill_to_words(r->top(), | |
4989 pointer_delta(r->end(), r->top())); | |
4990 } | |
4991 r->set_zero_fill_allocated(); | |
4992 } else { | |
4993 assert(r->is_empty(), "tautology"); | |
677 | 4994 _n++; |
4995 switch (r->zero_fill_state()) { | |
342 | 4996 case HeapRegion::NotZeroFilled: |
4997 case HeapRegion::ZeroFilling: | |
4998 _g1->put_region_on_unclean_list_locked(r); | |
4999 break; | |
5000 case HeapRegion::Allocated: | |
5001 r->set_zero_fill_complete(); | |
5002 // no break; go on to put on free list. | |
5003 case HeapRegion::ZeroFilled: | |
5004 _g1->put_free_region_on_list_locked(r); | |
5005 break; | |
5006 } | |
5007 } | |
5008 return false; | |
5009 } | |
5010 | |
5011 int getFreeRegionCount() {return _n;} | |
5012 }; | |
5013 | |
5014 // Done at the end of full GC. | |
5015 void G1CollectedHeap::rebuild_region_lists() { | |
5016 MutexLockerEx x(ZF_mon, Mutex::_no_safepoint_check_flag); | |
5017 // This needs to go at the end of the full GC. | |
5018 RegionResetter rs; | |
5019 heap_region_iterate(&rs); | |
5020 _free_regions = rs.getFreeRegionCount(); | |
5021 // Tell the ZF thread it may have work to do. | |
5022 if (should_zf()) ZF_mon->notify_all(); | |
5023 } | |
5024 | |
5025 class UsedRegionsNeedZeroFillSetter: public HeapRegionClosure { | |
5026 G1CollectedHeap* _g1; | |
5027 int _n; | |
5028 public: | |
5029 UsedRegionsNeedZeroFillSetter() : _g1(G1CollectedHeap::heap()), _n(0) {} | |
5030 bool doHeapRegion(HeapRegion* r) { | |
5031 if (r->continuesHumongous()) return false; | |
5032 if (r->top() > r->bottom()) { | |
5033 // There are assertions in "set_zero_fill_needed()" below that | |
5034 // require top() == bottom(), so this is technically illegal. | |
5035 // We'll skirt the law here, by making that true temporarily. | |
5036 DEBUG_ONLY(HeapWord* save_top = r->top(); | |
5037 r->set_top(r->bottom())); | |
5038 r->set_zero_fill_needed(); | |
5039 DEBUG_ONLY(r->set_top(save_top)); | |
5040 } | |
5041 return false; | |
5042 } | |
5043 }; | |
5044 | |
5045 // Done at the start of full GC. | |
5046 void G1CollectedHeap::set_used_regions_to_need_zero_fill() { | |
5047 MutexLockerEx x(ZF_mon, Mutex::_no_safepoint_check_flag); | |
5048 // This needs to go at the end of the full GC. | |
5049 UsedRegionsNeedZeroFillSetter rs; | |
5050 heap_region_iterate(&rs); | |
5051 } | |
5052 | |
5053 void G1CollectedHeap::set_refine_cte_cl_concurrency(bool concurrent) { | |
5054 _refine_cte_cl->set_concurrent(concurrent); | |
5055 } | |
5056 | |
5057 #ifndef PRODUCT | |
5058 | |
5059 class PrintHeapRegionClosure: public HeapRegionClosure { | |
5060 public: | |
5061 bool doHeapRegion(HeapRegion *r) { | |
5062 gclog_or_tty->print("Region: "PTR_FORMAT":", r); | |
5063 if (r != NULL) { | |
5064 if (r->is_on_free_list()) | |
5065 gclog_or_tty->print("Free "); | |
5066 if (r->is_young()) | |
5067 gclog_or_tty->print("Young "); | |
5068 if (r->isHumongous()) | |
5069 gclog_or_tty->print("Is Humongous "); | |
5070 r->print(); | |
5071 } | |
5072 return false; | |
5073 } | |
5074 }; | |
5075 | |
5076 class SortHeapRegionClosure : public HeapRegionClosure { | |
5077 size_t young_regions,free_regions, unclean_regions; | |
5078 size_t hum_regions, count; | |
5079 size_t unaccounted, cur_unclean, cur_alloc; | |
5080 size_t total_free; | |
5081 HeapRegion* cur; | |
5082 public: | |
5083 SortHeapRegionClosure(HeapRegion *_cur) : cur(_cur), young_regions(0), | |
5084 free_regions(0), unclean_regions(0), | |
5085 hum_regions(0), | |
5086 count(0), unaccounted(0), | |
5087 cur_alloc(0), total_free(0) | |
5088 {} | |
5089 bool doHeapRegion(HeapRegion *r) { | |
5090 count++; | |
5091 if (r->is_on_free_list()) free_regions++; | |
5092 else if (r->is_on_unclean_list()) unclean_regions++; | |
5093 else if (r->isHumongous()) hum_regions++; | |
5094 else if (r->is_young()) young_regions++; | |
5095 else if (r == cur) cur_alloc++; | |
5096 else unaccounted++; | |
5097 return false; | |
5098 } | |
5099 void print() { | |
5100 total_free = free_regions + unclean_regions; | |
5101 gclog_or_tty->print("%d regions\n", count); | |
5102 gclog_or_tty->print("%d free: free_list = %d unclean = %d\n", | |
5103 total_free, free_regions, unclean_regions); | |
5104 gclog_or_tty->print("%d humongous %d young\n", | |
5105 hum_regions, young_regions); | |
5106 gclog_or_tty->print("%d cur_alloc\n", cur_alloc); | |
5107 gclog_or_tty->print("UHOH unaccounted = %d\n", unaccounted); | |
5108 } | |
5109 }; | |
5110 | |
5111 void G1CollectedHeap::print_region_counts() { | |
5112 SortHeapRegionClosure sc(_cur_alloc_region); | |
5113 PrintHeapRegionClosure cl; | |
5114 heap_region_iterate(&cl); | |
5115 heap_region_iterate(&sc); | |
5116 sc.print(); | |
5117 print_region_accounting_info(); | |
5118 }; | |
5119 | |
5120 bool G1CollectedHeap::regions_accounted_for() { | |
5121 // TODO: regions accounting for young/survivor/tenured | |
5122 return true; | |
5123 } | |
5124 | |
5125 bool G1CollectedHeap::print_region_accounting_info() { | |
5126 gclog_or_tty->print_cr("Free regions: %d (count: %d count list %d) (clean: %d unclean: %d).", | |
5127 free_regions(), | |
5128 count_free_regions(), count_free_regions_list(), | |
5129 _free_region_list_size, _unclean_region_list.sz()); | |
5130 gclog_or_tty->print_cr("cur_alloc: %d.", | |
5131 (_cur_alloc_region == NULL ? 0 : 1)); | |
5132 gclog_or_tty->print_cr("H regions: %d.", _num_humongous_regions); | |
5133 | |
5134 // TODO: check regions accounting for young/survivor/tenured | |
5135 return true; | |
5136 } | |
5137 | |
5138 bool G1CollectedHeap::is_in_closed_subset(const void* p) const { | |
5139 HeapRegion* hr = heap_region_containing(p); | |
5140 if (hr == NULL) { | |
5141 return is_in_permanent(p); | |
5142 } else { | |
5143 return hr->is_in(p); | |
5144 } | |
5145 } | |
941 | 5146 #endif // !PRODUCT |
342 | 5147 |
5148 void G1CollectedHeap::g1_unimplemented() { | |
5149 // Unimplemented(); | |
5150 } |