Mercurial > hg > truffle
annotate src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp @ 265:f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
Summary: avoid computing the dense prefix if a space is empty
Reviewed-by: pbk, tonyp
author | jcoomes |
---|---|
date | Fri, 11 Jul 2008 16:11:43 -0700 |
parents | 15dd2594d08e |
children | 2214b226b7f0 |
rev | line source |
---|---|
0 | 1 /* |
2 * Copyright 2005-2007 Sun Microsystems, Inc. All Rights Reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact 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/_psParallelCompact.cpp.incl" | |
27 | |
28 #include <math.h> | |
29 | |
30 // All sizes are in HeapWords. | |
31 const size_t ParallelCompactData::Log2ChunkSize = 9; // 512 words | |
32 const size_t ParallelCompactData::ChunkSize = (size_t)1 << Log2ChunkSize; | |
33 const size_t ParallelCompactData::ChunkSizeBytes = ChunkSize << LogHeapWordSize; | |
34 const size_t ParallelCompactData::ChunkSizeOffsetMask = ChunkSize - 1; | |
35 const size_t ParallelCompactData::ChunkAddrOffsetMask = ChunkSizeBytes - 1; | |
36 const size_t ParallelCompactData::ChunkAddrMask = ~ChunkAddrOffsetMask; | |
37 | |
38 // 32-bit: 128 words covers 4 bitmap words | |
39 // 64-bit: 128 words covers 2 bitmap words | |
40 const size_t ParallelCompactData::Log2BlockSize = 7; // 128 words | |
41 const size_t ParallelCompactData::BlockSize = (size_t)1 << Log2BlockSize; | |
42 const size_t ParallelCompactData::BlockOffsetMask = BlockSize - 1; | |
43 const size_t ParallelCompactData::BlockMask = ~BlockOffsetMask; | |
44 | |
45 const size_t ParallelCompactData::BlocksPerChunk = ChunkSize / BlockSize; | |
46 | |
47 const ParallelCompactData::ChunkData::chunk_sz_t | |
48 ParallelCompactData::ChunkData::dc_shift = 27; | |
49 | |
50 const ParallelCompactData::ChunkData::chunk_sz_t | |
51 ParallelCompactData::ChunkData::dc_mask = ~0U << dc_shift; | |
52 | |
53 const ParallelCompactData::ChunkData::chunk_sz_t | |
54 ParallelCompactData::ChunkData::dc_one = 0x1U << dc_shift; | |
55 | |
56 const ParallelCompactData::ChunkData::chunk_sz_t | |
57 ParallelCompactData::ChunkData::los_mask = ~dc_mask; | |
58 | |
59 const ParallelCompactData::ChunkData::chunk_sz_t | |
60 ParallelCompactData::ChunkData::dc_claimed = 0x8U << dc_shift; | |
61 | |
62 const ParallelCompactData::ChunkData::chunk_sz_t | |
63 ParallelCompactData::ChunkData::dc_completed = 0xcU << dc_shift; | |
64 | |
65 #ifdef ASSERT | |
66 short ParallelCompactData::BlockData::_cur_phase = 0; | |
67 #endif | |
68 | |
69 SpaceInfo PSParallelCompact::_space_info[PSParallelCompact::last_space_id]; | |
70 bool PSParallelCompact::_print_phases = false; | |
71 | |
72 ReferenceProcessor* PSParallelCompact::_ref_processor = NULL; | |
73 klassOop PSParallelCompact::_updated_int_array_klass_obj = NULL; | |
74 | |
75 double PSParallelCompact::_dwl_mean; | |
76 double PSParallelCompact::_dwl_std_dev; | |
77 double PSParallelCompact::_dwl_first_term; | |
78 double PSParallelCompact::_dwl_adjustment; | |
79 #ifdef ASSERT | |
80 bool PSParallelCompact::_dwl_initialized = false; | |
81 #endif // #ifdef ASSERT | |
82 | |
83 #ifdef VALIDATE_MARK_SWEEP | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
79
diff
changeset
|
84 GrowableArray<void*>* PSParallelCompact::_root_refs_stack = NULL; |
0 | 85 GrowableArray<oop> * PSParallelCompact::_live_oops = NULL; |
86 GrowableArray<oop> * PSParallelCompact::_live_oops_moved_to = NULL; | |
87 GrowableArray<size_t>* PSParallelCompact::_live_oops_size = NULL; | |
88 size_t PSParallelCompact::_live_oops_index = 0; | |
89 size_t PSParallelCompact::_live_oops_index_at_perm = 0; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
79
diff
changeset
|
90 GrowableArray<void*>* PSParallelCompact::_other_refs_stack = NULL; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
79
diff
changeset
|
91 GrowableArray<void*>* PSParallelCompact::_adjusted_pointers = NULL; |
0 | 92 bool PSParallelCompact::_pointer_tracking = false; |
93 bool PSParallelCompact::_root_tracking = true; | |
94 | |
95 GrowableArray<HeapWord*>* PSParallelCompact::_cur_gc_live_oops = NULL; | |
96 GrowableArray<HeapWord*>* PSParallelCompact::_cur_gc_live_oops_moved_to = NULL; | |
97 GrowableArray<size_t> * PSParallelCompact::_cur_gc_live_oops_size = NULL; | |
98 GrowableArray<HeapWord*>* PSParallelCompact::_last_gc_live_oops = NULL; | |
99 GrowableArray<HeapWord*>* PSParallelCompact::_last_gc_live_oops_moved_to = NULL; | |
100 GrowableArray<size_t> * PSParallelCompact::_last_gc_live_oops_size = NULL; | |
101 #endif | |
102 | |
103 // XXX beg - verification code; only works while we also mark in object headers | |
104 static void | |
105 verify_mark_bitmap(ParMarkBitMap& _mark_bitmap) | |
106 { | |
107 ParallelScavengeHeap* heap = PSParallelCompact::gc_heap(); | |
108 | |
109 PSPermGen* perm_gen = heap->perm_gen(); | |
110 PSOldGen* old_gen = heap->old_gen(); | |
111 PSYoungGen* young_gen = heap->young_gen(); | |
112 | |
113 MutableSpace* perm_space = perm_gen->object_space(); | |
114 MutableSpace* old_space = old_gen->object_space(); | |
115 MutableSpace* eden_space = young_gen->eden_space(); | |
116 MutableSpace* from_space = young_gen->from_space(); | |
117 MutableSpace* to_space = young_gen->to_space(); | |
118 | |
119 // 'from_space' here is the survivor space at the lower address. | |
120 if (to_space->bottom() < from_space->bottom()) { | |
121 from_space = to_space; | |
122 to_space = young_gen->from_space(); | |
123 } | |
124 | |
125 HeapWord* boundaries[12]; | |
126 unsigned int bidx = 0; | |
127 const unsigned int bidx_max = sizeof(boundaries) / sizeof(boundaries[0]); | |
128 | |
129 boundaries[0] = perm_space->bottom(); | |
130 boundaries[1] = perm_space->top(); | |
131 boundaries[2] = old_space->bottom(); | |
132 boundaries[3] = old_space->top(); | |
133 boundaries[4] = eden_space->bottom(); | |
134 boundaries[5] = eden_space->top(); | |
135 boundaries[6] = from_space->bottom(); | |
136 boundaries[7] = from_space->top(); | |
137 boundaries[8] = to_space->bottom(); | |
138 boundaries[9] = to_space->top(); | |
139 boundaries[10] = to_space->end(); | |
140 boundaries[11] = to_space->end(); | |
141 | |
142 BitMap::idx_t beg_bit = 0; | |
143 BitMap::idx_t end_bit; | |
144 BitMap::idx_t tmp_bit; | |
145 const BitMap::idx_t last_bit = _mark_bitmap.size(); | |
146 do { | |
147 HeapWord* addr = _mark_bitmap.bit_to_addr(beg_bit); | |
148 if (_mark_bitmap.is_marked(beg_bit)) { | |
149 oop obj = (oop)addr; | |
150 assert(obj->is_gc_marked(), "obj header is not marked"); | |
151 end_bit = _mark_bitmap.find_obj_end(beg_bit, last_bit); | |
152 const size_t size = _mark_bitmap.obj_size(beg_bit, end_bit); | |
153 assert(size == (size_t)obj->size(), "end bit wrong?"); | |
154 beg_bit = _mark_bitmap.find_obj_beg(beg_bit + 1, last_bit); | |
155 assert(beg_bit > end_bit, "bit set in middle of an obj"); | |
156 } else { | |
157 if (addr >= boundaries[bidx] && addr < boundaries[bidx + 1]) { | |
158 // a dead object in the current space. | |
159 oop obj = (oop)addr; | |
160 end_bit = _mark_bitmap.addr_to_bit(addr + obj->size()); | |
161 assert(!obj->is_gc_marked(), "obj marked in header, not in bitmap"); | |
162 tmp_bit = beg_bit + 1; | |
163 beg_bit = _mark_bitmap.find_obj_beg(tmp_bit, end_bit); | |
164 assert(beg_bit == end_bit, "beg bit set in unmarked obj"); | |
165 beg_bit = _mark_bitmap.find_obj_end(tmp_bit, end_bit); | |
166 assert(beg_bit == end_bit, "end bit set in unmarked obj"); | |
167 } else if (addr < boundaries[bidx + 2]) { | |
168 // addr is between top in the current space and bottom in the next. | |
169 end_bit = beg_bit + pointer_delta(boundaries[bidx + 2], addr); | |
170 tmp_bit = beg_bit; | |
171 beg_bit = _mark_bitmap.find_obj_beg(tmp_bit, end_bit); | |
172 assert(beg_bit == end_bit, "beg bit set above top"); | |
173 beg_bit = _mark_bitmap.find_obj_end(tmp_bit, end_bit); | |
174 assert(beg_bit == end_bit, "end bit set above top"); | |
175 bidx += 2; | |
176 } else if (bidx < bidx_max - 2) { | |
177 bidx += 2; // ??? | |
178 } else { | |
179 tmp_bit = beg_bit; | |
180 beg_bit = _mark_bitmap.find_obj_beg(tmp_bit, last_bit); | |
181 assert(beg_bit == last_bit, "beg bit set outside heap"); | |
182 beg_bit = _mark_bitmap.find_obj_end(tmp_bit, last_bit); | |
183 assert(beg_bit == last_bit, "end bit set outside heap"); | |
184 } | |
185 } | |
186 } while (beg_bit < last_bit); | |
187 } | |
188 // XXX end - verification code; only works while we also mark in object headers | |
189 | |
190 #ifndef PRODUCT | |
191 const char* PSParallelCompact::space_names[] = { | |
192 "perm", "old ", "eden", "from", "to " | |
193 }; | |
194 | |
195 void PSParallelCompact::print_chunk_ranges() | |
196 { | |
197 tty->print_cr("space bottom top end new_top"); | |
198 tty->print_cr("------ ---------- ---------- ---------- ----------"); | |
199 | |
200 for (unsigned int id = 0; id < last_space_id; ++id) { | |
201 const MutableSpace* space = _space_info[id].space(); | |
202 tty->print_cr("%u %s " | |
264
15dd2594d08e
6718283: existing uses of *_FORMAT_W() were broken by 6521491
jcoomes
parents:
263
diff
changeset
|
203 SIZE_FORMAT_W(10) " " SIZE_FORMAT_W(10) " " |
15dd2594d08e
6718283: existing uses of *_FORMAT_W() were broken by 6521491
jcoomes
parents:
263
diff
changeset
|
204 SIZE_FORMAT_W(10) " " SIZE_FORMAT_W(10) " ", |
0 | 205 id, space_names[id], |
206 summary_data().addr_to_chunk_idx(space->bottom()), | |
207 summary_data().addr_to_chunk_idx(space->top()), | |
208 summary_data().addr_to_chunk_idx(space->end()), | |
209 summary_data().addr_to_chunk_idx(_space_info[id].new_top())); | |
210 } | |
211 } | |
212 | |
213 void | |
214 print_generic_summary_chunk(size_t i, const ParallelCompactData::ChunkData* c) | |
215 { | |
264
15dd2594d08e
6718283: existing uses of *_FORMAT_W() were broken by 6521491
jcoomes
parents:
263
diff
changeset
|
216 #define CHUNK_IDX_FORMAT SIZE_FORMAT_W(7) |
15dd2594d08e
6718283: existing uses of *_FORMAT_W() were broken by 6521491
jcoomes
parents:
263
diff
changeset
|
217 #define CHUNK_DATA_FORMAT SIZE_FORMAT_W(5) |
0 | 218 |
219 ParallelCompactData& sd = PSParallelCompact::summary_data(); | |
220 size_t dci = c->destination() ? sd.addr_to_chunk_idx(c->destination()) : 0; | |
221 tty->print_cr(CHUNK_IDX_FORMAT " " PTR_FORMAT " " | |
222 CHUNK_IDX_FORMAT " " PTR_FORMAT " " | |
223 CHUNK_DATA_FORMAT " " CHUNK_DATA_FORMAT " " | |
224 CHUNK_DATA_FORMAT " " CHUNK_IDX_FORMAT " %d", | |
225 i, c->data_location(), dci, c->destination(), | |
226 c->partial_obj_size(), c->live_obj_size(), | |
227 c->data_size(), c->source_chunk(), c->destination_count()); | |
228 | |
229 #undef CHUNK_IDX_FORMAT | |
230 #undef CHUNK_DATA_FORMAT | |
231 } | |
232 | |
233 void | |
234 print_generic_summary_data(ParallelCompactData& summary_data, | |
235 HeapWord* const beg_addr, | |
236 HeapWord* const end_addr) | |
237 { | |
238 size_t total_words = 0; | |
239 size_t i = summary_data.addr_to_chunk_idx(beg_addr); | |
240 const size_t last = summary_data.addr_to_chunk_idx(end_addr); | |
241 HeapWord* pdest = 0; | |
242 | |
243 while (i <= last) { | |
244 ParallelCompactData::ChunkData* c = summary_data.chunk(i); | |
245 if (c->data_size() != 0 || c->destination() != pdest) { | |
246 print_generic_summary_chunk(i, c); | |
247 total_words += c->data_size(); | |
248 pdest = c->destination(); | |
249 } | |
250 ++i; | |
251 } | |
252 | |
253 tty->print_cr("summary_data_bytes=" SIZE_FORMAT, total_words * HeapWordSize); | |
254 } | |
255 | |
256 void | |
257 print_generic_summary_data(ParallelCompactData& summary_data, | |
258 SpaceInfo* space_info) | |
259 { | |
260 for (unsigned int id = 0; id < PSParallelCompact::last_space_id; ++id) { | |
261 const MutableSpace* space = space_info[id].space(); | |
262 print_generic_summary_data(summary_data, space->bottom(), | |
263 MAX2(space->top(), space_info[id].new_top())); | |
264 } | |
265 } | |
266 | |
267 void | |
268 print_initial_summary_chunk(size_t i, | |
269 const ParallelCompactData::ChunkData* c, | |
270 bool newline = true) | |
271 { | |
264
15dd2594d08e
6718283: existing uses of *_FORMAT_W() were broken by 6521491
jcoomes
parents:
263
diff
changeset
|
272 tty->print(SIZE_FORMAT_W(5) " " PTR_FORMAT " " |
15dd2594d08e
6718283: existing uses of *_FORMAT_W() were broken by 6521491
jcoomes
parents:
263
diff
changeset
|
273 SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " " |
15dd2594d08e
6718283: existing uses of *_FORMAT_W() were broken by 6521491
jcoomes
parents:
263
diff
changeset
|
274 SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " %d", |
0 | 275 i, c->destination(), |
276 c->partial_obj_size(), c->live_obj_size(), | |
277 c->data_size(), c->source_chunk(), c->destination_count()); | |
278 if (newline) tty->cr(); | |
279 } | |
280 | |
281 void | |
282 print_initial_summary_data(ParallelCompactData& summary_data, | |
283 const MutableSpace* space) { | |
284 if (space->top() == space->bottom()) { | |
285 return; | |
286 } | |
287 | |
288 const size_t chunk_size = ParallelCompactData::ChunkSize; | |
289 HeapWord* const top_aligned_up = summary_data.chunk_align_up(space->top()); | |
290 const size_t end_chunk = summary_data.addr_to_chunk_idx(top_aligned_up); | |
291 const ParallelCompactData::ChunkData* c = summary_data.chunk(end_chunk - 1); | |
292 HeapWord* end_addr = c->destination() + c->data_size(); | |
293 const size_t live_in_space = pointer_delta(end_addr, space->bottom()); | |
294 | |
295 // Print (and count) the full chunks at the beginning of the space. | |
296 size_t full_chunk_count = 0; | |
297 size_t i = summary_data.addr_to_chunk_idx(space->bottom()); | |
298 while (i < end_chunk && summary_data.chunk(i)->data_size() == chunk_size) { | |
299 print_initial_summary_chunk(i, summary_data.chunk(i)); | |
300 ++full_chunk_count; | |
301 ++i; | |
302 } | |
303 | |
304 size_t live_to_right = live_in_space - full_chunk_count * chunk_size; | |
305 | |
306 double max_reclaimed_ratio = 0.0; | |
307 size_t max_reclaimed_ratio_chunk = 0; | |
308 size_t max_dead_to_right = 0; | |
309 size_t max_live_to_right = 0; | |
310 | |
311 // Print the 'reclaimed ratio' for chunks while there is something live in the | |
312 // chunk or to the right of it. The remaining chunks are empty (and | |
313 // uninteresting), and computing the ratio will result in division by 0. | |
314 while (i < end_chunk && live_to_right > 0) { | |
315 c = summary_data.chunk(i); | |
316 HeapWord* const chunk_addr = summary_data.chunk_to_addr(i); | |
317 const size_t used_to_right = pointer_delta(space->top(), chunk_addr); | |
318 const size_t dead_to_right = used_to_right - live_to_right; | |
319 const double reclaimed_ratio = double(dead_to_right) / live_to_right; | |
320 | |
321 if (reclaimed_ratio > max_reclaimed_ratio) { | |
322 max_reclaimed_ratio = reclaimed_ratio; | |
323 max_reclaimed_ratio_chunk = i; | |
324 max_dead_to_right = dead_to_right; | |
325 max_live_to_right = live_to_right; | |
326 } | |
327 | |
328 print_initial_summary_chunk(i, c, false); | |
264
15dd2594d08e
6718283: existing uses of *_FORMAT_W() were broken by 6521491
jcoomes
parents:
263
diff
changeset
|
329 tty->print_cr(" %12.10f " SIZE_FORMAT_W(10) " " SIZE_FORMAT_W(10), |
0 | 330 reclaimed_ratio, dead_to_right, live_to_right); |
331 | |
332 live_to_right -= c->data_size(); | |
333 ++i; | |
334 } | |
335 | |
336 // Any remaining chunks are empty. Print one more if there is one. | |
337 if (i < end_chunk) { | |
338 print_initial_summary_chunk(i, summary_data.chunk(i)); | |
339 } | |
340 | |
264
15dd2594d08e
6718283: existing uses of *_FORMAT_W() were broken by 6521491
jcoomes
parents:
263
diff
changeset
|
341 tty->print_cr("max: " SIZE_FORMAT_W(4) " d2r=" SIZE_FORMAT_W(10) " " |
15dd2594d08e
6718283: existing uses of *_FORMAT_W() were broken by 6521491
jcoomes
parents:
263
diff
changeset
|
342 "l2r=" SIZE_FORMAT_W(10) " max_ratio=%14.12f", |
0 | 343 max_reclaimed_ratio_chunk, max_dead_to_right, |
344 max_live_to_right, max_reclaimed_ratio); | |
345 } | |
346 | |
347 void | |
348 print_initial_summary_data(ParallelCompactData& summary_data, | |
349 SpaceInfo* space_info) { | |
350 unsigned int id = PSParallelCompact::perm_space_id; | |
351 const MutableSpace* space; | |
352 do { | |
353 space = space_info[id].space(); | |
354 print_initial_summary_data(summary_data, space); | |
355 } while (++id < PSParallelCompact::eden_space_id); | |
356 | |
357 do { | |
358 space = space_info[id].space(); | |
359 print_generic_summary_data(summary_data, space->bottom(), space->top()); | |
360 } while (++id < PSParallelCompact::last_space_id); | |
361 } | |
362 #endif // #ifndef PRODUCT | |
363 | |
364 #ifdef ASSERT | |
365 size_t add_obj_count; | |
366 size_t add_obj_size; | |
367 size_t mark_bitmap_count; | |
368 size_t mark_bitmap_size; | |
369 #endif // #ifdef ASSERT | |
370 | |
371 ParallelCompactData::ParallelCompactData() | |
372 { | |
373 _region_start = 0; | |
374 | |
375 _chunk_vspace = 0; | |
376 _chunk_data = 0; | |
377 _chunk_count = 0; | |
378 | |
379 _block_vspace = 0; | |
380 _block_data = 0; | |
381 _block_count = 0; | |
382 } | |
383 | |
384 bool ParallelCompactData::initialize(MemRegion covered_region) | |
385 { | |
386 _region_start = covered_region.start(); | |
387 const size_t region_size = covered_region.word_size(); | |
388 DEBUG_ONLY(_region_end = _region_start + region_size;) | |
389 | |
390 assert(chunk_align_down(_region_start) == _region_start, | |
391 "region start not aligned"); | |
392 assert((region_size & ChunkSizeOffsetMask) == 0, | |
393 "region size not a multiple of ChunkSize"); | |
394 | |
395 bool result = initialize_chunk_data(region_size); | |
396 | |
397 // Initialize the block data if it will be used for updating pointers, or if | |
398 // this is a debug build. | |
399 if (!UseParallelOldGCChunkPointerCalc || trueInDebug) { | |
400 result = result && initialize_block_data(region_size); | |
401 } | |
402 | |
403 return result; | |
404 } | |
405 | |
406 PSVirtualSpace* | |
407 ParallelCompactData::create_vspace(size_t count, size_t element_size) | |
408 { | |
409 const size_t raw_bytes = count * element_size; | |
410 const size_t page_sz = os::page_size_for_region(raw_bytes, raw_bytes, 10); | |
411 const size_t granularity = os::vm_allocation_granularity(); | |
412 const size_t bytes = align_size_up(raw_bytes, MAX2(page_sz, granularity)); | |
413 | |
414 const size_t rs_align = page_sz == (size_t) os::vm_page_size() ? 0 : | |
415 MAX2(page_sz, granularity); | |
79
82db0859acbe
6642862: Code cache allocation fails with large pages after 6588638
jcoomes
parents:
0
diff
changeset
|
416 ReservedSpace rs(bytes, rs_align, rs_align > 0); |
0 | 417 os::trace_page_sizes("par compact", raw_bytes, raw_bytes, page_sz, rs.base(), |
418 rs.size()); | |
419 PSVirtualSpace* vspace = new PSVirtualSpace(rs, page_sz); | |
420 if (vspace != 0) { | |
421 if (vspace->expand_by(bytes)) { | |
422 return vspace; | |
423 } | |
424 delete vspace; | |
425 } | |
426 | |
427 return 0; | |
428 } | |
429 | |
430 bool ParallelCompactData::initialize_chunk_data(size_t region_size) | |
431 { | |
432 const size_t count = (region_size + ChunkSizeOffsetMask) >> Log2ChunkSize; | |
433 _chunk_vspace = create_vspace(count, sizeof(ChunkData)); | |
434 if (_chunk_vspace != 0) { | |
435 _chunk_data = (ChunkData*)_chunk_vspace->reserved_low_addr(); | |
436 _chunk_count = count; | |
437 return true; | |
438 } | |
439 return false; | |
440 } | |
441 | |
442 bool ParallelCompactData::initialize_block_data(size_t region_size) | |
443 { | |
444 const size_t count = (region_size + BlockOffsetMask) >> Log2BlockSize; | |
445 _block_vspace = create_vspace(count, sizeof(BlockData)); | |
446 if (_block_vspace != 0) { | |
447 _block_data = (BlockData*)_block_vspace->reserved_low_addr(); | |
448 _block_count = count; | |
449 return true; | |
450 } | |
451 return false; | |
452 } | |
453 | |
454 void ParallelCompactData::clear() | |
455 { | |
456 if (_block_data) { | |
457 memset(_block_data, 0, _block_vspace->committed_size()); | |
458 } | |
459 memset(_chunk_data, 0, _chunk_vspace->committed_size()); | |
460 } | |
461 | |
462 void ParallelCompactData::clear_range(size_t beg_chunk, size_t end_chunk) { | |
463 assert(beg_chunk <= _chunk_count, "beg_chunk out of range"); | |
464 assert(end_chunk <= _chunk_count, "end_chunk out of range"); | |
465 assert(ChunkSize % BlockSize == 0, "ChunkSize not a multiple of BlockSize"); | |
466 | |
467 const size_t chunk_cnt = end_chunk - beg_chunk; | |
468 | |
469 if (_block_data) { | |
470 const size_t blocks_per_chunk = ChunkSize / BlockSize; | |
471 const size_t beg_block = beg_chunk * blocks_per_chunk; | |
472 const size_t block_cnt = chunk_cnt * blocks_per_chunk; | |
473 memset(_block_data + beg_block, 0, block_cnt * sizeof(BlockData)); | |
474 } | |
475 memset(_chunk_data + beg_chunk, 0, chunk_cnt * sizeof(ChunkData)); | |
476 } | |
477 | |
478 HeapWord* ParallelCompactData::partial_obj_end(size_t chunk_idx) const | |
479 { | |
480 const ChunkData* cur_cp = chunk(chunk_idx); | |
481 const ChunkData* const end_cp = chunk(chunk_count() - 1); | |
482 | |
483 HeapWord* result = chunk_to_addr(chunk_idx); | |
484 if (cur_cp < end_cp) { | |
485 do { | |
486 result += cur_cp->partial_obj_size(); | |
487 } while (cur_cp->partial_obj_size() == ChunkSize && ++cur_cp < end_cp); | |
488 } | |
489 return result; | |
490 } | |
491 | |
492 void ParallelCompactData::add_obj(HeapWord* addr, size_t len) | |
493 { | |
494 const size_t obj_ofs = pointer_delta(addr, _region_start); | |
495 const size_t beg_chunk = obj_ofs >> Log2ChunkSize; | |
496 const size_t end_chunk = (obj_ofs + len - 1) >> Log2ChunkSize; | |
497 | |
498 DEBUG_ONLY(Atomic::inc_ptr(&add_obj_count);) | |
499 DEBUG_ONLY(Atomic::add_ptr(len, &add_obj_size);) | |
500 | |
501 if (beg_chunk == end_chunk) { | |
502 // All in one chunk. | |
503 _chunk_data[beg_chunk].add_live_obj(len); | |
504 return; | |
505 } | |
506 | |
507 // First chunk. | |
508 const size_t beg_ofs = chunk_offset(addr); | |
509 _chunk_data[beg_chunk].add_live_obj(ChunkSize - beg_ofs); | |
510 | |
511 klassOop klass = ((oop)addr)->klass(); | |
512 // Middle chunks--completely spanned by this object. | |
513 for (size_t chunk = beg_chunk + 1; chunk < end_chunk; ++chunk) { | |
514 _chunk_data[chunk].set_partial_obj_size(ChunkSize); | |
515 _chunk_data[chunk].set_partial_obj_addr(addr); | |
516 } | |
517 | |
518 // Last chunk. | |
519 const size_t end_ofs = chunk_offset(addr + len - 1); | |
520 _chunk_data[end_chunk].set_partial_obj_size(end_ofs + 1); | |
521 _chunk_data[end_chunk].set_partial_obj_addr(addr); | |
522 } | |
523 | |
524 void | |
525 ParallelCompactData::summarize_dense_prefix(HeapWord* beg, HeapWord* end) | |
526 { | |
527 assert(chunk_offset(beg) == 0, "not ChunkSize aligned"); | |
528 assert(chunk_offset(end) == 0, "not ChunkSize aligned"); | |
529 | |
530 size_t cur_chunk = addr_to_chunk_idx(beg); | |
531 const size_t end_chunk = addr_to_chunk_idx(end); | |
532 HeapWord* addr = beg; | |
533 while (cur_chunk < end_chunk) { | |
534 _chunk_data[cur_chunk].set_destination(addr); | |
535 _chunk_data[cur_chunk].set_destination_count(0); | |
536 _chunk_data[cur_chunk].set_source_chunk(cur_chunk); | |
537 _chunk_data[cur_chunk].set_data_location(addr); | |
538 | |
539 // Update live_obj_size so the chunk appears completely full. | |
540 size_t live_size = ChunkSize - _chunk_data[cur_chunk].partial_obj_size(); | |
541 _chunk_data[cur_chunk].set_live_obj_size(live_size); | |
542 | |
543 ++cur_chunk; | |
544 addr += ChunkSize; | |
545 } | |
546 } | |
547 | |
548 bool ParallelCompactData::summarize(HeapWord* target_beg, HeapWord* target_end, | |
549 HeapWord* source_beg, HeapWord* source_end, | |
550 HeapWord** target_next, | |
551 HeapWord** source_next) { | |
552 // This is too strict. | |
553 // assert(chunk_offset(source_beg) == 0, "not ChunkSize aligned"); | |
554 | |
555 if (TraceParallelOldGCSummaryPhase) { | |
556 tty->print_cr("tb=" PTR_FORMAT " te=" PTR_FORMAT " " | |
557 "sb=" PTR_FORMAT " se=" PTR_FORMAT " " | |
558 "tn=" PTR_FORMAT " sn=" PTR_FORMAT, | |
559 target_beg, target_end, | |
560 source_beg, source_end, | |
561 target_next != 0 ? *target_next : (HeapWord*) 0, | |
562 source_next != 0 ? *source_next : (HeapWord*) 0); | |
563 } | |
564 | |
565 size_t cur_chunk = addr_to_chunk_idx(source_beg); | |
566 const size_t end_chunk = addr_to_chunk_idx(chunk_align_up(source_end)); | |
567 | |
568 HeapWord *dest_addr = target_beg; | |
569 while (cur_chunk < end_chunk) { | |
570 size_t words = _chunk_data[cur_chunk].data_size(); | |
571 | |
572 #if 1 | |
573 assert(pointer_delta(target_end, dest_addr) >= words, | |
574 "source region does not fit into target region"); | |
575 #else | |
576 // XXX - need some work on the corner cases here. If the chunk does not | |
577 // fit, then must either make sure any partial_obj from the chunk fits, or | |
578 // 'undo' the initial part of the partial_obj that is in the previous chunk. | |
579 if (dest_addr + words >= target_end) { | |
580 // Let the caller know where to continue. | |
581 *target_next = dest_addr; | |
582 *source_next = chunk_to_addr(cur_chunk); | |
583 return false; | |
584 } | |
585 #endif // #if 1 | |
586 | |
587 _chunk_data[cur_chunk].set_destination(dest_addr); | |
588 | |
589 // Set the destination_count for cur_chunk, and if necessary, update | |
590 // source_chunk for a destination chunk. The source_chunk field is updated | |
591 // if cur_chunk is the first (left-most) chunk to be copied to a destination | |
592 // chunk. | |
593 // | |
594 // The destination_count calculation is a bit subtle. A chunk that has data | |
595 // that compacts into itself does not count itself as a destination. This | |
596 // maintains the invariant that a zero count means the chunk is available | |
597 // and can be claimed and then filled. | |
598 if (words > 0) { | |
599 HeapWord* const last_addr = dest_addr + words - 1; | |
600 const size_t dest_chunk_1 = addr_to_chunk_idx(dest_addr); | |
601 const size_t dest_chunk_2 = addr_to_chunk_idx(last_addr); | |
602 #if 0 | |
603 // Initially assume that the destination chunks will be the same and | |
604 // adjust the value below if necessary. Under this assumption, if | |
605 // cur_chunk == dest_chunk_2, then cur_chunk will be compacted completely | |
606 // into itself. | |
607 uint destination_count = cur_chunk == dest_chunk_2 ? 0 : 1; | |
608 if (dest_chunk_1 != dest_chunk_2) { | |
609 // Destination chunks differ; adjust destination_count. | |
610 destination_count += 1; | |
611 // Data from cur_chunk will be copied to the start of dest_chunk_2. | |
612 _chunk_data[dest_chunk_2].set_source_chunk(cur_chunk); | |
613 } else if (chunk_offset(dest_addr) == 0) { | |
614 // Data from cur_chunk will be copied to the start of the destination | |
615 // chunk. | |
616 _chunk_data[dest_chunk_1].set_source_chunk(cur_chunk); | |
617 } | |
618 #else | |
619 // Initially assume that the destination chunks will be different and | |
620 // adjust the value below if necessary. Under this assumption, if | |
621 // cur_chunk == dest_chunk2, then cur_chunk will be compacted partially | |
622 // into dest_chunk_1 and partially into itself. | |
623 uint destination_count = cur_chunk == dest_chunk_2 ? 1 : 2; | |
624 if (dest_chunk_1 != dest_chunk_2) { | |
625 // Data from cur_chunk will be copied to the start of dest_chunk_2. | |
626 _chunk_data[dest_chunk_2].set_source_chunk(cur_chunk); | |
627 } else { | |
628 // Destination chunks are the same; adjust destination_count. | |
629 destination_count -= 1; | |
630 if (chunk_offset(dest_addr) == 0) { | |
631 // Data from cur_chunk will be copied to the start of the destination | |
632 // chunk. | |
633 _chunk_data[dest_chunk_1].set_source_chunk(cur_chunk); | |
634 } | |
635 } | |
636 #endif // #if 0 | |
637 | |
638 _chunk_data[cur_chunk].set_destination_count(destination_count); | |
639 _chunk_data[cur_chunk].set_data_location(chunk_to_addr(cur_chunk)); | |
640 dest_addr += words; | |
641 } | |
642 | |
643 ++cur_chunk; | |
644 } | |
645 | |
646 *target_next = dest_addr; | |
647 return true; | |
648 } | |
649 | |
650 bool ParallelCompactData::partial_obj_ends_in_block(size_t block_index) { | |
651 HeapWord* block_addr = block_to_addr(block_index); | |
652 HeapWord* block_end_addr = block_addr + BlockSize; | |
653 size_t chunk_index = addr_to_chunk_idx(block_addr); | |
654 HeapWord* partial_obj_end_addr = partial_obj_end(chunk_index); | |
655 | |
656 // An object that ends at the end of the block, ends | |
657 // in the block (the last word of the object is to | |
658 // the left of the end). | |
659 if ((block_addr < partial_obj_end_addr) && | |
660 (partial_obj_end_addr <= block_end_addr)) { | |
661 return true; | |
662 } | |
663 | |
664 return false; | |
665 } | |
666 | |
667 HeapWord* ParallelCompactData::calc_new_pointer(HeapWord* addr) { | |
668 HeapWord* result = NULL; | |
669 if (UseParallelOldGCChunkPointerCalc) { | |
670 result = chunk_calc_new_pointer(addr); | |
671 } else { | |
672 result = block_calc_new_pointer(addr); | |
673 } | |
674 return result; | |
675 } | |
676 | |
677 // This method is overly complicated (expensive) to be called | |
678 // for every reference. | |
679 // Try to restructure this so that a NULL is returned if | |
680 // the object is dead. But don't wast the cycles to explicitly check | |
681 // that it is dead since only live objects should be passed in. | |
682 | |
683 HeapWord* ParallelCompactData::chunk_calc_new_pointer(HeapWord* addr) { | |
684 assert(addr != NULL, "Should detect NULL oop earlier"); | |
685 assert(PSParallelCompact::gc_heap()->is_in(addr), "addr not in heap"); | |
686 #ifdef ASSERT | |
687 if (PSParallelCompact::mark_bitmap()->is_unmarked(addr)) { | |
688 gclog_or_tty->print_cr("calc_new_pointer:: addr " PTR_FORMAT, addr); | |
689 } | |
690 #endif | |
691 assert(PSParallelCompact::mark_bitmap()->is_marked(addr), "obj not marked"); | |
692 | |
693 // Chunk covering the object. | |
694 size_t chunk_index = addr_to_chunk_idx(addr); | |
695 const ChunkData* const chunk_ptr = chunk(chunk_index); | |
696 HeapWord* const chunk_addr = chunk_align_down(addr); | |
697 | |
698 assert(addr < chunk_addr + ChunkSize, "Chunk does not cover object"); | |
699 assert(addr_to_chunk_ptr(chunk_addr) == chunk_ptr, "sanity check"); | |
700 | |
701 HeapWord* result = chunk_ptr->destination(); | |
702 | |
703 // If all the data in the chunk is live, then the new location of the object | |
704 // can be calculated from the destination of the chunk plus the offset of the | |
705 // object in the chunk. | |
706 if (chunk_ptr->data_size() == ChunkSize) { | |
707 result += pointer_delta(addr, chunk_addr); | |
708 return result; | |
709 } | |
710 | |
711 // The new location of the object is | |
712 // chunk destination + | |
713 // size of the partial object extending onto the chunk + | |
714 // sizes of the live objects in the Chunk that are to the left of addr | |
715 const size_t partial_obj_size = chunk_ptr->partial_obj_size(); | |
716 HeapWord* const search_start = chunk_addr + partial_obj_size; | |
717 | |
718 const ParMarkBitMap* bitmap = PSParallelCompact::mark_bitmap(); | |
719 size_t live_to_left = bitmap->live_words_in_range(search_start, oop(addr)); | |
720 | |
721 result += partial_obj_size + live_to_left; | |
722 assert(result <= addr, "object cannot move to the right"); | |
723 return result; | |
724 } | |
725 | |
726 HeapWord* ParallelCompactData::block_calc_new_pointer(HeapWord* addr) { | |
727 assert(addr != NULL, "Should detect NULL oop earlier"); | |
728 assert(PSParallelCompact::gc_heap()->is_in(addr), "addr not in heap"); | |
729 #ifdef ASSERT | |
730 if (PSParallelCompact::mark_bitmap()->is_unmarked(addr)) { | |
731 gclog_or_tty->print_cr("calc_new_pointer:: addr " PTR_FORMAT, addr); | |
732 } | |
733 #endif | |
734 assert(PSParallelCompact::mark_bitmap()->is_marked(addr), "obj not marked"); | |
735 | |
736 // Chunk covering the object. | |
737 size_t chunk_index = addr_to_chunk_idx(addr); | |
738 const ChunkData* const chunk_ptr = chunk(chunk_index); | |
739 HeapWord* const chunk_addr = chunk_align_down(addr); | |
740 | |
741 assert(addr < chunk_addr + ChunkSize, "Chunk does not cover object"); | |
742 assert(addr_to_chunk_ptr(chunk_addr) == chunk_ptr, "sanity check"); | |
743 | |
744 HeapWord* result = chunk_ptr->destination(); | |
745 | |
746 // If all the data in the chunk is live, then the new location of the object | |
747 // can be calculated from the destination of the chunk plus the offset of the | |
748 // object in the chunk. | |
749 if (chunk_ptr->data_size() == ChunkSize) { | |
750 result += pointer_delta(addr, chunk_addr); | |
751 return result; | |
752 } | |
753 | |
754 // The new location of the object is | |
755 // chunk destination + | |
756 // block offset + | |
757 // sizes of the live objects in the Block that are to the left of addr | |
758 const size_t block_offset = addr_to_block_ptr(addr)->offset(); | |
759 HeapWord* const search_start = chunk_addr + block_offset; | |
760 | |
761 const ParMarkBitMap* bitmap = PSParallelCompact::mark_bitmap(); | |
762 size_t live_to_left = bitmap->live_words_in_range(search_start, oop(addr)); | |
763 | |
764 result += block_offset + live_to_left; | |
765 assert(result <= addr, "object cannot move to the right"); | |
766 assert(result == chunk_calc_new_pointer(addr), "Should match"); | |
767 return result; | |
768 } | |
769 | |
770 klassOop ParallelCompactData::calc_new_klass(klassOop old_klass) { | |
771 klassOop updated_klass; | |
772 if (PSParallelCompact::should_update_klass(old_klass)) { | |
773 updated_klass = (klassOop) calc_new_pointer(old_klass); | |
774 } else { | |
775 updated_klass = old_klass; | |
776 } | |
777 | |
778 return updated_klass; | |
779 } | |
780 | |
781 #ifdef ASSERT | |
782 void ParallelCompactData::verify_clear(const PSVirtualSpace* vspace) | |
783 { | |
784 const size_t* const beg = (const size_t*)vspace->committed_low_addr(); | |
785 const size_t* const end = (const size_t*)vspace->committed_high_addr(); | |
786 for (const size_t* p = beg; p < end; ++p) { | |
787 assert(*p == 0, "not zero"); | |
788 } | |
789 } | |
790 | |
791 void ParallelCompactData::verify_clear() | |
792 { | |
793 verify_clear(_chunk_vspace); | |
794 verify_clear(_block_vspace); | |
795 } | |
796 #endif // #ifdef ASSERT | |
797 | |
798 #ifdef NOT_PRODUCT | |
799 ParallelCompactData::ChunkData* debug_chunk(size_t chunk_index) { | |
800 ParallelCompactData& sd = PSParallelCompact::summary_data(); | |
801 return sd.chunk(chunk_index); | |
802 } | |
803 #endif | |
804 | |
805 elapsedTimer PSParallelCompact::_accumulated_time; | |
806 unsigned int PSParallelCompact::_total_invocations = 0; | |
807 unsigned int PSParallelCompact::_maximum_compaction_gc_num = 0; | |
808 jlong PSParallelCompact::_time_of_last_gc = 0; | |
809 CollectorCounters* PSParallelCompact::_counters = NULL; | |
810 ParMarkBitMap PSParallelCompact::_mark_bitmap; | |
811 ParallelCompactData PSParallelCompact::_summary_data; | |
812 | |
813 PSParallelCompact::IsAliveClosure PSParallelCompact::_is_alive_closure; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
79
diff
changeset
|
814 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
79
diff
changeset
|
815 void PSParallelCompact::IsAliveClosure::do_object(oop p) { ShouldNotReachHere(); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
79
diff
changeset
|
816 bool PSParallelCompact::IsAliveClosure::do_object_b(oop p) { return mark_bitmap()->is_marked(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
79
diff
changeset
|
817 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
79
diff
changeset
|
818 void PSParallelCompact::KeepAliveClosure::do_oop(oop* p) { PSParallelCompact::KeepAliveClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
79
diff
changeset
|
819 void PSParallelCompact::KeepAliveClosure::do_oop(narrowOop* p) { PSParallelCompact::KeepAliveClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
79
diff
changeset
|
820 |
0 | 821 PSParallelCompact::AdjustPointerClosure PSParallelCompact::_adjust_root_pointer_closure(true); |
822 PSParallelCompact::AdjustPointerClosure PSParallelCompact::_adjust_pointer_closure(false); | |
823 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
79
diff
changeset
|
824 void PSParallelCompact::AdjustPointerClosure::do_oop(oop* p) { adjust_pointer(p, _is_root); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
79
diff
changeset
|
825 void PSParallelCompact::AdjustPointerClosure::do_oop(narrowOop* p) { adjust_pointer(p, _is_root); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
79
diff
changeset
|
826 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
79
diff
changeset
|
827 void PSParallelCompact::FollowStackClosure::do_void() { follow_stack(_compaction_manager); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
79
diff
changeset
|
828 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
79
diff
changeset
|
829 void PSParallelCompact::MarkAndPushClosure::do_oop(oop* p) { mark_and_push(_compaction_manager, p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
79
diff
changeset
|
830 void PSParallelCompact::MarkAndPushClosure::do_oop(narrowOop* p) { mark_and_push(_compaction_manager, p); } |
0 | 831 |
832 void PSParallelCompact::post_initialize() { | |
833 ParallelScavengeHeap* heap = gc_heap(); | |
834 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); | |
835 | |
836 MemRegion mr = heap->reserved_region(); | |
837 _ref_processor = ReferenceProcessor::create_ref_processor( | |
838 mr, // span | |
839 true, // atomic_discovery | |
840 true, // mt_discovery | |
841 &_is_alive_closure, | |
842 ParallelGCThreads, | |
843 ParallelRefProcEnabled); | |
844 _counters = new CollectorCounters("PSParallelCompact", 1); | |
845 | |
846 // Initialize static fields in ParCompactionManager. | |
847 ParCompactionManager::initialize(mark_bitmap()); | |
848 } | |
849 | |
850 bool PSParallelCompact::initialize() { | |
851 ParallelScavengeHeap* heap = gc_heap(); | |
852 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); | |
853 MemRegion mr = heap->reserved_region(); | |
854 | |
855 // Was the old gen get allocated successfully? | |
856 if (!heap->old_gen()->is_allocated()) { | |
857 return false; | |
858 } | |
859 | |
860 initialize_space_info(); | |
861 initialize_dead_wood_limiter(); | |
862 | |
863 if (!_mark_bitmap.initialize(mr)) { | |
864 vm_shutdown_during_initialization("Unable to allocate bit map for " | |
865 "parallel garbage collection for the requested heap size."); | |
866 return false; | |
867 } | |
868 | |
869 if (!_summary_data.initialize(mr)) { | |
870 vm_shutdown_during_initialization("Unable to allocate tables for " | |
871 "parallel garbage collection for the requested heap size."); | |
872 return false; | |
873 } | |
874 | |
875 return true; | |
876 } | |
877 | |
878 void PSParallelCompact::initialize_space_info() | |
879 { | |
880 memset(&_space_info, 0, sizeof(_space_info)); | |
881 | |
882 ParallelScavengeHeap* heap = gc_heap(); | |
883 PSYoungGen* young_gen = heap->young_gen(); | |
884 MutableSpace* perm_space = heap->perm_gen()->object_space(); | |
885 | |
886 _space_info[perm_space_id].set_space(perm_space); | |
887 _space_info[old_space_id].set_space(heap->old_gen()->object_space()); | |
888 _space_info[eden_space_id].set_space(young_gen->eden_space()); | |
889 _space_info[from_space_id].set_space(young_gen->from_space()); | |
890 _space_info[to_space_id].set_space(young_gen->to_space()); | |
891 | |
892 _space_info[perm_space_id].set_start_array(heap->perm_gen()->start_array()); | |
893 _space_info[old_space_id].set_start_array(heap->old_gen()->start_array()); | |
894 | |
895 _space_info[perm_space_id].set_min_dense_prefix(perm_space->top()); | |
896 if (TraceParallelOldGCDensePrefix) { | |
897 tty->print_cr("perm min_dense_prefix=" PTR_FORMAT, | |
898 _space_info[perm_space_id].min_dense_prefix()); | |
899 } | |
900 } | |
901 | |
902 void PSParallelCompact::initialize_dead_wood_limiter() | |
903 { | |
904 const size_t max = 100; | |
905 _dwl_mean = double(MIN2(ParallelOldDeadWoodLimiterMean, max)) / 100.0; | |
906 _dwl_std_dev = double(MIN2(ParallelOldDeadWoodLimiterStdDev, max)) / 100.0; | |
907 _dwl_first_term = 1.0 / (sqrt(2.0 * M_PI) * _dwl_std_dev); | |
908 DEBUG_ONLY(_dwl_initialized = true;) | |
909 _dwl_adjustment = normal_distribution(1.0); | |
910 } | |
911 | |
912 // Simple class for storing info about the heap at the start of GC, to be used | |
913 // after GC for comparison/printing. | |
914 class PreGCValues { | |
915 public: | |
916 PreGCValues() { } | |
917 PreGCValues(ParallelScavengeHeap* heap) { fill(heap); } | |
918 | |
919 void fill(ParallelScavengeHeap* heap) { | |
920 _heap_used = heap->used(); | |
921 _young_gen_used = heap->young_gen()->used_in_bytes(); | |
922 _old_gen_used = heap->old_gen()->used_in_bytes(); | |
923 _perm_gen_used = heap->perm_gen()->used_in_bytes(); | |
924 }; | |
925 | |
926 size_t heap_used() const { return _heap_used; } | |
927 size_t young_gen_used() const { return _young_gen_used; } | |
928 size_t old_gen_used() const { return _old_gen_used; } | |
929 size_t perm_gen_used() const { return _perm_gen_used; } | |
930 | |
931 private: | |
932 size_t _heap_used; | |
933 size_t _young_gen_used; | |
934 size_t _old_gen_used; | |
935 size_t _perm_gen_used; | |
936 }; | |
937 | |
938 void | |
939 PSParallelCompact::clear_data_covering_space(SpaceId id) | |
940 { | |
941 // At this point, top is the value before GC, new_top() is the value that will | |
942 // be set at the end of GC. The marking bitmap is cleared to top; nothing | |
943 // should be marked above top. The summary data is cleared to the larger of | |
944 // top & new_top. | |
945 MutableSpace* const space = _space_info[id].space(); | |
946 HeapWord* const bot = space->bottom(); | |
947 HeapWord* const top = space->top(); | |
948 HeapWord* const max_top = MAX2(top, _space_info[id].new_top()); | |
949 | |
950 const idx_t beg_bit = _mark_bitmap.addr_to_bit(bot); | |
951 const idx_t end_bit = BitMap::word_align_up(_mark_bitmap.addr_to_bit(top)); | |
952 _mark_bitmap.clear_range(beg_bit, end_bit); | |
953 | |
954 const size_t beg_chunk = _summary_data.addr_to_chunk_idx(bot); | |
955 const size_t end_chunk = | |
956 _summary_data.addr_to_chunk_idx(_summary_data.chunk_align_up(max_top)); | |
957 _summary_data.clear_range(beg_chunk, end_chunk); | |
958 } | |
959 | |
960 void PSParallelCompact::pre_compact(PreGCValues* pre_gc_values) | |
961 { | |
962 // Update the from & to space pointers in space_info, since they are swapped | |
963 // at each young gen gc. Do the update unconditionally (even though a | |
964 // promotion failure does not swap spaces) because an unknown number of minor | |
965 // collections will have swapped the spaces an unknown number of times. | |
966 TraceTime tm("pre compact", print_phases(), true, gclog_or_tty); | |
967 ParallelScavengeHeap* heap = gc_heap(); | |
968 _space_info[from_space_id].set_space(heap->young_gen()->from_space()); | |
969 _space_info[to_space_id].set_space(heap->young_gen()->to_space()); | |
970 | |
971 pre_gc_values->fill(heap); | |
972 | |
973 ParCompactionManager::reset(); | |
974 NOT_PRODUCT(_mark_bitmap.reset_counters()); | |
975 DEBUG_ONLY(add_obj_count = add_obj_size = 0;) | |
976 DEBUG_ONLY(mark_bitmap_count = mark_bitmap_size = 0;) | |
977 | |
978 // Increment the invocation count | |
139
c0492d52d55b
6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents:
0
diff
changeset
|
979 heap->increment_total_collections(true); |
0 | 980 |
981 // We need to track unique mark sweep invocations as well. | |
982 _total_invocations++; | |
983 | |
984 if (PrintHeapAtGC) { | |
985 Universe::print_heap_before_gc(); | |
986 } | |
987 | |
988 // Fill in TLABs | |
989 heap->accumulate_statistics_all_tlabs(); | |
990 heap->ensure_parsability(true); // retire TLABs | |
991 | |
992 if (VerifyBeforeGC && heap->total_collections() >= VerifyGCStartAt) { | |
993 HandleMark hm; // Discard invalid handles created during verification | |
994 gclog_or_tty->print(" VerifyBeforeGC:"); | |
995 Universe::verify(true); | |
996 } | |
997 | |
998 // Verify object start arrays | |
999 if (VerifyObjectStartArray && | |
1000 VerifyBeforeGC) { | |
1001 heap->old_gen()->verify_object_start_array(); | |
1002 heap->perm_gen()->verify_object_start_array(); | |
1003 } | |
1004 | |
1005 DEBUG_ONLY(mark_bitmap()->verify_clear();) | |
1006 DEBUG_ONLY(summary_data().verify_clear();) | |
210 | 1007 |
1008 // Have worker threads release resources the next time they run a task. | |
1009 gc_task_manager()->release_all_resources(); | |
0 | 1010 } |
1011 | |
1012 void PSParallelCompact::post_compact() | |
1013 { | |
1014 TraceTime tm("post compact", print_phases(), true, gclog_or_tty); | |
1015 | |
1016 // Clear the marking bitmap and summary data and update top() in each space. | |
1017 for (unsigned int id = perm_space_id; id < last_space_id; ++id) { | |
1018 clear_data_covering_space(SpaceId(id)); | |
1019 _space_info[id].space()->set_top(_space_info[id].new_top()); | |
1020 } | |
1021 | |
1022 MutableSpace* const eden_space = _space_info[eden_space_id].space(); | |
1023 MutableSpace* const from_space = _space_info[from_space_id].space(); | |
1024 MutableSpace* const to_space = _space_info[to_space_id].space(); | |
1025 | |
1026 ParallelScavengeHeap* heap = gc_heap(); | |
1027 bool eden_empty = eden_space->is_empty(); | |
1028 if (!eden_empty) { | |
1029 eden_empty = absorb_live_data_from_eden(heap->size_policy(), | |
1030 heap->young_gen(), heap->old_gen()); | |
1031 } | |
1032 | |
1033 // Update heap occupancy information which is used as input to the soft ref | |
1034 // clearing policy at the next gc. | |
1035 Universe::update_heap_info_at_gc(); | |
1036 | |
1037 bool young_gen_empty = eden_empty && from_space->is_empty() && | |
1038 to_space->is_empty(); | |
1039 | |
1040 BarrierSet* bs = heap->barrier_set(); | |
1041 if (bs->is_a(BarrierSet::ModRef)) { | |
1042 ModRefBarrierSet* modBS = (ModRefBarrierSet*)bs; | |
1043 MemRegion old_mr = heap->old_gen()->reserved(); | |
1044 MemRegion perm_mr = heap->perm_gen()->reserved(); | |
1045 assert(perm_mr.end() <= old_mr.start(), "Generations out of order"); | |
1046 | |
1047 if (young_gen_empty) { | |
1048 modBS->clear(MemRegion(perm_mr.start(), old_mr.end())); | |
1049 } else { | |
1050 modBS->invalidate(MemRegion(perm_mr.start(), old_mr.end())); | |
1051 } | |
1052 } | |
1053 | |
1054 Threads::gc_epilogue(); | |
1055 CodeCache::gc_epilogue(); | |
1056 | |
1057 COMPILER2_PRESENT(DerivedPointerTable::update_pointers()); | |
1058 | |
1059 ref_processor()->enqueue_discovered_references(NULL); | |
1060 | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
1061 if (ZapUnusedHeapArea) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
1062 heap->gen_mangle_unused_area(); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
1063 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
1064 |
0 | 1065 // Update time of last GC |
1066 reset_millis_since_last_gc(); | |
1067 } | |
1068 | |
1069 HeapWord* | |
1070 PSParallelCompact::compute_dense_prefix_via_density(const SpaceId id, | |
1071 bool maximum_compaction) | |
1072 { | |
1073 const size_t chunk_size = ParallelCompactData::ChunkSize; | |
1074 const ParallelCompactData& sd = summary_data(); | |
1075 | |
1076 const MutableSpace* const space = _space_info[id].space(); | |
1077 HeapWord* const top_aligned_up = sd.chunk_align_up(space->top()); | |
1078 const ChunkData* const beg_cp = sd.addr_to_chunk_ptr(space->bottom()); | |
1079 const ChunkData* const end_cp = sd.addr_to_chunk_ptr(top_aligned_up); | |
1080 | |
1081 // Skip full chunks at the beginning of the space--they are necessarily part | |
1082 // of the dense prefix. | |
1083 size_t full_count = 0; | |
1084 const ChunkData* cp; | |
1085 for (cp = beg_cp; cp < end_cp && cp->data_size() == chunk_size; ++cp) { | |
1086 ++full_count; | |
1087 } | |
1088 | |
1089 assert(total_invocations() >= _maximum_compaction_gc_num, "sanity"); | |
1090 const size_t gcs_since_max = total_invocations() - _maximum_compaction_gc_num; | |
1091 const bool interval_ended = gcs_since_max > HeapMaximumCompactionInterval; | |
1092 if (maximum_compaction || cp == end_cp || interval_ended) { | |
1093 _maximum_compaction_gc_num = total_invocations(); | |
1094 return sd.chunk_to_addr(cp); | |
1095 } | |
1096 | |
1097 HeapWord* const new_top = _space_info[id].new_top(); | |
1098 const size_t space_live = pointer_delta(new_top, space->bottom()); | |
1099 const size_t space_used = space->used_in_words(); | |
1100 const size_t space_capacity = space->capacity_in_words(); | |
1101 | |
1102 const double cur_density = double(space_live) / space_capacity; | |
1103 const double deadwood_density = | |
1104 (1.0 - cur_density) * (1.0 - cur_density) * cur_density * cur_density; | |
1105 const size_t deadwood_goal = size_t(space_capacity * deadwood_density); | |
1106 | |
1107 if (TraceParallelOldGCDensePrefix) { | |
1108 tty->print_cr("cur_dens=%5.3f dw_dens=%5.3f dw_goal=" SIZE_FORMAT, | |
1109 cur_density, deadwood_density, deadwood_goal); | |
1110 tty->print_cr("space_live=" SIZE_FORMAT " " "space_used=" SIZE_FORMAT " " | |
1111 "space_cap=" SIZE_FORMAT, | |
1112 space_live, space_used, | |
1113 space_capacity); | |
1114 } | |
1115 | |
1116 // XXX - Use binary search? | |
1117 HeapWord* dense_prefix = sd.chunk_to_addr(cp); | |
1118 const ChunkData* full_cp = cp; | |
1119 const ChunkData* const top_cp = sd.addr_to_chunk_ptr(space->top() - 1); | |
1120 while (cp < end_cp) { | |
1121 HeapWord* chunk_destination = cp->destination(); | |
1122 const size_t cur_deadwood = pointer_delta(dense_prefix, chunk_destination); | |
1123 if (TraceParallelOldGCDensePrefix && Verbose) { | |
264
15dd2594d08e
6718283: existing uses of *_FORMAT_W() were broken by 6521491
jcoomes
parents:
263
diff
changeset
|
1124 tty->print_cr("c#=" SIZE_FORMAT_W(4) " dst=" PTR_FORMAT " " |
15dd2594d08e
6718283: existing uses of *_FORMAT_W() were broken by 6521491
jcoomes
parents:
263
diff
changeset
|
1125 "dp=" SIZE_FORMAT_W(8) " " "cdw=" SIZE_FORMAT_W(8), |
0 | 1126 sd.chunk(cp), chunk_destination, |
1127 dense_prefix, cur_deadwood); | |
1128 } | |
1129 | |
1130 if (cur_deadwood >= deadwood_goal) { | |
1131 // Found the chunk that has the correct amount of deadwood to the left. | |
1132 // This typically occurs after crossing a fairly sparse set of chunks, so | |
1133 // iterate backwards over those sparse chunks, looking for the chunk that | |
1134 // has the lowest density of live objects 'to the right.' | |
1135 size_t space_to_left = sd.chunk(cp) * chunk_size; | |
1136 size_t live_to_left = space_to_left - cur_deadwood; | |
1137 size_t space_to_right = space_capacity - space_to_left; | |
1138 size_t live_to_right = space_live - live_to_left; | |
1139 double density_to_right = double(live_to_right) / space_to_right; | |
1140 while (cp > full_cp) { | |
1141 --cp; | |
1142 const size_t prev_chunk_live_to_right = live_to_right - cp->data_size(); | |
1143 const size_t prev_chunk_space_to_right = space_to_right + chunk_size; | |
1144 double prev_chunk_density_to_right = | |
1145 double(prev_chunk_live_to_right) / prev_chunk_space_to_right; | |
1146 if (density_to_right <= prev_chunk_density_to_right) { | |
1147 return dense_prefix; | |
1148 } | |
1149 if (TraceParallelOldGCDensePrefix && Verbose) { | |
264
15dd2594d08e
6718283: existing uses of *_FORMAT_W() were broken by 6521491
jcoomes
parents:
263
diff
changeset
|
1150 tty->print_cr("backing up from c=" SIZE_FORMAT_W(4) " d2r=%10.8f " |
0 | 1151 "pc_d2r=%10.8f", sd.chunk(cp), density_to_right, |
1152 prev_chunk_density_to_right); | |
1153 } | |
1154 dense_prefix -= chunk_size; | |
1155 live_to_right = prev_chunk_live_to_right; | |
1156 space_to_right = prev_chunk_space_to_right; | |
1157 density_to_right = prev_chunk_density_to_right; | |
1158 } | |
1159 return dense_prefix; | |
1160 } | |
1161 | |
1162 dense_prefix += chunk_size; | |
1163 ++cp; | |
1164 } | |
1165 | |
1166 return dense_prefix; | |
1167 } | |
1168 | |
1169 #ifndef PRODUCT | |
1170 void PSParallelCompact::print_dense_prefix_stats(const char* const algorithm, | |
1171 const SpaceId id, | |
1172 const bool maximum_compaction, | |
1173 HeapWord* const addr) | |
1174 { | |
1175 const size_t chunk_idx = summary_data().addr_to_chunk_idx(addr); | |
1176 ChunkData* const cp = summary_data().chunk(chunk_idx); | |
1177 const MutableSpace* const space = _space_info[id].space(); | |
1178 HeapWord* const new_top = _space_info[id].new_top(); | |
1179 | |
1180 const size_t space_live = pointer_delta(new_top, space->bottom()); | |
1181 const size_t dead_to_left = pointer_delta(addr, cp->destination()); | |
1182 const size_t space_cap = space->capacity_in_words(); | |
1183 const double dead_to_left_pct = double(dead_to_left) / space_cap; | |
1184 const size_t live_to_right = new_top - cp->destination(); | |
1185 const size_t dead_to_right = space->top() - addr - live_to_right; | |
1186 | |
264
15dd2594d08e
6718283: existing uses of *_FORMAT_W() were broken by 6521491
jcoomes
parents:
263
diff
changeset
|
1187 tty->print_cr("%s=" PTR_FORMAT " dpc=" SIZE_FORMAT_W(5) " " |
0 | 1188 "spl=" SIZE_FORMAT " " |
1189 "d2l=" SIZE_FORMAT " d2l%%=%6.4f " | |
1190 "d2r=" SIZE_FORMAT " l2r=" SIZE_FORMAT | |
1191 " ratio=%10.8f", | |
1192 algorithm, addr, chunk_idx, | |
1193 space_live, | |
1194 dead_to_left, dead_to_left_pct, | |
1195 dead_to_right, live_to_right, | |
1196 double(dead_to_right) / live_to_right); | |
1197 } | |
1198 #endif // #ifndef PRODUCT | |
1199 | |
1200 // Return a fraction indicating how much of the generation can be treated as | |
1201 // "dead wood" (i.e., not reclaimed). The function uses a normal distribution | |
1202 // based on the density of live objects in the generation to determine a limit, | |
1203 // which is then adjusted so the return value is min_percent when the density is | |
1204 // 1. | |
1205 // | |
1206 // The following table shows some return values for a different values of the | |
1207 // standard deviation (ParallelOldDeadWoodLimiterStdDev); the mean is 0.5 and | |
1208 // min_percent is 1. | |
1209 // | |
1210 // fraction allowed as dead wood | |
1211 // ----------------------------------------------------------------- | |
1212 // density std_dev=70 std_dev=75 std_dev=80 std_dev=85 std_dev=90 std_dev=95 | |
1213 // ------- ---------- ---------- ---------- ---------- ---------- ---------- | |
1214 // 0.00000 0.01000000 0.01000000 0.01000000 0.01000000 0.01000000 0.01000000 | |
1215 // 0.05000 0.03193096 0.02836880 0.02550828 0.02319280 0.02130337 0.01974941 | |
1216 // 0.10000 0.05247504 0.04547452 0.03988045 0.03537016 0.03170171 0.02869272 | |
1217 // 0.15000 0.07135702 0.06111390 0.05296419 0.04641639 0.04110601 0.03676066 | |
1218 // 0.20000 0.08831616 0.07509618 0.06461766 0.05622444 0.04943437 0.04388975 | |
1219 // 0.25000 0.10311208 0.08724696 0.07471205 0.06469760 0.05661313 0.05002313 | |
1220 // 0.30000 0.11553050 0.09741183 0.08313394 0.07175114 0.06257797 0.05511132 | |
1221 // 0.35000 0.12538832 0.10545958 0.08978741 0.07731366 0.06727491 0.05911289 | |
1222 // 0.40000 0.13253818 0.11128511 0.09459590 0.08132834 0.07066107 0.06199500 | |
1223 // 0.45000 0.13687208 0.11481163 0.09750361 0.08375387 0.07270534 0.06373386 | |
1224 // 0.50000 0.13832410 0.11599237 0.09847664 0.08456518 0.07338887 0.06431510 | |
1225 // 0.55000 0.13687208 0.11481163 0.09750361 0.08375387 0.07270534 0.06373386 | |
1226 // 0.60000 0.13253818 0.11128511 0.09459590 0.08132834 0.07066107 0.06199500 | |
1227 // 0.65000 0.12538832 0.10545958 0.08978741 0.07731366 0.06727491 0.05911289 | |
1228 // 0.70000 0.11553050 0.09741183 0.08313394 0.07175114 0.06257797 0.05511132 | |
1229 // 0.75000 0.10311208 0.08724696 0.07471205 0.06469760 0.05661313 0.05002313 | |
1230 // 0.80000 0.08831616 0.07509618 0.06461766 0.05622444 0.04943437 0.04388975 | |
1231 // 0.85000 0.07135702 0.06111390 0.05296419 0.04641639 0.04110601 0.03676066 | |
1232 // 0.90000 0.05247504 0.04547452 0.03988045 0.03537016 0.03170171 0.02869272 | |
1233 // 0.95000 0.03193096 0.02836880 0.02550828 0.02319280 0.02130337 0.01974941 | |
1234 // 1.00000 0.01000000 0.01000000 0.01000000 0.01000000 0.01000000 0.01000000 | |
1235 | |
1236 double PSParallelCompact::dead_wood_limiter(double density, size_t min_percent) | |
1237 { | |
1238 assert(_dwl_initialized, "uninitialized"); | |
1239 | |
1240 // The raw limit is the value of the normal distribution at x = density. | |
1241 const double raw_limit = normal_distribution(density); | |
1242 | |
1243 // Adjust the raw limit so it becomes the minimum when the density is 1. | |
1244 // | |
1245 // First subtract the adjustment value (which is simply the precomputed value | |
1246 // normal_distribution(1.0)); this yields a value of 0 when the density is 1. | |
1247 // Then add the minimum value, so the minimum is returned when the density is | |
1248 // 1. Finally, prevent negative values, which occur when the mean is not 0.5. | |
1249 const double min = double(min_percent) / 100.0; | |
1250 const double limit = raw_limit - _dwl_adjustment + min; | |
1251 return MAX2(limit, 0.0); | |
1252 } | |
1253 | |
1254 ParallelCompactData::ChunkData* | |
1255 PSParallelCompact::first_dead_space_chunk(const ChunkData* beg, | |
1256 const ChunkData* end) | |
1257 { | |
1258 const size_t chunk_size = ParallelCompactData::ChunkSize; | |
1259 ParallelCompactData& sd = summary_data(); | |
1260 size_t left = sd.chunk(beg); | |
1261 size_t right = end > beg ? sd.chunk(end) - 1 : left; | |
1262 | |
1263 // Binary search. | |
1264 while (left < right) { | |
1265 // Equivalent to (left + right) / 2, but does not overflow. | |
1266 const size_t middle = left + (right - left) / 2; | |
1267 ChunkData* const middle_ptr = sd.chunk(middle); | |
1268 HeapWord* const dest = middle_ptr->destination(); | |
1269 HeapWord* const addr = sd.chunk_to_addr(middle); | |
1270 assert(dest != NULL, "sanity"); | |
1271 assert(dest <= addr, "must move left"); | |
1272 | |
1273 if (middle > left && dest < addr) { | |
1274 right = middle - 1; | |
1275 } else if (middle < right && middle_ptr->data_size() == chunk_size) { | |
1276 left = middle + 1; | |
1277 } else { | |
1278 return middle_ptr; | |
1279 } | |
1280 } | |
1281 return sd.chunk(left); | |
1282 } | |
1283 | |
1284 ParallelCompactData::ChunkData* | |
1285 PSParallelCompact::dead_wood_limit_chunk(const ChunkData* beg, | |
1286 const ChunkData* end, | |
1287 size_t dead_words) | |
1288 { | |
1289 ParallelCompactData& sd = summary_data(); | |
1290 size_t left = sd.chunk(beg); | |
1291 size_t right = end > beg ? sd.chunk(end) - 1 : left; | |
1292 | |
1293 // Binary search. | |
1294 while (left < right) { | |
1295 // Equivalent to (left + right) / 2, but does not overflow. | |
1296 const size_t middle = left + (right - left) / 2; | |
1297 ChunkData* const middle_ptr = sd.chunk(middle); | |
1298 HeapWord* const dest = middle_ptr->destination(); | |
1299 HeapWord* const addr = sd.chunk_to_addr(middle); | |
1300 assert(dest != NULL, "sanity"); | |
1301 assert(dest <= addr, "must move left"); | |
1302 | |
1303 const size_t dead_to_left = pointer_delta(addr, dest); | |
1304 if (middle > left && dead_to_left > dead_words) { | |
1305 right = middle - 1; | |
1306 } else if (middle < right && dead_to_left < dead_words) { | |
1307 left = middle + 1; | |
1308 } else { | |
1309 return middle_ptr; | |
1310 } | |
1311 } | |
1312 return sd.chunk(left); | |
1313 } | |
1314 | |
1315 // The result is valid during the summary phase, after the initial summarization | |
1316 // of each space into itself, and before final summarization. | |
1317 inline double | |
1318 PSParallelCompact::reclaimed_ratio(const ChunkData* const cp, | |
1319 HeapWord* const bottom, | |
1320 HeapWord* const top, | |
1321 HeapWord* const new_top) | |
1322 { | |
1323 ParallelCompactData& sd = summary_data(); | |
1324 | |
1325 assert(cp != NULL, "sanity"); | |
1326 assert(bottom != NULL, "sanity"); | |
1327 assert(top != NULL, "sanity"); | |
1328 assert(new_top != NULL, "sanity"); | |
1329 assert(top >= new_top, "summary data problem?"); | |
1330 assert(new_top > bottom, "space is empty; should not be here"); | |
1331 assert(new_top >= cp->destination(), "sanity"); | |
1332 assert(top >= sd.chunk_to_addr(cp), "sanity"); | |
1333 | |
1334 HeapWord* const destination = cp->destination(); | |
1335 const size_t dense_prefix_live = pointer_delta(destination, bottom); | |
1336 const size_t compacted_region_live = pointer_delta(new_top, destination); | |
1337 const size_t compacted_region_used = pointer_delta(top, sd.chunk_to_addr(cp)); | |
1338 const size_t reclaimable = compacted_region_used - compacted_region_live; | |
1339 | |
1340 const double divisor = dense_prefix_live + 1.25 * compacted_region_live; | |
1341 return double(reclaimable) / divisor; | |
1342 } | |
1343 | |
1344 // Return the address of the end of the dense prefix, a.k.a. the start of the | |
1345 // compacted region. The address is always on a chunk boundary. | |
1346 // | |
1347 // Completely full chunks at the left are skipped, since no compaction can occur | |
1348 // in those chunks. Then the maximum amount of dead wood to allow is computed, | |
1349 // based on the density (amount live / capacity) of the generation; the chunk | |
1350 // with approximately that amount of dead space to the left is identified as the | |
1351 // limit chunk. Chunks between the last completely full chunk and the limit | |
1352 // chunk are scanned and the one that has the best (maximum) reclaimed_ratio() | |
1353 // is selected. | |
1354 HeapWord* | |
1355 PSParallelCompact::compute_dense_prefix(const SpaceId id, | |
1356 bool maximum_compaction) | |
1357 { | |
1358 const size_t chunk_size = ParallelCompactData::ChunkSize; | |
1359 const ParallelCompactData& sd = summary_data(); | |
1360 | |
1361 const MutableSpace* const space = _space_info[id].space(); | |
1362 HeapWord* const top = space->top(); | |
1363 HeapWord* const top_aligned_up = sd.chunk_align_up(top); | |
1364 HeapWord* const new_top = _space_info[id].new_top(); | |
1365 HeapWord* const new_top_aligned_up = sd.chunk_align_up(new_top); | |
1366 HeapWord* const bottom = space->bottom(); | |
1367 const ChunkData* const beg_cp = sd.addr_to_chunk_ptr(bottom); | |
1368 const ChunkData* const top_cp = sd.addr_to_chunk_ptr(top_aligned_up); | |
1369 const ChunkData* const new_top_cp = sd.addr_to_chunk_ptr(new_top_aligned_up); | |
1370 | |
1371 // Skip full chunks at the beginning of the space--they are necessarily part | |
1372 // of the dense prefix. | |
1373 const ChunkData* const full_cp = first_dead_space_chunk(beg_cp, new_top_cp); | |
1374 assert(full_cp->destination() == sd.chunk_to_addr(full_cp) || | |
1375 space->is_empty(), "no dead space allowed to the left"); | |
1376 assert(full_cp->data_size() < chunk_size || full_cp == new_top_cp - 1, | |
1377 "chunk must have dead space"); | |
1378 | |
1379 // The gc number is saved whenever a maximum compaction is done, and used to | |
1380 // determine when the maximum compaction interval has expired. This avoids | |
1381 // successive max compactions for different reasons. | |
1382 assert(total_invocations() >= _maximum_compaction_gc_num, "sanity"); | |
1383 const size_t gcs_since_max = total_invocations() - _maximum_compaction_gc_num; | |
1384 const bool interval_ended = gcs_since_max > HeapMaximumCompactionInterval || | |
1385 total_invocations() == HeapFirstMaximumCompactionCount; | |
1386 if (maximum_compaction || full_cp == top_cp || interval_ended) { | |
1387 _maximum_compaction_gc_num = total_invocations(); | |
1388 return sd.chunk_to_addr(full_cp); | |
1389 } | |
1390 | |
1391 const size_t space_live = pointer_delta(new_top, bottom); | |
1392 const size_t space_used = space->used_in_words(); | |
1393 const size_t space_capacity = space->capacity_in_words(); | |
1394 | |
1395 const double density = double(space_live) / double(space_capacity); | |
1396 const size_t min_percent_free = | |
1397 id == perm_space_id ? PermMarkSweepDeadRatio : MarkSweepDeadRatio; | |
1398 const double limiter = dead_wood_limiter(density, min_percent_free); | |
1399 const size_t dead_wood_max = space_used - space_live; | |
1400 const size_t dead_wood_limit = MIN2(size_t(space_capacity * limiter), | |
1401 dead_wood_max); | |
1402 | |
1403 if (TraceParallelOldGCDensePrefix) { | |
1404 tty->print_cr("space_live=" SIZE_FORMAT " " "space_used=" SIZE_FORMAT " " | |
1405 "space_cap=" SIZE_FORMAT, | |
1406 space_live, space_used, | |
1407 space_capacity); | |
1408 tty->print_cr("dead_wood_limiter(%6.4f, %d)=%6.4f " | |
1409 "dead_wood_max=" SIZE_FORMAT " dead_wood_limit=" SIZE_FORMAT, | |
1410 density, min_percent_free, limiter, | |
1411 dead_wood_max, dead_wood_limit); | |
1412 } | |
1413 | |
1414 // Locate the chunk with the desired amount of dead space to the left. | |
1415 const ChunkData* const limit_cp = | |
1416 dead_wood_limit_chunk(full_cp, top_cp, dead_wood_limit); | |
1417 | |
1418 // Scan from the first chunk with dead space to the limit chunk and find the | |
1419 // one with the best (largest) reclaimed ratio. | |
1420 double best_ratio = 0.0; | |
1421 const ChunkData* best_cp = full_cp; | |
1422 for (const ChunkData* cp = full_cp; cp < limit_cp; ++cp) { | |
1423 double tmp_ratio = reclaimed_ratio(cp, bottom, top, new_top); | |
1424 if (tmp_ratio > best_ratio) { | |
1425 best_cp = cp; | |
1426 best_ratio = tmp_ratio; | |
1427 } | |
1428 } | |
1429 | |
1430 #if 0 | |
1431 // Something to consider: if the chunk with the best ratio is 'close to' the | |
1432 // first chunk w/free space, choose the first chunk with free space | |
1433 // ("first-free"). The first-free chunk is usually near the start of the | |
1434 // heap, which means we are copying most of the heap already, so copy a bit | |
1435 // more to get complete compaction. | |
1436 if (pointer_delta(best_cp, full_cp, sizeof(ChunkData)) < 4) { | |
1437 _maximum_compaction_gc_num = total_invocations(); | |
1438 best_cp = full_cp; | |
1439 } | |
1440 #endif // #if 0 | |
1441 | |
1442 return sd.chunk_to_addr(best_cp); | |
1443 } | |
1444 | |
1445 void PSParallelCompact::summarize_spaces_quick() | |
1446 { | |
1447 for (unsigned int i = 0; i < last_space_id; ++i) { | |
1448 const MutableSpace* space = _space_info[i].space(); | |
1449 bool result = _summary_data.summarize(space->bottom(), space->end(), | |
1450 space->bottom(), space->top(), | |
1451 _space_info[i].new_top_addr()); | |
1452 assert(result, "should never fail"); | |
1453 _space_info[i].set_dense_prefix(space->bottom()); | |
1454 } | |
1455 } | |
1456 | |
1457 void PSParallelCompact::fill_dense_prefix_end(SpaceId id) | |
1458 { | |
1459 HeapWord* const dense_prefix_end = dense_prefix(id); | |
1460 const ChunkData* chunk = _summary_data.addr_to_chunk_ptr(dense_prefix_end); | |
1461 const idx_t dense_prefix_bit = _mark_bitmap.addr_to_bit(dense_prefix_end); | |
1462 if (dead_space_crosses_boundary(chunk, dense_prefix_bit)) { | |
1463 // Only enough dead space is filled so that any remaining dead space to the | |
1464 // left is larger than the minimum filler object. (The remainder is filled | |
1465 // during the copy/update phase.) | |
1466 // | |
1467 // The size of the dead space to the right of the boundary is not a | |
1468 // concern, since compaction will be able to use whatever space is | |
1469 // available. | |
1470 // | |
1471 // Here '||' is the boundary, 'x' represents a don't care bit and a box | |
1472 // surrounds the space to be filled with an object. | |
1473 // | |
1474 // In the 32-bit VM, each bit represents two 32-bit words: | |
1475 // +---+ | |
1476 // a) beg_bits: ... x x x | 0 | || 0 x x ... | |
1477 // end_bits: ... x x x | 0 | || 0 x x ... | |
1478 // +---+ | |
1479 // | |
1480 // In the 64-bit VM, each bit represents one 64-bit word: | |
1481 // +------------+ | |
1482 // b) beg_bits: ... x x x | 0 || 0 | x x ... | |
1483 // end_bits: ... x x 1 | 0 || 0 | x x ... | |
1484 // +------------+ | |
1485 // +-------+ | |
1486 // c) beg_bits: ... x x | 0 0 | || 0 x x ... | |
1487 // end_bits: ... x 1 | 0 0 | || 0 x x ... | |
1488 // +-------+ | |
1489 // +-----------+ | |
1490 // d) beg_bits: ... x | 0 0 0 | || 0 x x ... | |
1491 // end_bits: ... 1 | 0 0 0 | || 0 x x ... | |
1492 // +-----------+ | |
1493 // +-------+ | |
1494 // e) beg_bits: ... 0 0 | 0 0 | || 0 x x ... | |
1495 // end_bits: ... 0 0 | 0 0 | || 0 x x ... | |
1496 // +-------+ | |
1497 | |
1498 // Initially assume case a, c or e will apply. | |
1499 size_t obj_len = (size_t)oopDesc::header_size(); | |
1500 HeapWord* obj_beg = dense_prefix_end - obj_len; | |
1501 | |
1502 #ifdef _LP64 | |
1503 if (_mark_bitmap.is_obj_end(dense_prefix_bit - 2)) { | |
1504 // Case b above. | |
1505 obj_beg = dense_prefix_end - 1; | |
1506 } else if (!_mark_bitmap.is_obj_end(dense_prefix_bit - 3) && | |
1507 _mark_bitmap.is_obj_end(dense_prefix_bit - 4)) { | |
1508 // Case d above. | |
1509 obj_beg = dense_prefix_end - 3; | |
1510 obj_len = 3; | |
1511 } | |
1512 #endif // #ifdef _LP64 | |
1513 | |
1514 MemRegion region(obj_beg, obj_len); | |
1515 SharedHeap::fill_region_with_object(region); | |
1516 _mark_bitmap.mark_obj(obj_beg, obj_len); | |
1517 _summary_data.add_obj(obj_beg, obj_len); | |
1518 assert(start_array(id) != NULL, "sanity"); | |
1519 start_array(id)->allocate_block(obj_beg); | |
1520 } | |
1521 } | |
1522 | |
1523 void | |
1524 PSParallelCompact::summarize_space(SpaceId id, bool maximum_compaction) | |
1525 { | |
1526 assert(id < last_space_id, "id out of range"); | |
265
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1527 assert(_space_info[id].dense_prefix() == _space_info[id].space()->bottom(), |
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1528 "should have been set in summarize_spaces_quick()"); |
0 | 1529 |
1530 const MutableSpace* space = _space_info[id].space(); | |
265
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1531 if (_space_info[id].new_top() != space->bottom()) { |
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1532 HeapWord* dense_prefix_end = compute_dense_prefix(id, maximum_compaction); |
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1533 _space_info[id].set_dense_prefix(dense_prefix_end); |
0 | 1534 |
1535 #ifndef PRODUCT | |
265
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1536 if (TraceParallelOldGCDensePrefix) { |
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1537 print_dense_prefix_stats("ratio", id, maximum_compaction, |
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1538 dense_prefix_end); |
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1539 HeapWord* addr = compute_dense_prefix_via_density(id, maximum_compaction); |
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1540 print_dense_prefix_stats("density", id, maximum_compaction, addr); |
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1541 } |
0 | 1542 #endif // #ifndef PRODUCT |
1543 | |
265
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1544 // If dead space crosses the dense prefix boundary, it is (at least |
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1545 // partially) filled with a dummy object, marked live and added to the |
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1546 // summary data. This simplifies the copy/update phase and must be done |
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1547 // before the final locations of objects are determined, to prevent leaving |
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1548 // a fragment of dead space that is too small to fill with an object. |
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1549 if (!maximum_compaction && dense_prefix_end != space->bottom()) { |
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1550 fill_dense_prefix_end(id); |
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1551 } |
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1552 |
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1553 // Compute the destination of each Chunk, and thus each object. |
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1554 _summary_data.summarize_dense_prefix(space->bottom(), dense_prefix_end); |
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1555 _summary_data.summarize(dense_prefix_end, space->end(), |
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1556 dense_prefix_end, space->top(), |
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1557 _space_info[id].new_top_addr()); |
0 | 1558 } |
1559 | |
1560 if (TraceParallelOldGCSummaryPhase) { | |
1561 const size_t chunk_size = ParallelCompactData::ChunkSize; | |
265
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1562 HeapWord* const dense_prefix_end = _space_info[id].dense_prefix(); |
0 | 1563 const size_t dp_chunk = _summary_data.addr_to_chunk_idx(dense_prefix_end); |
1564 const size_t dp_words = pointer_delta(dense_prefix_end, space->bottom()); | |
265
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1565 HeapWord* const new_top = _space_info[id].new_top(); |
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1566 const HeapWord* nt_aligned_up = _summary_data.chunk_align_up(new_top); |
0 | 1567 const size_t cr_words = pointer_delta(nt_aligned_up, dense_prefix_end); |
1568 tty->print_cr("id=%d cap=" SIZE_FORMAT " dp=" PTR_FORMAT " " | |
1569 "dp_chunk=" SIZE_FORMAT " " "dp_count=" SIZE_FORMAT " " | |
1570 "cr_count=" SIZE_FORMAT " " "nt=" PTR_FORMAT, | |
1571 id, space->capacity_in_words(), dense_prefix_end, | |
1572 dp_chunk, dp_words / chunk_size, | |
265
f88815ca1af1
6483129: par compact assertion failure (new_top > bottom)
jcoomes
parents:
264
diff
changeset
|
1573 cr_words / chunk_size, new_top); |
0 | 1574 } |
1575 } | |
1576 | |
1577 void PSParallelCompact::summary_phase(ParCompactionManager* cm, | |
1578 bool maximum_compaction) | |
1579 { | |
1580 EventMark m("2 summarize"); | |
1581 TraceTime tm("summary phase", print_phases(), true, gclog_or_tty); | |
1582 // trace("2"); | |
1583 | |
1584 #ifdef ASSERT | |
1585 if (VerifyParallelOldWithMarkSweep && | |
1586 (PSParallelCompact::total_invocations() % | |
1587 VerifyParallelOldWithMarkSweepInterval) == 0) { | |
1588 verify_mark_bitmap(_mark_bitmap); | |
1589 } | |
1590 if (TraceParallelOldGCMarkingPhase) { | |
1591 tty->print_cr("add_obj_count=" SIZE_FORMAT " " | |
1592 "add_obj_bytes=" SIZE_FORMAT, | |
1593 add_obj_count, add_obj_size * HeapWordSize); | |
1594 tty->print_cr("mark_bitmap_count=" SIZE_FORMAT " " | |
1595 "mark_bitmap_bytes=" SIZE_FORMAT, | |
1596 mark_bitmap_count, mark_bitmap_size * HeapWordSize); | |
1597 } | |
1598 #endif // #ifdef ASSERT | |
1599 | |
1600 // Quick summarization of each space into itself, to see how much is live. | |
1601 summarize_spaces_quick(); | |
1602 | |
1603 if (TraceParallelOldGCSummaryPhase) { | |
1604 tty->print_cr("summary_phase: after summarizing each space to self"); | |
1605 Universe::print(); | |
1606 NOT_PRODUCT(print_chunk_ranges()); | |
1607 if (Verbose) { | |
1608 NOT_PRODUCT(print_initial_summary_data(_summary_data, _space_info)); | |
1609 } | |
1610 } | |
1611 | |
1612 // The amount of live data that will end up in old space (assuming it fits). | |
1613 size_t old_space_total_live = 0; | |
1614 unsigned int id; | |
1615 for (id = old_space_id; id < last_space_id; ++id) { | |
1616 old_space_total_live += pointer_delta(_space_info[id].new_top(), | |
1617 _space_info[id].space()->bottom()); | |
1618 } | |
1619 | |
1620 const MutableSpace* old_space = _space_info[old_space_id].space(); | |
1621 if (old_space_total_live > old_space->capacity_in_words()) { | |
1622 // XXX - should also try to expand | |
1623 maximum_compaction = true; | |
1624 } else if (!UseParallelOldGCDensePrefix) { | |
1625 maximum_compaction = true; | |
1626 } | |
1627 | |
1628 // Permanent and Old generations. | |
1629 summarize_space(perm_space_id, maximum_compaction); | |
1630 summarize_space(old_space_id, maximum_compaction); | |
1631 | |
1632 // Summarize the remaining spaces (those in the young gen) into old space. If | |
1633 // the live data from a space doesn't fit, the existing summarization is left | |
1634 // intact, so the data is compacted down within the space itself. | |
1635 HeapWord** new_top_addr = _space_info[old_space_id].new_top_addr(); | |
1636 HeapWord* const target_space_end = old_space->end(); | |
1637 for (id = eden_space_id; id < last_space_id; ++id) { | |
1638 const MutableSpace* space = _space_info[id].space(); | |
1639 const size_t live = pointer_delta(_space_info[id].new_top(), | |
1640 space->bottom()); | |
1641 const size_t available = pointer_delta(target_space_end, *new_top_addr); | |
1642 if (live <= available) { | |
1643 // All the live data will fit. | |
1644 if (TraceParallelOldGCSummaryPhase) { | |
1645 tty->print_cr("summarizing %d into old_space @ " PTR_FORMAT, | |
1646 id, *new_top_addr); | |
1647 } | |
1648 _summary_data.summarize(*new_top_addr, target_space_end, | |
1649 space->bottom(), space->top(), | |
1650 new_top_addr); | |
1651 | |
1652 // Reset the new_top value for the space. | |
1653 _space_info[id].set_new_top(space->bottom()); | |
1654 | |
1655 // Clear the source_chunk field for each chunk in the space. | |
1656 ChunkData* beg_chunk = _summary_data.addr_to_chunk_ptr(space->bottom()); | |
1657 ChunkData* end_chunk = _summary_data.addr_to_chunk_ptr(space->top() - 1); | |
1658 while (beg_chunk <= end_chunk) { | |
1659 beg_chunk->set_source_chunk(0); | |
1660 ++beg_chunk; | |
1661 } | |
1662 } | |
1663 } | |
1664 | |
1665 // Fill in the block data after any changes to the chunks have | |
1666 // been made. | |
1667 #ifdef ASSERT | |
1668 summarize_blocks(cm, perm_space_id); | |
1669 summarize_blocks(cm, old_space_id); | |
1670 #else | |
1671 if (!UseParallelOldGCChunkPointerCalc) { | |
1672 summarize_blocks(cm, perm_space_id); | |
1673 summarize_blocks(cm, old_space_id); | |
1674 } | |
1675 #endif | |
1676 | |
1677 if (TraceParallelOldGCSummaryPhase) { | |
1678 tty->print_cr("summary_phase: after final summarization"); | |
1679 Universe::print(); | |
1680 NOT_PRODUCT(print_chunk_ranges()); | |
1681 if (Verbose) { | |
1682 NOT_PRODUCT(print_generic_summary_data(_summary_data, _space_info)); | |
1683 } | |
1684 } | |
1685 } | |
1686 | |
1687 // Fill in the BlockData. | |
1688 // Iterate over the spaces and within each space iterate over | |
1689 // the chunks and fill in the BlockData for each chunk. | |
1690 | |
1691 void PSParallelCompact::summarize_blocks(ParCompactionManager* cm, | |
1692 SpaceId first_compaction_space_id) { | |
1693 #if 0 | |
1694 DEBUG_ONLY(ParallelCompactData::BlockData::set_cur_phase(1);) | |
1695 for (SpaceId cur_space_id = first_compaction_space_id; | |
1696 cur_space_id != last_space_id; | |
1697 cur_space_id = next_compaction_space_id(cur_space_id)) { | |
1698 // Iterate over the chunks in the space | |
1699 size_t start_chunk_index = | |
1700 _summary_data.addr_to_chunk_idx(space(cur_space_id)->bottom()); | |
1701 BitBlockUpdateClosure bbu(mark_bitmap(), | |
1702 cm, | |
1703 start_chunk_index); | |
1704 // Iterate over blocks. | |
1705 for (size_t chunk_index = start_chunk_index; | |
1706 chunk_index < _summary_data.chunk_count() && | |
1707 _summary_data.chunk_to_addr(chunk_index) < space(cur_space_id)->top(); | |
1708 chunk_index++) { | |
1709 | |
1710 // Reset the closure for the new chunk. Note that the closure | |
1711 // maintains some data that does not get reset for each chunk | |
1712 // so a new instance of the closure is no appropriate. | |
1713 bbu.reset_chunk(chunk_index); | |
1714 | |
1715 // Start the iteration with the first live object. This | |
1716 // may return the end of the chunk. That is acceptable since | |
1717 // it will properly limit the iterations. | |
1718 ParMarkBitMap::idx_t left_offset = mark_bitmap()->addr_to_bit( | |
1719 _summary_data.first_live_or_end_in_chunk(chunk_index)); | |
1720 | |
1721 // End the iteration at the end of the chunk. | |
1722 HeapWord* chunk_addr = _summary_data.chunk_to_addr(chunk_index); | |
1723 HeapWord* chunk_end = chunk_addr + ParallelCompactData::ChunkSize; | |
1724 ParMarkBitMap::idx_t right_offset = | |
1725 mark_bitmap()->addr_to_bit(chunk_end); | |
1726 | |
1727 // Blocks that have not objects starting in them can be | |
1728 // skipped because their data will never be used. | |
1729 if (left_offset < right_offset) { | |
1730 | |
1731 // Iterate through the objects in the chunk. | |
1732 ParMarkBitMap::idx_t last_offset = | |
1733 mark_bitmap()->pair_iterate(&bbu, left_offset, right_offset); | |
1734 | |
1735 // If last_offset is less than right_offset, then the iterations | |
1736 // terminated while it was looking for an end bit. "last_offset" | |
1737 // is then the offset for the last start bit. In this situation | |
1738 // the "offset" field for the next block to the right (_cur_block + 1) | |
1739 // will not have been update although there may be live data | |
1740 // to the left of the chunk. | |
1741 | |
1742 size_t cur_block_plus_1 = bbu.cur_block() + 1; | |
1743 HeapWord* cur_block_plus_1_addr = | |
1744 _summary_data.block_to_addr(bbu.cur_block()) + | |
1745 ParallelCompactData::BlockSize; | |
1746 HeapWord* last_offset_addr = mark_bitmap()->bit_to_addr(last_offset); | |
1747 #if 1 // This code works. The else doesn't but should. Why does it? | |
1748 // The current block (cur_block()) has already been updated. | |
1749 // The last block that may need to be updated is either the | |
1750 // next block (current block + 1) or the block where the | |
1751 // last object starts (which can be greater than the | |
1752 // next block if there were no objects found in intervening | |
1753 // blocks). | |
1754 size_t last_block = | |
1755 MAX2(bbu.cur_block() + 1, | |
1756 _summary_data.addr_to_block_idx(last_offset_addr)); | |
1757 #else | |
1758 // The current block has already been updated. The only block | |
1759 // that remains to be updated is the block where the last | |
1760 // object in the chunk starts. | |
1761 size_t last_block = _summary_data.addr_to_block_idx(last_offset_addr); | |
1762 #endif | |
1763 assert_bit_is_start(last_offset); | |
1764 assert((last_block == _summary_data.block_count()) || | |
1765 (_summary_data.block(last_block)->raw_offset() == 0), | |
1766 "Should not have been set"); | |
1767 // Is the last block still in the current chunk? If still | |
1768 // in this chunk, update the last block (the counting that | |
1769 // included the current block is meant for the offset of the last | |
1770 // block). If not in this chunk, do nothing. Should not | |
1771 // update a block in the next chunk. | |
1772 if (ParallelCompactData::chunk_contains_block(bbu.chunk_index(), | |
1773 last_block)) { | |
1774 if (last_offset < right_offset) { | |
1775 // The last object started in this chunk but ends beyond | |
1776 // this chunk. Update the block for this last object. | |
1777 assert(mark_bitmap()->is_marked(last_offset), "Should be marked"); | |
1778 // No end bit was found. The closure takes care of | |
1779 // the cases where | |
1780 // an objects crosses over into the next block | |
1781 // an objects starts and ends in the next block | |
1782 // It does not handle the case where an object is | |
1783 // the first object in a later block and extends | |
1784 // past the end of the chunk (i.e., the closure | |
1785 // only handles complete objects that are in the range | |
1786 // it is given). That object is handed back here | |
1787 // for any special consideration necessary. | |
1788 // | |
1789 // Is the first bit in the last block a start or end bit? | |
1790 // | |
1791 // If the partial object ends in the last block L, | |
1792 // then the 1st bit in L may be an end bit. | |
1793 // | |
1794 // Else does the last object start in a block after the current | |
1795 // block? A block AA will already have been updated if an | |
1796 // object ends in the next block AA+1. An object found to end in | |
1797 // the AA+1 is the trigger that updates AA. Objects are being | |
1798 // counted in the current block for updaing a following | |
1799 // block. An object may start in later block | |
1800 // block but may extend beyond the last block in the chunk. | |
1801 // Updates are only done when the end of an object has been | |
1802 // found. If the last object (covered by block L) starts | |
1803 // beyond the current block, then no object ends in L (otherwise | |
1804 // L would be the current block). So the first bit in L is | |
1805 // a start bit. | |
1806 // | |
1807 // Else the last objects start in the current block and ends | |
1808 // beyond the chunk. The current block has already been | |
1809 // updated and there is no later block (with an object | |
1810 // starting in it) that needs to be updated. | |
1811 // | |
1812 if (_summary_data.partial_obj_ends_in_block(last_block)) { | |
1813 _summary_data.block(last_block)->set_end_bit_offset( | |
1814 bbu.live_data_left()); | |
1815 } else if (last_offset_addr >= cur_block_plus_1_addr) { | |
1816 // The start of the object is on a later block | |
1817 // (to the right of the current block and there are no | |
1818 // complete live objects to the left of this last object | |
1819 // within the chunk. | |
1820 // The first bit in the block is for the start of the | |
1821 // last object. | |
1822 _summary_data.block(last_block)->set_start_bit_offset( | |
1823 bbu.live_data_left()); | |
1824 } else { | |
1825 // The start of the last object was found in | |
1826 // the current chunk (which has already | |
1827 // been updated). | |
1828 assert(bbu.cur_block() == | |
1829 _summary_data.addr_to_block_idx(last_offset_addr), | |
1830 "Should be a block already processed"); | |
1831 } | |
1832 #ifdef ASSERT | |
1833 // Is there enough block information to find this object? | |
1834 // The destination of the chunk has not been set so the | |
1835 // values returned by calc_new_pointer() and | |
1836 // block_calc_new_pointer() will only be | |
1837 // offsets. But they should agree. | |
1838 HeapWord* moved_obj_with_chunks = | |
1839 _summary_data.chunk_calc_new_pointer(last_offset_addr); | |
1840 HeapWord* moved_obj_with_blocks = | |
1841 _summary_data.calc_new_pointer(last_offset_addr); | |
1842 assert(moved_obj_with_chunks == moved_obj_with_blocks, | |
1843 "Block calculation is wrong"); | |
1844 #endif | |
1845 } else if (last_block < _summary_data.block_count()) { | |
1846 // Iterations ended looking for a start bit (but | |
1847 // did not run off the end of the block table). | |
1848 _summary_data.block(last_block)->set_start_bit_offset( | |
1849 bbu.live_data_left()); | |
1850 } | |
1851 } | |
1852 #ifdef ASSERT | |
1853 // Is there enough block information to find this object? | |
1854 HeapWord* left_offset_addr = mark_bitmap()->bit_to_addr(left_offset); | |
1855 HeapWord* moved_obj_with_chunks = | |
1856 _summary_data.calc_new_pointer(left_offset_addr); | |
1857 HeapWord* moved_obj_with_blocks = | |
1858 _summary_data.calc_new_pointer(left_offset_addr); | |
1859 assert(moved_obj_with_chunks == moved_obj_with_blocks, | |
1860 "Block calculation is wrong"); | |
1861 #endif | |
1862 | |
1863 // Is there another block after the end of this chunk? | |
1864 #ifdef ASSERT | |
1865 if (last_block < _summary_data.block_count()) { | |
1866 // No object may have been found in a block. If that | |
1867 // block is at the end of the chunk, the iteration will | |
1868 // terminate without incrementing the current block so | |
1869 // that the current block is not the last block in the | |
1870 // chunk. That situation precludes asserting that the | |
1871 // current block is the last block in the chunk. Assert | |
1872 // the lesser condition that the current block does not | |
1873 // exceed the chunk. | |
1874 assert(_summary_data.block_to_addr(last_block) <= | |
1875 (_summary_data.chunk_to_addr(chunk_index) + | |
1876 ParallelCompactData::ChunkSize), | |
1877 "Chunk and block inconsistency"); | |
1878 assert(last_offset <= right_offset, "Iteration over ran end"); | |
1879 } | |
1880 #endif | |
1881 } | |
1882 #ifdef ASSERT | |
1883 if (PrintGCDetails && Verbose) { | |
1884 if (_summary_data.chunk(chunk_index)->partial_obj_size() == 1) { | |
1885 size_t first_block = | |
1886 chunk_index / ParallelCompactData::BlocksPerChunk; | |
1887 gclog_or_tty->print_cr("first_block " PTR_FORMAT | |
1888 " _offset " PTR_FORMAT | |
1889 "_first_is_start_bit %d", | |
1890 first_block, | |
1891 _summary_data.block(first_block)->raw_offset(), | |
1892 _summary_data.block(first_block)->first_is_start_bit()); | |
1893 } | |
1894 } | |
1895 #endif | |
1896 } | |
1897 } | |
1898 DEBUG_ONLY(ParallelCompactData::BlockData::set_cur_phase(16);) | |
1899 #endif // #if 0 | |
1900 } | |
1901 | |
1902 // This method should contain all heap-specific policy for invoking a full | |
1903 // collection. invoke_no_policy() will only attempt to compact the heap; it | |
1904 // will do nothing further. If we need to bail out for policy reasons, scavenge | |
1905 // before full gc, or any other specialized behavior, it needs to be added here. | |
1906 // | |
1907 // Note that this method should only be called from the vm_thread while at a | |
1908 // safepoint. | |
1909 void PSParallelCompact::invoke(bool maximum_heap_compaction) { | |
1910 assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint"); | |
1911 assert(Thread::current() == (Thread*)VMThread::vm_thread(), | |
1912 "should be in vm thread"); | |
1913 ParallelScavengeHeap* heap = gc_heap(); | |
1914 GCCause::Cause gc_cause = heap->gc_cause(); | |
1915 assert(!heap->is_gc_active(), "not reentrant"); | |
1916 | |
1917 PSAdaptiveSizePolicy* policy = heap->size_policy(); | |
1918 | |
1919 // Before each allocation/collection attempt, find out from the | |
1920 // policy object if GCs are, on the whole, taking too long. If so, | |
1921 // bail out without attempting a collection. The exceptions are | |
1922 // for explicitly requested GC's. | |
1923 if (!policy->gc_time_limit_exceeded() || | |
1924 GCCause::is_user_requested_gc(gc_cause) || | |
1925 GCCause::is_serviceability_requested_gc(gc_cause)) { | |
1926 IsGCActiveMark mark; | |
1927 | |
1928 if (ScavengeBeforeFullGC) { | |
1929 PSScavenge::invoke_no_policy(); | |
1930 } | |
1931 | |
1932 PSParallelCompact::invoke_no_policy(maximum_heap_compaction); | |
1933 } | |
1934 } | |
1935 | |
1936 bool ParallelCompactData::chunk_contains(size_t chunk_index, HeapWord* addr) { | |
1937 size_t addr_chunk_index = addr_to_chunk_idx(addr); | |
1938 return chunk_index == addr_chunk_index; | |
1939 } | |
1940 | |
1941 bool ParallelCompactData::chunk_contains_block(size_t chunk_index, | |
1942 size_t block_index) { | |
1943 size_t first_block_in_chunk = chunk_index * BlocksPerChunk; | |
1944 size_t last_block_in_chunk = (chunk_index + 1) * BlocksPerChunk - 1; | |
1945 | |
1946 return (first_block_in_chunk <= block_index) && | |
1947 (block_index <= last_block_in_chunk); | |
1948 } | |
1949 | |
1950 // This method contains no policy. You should probably | |
1951 // be calling invoke() instead. | |
1952 void PSParallelCompact::invoke_no_policy(bool maximum_heap_compaction) { | |
1953 assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint"); | |
1954 assert(ref_processor() != NULL, "Sanity"); | |
1955 | |
139
c0492d52d55b
6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents:
0
diff
changeset
|
1956 if (GC_locker::check_active_before_gc()) { |
0 | 1957 return; |
1958 } | |
1959 | |
1960 TimeStamp marking_start; | |
1961 TimeStamp compaction_start; | |
1962 TimeStamp collection_exit; | |
1963 | |
1964 ParallelScavengeHeap* heap = gc_heap(); | |
1965 GCCause::Cause gc_cause = heap->gc_cause(); | |
1966 PSYoungGen* young_gen = heap->young_gen(); | |
1967 PSOldGen* old_gen = heap->old_gen(); | |
1968 PSPermGen* perm_gen = heap->perm_gen(); | |
1969 PSAdaptiveSizePolicy* size_policy = heap->size_policy(); | |
1970 | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
1971 if (ZapUnusedHeapArea) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
1972 // Save information needed to minimize mangling |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
1973 heap->record_gen_tops_before_GC(); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
1974 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
1975 |
0 | 1976 _print_phases = PrintGCDetails && PrintParallelOldGCPhaseTimes; |
1977 | |
1978 // Make sure data structures are sane, make the heap parsable, and do other | |
1979 // miscellaneous bookkeeping. | |
1980 PreGCValues pre_gc_values; | |
1981 pre_compact(&pre_gc_values); | |
1982 | |
210 | 1983 // Get the compaction manager reserved for the VM thread. |
1984 ParCompactionManager* const vmthread_cm = | |
1985 ParCompactionManager::manager_array(gc_task_manager()->workers()); | |
1986 | |
0 | 1987 // Place after pre_compact() where the number of invocations is incremented. |
1988 AdaptiveSizePolicyOutput(size_policy, heap->total_collections()); | |
1989 | |
1990 { | |
1991 ResourceMark rm; | |
1992 HandleMark hm; | |
1993 | |
1994 const bool is_system_gc = gc_cause == GCCause::_java_lang_system_gc; | |
1995 | |
1996 // This is useful for debugging but don't change the output the | |
1997 // the customer sees. | |
1998 const char* gc_cause_str = "Full GC"; | |
1999 if (is_system_gc && PrintGCDetails) { | |
2000 gc_cause_str = "Full GC (System)"; | |
2001 } | |
2002 gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps); | |
2003 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); | |
2004 TraceTime t1(gc_cause_str, PrintGC, !PrintGCDetails, gclog_or_tty); | |
2005 TraceCollectorStats tcs(counters()); | |
2006 TraceMemoryManagerStats tms(true /* Full GC */); | |
2007 | |
2008 if (TraceGen1Time) accumulated_time()->start(); | |
2009 | |
2010 // Let the size policy know we're starting | |
2011 size_policy->major_collection_begin(); | |
2012 | |
2013 // When collecting the permanent generation methodOops may be moving, | |
2014 // so we either have to flush all bcp data or convert it into bci. | |
2015 CodeCache::gc_prologue(); | |
2016 Threads::gc_prologue(); | |
2017 | |
2018 NOT_PRODUCT(ref_processor()->verify_no_references_recorded()); | |
2019 COMPILER2_PRESENT(DerivedPointerTable::clear()); | |
2020 | |
2021 ref_processor()->enable_discovery(); | |
2022 | |
2023 bool marked_for_unloading = false; | |
2024 | |
2025 marking_start.update(); | |
210 | 2026 marking_phase(vmthread_cm, maximum_heap_compaction); |
0 | 2027 |
2028 #ifndef PRODUCT | |
2029 if (TraceParallelOldGCMarkingPhase) { | |
2030 gclog_or_tty->print_cr("marking_phase: cas_tries %d cas_retries %d " | |
2031 "cas_by_another %d", | |
2032 mark_bitmap()->cas_tries(), mark_bitmap()->cas_retries(), | |
2033 mark_bitmap()->cas_by_another()); | |
2034 } | |
2035 #endif // #ifndef PRODUCT | |
2036 | |
2037 #ifdef ASSERT | |
2038 if (VerifyParallelOldWithMarkSweep && | |
2039 (PSParallelCompact::total_invocations() % | |
2040 VerifyParallelOldWithMarkSweepInterval) == 0) { | |
2041 gclog_or_tty->print_cr("Verify marking with mark_sweep_phase1()"); | |
2042 if (PrintGCDetails && Verbose) { | |
2043 gclog_or_tty->print_cr("mark_sweep_phase1:"); | |
2044 } | |
2045 // Clear the discovered lists so that discovered objects | |
2046 // don't look like they have been discovered twice. | |
2047 ref_processor()->clear_discovered_references(); | |
2048 | |
2049 PSMarkSweep::allocate_stacks(); | |
2050 MemRegion mr = Universe::heap()->reserved_region(); | |
2051 PSMarkSweep::ref_processor()->enable_discovery(); | |
2052 PSMarkSweep::mark_sweep_phase1(maximum_heap_compaction); | |
2053 } | |
2054 #endif | |
2055 | |
2056 bool max_on_system_gc = UseMaximumCompactionOnSystemGC && is_system_gc; | |
210 | 2057 summary_phase(vmthread_cm, maximum_heap_compaction || max_on_system_gc); |
0 | 2058 |
2059 #ifdef ASSERT | |
2060 if (VerifyParallelOldWithMarkSweep && | |
2061 (PSParallelCompact::total_invocations() % | |
2062 VerifyParallelOldWithMarkSweepInterval) == 0) { | |
2063 if (PrintGCDetails && Verbose) { | |
2064 gclog_or_tty->print_cr("mark_sweep_phase2:"); | |
2065 } | |
2066 PSMarkSweep::mark_sweep_phase2(); | |
2067 } | |
2068 #endif | |
2069 | |
2070 COMPILER2_PRESENT(assert(DerivedPointerTable::is_active(), "Sanity")); | |
2071 COMPILER2_PRESENT(DerivedPointerTable::set_active(false)); | |
2072 | |
2073 // adjust_roots() updates Universe::_intArrayKlassObj which is | |
2074 // needed by the compaction for filling holes in the dense prefix. | |
2075 adjust_roots(); | |
2076 | |
2077 #ifdef ASSERT | |
2078 if (VerifyParallelOldWithMarkSweep && | |
2079 (PSParallelCompact::total_invocations() % | |
2080 VerifyParallelOldWithMarkSweepInterval) == 0) { | |
2081 // Do a separate verify phase so that the verify | |
2082 // code can use the the forwarding pointers to | |
2083 // check the new pointer calculation. The restore_marks() | |
2084 // has to be done before the real compact. | |
210 | 2085 vmthread_cm->set_action(ParCompactionManager::VerifyUpdate); |
2086 compact_perm(vmthread_cm); | |
2087 compact_serial(vmthread_cm); | |
2088 vmthread_cm->set_action(ParCompactionManager::ResetObjects); | |
2089 compact_perm(vmthread_cm); | |
2090 compact_serial(vmthread_cm); | |
2091 vmthread_cm->set_action(ParCompactionManager::UpdateAndCopy); | |
0 | 2092 |
2093 // For debugging only | |
2094 PSMarkSweep::restore_marks(); | |
2095 PSMarkSweep::deallocate_stacks(); | |
2096 } | |
2097 #endif | |
2098 | |
2099 compaction_start.update(); | |
2100 // Does the perm gen always have to be done serially because | |
2101 // klasses are used in the update of an object? | |
210 | 2102 compact_perm(vmthread_cm); |
0 | 2103 |
2104 if (UseParallelOldGCCompacting) { | |
2105 compact(); | |
2106 } else { | |
210 | 2107 compact_serial(vmthread_cm); |
0 | 2108 } |
2109 | |
2110 // Reset the mark bitmap, summary data, and do other bookkeeping. Must be | |
2111 // done before resizing. | |
2112 post_compact(); | |
2113 | |
2114 // Let the size policy know we're done | |
2115 size_policy->major_collection_end(old_gen->used_in_bytes(), gc_cause); | |
2116 | |
2117 if (UseAdaptiveSizePolicy) { | |
2118 if (PrintAdaptiveSizePolicy) { | |
2119 gclog_or_tty->print("AdaptiveSizeStart: "); | |
2120 gclog_or_tty->stamp(); | |
2121 gclog_or_tty->print_cr(" collection: %d ", | |
2122 heap->total_collections()); | |
2123 if (Verbose) { | |
2124 gclog_or_tty->print("old_gen_capacity: %d young_gen_capacity: %d" | |
2125 " perm_gen_capacity: %d ", | |
2126 old_gen->capacity_in_bytes(), young_gen->capacity_in_bytes(), | |
2127 perm_gen->capacity_in_bytes()); | |
2128 } | |
2129 } | |
2130 | |
2131 // Don't check if the size_policy is ready here. Let | |
2132 // the size_policy check that internally. | |
2133 if (UseAdaptiveGenerationSizePolicyAtMajorCollection && | |
2134 ((gc_cause != GCCause::_java_lang_system_gc) || | |
2135 UseAdaptiveSizePolicyWithSystemGC)) { | |
2136 // Calculate optimal free space amounts | |
2137 assert(young_gen->max_size() > | |
2138 young_gen->from_space()->capacity_in_bytes() + | |
2139 young_gen->to_space()->capacity_in_bytes(), | |
2140 "Sizes of space in young gen are out-of-bounds"); | |
2141 size_t max_eden_size = young_gen->max_size() - | |
2142 young_gen->from_space()->capacity_in_bytes() - | |
2143 young_gen->to_space()->capacity_in_bytes(); | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
2144 size_policy->compute_generation_free_space( |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
2145 young_gen->used_in_bytes(), |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
2146 young_gen->eden_space()->used_in_bytes(), |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
2147 old_gen->used_in_bytes(), |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
2148 perm_gen->used_in_bytes(), |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
2149 young_gen->eden_space()->capacity_in_bytes(), |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
2150 old_gen->max_gen_size(), |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
2151 max_eden_size, |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
2152 true /* full gc*/, |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
2153 gc_cause); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
2154 |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
2155 heap->resize_old_gen( |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
2156 size_policy->calculated_old_free_size_in_bytes()); |
0 | 2157 |
2158 // Don't resize the young generation at an major collection. A | |
2159 // desired young generation size may have been calculated but | |
2160 // resizing the young generation complicates the code because the | |
2161 // resizing of the old generation may have moved the boundary | |
2162 // between the young generation and the old generation. Let the | |
2163 // young generation resizing happen at the minor collections. | |
2164 } | |
2165 if (PrintAdaptiveSizePolicy) { | |
2166 gclog_or_tty->print_cr("AdaptiveSizeStop: collection: %d ", | |
2167 heap->total_collections()); | |
2168 } | |
2169 } | |
2170 | |
2171 if (UsePerfData) { | |
2172 PSGCAdaptivePolicyCounters* const counters = heap->gc_policy_counters(); | |
2173 counters->update_counters(); | |
2174 counters->update_old_capacity(old_gen->capacity_in_bytes()); | |
2175 counters->update_young_capacity(young_gen->capacity_in_bytes()); | |
2176 } | |
2177 | |
2178 heap->resize_all_tlabs(); | |
2179 | |
2180 // We collected the perm gen, so we'll resize it here. | |
2181 perm_gen->compute_new_size(pre_gc_values.perm_gen_used()); | |
2182 | |
2183 if (TraceGen1Time) accumulated_time()->stop(); | |
2184 | |
2185 if (PrintGC) { | |
2186 if (PrintGCDetails) { | |
2187 // No GC timestamp here. This is after GC so it would be confusing. | |
2188 young_gen->print_used_change(pre_gc_values.young_gen_used()); | |
2189 old_gen->print_used_change(pre_gc_values.old_gen_used()); | |
2190 heap->print_heap_change(pre_gc_values.heap_used()); | |
2191 // Print perm gen last (print_heap_change() excludes the perm gen). | |
2192 perm_gen->print_used_change(pre_gc_values.perm_gen_used()); | |
2193 } else { | |
2194 heap->print_heap_change(pre_gc_values.heap_used()); | |
2195 } | |
2196 } | |
2197 | |
2198 // Track memory usage and detect low memory | |
2199 MemoryService::track_memory_usage(); | |
2200 heap->update_counters(); | |
2201 | |
2202 if (PrintGCDetails) { | |
2203 if (size_policy->print_gc_time_limit_would_be_exceeded()) { | |
2204 if (size_policy->gc_time_limit_exceeded()) { | |
2205 gclog_or_tty->print_cr(" GC time is exceeding GCTimeLimit " | |
2206 "of %d%%", GCTimeLimit); | |
2207 } else { | |
2208 gclog_or_tty->print_cr(" GC time would exceed GCTimeLimit " | |
2209 "of %d%%", GCTimeLimit); | |
2210 } | |
2211 } | |
2212 size_policy->set_print_gc_time_limit_would_be_exceeded(false); | |
2213 } | |
2214 } | |
2215 | |
2216 if (VerifyAfterGC && heap->total_collections() >= VerifyGCStartAt) { | |
2217 HandleMark hm; // Discard invalid handles created during verification | |
2218 gclog_or_tty->print(" VerifyAfterGC:"); | |
2219 Universe::verify(false); | |
2220 } | |
2221 | |
2222 // Re-verify object start arrays | |
2223 if (VerifyObjectStartArray && | |
2224 VerifyAfterGC) { | |
2225 old_gen->verify_object_start_array(); | |
2226 perm_gen->verify_object_start_array(); | |
2227 } | |
2228 | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
2229 if (ZapUnusedHeapArea) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
2230 old_gen->object_space()->check_mangled_unused_area_complete(); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
2231 perm_gen->object_space()->check_mangled_unused_area_complete(); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
2232 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
210
diff
changeset
|
2233 |
0 | 2234 NOT_PRODUCT(ref_processor()->verify_no_references_recorded()); |
2235 | |
2236 collection_exit.update(); | |
2237 | |
2238 if (PrintHeapAtGC) { | |
2239 Universe::print_heap_after_gc(); | |
2240 } | |
2241 if (PrintGCTaskTimeStamps) { | |
2242 gclog_or_tty->print_cr("VM-Thread " INT64_FORMAT " " INT64_FORMAT " " | |
2243 INT64_FORMAT, | |
2244 marking_start.ticks(), compaction_start.ticks(), | |
2245 collection_exit.ticks()); | |
2246 gc_task_manager()->print_task_time_stamps(); | |
2247 } | |
2248 } | |
2249 | |
2250 bool PSParallelCompact::absorb_live_data_from_eden(PSAdaptiveSizePolicy* size_policy, | |
2251 PSYoungGen* young_gen, | |
2252 PSOldGen* old_gen) { | |
2253 MutableSpace* const eden_space = young_gen->eden_space(); | |
2254 assert(!eden_space->is_empty(), "eden must be non-empty"); | |
2255 assert(young_gen->virtual_space()->alignment() == | |
2256 old_gen->virtual_space()->alignment(), "alignments do not match"); | |
2257 | |
2258 if (!(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary)) { | |
2259 return false; | |
2260 } | |
2261 | |
2262 // Both generations must be completely committed. | |
2263 if (young_gen->virtual_space()->uncommitted_size() != 0) { | |
2264 return false; | |
2265 } | |
2266 if (old_gen->virtual_space()->uncommitted_size() != 0) { | |
2267 return false; | |
2268 } | |
2269 | |
2270 // Figure out how much to take from eden. Include the average amount promoted | |
2271 // in the total; otherwise the next young gen GC will simply bail out to a | |
2272 // full GC. | |
2273 const size_t alignment = old_gen->virtual_space()->alignment(); | |
2274 const size_t eden_used = eden_space->used_in_bytes(); | |
2275 const size_t promoted = (size_t)size_policy->avg_promoted()->padded_average(); | |
2276 const size_t absorb_size = align_size_up(eden_used + promoted, alignment); | |
2277 const size_t eden_capacity = eden_space->capacity_in_bytes(); | |
2278 | |
2279 if (absorb_size >= eden_capacity) { | |
2280 return false; // Must leave some space in eden. | |
2281 } | |
2282 | |
2283 const size_t new_young_size = young_gen->capacity_in_bytes() - absorb_size; | |
2284 if (new_young_size < young_gen->min_gen_size()) { | |
2285 return false; // Respect young gen minimum size. | |
2286 } | |
2287 | |
2288 if (TraceAdaptiveGCBoundary && Verbose) { | |
2289 gclog_or_tty->print(" absorbing " SIZE_FORMAT "K: " | |
2290 "eden " SIZE_FORMAT "K->" SIZE_FORMAT "K " | |
2291 "from " SIZE_FORMAT "K, to " SIZE_FORMAT "K " | |
2292 "young_gen " SIZE_FORMAT "K->" SIZE_FORMAT "K ", | |
2293 absorb_size / K, | |
2294 eden_capacity / K, (eden_capacity - absorb_size) / K, | |
2295 young_gen->from_space()->used_in_bytes() / K, | |
2296 young_gen->to_space()->used_in_bytes() / K, | |
2297 young_gen->capacity_in_bytes() / K, new_young_size / K); | |
2298 } | |
2299 | |
2300 // Fill the unused part of the old gen. | |
2301 MutableSpace* const old_space = old_gen->object_space(); | |
2302 MemRegion old_gen_unused(old_space->top(), old_space->end()); | |
2303 if (!old_gen_unused.is_empty()) { | |
2304 SharedHeap::fill_region_with_object(old_gen_unused); | |
2305 } | |
2306 | |
2307 // Take the live data from eden and set both top and end in the old gen to | |
2308 // eden top. (Need to set end because reset_after_change() mangles the region | |
2309 // from end to virtual_space->high() in debug builds). | |
2310 HeapWord* const new_top = eden_space->top(); | |
2311 old_gen->virtual_space()->expand_into(young_gen->virtual_space(), | |
2312 absorb_size); | |
2313 young_gen->reset_after_change(); | |
2314 old_space->set_top(new_top); | |
2315 old_space->set_end(new_top); | |
2316 old_gen->reset_after_change(); | |
2317 | |
2318 // Update the object start array for the filler object and the data from eden. | |
2319 ObjectStartArray* const start_array = old_gen->start_array(); | |
2320 HeapWord* const start = old_gen_unused.start(); | |
2321 for (HeapWord* addr = start; addr < new_top; addr += oop(addr)->size()) { | |
2322 start_array->allocate_block(addr); | |
2323 } | |
2324 | |
2325 // Could update the promoted average here, but it is not typically updated at | |
2326 // full GCs and the value to use is unclear. Something like | |
2327 // | |
2328 // cur_promoted_avg + absorb_size / number_of_scavenges_since_last_full_gc. | |
2329 | |
2330 size_policy->set_bytes_absorbed_from_eden(absorb_size); | |
2331 return true; | |
2332 } | |
2333 | |
2334 GCTaskManager* const PSParallelCompact::gc_task_manager() { | |
2335 assert(ParallelScavengeHeap::gc_task_manager() != NULL, | |
2336 "shouldn't return NULL"); | |
2337 return ParallelScavengeHeap::gc_task_manager(); | |
2338 } | |
2339 | |
2340 void PSParallelCompact::marking_phase(ParCompactionManager* cm, | |
2341 bool maximum_heap_compaction) { | |
2342 // Recursively traverse all live objects and mark them | |
2343 EventMark m("1 mark object"); | |
2344 TraceTime tm("marking phase", print_phases(), true, gclog_or_tty); | |
2345 | |
2346 ParallelScavengeHeap* heap = gc_heap(); | |
2347 uint parallel_gc_threads = heap->gc_task_manager()->workers(); | |
2348 TaskQueueSetSuper* qset = ParCompactionManager::chunk_array(); | |
2349 ParallelTaskTerminator terminator(parallel_gc_threads, qset); | |
2350 | |
2351 PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm); | |
2352 PSParallelCompact::FollowStackClosure follow_stack_closure(cm); | |
2353 | |
2354 { | |
2355 TraceTime tm_m("par mark", print_phases(), true, gclog_or_tty); | |
2356 | |
2357 GCTaskQueue* q = GCTaskQueue::create(); | |
2358 | |
2359 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::universe)); | |
2360 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::jni_handles)); | |
2361 // We scan the thread roots in parallel | |
2362 Threads::create_thread_roots_marking_tasks(q); | |
2363 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::object_synchronizer)); | |
2364 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::flat_profiler)); | |
2365 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::management)); | |
2366 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::system_dictionary)); | |
2367 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::jvmti)); | |
2368 q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::vm_symbols)); | |
2369 | |
2370 if (parallel_gc_threads > 1) { | |
2371 for (uint j = 0; j < parallel_gc_threads; j++) { | |
2372 q->enqueue(new StealMarkingTask(&terminator)); | |
2373 } | |
2374 } | |
2375 | |
2376 WaitForBarrierGCTask* fin = WaitForBarrierGCTask::create(); | |
2377 q->enqueue(fin); | |
2378 | |
2379 gc_task_manager()->add_list(q); | |
2380 | |
2381 fin->wait_for(); | |
2382 | |
2383 // We have to release the barrier tasks! | |
2384 WaitForBarrierGCTask::destroy(fin); | |
2385 } | |
2386 | |
2387 // Process reference objects found during marking | |
2388 { | |
2389 TraceTime tm_r("reference processing", print_phases(), true, gclog_or_tty); | |
2390 ReferencePolicy *soft_ref_policy; | |
2391 if (maximum_heap_compaction) { | |
2392 soft_ref_policy = new AlwaysClearPolicy(); | |
2393 } else { | |
2394 #ifdef COMPILER2 | |
2395 soft_ref_policy = new LRUMaxHeapPolicy(); | |
2396 #else | |
2397 soft_ref_policy = new LRUCurrentHeapPolicy(); | |
2398 #endif // COMPILER2 | |
2399 } | |
2400 assert(soft_ref_policy != NULL, "No soft reference policy"); | |
2401 if (ref_processor()->processing_is_mt()) { | |
2402 RefProcTaskExecutor task_executor; | |
2403 ref_processor()->process_discovered_references( | |
2404 soft_ref_policy, is_alive_closure(), &mark_and_push_closure, | |
2405 &follow_stack_closure, &task_executor); | |
2406 } else { | |
2407 ref_processor()->process_discovered_references( | |
2408 soft_ref_policy, is_alive_closure(), &mark_and_push_closure, | |
2409 &follow_stack_closure, NULL); | |
2410 } | |
2411 } | |
2412 | |
2413 TraceTime tm_c("class unloading", print_phases(), true, gclog_or_tty); | |
2414 // Follow system dictionary roots and unload classes. | |
2415 bool purged_class = SystemDictionary::do_unloading(is_alive_closure()); | |
2416 | |
2417 // Follow code cache roots. | |
2418 CodeCache::do_unloading(is_alive_closure(), &mark_and_push_closure, | |
2419 purged_class); | |
2420 follow_stack(cm); // Flush marking stack. | |
2421 | |
2422 // Update subklass/sibling/implementor links of live klasses | |
2423 // revisit_klass_stack is used in follow_weak_klass_links(). | |
2424 follow_weak_klass_links(cm); | |
2425 | |
2426 // Visit symbol and interned string tables and delete unmarked oops | |
2427 SymbolTable::unlink(is_alive_closure()); | |
2428 StringTable::unlink(is_alive_closure()); | |
2429 | |
2430 assert(cm->marking_stack()->size() == 0, "stack should be empty by now"); | |
2431 assert(cm->overflow_stack()->is_empty(), "stack should be empty by now"); | |
2432 } | |
2433 | |
2434 // This should be moved to the shared markSweep code! | |
2435 class PSAlwaysTrueClosure: public BoolObjectClosure { | |
2436 public: | |
2437 void do_object(oop p) { ShouldNotReachHere(); } | |
2438 bool do_object_b(oop p) { return true; } | |
2439 }; | |
2440 static PSAlwaysTrueClosure always_true; | |
2441 | |
2442 void PSParallelCompact::adjust_roots() { | |
2443 // Adjust the pointers to reflect the new locations | |
2444 EventMark m("3 adjust roots"); | |
2445 TraceTime tm("adjust roots", print_phases(), true, gclog_or_tty); | |
2446 | |
2447 // General strong roots. | |
2448 Universe::oops_do(adjust_root_pointer_closure()); | |
2449 ReferenceProcessor::oops_do(adjust_root_pointer_closure()); | |
2450 JNIHandles::oops_do(adjust_root_pointer_closure()); // Global (strong) JNI handles | |
2451 Threads::oops_do(adjust_root_pointer_closure()); | |
2452 ObjectSynchronizer::oops_do(adjust_root_pointer_closure()); | |
2453 FlatProfiler::oops_do(adjust_root_pointer_closure()); | |
2454 Management::oops_do(adjust_root_pointer_closure()); | |
2455 JvmtiExport::oops_do(adjust_root_pointer_closure()); | |
2456 // SO_AllClasses | |
2457 SystemDictionary::oops_do(adjust_root_pointer_closure()); | |
2458 vmSymbols::oops_do(adjust_root_pointer_closure()); | |
2459 | |
2460 // Now adjust pointers in remaining weak roots. (All of which should | |
2461 // have been cleared if they pointed to non-surviving objects.) | |
2462 // Global (weak) JNI handles | |
2463 JNIHandles::weak_oops_do(&always_true, adjust_root_pointer_closure()); | |
2464 | |
2465 CodeCache::oops_do(adjust_pointer_closure()); | |
2466 SymbolTable::oops_do(adjust_root_pointer_closure()); | |
2467 StringTable::oops_do(adjust_root_pointer_closure()); | |
2468 ref_processor()->weak_oops_do(adjust_root_pointer_closure()); | |
2469 // Roots were visited so references into the young gen in roots | |
2470 // may have been scanned. Process them also. | |
2471 // Should the reference processor have a span that excludes | |
2472 // young gen objects? | |
2473 PSScavenge::reference_processor()->weak_oops_do( | |
2474 adjust_root_pointer_closure()); | |
2475 } | |
2476 | |
2477 void PSParallelCompact::compact_perm(ParCompactionManager* cm) { | |
2478 EventMark m("4 compact perm"); | |
2479 TraceTime tm("compact perm gen", print_phases(), true, gclog_or_tty); | |
2480 // trace("4"); | |
2481 | |
2482 gc_heap()->perm_gen()->start_array()->reset(); | |
2483 move_and_update(cm, perm_space_id); | |
2484 } | |
2485 | |
2486 void PSParallelCompact::enqueue_chunk_draining_tasks(GCTaskQueue* q, | |
2487 uint parallel_gc_threads) { | |
2488 TraceTime tm("drain task setup", print_phases(), true, gclog_or_tty); | |
2489 | |
2490 const unsigned int task_count = MAX2(parallel_gc_threads, 1U); | |
2491 for (unsigned int j = 0; j < task_count; j++) { | |
2492 q->enqueue(new DrainStacksCompactionTask()); | |
2493 } | |
2494 | |
2495 // Find all chunks that are available (can be filled immediately) and | |
2496 // distribute them to the thread stacks. The iteration is done in reverse | |
2497 // order (high to low) so the chunks will be removed in ascending order. | |
2498 | |
2499 const ParallelCompactData& sd = PSParallelCompact::summary_data(); | |
2500 | |
2501 size_t fillable_chunks = 0; // A count for diagnostic purposes. | |
2502 unsigned int which = 0; // The worker thread number. | |
2503 | |
2504 for (unsigned int id = to_space_id; id > perm_space_id; --id) { | |
2505 SpaceInfo* const space_info = _space_info + id; | |
2506 MutableSpace* const space = space_info->space(); | |
2507 HeapWord* const new_top = space_info->new_top(); | |
2508 | |
2509 const size_t beg_chunk = sd.addr_to_chunk_idx(space_info->dense_prefix()); | |
2510 const size_t end_chunk = sd.addr_to_chunk_idx(sd.chunk_align_up(new_top)); | |
2511 assert(end_chunk > 0, "perm gen cannot be empty"); | |
2512 | |
2513 for (size_t cur = end_chunk - 1; cur >= beg_chunk; --cur) { | |
2514 if (sd.chunk(cur)->claim_unsafe()) { | |
2515 ParCompactionManager* cm = ParCompactionManager::manager_array(which); | |
2516 cm->save_for_processing(cur); | |
2517 | |
2518 if (TraceParallelOldGCCompactionPhase && Verbose) { | |
2519 const size_t count_mod_8 = fillable_chunks & 7; | |
2520 if (count_mod_8 == 0) gclog_or_tty->print("fillable: "); | |
264
15dd2594d08e
6718283: existing uses of *_FORMAT_W() were broken by 6521491
jcoomes
parents:
263
diff
changeset
|
2521 gclog_or_tty->print(" " SIZE_FORMAT_W(7), cur); |
0 | 2522 if (count_mod_8 == 7) gclog_or_tty->cr(); |
2523 } | |
2524 | |
2525 NOT_PRODUCT(++fillable_chunks;) | |
2526 | |
2527 // Assign chunks to threads in round-robin fashion. | |
2528 if (++which == task_count) { | |
2529 which = 0; | |
2530 } | |
2531 } | |
2532 } | |
2533 } | |
2534 | |
2535 if (TraceParallelOldGCCompactionPhase) { | |
2536 if (Verbose && (fillable_chunks & 7) != 0) gclog_or_tty->cr(); | |
2537 gclog_or_tty->print_cr("%u initially fillable chunks", fillable_chunks); | |
2538 } | |
2539 } | |
2540 | |
2541 #define PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING 4 | |
2542 | |
2543 void PSParallelCompact::enqueue_dense_prefix_tasks(GCTaskQueue* q, | |
2544 uint parallel_gc_threads) { | |
2545 TraceTime tm("dense prefix task setup", print_phases(), true, gclog_or_tty); | |
2546 | |
2547 ParallelCompactData& sd = PSParallelCompact::summary_data(); | |
2548 | |
2549 // Iterate over all the spaces adding tasks for updating | |
2550 // chunks in the dense prefix. Assume that 1 gc thread | |
2551 // will work on opening the gaps and the remaining gc threads | |
2552 // will work on the dense prefix. | |
2553 SpaceId space_id = old_space_id; | |
2554 while (space_id != last_space_id) { | |
2555 HeapWord* const dense_prefix_end = _space_info[space_id].dense_prefix(); | |
2556 const MutableSpace* const space = _space_info[space_id].space(); | |
2557 | |
2558 if (dense_prefix_end == space->bottom()) { | |
2559 // There is no dense prefix for this space. | |
2560 space_id = next_compaction_space_id(space_id); | |
2561 continue; | |
2562 } | |
2563 | |
2564 // The dense prefix is before this chunk. | |
2565 size_t chunk_index_end_dense_prefix = | |
2566 sd.addr_to_chunk_idx(dense_prefix_end); | |
2567 ChunkData* const dense_prefix_cp = sd.chunk(chunk_index_end_dense_prefix); | |
2568 assert(dense_prefix_end == space->end() || | |
2569 dense_prefix_cp->available() || | |
2570 dense_prefix_cp->claimed(), | |
2571 "The chunk after the dense prefix should always be ready to fill"); | |
2572 | |
2573 size_t chunk_index_start = sd.addr_to_chunk_idx(space->bottom()); | |
2574 | |
2575 // Is there dense prefix work? | |
2576 size_t total_dense_prefix_chunks = | |
2577 chunk_index_end_dense_prefix - chunk_index_start; | |
2578 // How many chunks of the dense prefix should be given to | |
2579 // each thread? | |
2580 if (total_dense_prefix_chunks > 0) { | |
2581 uint tasks_for_dense_prefix = 1; | |
2582 if (UseParallelDensePrefixUpdate) { | |
2583 if (total_dense_prefix_chunks <= | |
2584 (parallel_gc_threads * PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING)) { | |
2585 // Don't over partition. This assumes that | |
2586 // PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING is a small integer value | |
2587 // so there are not many chunks to process. | |
2588 tasks_for_dense_prefix = parallel_gc_threads; | |
2589 } else { | |
2590 // Over partition | |
2591 tasks_for_dense_prefix = parallel_gc_threads * | |
2592 PAR_OLD_DENSE_PREFIX_OVER_PARTITIONING; | |
2593 } | |
2594 } | |
2595 size_t chunks_per_thread = total_dense_prefix_chunks / | |
2596 tasks_for_dense_prefix; | |
2597 // Give each thread at least 1 chunk. | |
2598 if (chunks_per_thread == 0) { | |
2599 chunks_per_thread = 1; | |
2600 } | |
2601 | |
2602 for (uint k = 0; k < tasks_for_dense_prefix; k++) { | |
2603 if (chunk_index_start >= chunk_index_end_dense_prefix) { | |
2604 break; | |
2605 } | |
2606 // chunk_index_end is not processed | |
2607 size_t chunk_index_end = MIN2(chunk_index_start + chunks_per_thread, | |
2608 chunk_index_end_dense_prefix); | |
2609 q->enqueue(new UpdateDensePrefixTask( | |
2610 space_id, | |
2611 chunk_index_start, | |
2612 chunk_index_end)); | |
2613 chunk_index_start = chunk_index_end; | |
2614 } | |
2615 } | |
2616 // This gets any part of the dense prefix that did not | |
2617 // fit evenly. | |
2618 if (chunk_index_start < chunk_index_end_dense_prefix) { | |
2619 q->enqueue(new UpdateDensePrefixTask( | |
2620 space_id, | |
2621 chunk_index_start, | |
2622 chunk_index_end_dense_prefix)); | |
2623 } | |
2624 space_id = next_compaction_space_id(space_id); | |
2625 } // End tasks for dense prefix | |
2626 } | |
2627 | |
2628 void PSParallelCompact::enqueue_chunk_stealing_tasks( | |
2629 GCTaskQueue* q, | |
2630 ParallelTaskTerminator* terminator_ptr, | |
2631 uint parallel_gc_threads) { | |
2632 TraceTime tm("steal task setup", print_phases(), true, gclog_or_tty); | |
2633 | |
2634 // Once a thread has drained it's stack, it should try to steal chunks from | |
2635 // other threads. | |
2636 if (parallel_gc_threads > 1) { | |
2637 for (uint j = 0; j < parallel_gc_threads; j++) { | |
2638 q->enqueue(new StealChunkCompactionTask(terminator_ptr)); | |
2639 } | |
2640 } | |
2641 } | |
2642 | |
2643 void PSParallelCompact::compact() { | |
2644 EventMark m("5 compact"); | |
2645 // trace("5"); | |
2646 TraceTime tm("compaction phase", print_phases(), true, gclog_or_tty); | |
2647 | |
2648 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); | |
2649 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); | |
2650 PSOldGen* old_gen = heap->old_gen(); | |
2651 old_gen->start_array()->reset(); | |
2652 uint parallel_gc_threads = heap->gc_task_manager()->workers(); | |
2653 TaskQueueSetSuper* qset = ParCompactionManager::chunk_array(); | |
2654 ParallelTaskTerminator terminator(parallel_gc_threads, qset); | |
2655 | |
2656 GCTaskQueue* q = GCTaskQueue::create(); | |
2657 enqueue_chunk_draining_tasks(q, parallel_gc_threads); | |
2658 enqueue_dense_prefix_tasks(q, parallel_gc_threads); | |
2659 enqueue_chunk_stealing_tasks(q, &terminator, parallel_gc_threads); | |
2660 | |
2661 { | |
2662 TraceTime tm_pc("par compact", print_phases(), true, gclog_or_tty); | |
2663 | |
2664 WaitForBarrierGCTask* fin = WaitForBarrierGCTask::create(); | |
2665 q->enqueue(fin); | |
2666 | |
2667 gc_task_manager()->add_list(q); | |
2668 | |
2669 fin->wait_for(); | |
2670 | |
2671 // We have to release the barrier tasks! | |
2672 WaitForBarrierGCTask::destroy(fin); | |
2673 | |
2674 #ifdef ASSERT | |
2675 // Verify that all chunks have been processed before the deferred updates. | |
2676 // Note that perm_space_id is skipped; this type of verification is not | |
2677 // valid until the perm gen is compacted by chunks. | |
2678 for (unsigned int id = old_space_id; id < last_space_id; ++id) { | |
2679 verify_complete(SpaceId(id)); | |
2680 } | |
2681 #endif | |
2682 } | |
2683 | |
2684 { | |
2685 // Update the deferred objects, if any. Any compaction manager can be used. | |
2686 TraceTime tm_du("deferred updates", print_phases(), true, gclog_or_tty); | |
2687 ParCompactionManager* cm = ParCompactionManager::manager_array(0); | |
2688 for (unsigned int id = old_space_id; id < last_space_id; ++id) { | |
2689 update_deferred_objects(cm, SpaceId(id)); | |
2690 } | |
2691 } | |
2692 } | |
2693 | |
2694 #ifdef ASSERT | |
2695 void PSParallelCompact::verify_complete(SpaceId space_id) { | |
2696 // All Chunks between space bottom() to new_top() should be marked as filled | |
2697 // and all Chunks between new_top() and top() should be available (i.e., | |
2698 // should have been emptied). | |
2699 ParallelCompactData& sd = summary_data(); | |
2700 SpaceInfo si = _space_info[space_id]; | |
2701 HeapWord* new_top_addr = sd.chunk_align_up(si.new_top()); | |
2702 HeapWord* old_top_addr = sd.chunk_align_up(si.space()->top()); | |
2703 const size_t beg_chunk = sd.addr_to_chunk_idx(si.space()->bottom()); | |
2704 const size_t new_top_chunk = sd.addr_to_chunk_idx(new_top_addr); | |
2705 const size_t old_top_chunk = sd.addr_to_chunk_idx(old_top_addr); | |
2706 | |
2707 bool issued_a_warning = false; | |
2708 | |
2709 size_t cur_chunk; | |
2710 for (cur_chunk = beg_chunk; cur_chunk < new_top_chunk; ++cur_chunk) { | |
2711 const ChunkData* const c = sd.chunk(cur_chunk); | |
2712 if (!c->completed()) { | |
2713 warning("chunk " SIZE_FORMAT " not filled: " | |
2714 "destination_count=" SIZE_FORMAT, | |
2715 cur_chunk, c->destination_count()); | |
2716 issued_a_warning = true; | |
2717 } | |
2718 } | |
2719 | |
2720 for (cur_chunk = new_top_chunk; cur_chunk < old_top_chunk; ++cur_chunk) { | |
2721 const ChunkData* const c = sd.chunk(cur_chunk); | |
2722 if (!c->available()) { | |
2723 warning("chunk " SIZE_FORMAT " not empty: " | |
2724 "destination_count=" SIZE_FORMAT, | |
2725 cur_chunk, c->destination_count()); | |
2726 issued_a_warning = true; | |
2727 } | |
2728 } | |
2729 | |
2730 if (issued_a_warning) { | |
2731 print_chunk_ranges(); | |
2732 } | |
2733 } | |
2734 #endif // #ifdef ASSERT | |
2735 | |
2736 void PSParallelCompact::compact_serial(ParCompactionManager* cm) { | |
2737 EventMark m("5 compact serial"); | |
2738 TraceTime tm("compact serial", print_phases(), true, gclog_or_tty); | |
2739 | |
2740 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); | |
2741 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); | |
2742 | |
2743 PSYoungGen* young_gen = heap->young_gen(); | |
2744 PSOldGen* old_gen = heap->old_gen(); | |
2745 | |
2746 old_gen->start_array()->reset(); | |
2747 old_gen->move_and_update(cm); | |
2748 young_gen->move_and_update(cm); | |
2749 } | |
2750 | |
2751 | |
2752 void PSParallelCompact::follow_stack(ParCompactionManager* cm) { | |
2753 while(!cm->overflow_stack()->is_empty()) { | |
2754 oop obj = cm->overflow_stack()->pop(); | |
2755 obj->follow_contents(cm); | |
2756 } | |
2757 | |
2758 oop obj; | |
2759 // obj is a reference!!! | |
2760 while (cm->marking_stack()->pop_local(obj)) { | |
2761 // It would be nice to assert about the type of objects we might | |
2762 // pop, but they can come from anywhere, unfortunately. | |
2763 obj->follow_contents(cm); | |
2764 } | |
2765 } | |
2766 | |
2767 void | |
2768 PSParallelCompact::follow_weak_klass_links(ParCompactionManager* serial_cm) { | |
2769 // All klasses on the revisit stack are marked at this point. | |
2770 // Update and follow all subklass, sibling and implementor links. | |
2771 for (uint i = 0; i < ParallelGCThreads+1; i++) { | |
2772 ParCompactionManager* cm = ParCompactionManager::manager_array(i); | |
2773 KeepAliveClosure keep_alive_closure(cm); | |
2774 for (int i = 0; i < cm->revisit_klass_stack()->length(); i++) { | |
2775 cm->revisit_klass_stack()->at(i)->follow_weak_klass_links( | |
2776 is_alive_closure(), | |
2777 &keep_alive_closure); | |
2778 } | |
2779 follow_stack(cm); | |
2780 } | |
2781 } | |
2782 | |
2783 void | |
2784 PSParallelCompact::revisit_weak_klass_link(ParCompactionManager* cm, Klass* k) { | |
2785 cm->revisit_klass_stack()->push(k); | |
2786 } | |
2787 | |
2788 #ifdef VALIDATE_MARK_SWEEP | |
2789 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
79
diff
changeset
|
2790 void PSParallelCompact::track_adjusted_pointer(void* p, bool isroot) { |
0 | 2791 if (!ValidateMarkSweep) |
2792 return; | |
2793 | |
2794 if (!isroot) { | |
2795 if (_pointer_tracking) { | |
2796 guarantee(_adjusted_pointers->contains(p), "should have seen this pointer"); | |
2797 _adjusted_pointers->remove(p); | |
2798 } | |
2799 } else { | |
2800 ptrdiff_t index = _root_refs_stack->find(p); | |
2801 if (index != -1) { | |
2802 int l = _root_refs_stack->length(); | |
2803 if (l > 0 && l - 1 != index) { | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
79
diff
changeset
|
2804 void* last = _root_refs_stack->pop(); |
0 | 2805 assert(last != p, "should be different"); |
2806 _root_refs_stack->at_put(index, last); | |
2807 } else { | |
2808 _root_refs_stack->remove(p); | |
2809 } | |
2810 } | |
2811 } | |
2812 } | |
2813 | |
2814 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
79
diff
changeset
|
2815 void PSParallelCompact::check_adjust_pointer(void* p) { |
0 | 2816 _adjusted_pointers->push(p); |
2817 } | |
2818 | |
2819 | |
2820 class AdjusterTracker: public OopClosure { | |
2821 public: | |
2822 AdjusterTracker() {}; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
79
diff
changeset
|
2823 void do_oop(oop* o) { PSParallelCompact::check_adjust_pointer(o); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
79
diff
changeset
|
2824 void do_oop(narrowOop* o) { PSParallelCompact::check_adjust_pointer(o); } |
0 | 2825 }; |
2826 | |
2827 | |
2828 void PSParallelCompact::track_interior_pointers(oop obj) { | |
2829 if (ValidateMarkSweep) { | |
2830 _adjusted_pointers->clear(); | |
2831 _pointer_tracking = true; | |
2832 | |
2833 AdjusterTracker checker; | |
2834 obj->oop_iterate(&checker); | |
2835 } | |
2836 } | |
2837 | |
2838 | |
2839 void PSParallelCompact::check_interior_pointers() { | |
2840 if (ValidateMarkSweep) { | |
2841 _pointer_tracking = false; | |
2842 guarantee(_adjusted_pointers->length() == 0, "should have processed the same pointers"); | |
2843 } | |
2844 } | |
2845 | |
2846 | |
2847 void PSParallelCompact::reset_live_oop_tracking(bool at_perm) { | |
2848 if (ValidateMarkSweep) { | |
2849 guarantee((size_t)_live_oops->length() == _live_oops_index, "should be at end of live oops"); | |
2850 _live_oops_index = at_perm ? _live_oops_index_at_perm : 0; | |
2851 } | |
2852 } | |
2853 | |
2854 | |
2855 void PSParallelCompact::register_live_oop(oop p, size_t size) { | |
2856 if (ValidateMarkSweep) { | |
2857 _live_oops->push(p); | |
2858 _live_oops_size->push(size); | |
2859 _live_oops_index++; | |
2860 } | |
2861 } | |
2862 | |
2863 void PSParallelCompact::validate_live_oop(oop p, size_t size) { | |
2864 if (ValidateMarkSweep) { | |
2865 oop obj = _live_oops->at((int)_live_oops_index); | |
2866 guarantee(obj == p, "should be the same object"); | |
2867 guarantee(_live_oops_size->at((int)_live_oops_index) == size, "should be the same size"); | |
2868 _live_oops_index++; | |
2869 } | |
2870 } | |
2871 | |
2872 void PSParallelCompact::live_oop_moved_to(HeapWord* q, size_t size, | |
2873 HeapWord* compaction_top) { | |
2874 assert(oop(q)->forwardee() == NULL || oop(q)->forwardee() == oop(compaction_top), | |
2875 "should be moved to forwarded location"); | |
2876 if (ValidateMarkSweep) { | |
2877 PSParallelCompact::validate_live_oop(oop(q), size); | |
2878 _live_oops_moved_to->push(oop(compaction_top)); | |
2879 } | |
2880 if (RecordMarkSweepCompaction) { | |
2881 _cur_gc_live_oops->push(q); | |
2882 _cur_gc_live_oops_moved_to->push(compaction_top); | |
2883 _cur_gc_live_oops_size->push(size); | |
2884 } | |
2885 } | |
2886 | |
2887 | |
2888 void PSParallelCompact::compaction_complete() { | |
2889 if (RecordMarkSweepCompaction) { | |
2890 GrowableArray<HeapWord*>* _tmp_live_oops = _cur_gc_live_oops; | |
2891 GrowableArray<HeapWord*>* _tmp_live_oops_moved_to = _cur_gc_live_oops_moved_to; | |
2892 GrowableArray<size_t> * _tmp_live_oops_size = _cur_gc_live_oops_size; | |
2893 | |
2894 _cur_gc_live_oops = _last_gc_live_oops; | |
2895 _cur_gc_live_oops_moved_to = _last_gc_live_oops_moved_to; | |
2896 _cur_gc_live_oops_size = _last_gc_live_oops_size; | |
2897 _last_gc_live_oops = _tmp_live_oops; | |
2898 _last_gc_live_oops_moved_to = _tmp_live_oops_moved_to; | |
2899 _last_gc_live_oops_size = _tmp_live_oops_size; | |
2900 } | |
2901 } | |
2902 | |
2903 | |
2904 void PSParallelCompact::print_new_location_of_heap_address(HeapWord* q) { | |
2905 if (!RecordMarkSweepCompaction) { | |
2906 tty->print_cr("Requires RecordMarkSweepCompaction to be enabled"); | |
2907 return; | |
2908 } | |
2909 | |
2910 if (_last_gc_live_oops == NULL) { | |
2911 tty->print_cr("No compaction information gathered yet"); | |
2912 return; | |
2913 } | |
2914 | |
2915 for (int i = 0; i < _last_gc_live_oops->length(); i++) { | |
2916 HeapWord* old_oop = _last_gc_live_oops->at(i); | |
2917 size_t sz = _last_gc_live_oops_size->at(i); | |
2918 if (old_oop <= q && q < (old_oop + sz)) { | |
2919 HeapWord* new_oop = _last_gc_live_oops_moved_to->at(i); | |
2920 size_t offset = (q - old_oop); | |
2921 tty->print_cr("Address " PTR_FORMAT, q); | |
2922 tty->print_cr(" Was in oop " PTR_FORMAT ", size %d, at offset %d", old_oop, sz, offset); | |
2923 tty->print_cr(" Now in oop " PTR_FORMAT ", actual address " PTR_FORMAT, new_oop, new_oop + offset); | |
2924 return; | |
2925 } | |
2926 } | |
2927 | |
2928 tty->print_cr("Address " PTR_FORMAT " not found in live oop information from last GC", q); | |
2929 } | |
2930 #endif //VALIDATE_MARK_SWEEP | |
2931 | |
2932 // Update interior oops in the ranges of chunks [beg_chunk, end_chunk). | |
2933 void | |
2934 PSParallelCompact::update_and_deadwood_in_dense_prefix(ParCompactionManager* cm, | |
2935 SpaceId space_id, | |
2936 size_t beg_chunk, | |
2937 size_t end_chunk) { | |
2938 ParallelCompactData& sd = summary_data(); | |
2939 ParMarkBitMap* const mbm = mark_bitmap(); | |
2940 | |
2941 HeapWord* beg_addr = sd.chunk_to_addr(beg_chunk); | |
2942 HeapWord* const end_addr = sd.chunk_to_addr(end_chunk); | |
2943 assert(beg_chunk <= end_chunk, "bad chunk range"); | |
2944 assert(end_addr <= dense_prefix(space_id), "not in the dense prefix"); | |
2945 | |
2946 #ifdef ASSERT | |
2947 // Claim the chunks to avoid triggering an assert when they are marked as | |
2948 // filled. | |
2949 for (size_t claim_chunk = beg_chunk; claim_chunk < end_chunk; ++claim_chunk) { | |
2950 assert(sd.chunk(claim_chunk)->claim_unsafe(), "claim() failed"); | |
2951 } | |
2952 #endif // #ifdef ASSERT | |
2953 | |
2954 if (beg_addr != space(space_id)->bottom()) { | |
2955 // Find the first live object or block of dead space that *starts* in this | |
2956 // range of chunks. If a partial object crosses onto the chunk, skip it; it | |
2957 // will be marked for 'deferred update' when the object head is processed. | |
2958 // If dead space crosses onto the chunk, it is also skipped; it will be | |
2959 // filled when the prior chunk is processed. If neither of those apply, the | |
2960 // first word in the chunk is the start of a live object or dead space. | |
2961 assert(beg_addr > space(space_id)->bottom(), "sanity"); | |
2962 const ChunkData* const cp = sd.chunk(beg_chunk); | |
2963 if (cp->partial_obj_size() != 0) { | |
2964 beg_addr = sd.partial_obj_end(beg_chunk); | |
2965 } else if (dead_space_crosses_boundary(cp, mbm->addr_to_bit(beg_addr))) { | |
2966 beg_addr = mbm->find_obj_beg(beg_addr, end_addr); | |
2967 } | |
2968 } | |
2969 | |
2970 if (beg_addr < end_addr) { | |
2971 // A live object or block of dead space starts in this range of Chunks. | |
2972 HeapWord* const dense_prefix_end = dense_prefix(space_id); | |
2973 | |
2974 // Create closures and iterate. | |
2975 UpdateOnlyClosure update_closure(mbm, cm, space_id); | |
2976 FillClosure fill_closure(cm, space_id); | |
2977 ParMarkBitMap::IterationStatus status; | |
2978 status = mbm->iterate(&update_closure, &fill_closure, beg_addr, end_addr, | |
2979 dense_prefix_end); | |
2980 if (status == ParMarkBitMap::incomplete) { | |
2981 update_closure.do_addr(update_closure.source()); | |
2982 } | |
2983 } | |
2984 | |
2985 // Mark the chunks as filled. | |
2986 ChunkData* const beg_cp = sd.chunk(beg_chunk); | |
2987 ChunkData* const end_cp = sd.chunk(end_chunk); | |
2988 for (ChunkData* cp = beg_cp; cp < end_cp; ++cp) { | |
2989 cp->set_completed(); | |
2990 } | |
2991 } | |
2992 | |
2993 // Return the SpaceId for the space containing addr. If addr is not in the | |
2994 // heap, last_space_id is returned. In debug mode it expects the address to be | |
2995 // in the heap and asserts such. | |
2996 PSParallelCompact::SpaceId PSParallelCompact::space_id(HeapWord* addr) { | |
2997 assert(Universe::heap()->is_in_reserved(addr), "addr not in the heap"); | |
2998 | |
2999 for (unsigned int id = perm_space_id; id < last_space_id; ++id) { | |
3000 if (_space_info[id].space()->contains(addr)) { | |
3001 return SpaceId(id); | |
3002 } | |
3003 } | |
3004 | |
3005 assert(false, "no space contains the addr"); | |
3006 return last_space_id; | |
3007 } | |
3008 | |
3009 void PSParallelCompact::update_deferred_objects(ParCompactionManager* cm, | |
3010 SpaceId id) { | |
3011 assert(id < last_space_id, "bad space id"); | |
3012 | |
3013 ParallelCompactData& sd = summary_data(); | |
3014 const SpaceInfo* const space_info = _space_info + id; | |
3015 ObjectStartArray* const start_array = space_info->start_array(); | |
3016 | |
3017 const MutableSpace* const space = space_info->space(); | |
3018 assert(space_info->dense_prefix() >= space->bottom(), "dense_prefix not set"); | |
3019 HeapWord* const beg_addr = space_info->dense_prefix(); | |
3020 HeapWord* const end_addr = sd.chunk_align_up(space_info->new_top()); | |
3021 | |
3022 const ChunkData* const beg_chunk = sd.addr_to_chunk_ptr(beg_addr); | |
3023 const ChunkData* const end_chunk = sd.addr_to_chunk_ptr(end_addr); | |
3024 const ChunkData* cur_chunk; | |
3025 for (cur_chunk = beg_chunk; cur_chunk < end_chunk; ++cur_chunk) { | |
3026 HeapWord* const addr = cur_chunk->deferred_obj_addr(); | |
3027 if (addr != NULL) { | |
3028 if (start_array != NULL) { | |
3029 start_array->allocate_block(addr); | |
3030 } | |
3031 oop(addr)->update_contents(cm); | |
3032 assert(oop(addr)->is_oop_or_null(), "should be an oop now"); | |
3033 } | |
3034 } | |
3035 } | |
3036 | |
3037 // Skip over count live words starting from beg, and return the address of the | |
3038 // next live word. Unless marked, the word corresponding to beg is assumed to | |
3039 // be dead. Callers must either ensure beg does not correspond to the middle of | |
3040 // an object, or account for those live words in some other way. Callers must | |
3041 // also ensure that there are enough live words in the range [beg, end) to skip. | |
3042 HeapWord* | |
3043 PSParallelCompact::skip_live_words(HeapWord* beg, HeapWord* end, size_t count) | |
3044 { | |
3045 assert(count > 0, "sanity"); | |
3046 | |
3047 ParMarkBitMap* m = mark_bitmap(); | |
3048 idx_t bits_to_skip = m->words_to_bits(count); | |
3049 idx_t cur_beg = m->addr_to_bit(beg); | |
3050 const idx_t search_end = BitMap::word_align_up(m->addr_to_bit(end)); | |
3051 | |
3052 do { | |
3053 cur_beg = m->find_obj_beg(cur_beg, search_end); | |
3054 idx_t cur_end = m->find_obj_end(cur_beg, search_end); | |
3055 const size_t obj_bits = cur_end - cur_beg + 1; | |
3056 if (obj_bits > bits_to_skip) { | |
3057 return m->bit_to_addr(cur_beg + bits_to_skip); | |
3058 } | |
3059 bits_to_skip -= obj_bits; | |
3060 cur_beg = cur_end + 1; | |
3061 } while (bits_to_skip > 0); | |
3062 | |
3063 // Skipping the desired number of words landed just past the end of an object. | |
3064 // Find the start of the next object. | |
3065 cur_beg = m->find_obj_beg(cur_beg, search_end); | |
3066 assert(cur_beg < m->addr_to_bit(end), "not enough live words to skip"); | |
3067 return m->bit_to_addr(cur_beg); | |
3068 } | |
3069 | |
3070 HeapWord* | |
3071 PSParallelCompact::first_src_addr(HeapWord* const dest_addr, | |
3072 size_t src_chunk_idx) | |
3073 { | |
3074 ParMarkBitMap* const bitmap = mark_bitmap(); | |
3075 const ParallelCompactData& sd = summary_data(); | |
3076 const size_t ChunkSize = ParallelCompactData::ChunkSize; | |
3077 | |
3078 assert(sd.is_chunk_aligned(dest_addr), "not aligned"); | |
3079 | |
3080 const ChunkData* const src_chunk_ptr = sd.chunk(src_chunk_idx); | |
3081 const size_t partial_obj_size = src_chunk_ptr->partial_obj_size(); | |
3082 HeapWord* const src_chunk_destination = src_chunk_ptr->destination(); | |
3083 | |
3084 assert(dest_addr >= src_chunk_destination, "wrong src chunk"); | |
3085 assert(src_chunk_ptr->data_size() > 0, "src chunk cannot be empty"); | |
3086 | |
3087 HeapWord* const src_chunk_beg = sd.chunk_to_addr(src_chunk_idx); | |
3088 HeapWord* const src_chunk_end = src_chunk_beg + ChunkSize; | |
3089 | |
3090 HeapWord* addr = src_chunk_beg; | |
3091 if (dest_addr == src_chunk_destination) { | |
3092 // Return the first live word in the source chunk. | |
3093 if (partial_obj_size == 0) { | |
3094 addr = bitmap->find_obj_beg(addr, src_chunk_end); | |
3095 assert(addr < src_chunk_end, "no objects start in src chunk"); | |
3096 } | |
3097 return addr; | |
3098 } | |
3099 | |
3100 // Must skip some live data. | |
3101 size_t words_to_skip = dest_addr - src_chunk_destination; | |
3102 assert(src_chunk_ptr->data_size() > words_to_skip, "wrong src chunk"); | |
3103 | |
3104 if (partial_obj_size >= words_to_skip) { | |
3105 // All the live words to skip are part of the partial object. | |
3106 addr += words_to_skip; | |
3107 if (partial_obj_size == words_to_skip) { | |
3108 // Find the first live word past the partial object. | |
3109 addr = bitmap->find_obj_beg(addr, src_chunk_end); | |
3110 assert(addr < src_chunk_end, "wrong src chunk"); | |
3111 } | |
3112 return addr; | |
3113 } | |
3114 | |
3115 // Skip over the partial object (if any). | |
3116 if (partial_obj_size != 0) { | |
3117 words_to_skip -= partial_obj_size; | |
3118 addr += partial_obj_size; | |
3119 } | |
3120 | |
3121 // Skip over live words due to objects that start in the chunk. | |
3122 addr = skip_live_words(addr, src_chunk_end, words_to_skip); | |
3123 assert(addr < src_chunk_end, "wrong src chunk"); | |
3124 return addr; | |
3125 } | |
3126 | |
3127 void PSParallelCompact::decrement_destination_counts(ParCompactionManager* cm, | |
3128 size_t beg_chunk, | |
3129 HeapWord* end_addr) | |
3130 { | |
3131 ParallelCompactData& sd = summary_data(); | |
3132 ChunkData* const beg = sd.chunk(beg_chunk); | |
3133 HeapWord* const end_addr_aligned_up = sd.chunk_align_up(end_addr); | |
3134 ChunkData* const end = sd.addr_to_chunk_ptr(end_addr_aligned_up); | |
3135 size_t cur_idx = beg_chunk; | |
3136 for (ChunkData* cur = beg; cur < end; ++cur, ++cur_idx) { | |
3137 assert(cur->data_size() > 0, "chunk must have live data"); | |
3138 cur->decrement_destination_count(); | |
3139 if (cur_idx <= cur->source_chunk() && cur->available() && cur->claim()) { | |
3140 cm->save_for_processing(cur_idx); | |
3141 } | |
3142 } | |
3143 } | |
3144 | |
3145 size_t PSParallelCompact::next_src_chunk(MoveAndUpdateClosure& closure, | |
3146 SpaceId& src_space_id, | |
3147 HeapWord*& src_space_top, | |
3148 HeapWord* end_addr) | |
3149 { | |
3150 typedef ParallelCompactData::ChunkData ChunkData; | |
3151 | |
3152 ParallelCompactData& sd = PSParallelCompact::summary_data(); | |
3153 const size_t chunk_size = ParallelCompactData::ChunkSize; | |
3154 | |
3155 size_t src_chunk_idx = 0; | |
3156 | |
3157 // Skip empty chunks (if any) up to the top of the space. | |
3158 HeapWord* const src_aligned_up = sd.chunk_align_up(end_addr); | |
3159 ChunkData* src_chunk_ptr = sd.addr_to_chunk_ptr(src_aligned_up); | |
3160 HeapWord* const top_aligned_up = sd.chunk_align_up(src_space_top); | |
3161 const ChunkData* const top_chunk_ptr = sd.addr_to_chunk_ptr(top_aligned_up); | |
3162 while (src_chunk_ptr < top_chunk_ptr && src_chunk_ptr->data_size() == 0) { | |
3163 ++src_chunk_ptr; | |
3164 } | |
3165 | |
3166 if (src_chunk_ptr < top_chunk_ptr) { | |
3167 // The next source chunk is in the current space. Update src_chunk_idx and | |
3168 // the source address to match src_chunk_ptr. | |
3169 src_chunk_idx = sd.chunk(src_chunk_ptr); | |
3170 HeapWord* const src_chunk_addr = sd.chunk_to_addr(src_chunk_idx); | |
3171 if (src_chunk_addr > closure.source()) { | |
3172 closure.set_source(src_chunk_addr); | |
3173 } | |
3174 return src_chunk_idx; | |
3175 } | |
3176 | |
3177 // Switch to a new source space and find the first non-empty chunk. | |
3178 unsigned int space_id = src_space_id + 1; | |
3179 assert(space_id < last_space_id, "not enough spaces"); | |
3180 | |
3181 HeapWord* const destination = closure.destination(); | |
3182 | |
3183 do { | |
3184 MutableSpace* space = _space_info[space_id].space(); | |
3185 HeapWord* const bottom = space->bottom(); | |
3186 const ChunkData* const bottom_cp = sd.addr_to_chunk_ptr(bottom); | |
3187 | |
3188 // Iterate over the spaces that do not compact into themselves. | |
3189 if (bottom_cp->destination() != bottom) { | |
3190 HeapWord* const top_aligned_up = sd.chunk_align_up(space->top()); | |
3191 const ChunkData* const top_cp = sd.addr_to_chunk_ptr(top_aligned_up); | |
3192 | |
3193 for (const ChunkData* src_cp = bottom_cp; src_cp < top_cp; ++src_cp) { | |
3194 if (src_cp->live_obj_size() > 0) { | |
3195 // Found it. | |
3196 assert(src_cp->destination() == destination, | |
3197 "first live obj in the space must match the destination"); | |
3198 assert(src_cp->partial_obj_size() == 0, | |
3199 "a space cannot begin with a partial obj"); | |
3200 | |
3201 src_space_id = SpaceId(space_id); | |
3202 src_space_top = space->top(); | |
3203 const size_t src_chunk_idx = sd.chunk(src_cp); | |
3204 closure.set_source(sd.chunk_to_addr(src_chunk_idx)); | |
3205 return src_chunk_idx; | |
3206 } else { | |
3207 assert(src_cp->data_size() == 0, "sanity"); | |
3208 } | |
3209 } | |
3210 } | |
3211 } while (++space_id < last_space_id); | |
3212 | |
3213 assert(false, "no source chunk was found"); | |
3214 return 0; | |
3215 } | |
3216 | |
3217 void PSParallelCompact::fill_chunk(ParCompactionManager* cm, size_t chunk_idx) | |
3218 { | |
3219 typedef ParMarkBitMap::IterationStatus IterationStatus; | |
3220 const size_t ChunkSize = ParallelCompactData::ChunkSize; | |
3221 ParMarkBitMap* const bitmap = mark_bitmap(); | |
3222 ParallelCompactData& sd = summary_data(); | |
3223 ChunkData* const chunk_ptr = sd.chunk(chunk_idx); | |
3224 | |
3225 // Get the items needed to construct the closure. | |
3226 HeapWord* dest_addr = sd.chunk_to_addr(chunk_idx); | |
3227 SpaceId dest_space_id = space_id(dest_addr); | |
3228 ObjectStartArray* start_array = _space_info[dest_space_id].start_array(); | |
3229 HeapWord* new_top = _space_info[dest_space_id].new_top(); | |
3230 assert(dest_addr < new_top, "sanity"); | |
3231 const size_t words = MIN2(pointer_delta(new_top, dest_addr), ChunkSize); | |
3232 | |
3233 // Get the source chunk and related info. | |
3234 size_t src_chunk_idx = chunk_ptr->source_chunk(); | |
3235 SpaceId src_space_id = space_id(sd.chunk_to_addr(src_chunk_idx)); | |
3236 HeapWord* src_space_top = _space_info[src_space_id].space()->top(); | |
3237 | |
3238 MoveAndUpdateClosure closure(bitmap, cm, start_array, dest_addr, words); | |
3239 closure.set_source(first_src_addr(dest_addr, src_chunk_idx)); | |
3240 | |
3241 // Adjust src_chunk_idx to prepare for decrementing destination counts (the | |
3242 // destination count is not decremented when a chunk is copied to itself). | |
3243 if (src_chunk_idx == chunk_idx) { | |
3244 src_chunk_idx += 1; | |
3245 } | |
3246 | |
3247 if (bitmap->is_unmarked(closure.source())) { | |
3248 // The first source word is in the middle of an object; copy the remainder | |
3249 // of the object or as much as will fit. The fact that pointer updates were | |
3250 // deferred will be noted when the object header is processed. | |
3251 HeapWord* const old_src_addr = closure.source(); | |
3252 closure.copy_partial_obj(); | |
3253 if (closure.is_full()) { | |
3254 decrement_destination_counts(cm, src_chunk_idx, closure.source()); | |
3255 chunk_ptr->set_deferred_obj_addr(NULL); | |
3256 chunk_ptr->set_completed(); | |
3257 return; | |
3258 } | |
3259 | |
3260 HeapWord* const end_addr = sd.chunk_align_down(closure.source()); | |
3261 if (sd.chunk_align_down(old_src_addr) != end_addr) { | |
3262 // The partial object was copied from more than one source chunk. | |
3263 decrement_destination_counts(cm, src_chunk_idx, end_addr); | |
3264 | |
3265 // Move to the next source chunk, possibly switching spaces as well. All | |
3266 // args except end_addr may be modified. | |
3267 src_chunk_idx = next_src_chunk(closure, src_space_id, src_space_top, | |
3268 end_addr); | |
3269 } | |
3270 } | |
3271 | |
3272 do { | |
3273 HeapWord* const cur_addr = closure.source(); | |
3274 HeapWord* const end_addr = MIN2(sd.chunk_align_up(cur_addr + 1), | |
3275 src_space_top); | |
3276 IterationStatus status = bitmap->iterate(&closure, cur_addr, end_addr); | |
3277 | |
3278 if (status == ParMarkBitMap::incomplete) { | |
3279 // The last obj that starts in the source chunk does not end in the chunk. | |
3280 assert(closure.source() < end_addr, "sanity") | |
3281 HeapWord* const obj_beg = closure.source(); | |
3282 HeapWord* const range_end = MIN2(obj_beg + closure.words_remaining(), | |
3283 src_space_top); | |
3284 HeapWord* const obj_end = bitmap->find_obj_end(obj_beg, range_end); | |
3285 if (obj_end < range_end) { | |
3286 // The end was found; the entire object will fit. | |
3287 status = closure.do_addr(obj_beg, bitmap->obj_size(obj_beg, obj_end)); | |
3288 assert(status != ParMarkBitMap::would_overflow, "sanity"); | |
3289 } else { | |
3290 // The end was not found; the object will not fit. | |
3291 assert(range_end < src_space_top, "obj cannot cross space boundary"); | |
3292 status = ParMarkBitMap::would_overflow; | |
3293 } | |
3294 } | |
3295 | |
3296 if (status == ParMarkBitMap::would_overflow) { | |
3297 // The last object did not fit. Note that interior oop updates were | |
3298 // deferred, then copy enough of the object to fill the chunk. | |
3299 chunk_ptr->set_deferred_obj_addr(closure.destination()); | |
3300 status = closure.copy_until_full(); // copies from closure.source() | |
3301 | |
3302 decrement_destination_counts(cm, src_chunk_idx, closure.source()); | |
3303 chunk_ptr->set_completed(); | |
3304 return; | |
3305 } | |
3306 | |
3307 if (status == ParMarkBitMap::full) { | |
3308 decrement_destination_counts(cm, src_chunk_idx, closure.source()); | |
3309 chunk_ptr->set_deferred_obj_addr(NULL); | |
3310 chunk_ptr->set_completed(); | |
3311 return; | |
3312 } | |
3313 | |
3314 decrement_destination_counts(cm, src_chunk_idx, end_addr); | |
3315 | |
3316 // Move to the next source chunk, possibly switching spaces as well. All | |
3317 // args except end_addr may be modified. | |
3318 src_chunk_idx = next_src_chunk(closure, src_space_id, src_space_top, | |
3319 end_addr); | |
3320 } while (true); | |
3321 } | |
3322 | |
3323 void | |
3324 PSParallelCompact::move_and_update(ParCompactionManager* cm, SpaceId space_id) { | |
3325 const MutableSpace* sp = space(space_id); | |
3326 if (sp->is_empty()) { | |
3327 return; | |
3328 } | |
3329 | |
3330 ParallelCompactData& sd = PSParallelCompact::summary_data(); | |
3331 ParMarkBitMap* const bitmap = mark_bitmap(); | |
3332 HeapWord* const dp_addr = dense_prefix(space_id); | |
3333 HeapWord* beg_addr = sp->bottom(); | |
3334 HeapWord* end_addr = sp->top(); | |
3335 | |
3336 #ifdef ASSERT | |
3337 assert(beg_addr <= dp_addr && dp_addr <= end_addr, "bad dense prefix"); | |
3338 if (cm->should_verify_only()) { | |
3339 VerifyUpdateClosure verify_update(cm, sp); | |
3340 bitmap->iterate(&verify_update, beg_addr, end_addr); | |
3341 return; | |
3342 } | |
3343 | |
3344 if (cm->should_reset_only()) { | |
3345 ResetObjectsClosure reset_objects(cm); | |
3346 bitmap->iterate(&reset_objects, beg_addr, end_addr); | |
3347 return; | |
3348 } | |
3349 #endif | |
3350 | |
3351 const size_t beg_chunk = sd.addr_to_chunk_idx(beg_addr); | |
3352 const size_t dp_chunk = sd.addr_to_chunk_idx(dp_addr); | |
3353 if (beg_chunk < dp_chunk) { | |
3354 update_and_deadwood_in_dense_prefix(cm, space_id, beg_chunk, dp_chunk); | |
3355 } | |
3356 | |
3357 // The destination of the first live object that starts in the chunk is one | |
3358 // past the end of the partial object entering the chunk (if any). | |
3359 HeapWord* const dest_addr = sd.partial_obj_end(dp_chunk); | |
3360 HeapWord* const new_top = _space_info[space_id].new_top(); | |
3361 assert(new_top >= dest_addr, "bad new_top value"); | |
3362 const size_t words = pointer_delta(new_top, dest_addr); | |
3363 | |
3364 if (words > 0) { | |
3365 ObjectStartArray* start_array = _space_info[space_id].start_array(); | |
3366 MoveAndUpdateClosure closure(bitmap, cm, start_array, dest_addr, words); | |
3367 | |
3368 ParMarkBitMap::IterationStatus status; | |
3369 status = bitmap->iterate(&closure, dest_addr, end_addr); | |
3370 assert(status == ParMarkBitMap::full, "iteration not complete"); | |
3371 assert(bitmap->find_obj_beg(closure.source(), end_addr) == end_addr, | |
3372 "live objects skipped because closure is full"); | |
3373 } | |
3374 } | |
3375 | |
3376 jlong PSParallelCompact::millis_since_last_gc() { | |
3377 jlong ret_val = os::javaTimeMillis() - _time_of_last_gc; | |
3378 // XXX See note in genCollectedHeap::millis_since_last_gc(). | |
3379 if (ret_val < 0) { | |
3380 NOT_PRODUCT(warning("time warp: %d", ret_val);) | |
3381 return 0; | |
3382 } | |
3383 return ret_val; | |
3384 } | |
3385 | |
3386 void PSParallelCompact::reset_millis_since_last_gc() { | |
3387 _time_of_last_gc = os::javaTimeMillis(); | |
3388 } | |
3389 | |
3390 ParMarkBitMap::IterationStatus MoveAndUpdateClosure::copy_until_full() | |
3391 { | |
3392 if (source() != destination()) { | |
3393 assert(source() > destination(), "must copy to the left"); | |
3394 Copy::aligned_conjoint_words(source(), destination(), words_remaining()); | |
3395 } | |
3396 update_state(words_remaining()); | |
3397 assert(is_full(), "sanity"); | |
3398 return ParMarkBitMap::full; | |
3399 } | |
3400 | |
3401 void MoveAndUpdateClosure::copy_partial_obj() | |
3402 { | |
3403 size_t words = words_remaining(); | |
3404 | |
3405 HeapWord* const range_end = MIN2(source() + words, bitmap()->region_end()); | |
3406 HeapWord* const end_addr = bitmap()->find_obj_end(source(), range_end); | |
3407 if (end_addr < range_end) { | |
3408 words = bitmap()->obj_size(source(), end_addr); | |
3409 } | |
3410 | |
3411 // This test is necessary; if omitted, the pointer updates to a partial object | |
3412 // that crosses the dense prefix boundary could be overwritten. | |
3413 if (source() != destination()) { | |
3414 assert(source() > destination(), "must copy to the left"); | |
3415 Copy::aligned_conjoint_words(source(), destination(), words); | |
3416 } | |
3417 update_state(words); | |
3418 } | |
3419 | |
3420 ParMarkBitMapClosure::IterationStatus | |
3421 MoveAndUpdateClosure::do_addr(HeapWord* addr, size_t words) { | |
3422 assert(destination() != NULL, "sanity"); | |
3423 assert(bitmap()->obj_size(addr) == words, "bad size"); | |
3424 | |
3425 _source = addr; | |
3426 assert(PSParallelCompact::summary_data().calc_new_pointer(source()) == | |
3427 destination(), "wrong destination"); | |
3428 | |
3429 if (words > words_remaining()) { | |
3430 return ParMarkBitMap::would_overflow; | |
3431 } | |
3432 | |
3433 // The start_array must be updated even if the object is not moving. | |
3434 if (_start_array != NULL) { | |
3435 _start_array->allocate_block(destination()); | |
3436 } | |
3437 | |
3438 if (destination() != source()) { | |
3439 assert(destination() < source(), "must copy to the left"); | |
3440 Copy::aligned_conjoint_words(source(), destination(), words); | |
3441 } | |
3442 | |
3443 oop moved_oop = (oop) destination(); | |
3444 moved_oop->update_contents(compaction_manager()); | |
3445 assert(moved_oop->is_oop_or_null(), "Object should be whole at this point"); | |
3446 | |
3447 update_state(words); | |
3448 assert(destination() == (HeapWord*)moved_oop + moved_oop->size(), "sanity"); | |
3449 return is_full() ? ParMarkBitMap::full : ParMarkBitMap::incomplete; | |
3450 } | |
3451 | |
3452 UpdateOnlyClosure::UpdateOnlyClosure(ParMarkBitMap* mbm, | |
3453 ParCompactionManager* cm, | |
3454 PSParallelCompact::SpaceId space_id) : | |
3455 ParMarkBitMapClosure(mbm, cm), | |
3456 _space_id(space_id), | |
3457 _start_array(PSParallelCompact::start_array(space_id)) | |
3458 { | |
3459 } | |
3460 | |
3461 // Updates the references in the object to their new values. | |
3462 ParMarkBitMapClosure::IterationStatus | |
3463 UpdateOnlyClosure::do_addr(HeapWord* addr, size_t words) { | |
3464 do_addr(addr); | |
3465 return ParMarkBitMap::incomplete; | |
3466 } | |
3467 | |
3468 BitBlockUpdateClosure::BitBlockUpdateClosure(ParMarkBitMap* mbm, | |
3469 ParCompactionManager* cm, | |
3470 size_t chunk_index) : | |
3471 ParMarkBitMapClosure(mbm, cm), | |
3472 _live_data_left(0), | |
3473 _cur_block(0) { | |
3474 _chunk_start = | |
3475 PSParallelCompact::summary_data().chunk_to_addr(chunk_index); | |
3476 _chunk_end = | |
3477 PSParallelCompact::summary_data().chunk_to_addr(chunk_index) + | |
3478 ParallelCompactData::ChunkSize; | |
3479 _chunk_index = chunk_index; | |
3480 _cur_block = | |
3481 PSParallelCompact::summary_data().addr_to_block_idx(_chunk_start); | |
3482 } | |
3483 | |
3484 bool BitBlockUpdateClosure::chunk_contains_cur_block() { | |
3485 return ParallelCompactData::chunk_contains_block(_chunk_index, _cur_block); | |
3486 } | |
3487 | |
3488 void BitBlockUpdateClosure::reset_chunk(size_t chunk_index) { | |
3489 DEBUG_ONLY(ParallelCompactData::BlockData::set_cur_phase(7);) | |
3490 ParallelCompactData& sd = PSParallelCompact::summary_data(); | |
3491 _chunk_index = chunk_index; | |
3492 _live_data_left = 0; | |
3493 _chunk_start = sd.chunk_to_addr(chunk_index); | |
3494 _chunk_end = sd.chunk_to_addr(chunk_index) + ParallelCompactData::ChunkSize; | |
3495 | |
3496 // The first block in this chunk | |
3497 size_t first_block = sd.addr_to_block_idx(_chunk_start); | |
3498 size_t partial_live_size = sd.chunk(chunk_index)->partial_obj_size(); | |
3499 | |
3500 // Set the offset to 0. By definition it should have that value | |
3501 // but it may have been written while processing an earlier chunk. | |
3502 if (partial_live_size == 0) { | |
3503 // No live object extends onto the chunk. The first bit | |
3504 // in the bit map for the first chunk must be a start bit. | |
3505 // Although there may not be any marked bits, it is safe | |
3506 // to set it as a start bit. | |
3507 sd.block(first_block)->set_start_bit_offset(0); | |
3508 sd.block(first_block)->set_first_is_start_bit(true); | |
3509 } else if (sd.partial_obj_ends_in_block(first_block)) { | |
3510 sd.block(first_block)->set_end_bit_offset(0); | |
3511 sd.block(first_block)->set_first_is_start_bit(false); | |
3512 } else { | |
3513 // The partial object extends beyond the first block. | |
3514 // There is no object starting in the first block | |
3515 // so the offset and bit parity are not needed. | |
3516 // Set the the bit parity to start bit so assertions | |
3517 // work when not bit is found. | |
3518 sd.block(first_block)->set_end_bit_offset(0); | |
3519 sd.block(first_block)->set_first_is_start_bit(false); | |
3520 } | |
3521 _cur_block = first_block; | |
3522 #ifdef ASSERT | |
3523 if (sd.block(first_block)->first_is_start_bit()) { | |
3524 assert(!sd.partial_obj_ends_in_block(first_block), | |
3525 "Partial object cannot end in first block"); | |
3526 } | |
3527 | |
3528 if (PrintGCDetails && Verbose) { | |
3529 if (partial_live_size == 1) { | |
3530 gclog_or_tty->print_cr("first_block " PTR_FORMAT | |
3531 " _offset " PTR_FORMAT | |
3532 " _first_is_start_bit %d", | |
3533 first_block, | |
3534 sd.block(first_block)->raw_offset(), | |
3535 sd.block(first_block)->first_is_start_bit()); | |
3536 } | |
3537 } | |
3538 #endif | |
3539 DEBUG_ONLY(ParallelCompactData::BlockData::set_cur_phase(17);) | |
3540 } | |
3541 | |
3542 // This method is called when a object has been found (both beginning | |
3543 // and end of the object) in the range of iteration. This method is | |
3544 // calculating the words of live data to the left of a block. That live | |
3545 // data includes any object starting to the left of the block (i.e., | |
3546 // the live-data-to-the-left of block AAA will include the full size | |
3547 // of any object entering AAA). | |
3548 | |
3549 ParMarkBitMapClosure::IterationStatus | |
3550 BitBlockUpdateClosure::do_addr(HeapWord* addr, size_t words) { | |
3551 // add the size to the block data. | |
3552 HeapWord* obj = addr; | |
3553 ParallelCompactData& sd = PSParallelCompact::summary_data(); | |
3554 | |
3555 assert(bitmap()->obj_size(obj) == words, "bad size"); | |
3556 assert(_chunk_start <= obj, "object is not in chunk"); | |
3557 assert(obj + words <= _chunk_end, "object is not in chunk"); | |
3558 | |
3559 // Update the live data to the left | |
3560 size_t prev_live_data_left = _live_data_left; | |
3561 _live_data_left = _live_data_left + words; | |
3562 | |
3563 // Is this object in the current block. | |
3564 size_t block_of_obj = sd.addr_to_block_idx(obj); | |
3565 size_t block_of_obj_last = sd.addr_to_block_idx(obj + words - 1); | |
3566 HeapWord* block_of_obj_last_addr = sd.block_to_addr(block_of_obj_last); | |
3567 if (_cur_block < block_of_obj) { | |
3568 | |
3569 // | |
3570 // No object crossed the block boundary and this object was found | |
3571 // on the other side of the block boundary. Update the offset for | |
3572 // the new block with the data size that does not include this object. | |
3573 // | |
3574 // The first bit in block_of_obj is a start bit except in the | |
3575 // case where the partial object for the chunk extends into | |
3576 // this block. | |
3577 if (sd.partial_obj_ends_in_block(block_of_obj)) { | |
3578 sd.block(block_of_obj)->set_end_bit_offset(prev_live_data_left); | |
3579 } else { | |
3580 sd.block(block_of_obj)->set_start_bit_offset(prev_live_data_left); | |
3581 } | |
3582 | |
3583 // Does this object pass beyond the its block? | |
3584 if (block_of_obj < block_of_obj_last) { | |
3585 // Object crosses block boundary. Two blocks need to be udpated: | |
3586 // the current block where the object started | |
3587 // the block where the object ends | |
3588 // | |
3589 // The offset for blocks with no objects starting in them | |
3590 // (e.g., blocks between _cur_block and block_of_obj_last) | |
3591 // should not be needed. | |
3592 // Note that block_of_obj_last may be in another chunk. If so, | |
3593 // it should be overwritten later. This is a problem (writting | |
3594 // into a block in a later chunk) for parallel execution. | |
3595 assert(obj < block_of_obj_last_addr, | |
3596 "Object should start in previous block"); | |
3597 | |
3598 // obj is crossing into block_of_obj_last so the first bit | |
3599 // is and end bit. | |
3600 sd.block(block_of_obj_last)->set_end_bit_offset(_live_data_left); | |
3601 | |
3602 _cur_block = block_of_obj_last; | |
3603 } else { | |
3604 // _first_is_start_bit has already been set correctly | |
3605 // in the if-then-else above so don't reset it here. | |
3606 _cur_block = block_of_obj; | |
3607 } | |
3608 } else { | |
3609 // The current block only changes if the object extends beyound | |
3610 // the block it starts in. | |
3611 // | |
3612 // The object starts in the current block. | |
3613 // Does this object pass beyond the end of it? | |
3614 if (block_of_obj < block_of_obj_last) { | |
3615 // Object crosses block boundary. | |
3616 // See note above on possible blocks between block_of_obj and | |
3617 // block_of_obj_last | |
3618 assert(obj < block_of_obj_last_addr, | |
3619 "Object should start in previous block"); | |
3620 | |
3621 sd.block(block_of_obj_last)->set_end_bit_offset(_live_data_left); | |
3622 | |
3623 _cur_block = block_of_obj_last; | |
3624 } | |
3625 } | |
3626 | |
3627 // Return incomplete if there are more blocks to be done. | |
3628 if (chunk_contains_cur_block()) { | |
3629 return ParMarkBitMap::incomplete; | |
3630 } | |
3631 return ParMarkBitMap::complete; | |
3632 } | |
3633 | |
3634 // Verify the new location using the forwarding pointer | |
3635 // from MarkSweep::mark_sweep_phase2(). Set the mark_word | |
3636 // to the initial value. | |
3637 ParMarkBitMapClosure::IterationStatus | |
3638 PSParallelCompact::VerifyUpdateClosure::do_addr(HeapWord* addr, size_t words) { | |
3639 // The second arg (words) is not used. | |
3640 oop obj = (oop) addr; | |
3641 HeapWord* forwarding_ptr = (HeapWord*) obj->mark()->decode_pointer(); | |
3642 HeapWord* new_pointer = summary_data().calc_new_pointer(obj); | |
3643 if (forwarding_ptr == NULL) { | |
3644 // The object is dead or not moving. | |
3645 assert(bitmap()->is_unmarked(obj) || (new_pointer == (HeapWord*) obj), | |
3646 "Object liveness is wrong."); | |
3647 return ParMarkBitMap::incomplete; | |
3648 } | |
3649 assert(UseParallelOldGCDensePrefix || | |
3650 (HeapMaximumCompactionInterval > 1) || | |
3651 (MarkSweepAlwaysCompactCount > 1) || | |
3652 (forwarding_ptr == new_pointer), | |
3653 "Calculation of new location is incorrect"); | |
3654 return ParMarkBitMap::incomplete; | |
3655 } | |
3656 | |
3657 // Reset objects modified for debug checking. | |
3658 ParMarkBitMapClosure::IterationStatus | |
3659 PSParallelCompact::ResetObjectsClosure::do_addr(HeapWord* addr, size_t words) { | |
3660 // The second arg (words) is not used. | |
3661 oop obj = (oop) addr; | |
3662 obj->init_mark(); | |
3663 return ParMarkBitMap::incomplete; | |
3664 } | |
3665 | |
3666 // Prepare for compaction. This method is executed once | |
3667 // (i.e., by a single thread) before compaction. | |
3668 // Save the updated location of the intArrayKlassObj for | |
3669 // filling holes in the dense prefix. | |
3670 void PSParallelCompact::compact_prologue() { | |
3671 _updated_int_array_klass_obj = (klassOop) | |
3672 summary_data().calc_new_pointer(Universe::intArrayKlassObj()); | |
3673 } | |
3674 | |
3675 // The initial implementation of this method created a field | |
3676 // _next_compaction_space_id in SpaceInfo and initialized | |
3677 // that field in SpaceInfo::initialize_space_info(). That | |
3678 // required that _next_compaction_space_id be declared a | |
3679 // SpaceId in SpaceInfo and that would have required that | |
3680 // either SpaceId be declared in a separate class or that | |
3681 // it be declared in SpaceInfo. It didn't seem consistent | |
3682 // to declare it in SpaceInfo (didn't really fit logically). | |
3683 // Alternatively, defining a separate class to define SpaceId | |
3684 // seem excessive. This implementation is simple and localizes | |
3685 // the knowledge. | |
3686 | |
3687 PSParallelCompact::SpaceId | |
3688 PSParallelCompact::next_compaction_space_id(SpaceId id) { | |
3689 assert(id < last_space_id, "id out of range"); | |
3690 switch (id) { | |
3691 case perm_space_id : | |
3692 return last_space_id; | |
3693 case old_space_id : | |
3694 return eden_space_id; | |
3695 case eden_space_id : | |
3696 return from_space_id; | |
3697 case from_space_id : | |
3698 return to_space_id; | |
3699 case to_space_id : | |
3700 return last_space_id; | |
3701 default: | |
3702 assert(false, "Bad space id"); | |
3703 return last_space_id; | |
3704 } | |
3705 } | |
3706 | |
3707 // Here temporarily for debugging | |
3708 #ifdef ASSERT | |
3709 size_t ParallelCompactData::block_idx(BlockData* block) { | |
3710 size_t index = pointer_delta(block, | |
3711 PSParallelCompact::summary_data()._block_data, sizeof(BlockData)); | |
3712 return index; | |
3713 } | |
3714 #endif |