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 class ParallelScavengeHeap;
|
|
26 class PSAdaptiveSizePolicy;
|
|
27 class PSYoungGen;
|
|
28 class PSOldGen;
|
|
29 class PSPermGen;
|
|
30 class ParCompactionManager;
|
|
31 class ParallelTaskTerminator;
|
|
32 class PSParallelCompact;
|
|
33 class GCTaskManager;
|
|
34 class GCTaskQueue;
|
|
35 class PreGCValues;
|
|
36 class MoveAndUpdateClosure;
|
|
37 class RefProcTaskExecutor;
|
|
38
|
|
39 class SpaceInfo
|
|
40 {
|
|
41 public:
|
|
42 MutableSpace* space() const { return _space; }
|
|
43
|
|
44 // Where the free space will start after the collection. Valid only after the
|
|
45 // summary phase completes.
|
|
46 HeapWord* new_top() const { return _new_top; }
|
|
47
|
|
48 // Allows new_top to be set.
|
|
49 HeapWord** new_top_addr() { return &_new_top; }
|
|
50
|
|
51 // Where the smallest allowable dense prefix ends (used only for perm gen).
|
|
52 HeapWord* min_dense_prefix() const { return _min_dense_prefix; }
|
|
53
|
|
54 // Where the dense prefix ends, or the compacted region begins.
|
|
55 HeapWord* dense_prefix() const { return _dense_prefix; }
|
|
56
|
|
57 // The start array for the (generation containing the) space, or NULL if there
|
|
58 // is no start array.
|
|
59 ObjectStartArray* start_array() const { return _start_array; }
|
|
60
|
|
61 void set_space(MutableSpace* s) { _space = s; }
|
|
62 void set_new_top(HeapWord* addr) { _new_top = addr; }
|
|
63 void set_min_dense_prefix(HeapWord* addr) { _min_dense_prefix = addr; }
|
|
64 void set_dense_prefix(HeapWord* addr) { _dense_prefix = addr; }
|
|
65 void set_start_array(ObjectStartArray* s) { _start_array = s; }
|
|
66
|
|
67 private:
|
|
68 MutableSpace* _space;
|
|
69 HeapWord* _new_top;
|
|
70 HeapWord* _min_dense_prefix;
|
|
71 HeapWord* _dense_prefix;
|
|
72 ObjectStartArray* _start_array;
|
|
73 };
|
|
74
|
|
75 class ParallelCompactData
|
|
76 {
|
|
77 public:
|
|
78 // Sizes are in HeapWords, unless indicated otherwise.
|
|
79 static const size_t Log2ChunkSize;
|
|
80 static const size_t ChunkSize;
|
|
81 static const size_t ChunkSizeBytes;
|
|
82
|
|
83 // Mask for the bits in a size_t to get an offset within a chunk.
|
|
84 static const size_t ChunkSizeOffsetMask;
|
|
85 // Mask for the bits in a pointer to get an offset within a chunk.
|
|
86 static const size_t ChunkAddrOffsetMask;
|
|
87 // Mask for the bits in a pointer to get the address of the start of a chunk.
|
|
88 static const size_t ChunkAddrMask;
|
|
89
|
|
90 static const size_t Log2BlockSize;
|
|
91 static const size_t BlockSize;
|
|
92 static const size_t BlockOffsetMask;
|
|
93 static const size_t BlockMask;
|
|
94
|
|
95 static const size_t BlocksPerChunk;
|
|
96
|
|
97 class ChunkData
|
|
98 {
|
|
99 public:
|
|
100 // Destination address of the chunk.
|
|
101 HeapWord* destination() const { return _destination; }
|
|
102
|
|
103 // The first chunk containing data destined for this chunk.
|
|
104 size_t source_chunk() const { return _source_chunk; }
|
|
105
|
|
106 // The object (if any) starting in this chunk and ending in a different
|
|
107 // chunk that could not be updated during the main (parallel) compaction
|
|
108 // phase. This is different from _partial_obj_addr, which is an object that
|
|
109 // extends onto a source chunk. However, the two uses do not overlap in
|
|
110 // time, so the same field is used to save space.
|
|
111 HeapWord* deferred_obj_addr() const { return _partial_obj_addr; }
|
|
112
|
|
113 // The starting address of the partial object extending onto the chunk.
|
|
114 HeapWord* partial_obj_addr() const { return _partial_obj_addr; }
|
|
115
|
|
116 // Size of the partial object extending onto the chunk (words).
|
|
117 size_t partial_obj_size() const { return _partial_obj_size; }
|
|
118
|
|
119 // Size of live data that lies within this chunk due to objects that start
|
|
120 // in this chunk (words). This does not include the partial object
|
|
121 // extending onto the chunk (if any), or the part of an object that extends
|
|
122 // onto the next chunk (if any).
|
|
123 size_t live_obj_size() const { return _dc_and_los & los_mask; }
|
|
124
|
|
125 // Total live data that lies within the chunk (words).
|
|
126 size_t data_size() const { return partial_obj_size() + live_obj_size(); }
|
|
127
|
|
128 // The destination_count is the number of other chunks to which data from
|
|
129 // this chunk will be copied. At the end of the summary phase, the valid
|
|
130 // values of destination_count are
|
|
131 //
|
|
132 // 0 - data from the chunk will be compacted completely into itself, or the
|
|
133 // chunk is empty. The chunk can be claimed and then filled.
|
|
134 // 1 - data from the chunk will be compacted into 1 other chunk; some
|
|
135 // data from the chunk may also be compacted into the chunk itself.
|
|
136 // 2 - data from the chunk will be copied to 2 other chunks.
|
|
137 //
|
|
138 // During compaction as chunks are emptied, the destination_count is
|
|
139 // decremented (atomically) and when it reaches 0, it can be claimed and
|
|
140 // then filled.
|
|
141 //
|
|
142 // A chunk is claimed for processing by atomically changing the
|
|
143 // destination_count to the claimed value (dc_claimed). After a chunk has
|
|
144 // been filled, the destination_count should be set to the completed value
|
|
145 // (dc_completed).
|
|
146 inline uint destination_count() const;
|
|
147 inline uint destination_count_raw() const;
|
|
148
|
|
149 // The location of the java heap data that corresponds to this chunk.
|
|
150 inline HeapWord* data_location() const;
|
|
151
|
|
152 // The highest address referenced by objects in this chunk.
|
|
153 inline HeapWord* highest_ref() const;
|
|
154
|
|
155 // Whether this chunk is available to be claimed, has been claimed, or has
|
|
156 // been completed.
|
|
157 //
|
|
158 // Minor subtlety: claimed() returns true if the chunk is marked
|
|
159 // completed(), which is desirable since a chunk must be claimed before it
|
|
160 // can be completed.
|
|
161 bool available() const { return _dc_and_los < dc_one; }
|
|
162 bool claimed() const { return _dc_and_los >= dc_claimed; }
|
|
163 bool completed() const { return _dc_and_los >= dc_completed; }
|
|
164
|
|
165 // These are not atomic.
|
|
166 void set_destination(HeapWord* addr) { _destination = addr; }
|
|
167 void set_source_chunk(size_t chunk) { _source_chunk = chunk; }
|
|
168 void set_deferred_obj_addr(HeapWord* addr) { _partial_obj_addr = addr; }
|
|
169 void set_partial_obj_addr(HeapWord* addr) { _partial_obj_addr = addr; }
|
|
170 void set_partial_obj_size(size_t words) {
|
|
171 _partial_obj_size = (chunk_sz_t) words;
|
|
172 }
|
|
173
|
|
174 inline void set_destination_count(uint count);
|
|
175 inline void set_live_obj_size(size_t words);
|
|
176 inline void set_data_location(HeapWord* addr);
|
|
177 inline void set_completed();
|
|
178 inline bool claim_unsafe();
|
|
179
|
|
180 // These are atomic.
|
|
181 inline void add_live_obj(size_t words);
|
|
182 inline void set_highest_ref(HeapWord* addr);
|
|
183 inline void decrement_destination_count();
|
|
184 inline bool claim();
|
|
185
|
|
186 private:
|
|
187 // The type used to represent object sizes within a chunk.
|
|
188 typedef uint chunk_sz_t;
|
|
189
|
|
190 // Constants for manipulating the _dc_and_los field, which holds both the
|
|
191 // destination count and live obj size. The live obj size lives at the
|
|
192 // least significant end so no masking is necessary when adding.
|
|
193 static const chunk_sz_t dc_shift; // Shift amount.
|
|
194 static const chunk_sz_t dc_mask; // Mask for destination count.
|
|
195 static const chunk_sz_t dc_one; // 1, shifted appropriately.
|
|
196 static const chunk_sz_t dc_claimed; // Chunk has been claimed.
|
|
197 static const chunk_sz_t dc_completed; // Chunk has been completed.
|
|
198 static const chunk_sz_t los_mask; // Mask for live obj size.
|
|
199
|
|
200 HeapWord* _destination;
|
|
201 size_t _source_chunk;
|
|
202 HeapWord* _partial_obj_addr;
|
|
203 chunk_sz_t _partial_obj_size;
|
|
204 chunk_sz_t volatile _dc_and_los;
|
|
205 #ifdef ASSERT
|
|
206 // These enable optimizations that are only partially implemented. Use
|
|
207 // debug builds to prevent the code fragments from breaking.
|
|
208 HeapWord* _data_location;
|
|
209 HeapWord* _highest_ref;
|
|
210 #endif // #ifdef ASSERT
|
|
211
|
|
212 #ifdef ASSERT
|
|
213 public:
|
|
214 uint _pushed; // 0 until chunk is pushed onto a worker's stack
|
|
215 private:
|
|
216 #endif
|
|
217 };
|
|
218
|
|
219 // 'Blocks' allow shorter sections of the bitmap to be searched. Each Block
|
|
220 // holds an offset, which is the amount of live data in the Chunk to the left
|
|
221 // of the first live object in the Block. This amount of live data will
|
|
222 // include any object extending into the block. The first block in
|
|
223 // a chunk does not include any partial object extending into the
|
|
224 // the chunk.
|
|
225 //
|
|
226 // The offset also encodes the
|
|
227 // 'parity' of the first 1 bit in the Block: a positive offset means the
|
|
228 // first 1 bit marks the start of an object, a negative offset means the first
|
|
229 // 1 bit marks the end of an object.
|
|
230 class BlockData
|
|
231 {
|
|
232 public:
|
|
233 typedef short int blk_ofs_t;
|
|
234
|
|
235 blk_ofs_t offset() const { return _offset >= 0 ? _offset : -_offset; }
|
|
236 blk_ofs_t raw_offset() const { return _offset; }
|
|
237 void set_first_is_start_bit(bool v) { _first_is_start_bit = v; }
|
|
238
|
|
239 #if 0
|
|
240 // The need for this method was anticipated but it is
|
|
241 // never actually used. Do not include it for now. If
|
|
242 // it is needed, consider the problem of what is passed
|
|
243 // as "v". To avoid warning errors the method set_start_bit_offset()
|
|
244 // was changed to take a size_t as the parameter and to do the
|
|
245 // check for the possible overflow. Doing the cast in these
|
|
246 // methods better limits the potential problems because of
|
|
247 // the size of the field to this class.
|
|
248 void set_raw_offset(blk_ofs_t v) { _offset = v; }
|
|
249 #endif
|
|
250 void set_start_bit_offset(size_t val) {
|
|
251 assert(val >= 0, "sanity");
|
|
252 _offset = (blk_ofs_t) val;
|
|
253 assert(val == (size_t) _offset, "Value is too large");
|
|
254 _first_is_start_bit = true;
|
|
255 }
|
|
256 void set_end_bit_offset(size_t val) {
|
|
257 assert(val >= 0, "sanity");
|
|
258 _offset = (blk_ofs_t) val;
|
|
259 assert(val == (size_t) _offset, "Value is too large");
|
|
260 _offset = - _offset;
|
|
261 _first_is_start_bit = false;
|
|
262 }
|
|
263 bool first_is_start_bit() {
|
|
264 assert(_set_phase > 0, "Not initialized");
|
|
265 return _first_is_start_bit;
|
|
266 }
|
|
267 bool first_is_end_bit() {
|
|
268 assert(_set_phase > 0, "Not initialized");
|
|
269 return !_first_is_start_bit;
|
|
270 }
|
|
271
|
|
272 private:
|
|
273 blk_ofs_t _offset;
|
|
274 // This is temporary until the mark_bitmap is separated into
|
|
275 // a start bit array and an end bit array.
|
|
276 bool _first_is_start_bit;
|
|
277 #ifdef ASSERT
|
|
278 short _set_phase;
|
|
279 static short _cur_phase;
|
|
280 public:
|
|
281 static void set_cur_phase(short v) { _cur_phase = v; }
|
|
282 #endif
|
|
283 };
|
|
284
|
|
285 public:
|
|
286 ParallelCompactData();
|
|
287 bool initialize(MemRegion covered_region);
|
|
288
|
|
289 size_t chunk_count() const { return _chunk_count; }
|
|
290
|
|
291 // Convert chunk indices to/from ChunkData pointers.
|
|
292 inline ChunkData* chunk(size_t chunk_idx) const;
|
|
293 inline size_t chunk(const ChunkData* const chunk_ptr) const;
|
|
294
|
|
295 // Returns true if the given address is contained within the chunk
|
|
296 bool chunk_contains(size_t chunk_index, HeapWord* addr);
|
|
297
|
|
298 size_t block_count() const { return _block_count; }
|
|
299 inline BlockData* block(size_t n) const;
|
|
300
|
|
301 // Returns true if the given block is in the given chunk.
|
|
302 static bool chunk_contains_block(size_t chunk_index, size_t block_index);
|
|
303
|
|
304 void add_obj(HeapWord* addr, size_t len);
|
|
305 void add_obj(oop p, size_t len) { add_obj((HeapWord*)p, len); }
|
|
306
|
|
307 // Fill in the chunks covering [beg, end) so that no data moves; i.e., the
|
|
308 // destination of chunk n is simply the start of chunk n. The argument beg
|
|
309 // must be chunk-aligned; end need not be.
|
|
310 void summarize_dense_prefix(HeapWord* beg, HeapWord* end);
|
|
311
|
|
312 bool summarize(HeapWord* target_beg, HeapWord* target_end,
|
|
313 HeapWord* source_beg, HeapWord* source_end,
|
|
314 HeapWord** target_next, HeapWord** source_next = 0);
|
|
315
|
|
316 void clear();
|
|
317 void clear_range(size_t beg_chunk, size_t end_chunk);
|
|
318 void clear_range(HeapWord* beg, HeapWord* end) {
|
|
319 clear_range(addr_to_chunk_idx(beg), addr_to_chunk_idx(end));
|
|
320 }
|
|
321
|
|
322 // Return the number of words between addr and the start of the chunk
|
|
323 // containing addr.
|
|
324 inline size_t chunk_offset(const HeapWord* addr) const;
|
|
325
|
|
326 // Convert addresses to/from a chunk index or chunk pointer.
|
|
327 inline size_t addr_to_chunk_idx(const HeapWord* addr) const;
|
|
328 inline ChunkData* addr_to_chunk_ptr(const HeapWord* addr) const;
|
|
329 inline HeapWord* chunk_to_addr(size_t chunk) const;
|
|
330 inline HeapWord* chunk_to_addr(size_t chunk, size_t offset) const;
|
|
331 inline HeapWord* chunk_to_addr(const ChunkData* chunk) const;
|
|
332
|
|
333 inline HeapWord* chunk_align_down(HeapWord* addr) const;
|
|
334 inline HeapWord* chunk_align_up(HeapWord* addr) const;
|
|
335 inline bool is_chunk_aligned(HeapWord* addr) const;
|
|
336
|
|
337 // Analogous to chunk_offset() for blocks.
|
|
338 size_t block_offset(const HeapWord* addr) const;
|
|
339 size_t addr_to_block_idx(const HeapWord* addr) const;
|
|
340 size_t addr_to_block_idx(const oop obj) const {
|
|
341 return addr_to_block_idx((HeapWord*) obj);
|
|
342 }
|
|
343 inline BlockData* addr_to_block_ptr(const HeapWord* addr) const;
|
|
344 inline HeapWord* block_to_addr(size_t block) const;
|
|
345
|
|
346 // Return the address one past the end of the partial object.
|
|
347 HeapWord* partial_obj_end(size_t chunk_idx) const;
|
|
348
|
|
349 // Return the new location of the object p after the
|
|
350 // the compaction.
|
|
351 HeapWord* calc_new_pointer(HeapWord* addr);
|
|
352
|
|
353 // Same as calc_new_pointer() using blocks.
|
|
354 HeapWord* block_calc_new_pointer(HeapWord* addr);
|
|
355
|
|
356 // Same as calc_new_pointer() using chunks.
|
|
357 HeapWord* chunk_calc_new_pointer(HeapWord* addr);
|
|
358
|
|
359 HeapWord* calc_new_pointer(oop p) {
|
|
360 return calc_new_pointer((HeapWord*) p);
|
|
361 }
|
|
362
|
|
363 // Return the updated address for the given klass
|
|
364 klassOop calc_new_klass(klassOop);
|
|
365
|
|
366 // Given a block returns true if the partial object for the
|
|
367 // corresponding chunk ends in the block. Returns false, otherwise
|
|
368 // If there is no partial object, returns false.
|
|
369 bool partial_obj_ends_in_block(size_t block_index);
|
|
370
|
|
371 // Returns the block index for the block
|
|
372 static size_t block_idx(BlockData* block);
|
|
373
|
|
374 #ifdef ASSERT
|
|
375 void verify_clear(const PSVirtualSpace* vspace);
|
|
376 void verify_clear();
|
|
377 #endif // #ifdef ASSERT
|
|
378
|
|
379 private:
|
|
380 bool initialize_block_data(size_t region_size);
|
|
381 bool initialize_chunk_data(size_t region_size);
|
|
382 PSVirtualSpace* create_vspace(size_t count, size_t element_size);
|
|
383
|
|
384 private:
|
|
385 HeapWord* _region_start;
|
|
386 #ifdef ASSERT
|
|
387 HeapWord* _region_end;
|
|
388 #endif // #ifdef ASSERT
|
|
389
|
|
390 PSVirtualSpace* _chunk_vspace;
|
|
391 ChunkData* _chunk_data;
|
|
392 size_t _chunk_count;
|
|
393
|
|
394 PSVirtualSpace* _block_vspace;
|
|
395 BlockData* _block_data;
|
|
396 size_t _block_count;
|
|
397 };
|
|
398
|
|
399 inline uint
|
|
400 ParallelCompactData::ChunkData::destination_count_raw() const
|
|
401 {
|
|
402 return _dc_and_los & dc_mask;
|
|
403 }
|
|
404
|
|
405 inline uint
|
|
406 ParallelCompactData::ChunkData::destination_count() const
|
|
407 {
|
|
408 return destination_count_raw() >> dc_shift;
|
|
409 }
|
|
410
|
|
411 inline void
|
|
412 ParallelCompactData::ChunkData::set_destination_count(uint count)
|
|
413 {
|
|
414 assert(count <= (dc_completed >> dc_shift), "count too large");
|
|
415 const chunk_sz_t live_sz = (chunk_sz_t) live_obj_size();
|
|
416 _dc_and_los = (count << dc_shift) | live_sz;
|
|
417 }
|
|
418
|
|
419 inline void ParallelCompactData::ChunkData::set_live_obj_size(size_t words)
|
|
420 {
|
|
421 assert(words <= los_mask, "would overflow");
|
|
422 _dc_and_los = destination_count_raw() | (chunk_sz_t)words;
|
|
423 }
|
|
424
|
|
425 inline void ParallelCompactData::ChunkData::decrement_destination_count()
|
|
426 {
|
|
427 assert(_dc_and_los < dc_claimed, "already claimed");
|
|
428 assert(_dc_and_los >= dc_one, "count would go negative");
|
|
429 Atomic::add((int)dc_mask, (volatile int*)&_dc_and_los);
|
|
430 }
|
|
431
|
|
432 inline HeapWord* ParallelCompactData::ChunkData::data_location() const
|
|
433 {
|
|
434 DEBUG_ONLY(return _data_location;)
|
|
435 NOT_DEBUG(return NULL;)
|
|
436 }
|
|
437
|
|
438 inline HeapWord* ParallelCompactData::ChunkData::highest_ref() const
|
|
439 {
|
|
440 DEBUG_ONLY(return _highest_ref;)
|
|
441 NOT_DEBUG(return NULL;)
|
|
442 }
|
|
443
|
|
444 inline void ParallelCompactData::ChunkData::set_data_location(HeapWord* addr)
|
|
445 {
|
|
446 DEBUG_ONLY(_data_location = addr;)
|
|
447 }
|
|
448
|
|
449 inline void ParallelCompactData::ChunkData::set_completed()
|
|
450 {
|
|
451 assert(claimed(), "must be claimed first");
|
|
452 _dc_and_los = dc_completed | (chunk_sz_t) live_obj_size();
|
|
453 }
|
|
454
|
|
455 // MT-unsafe claiming of a chunk. Should only be used during single threaded
|
|
456 // execution.
|
|
457 inline bool ParallelCompactData::ChunkData::claim_unsafe()
|
|
458 {
|
|
459 if (available()) {
|
|
460 _dc_and_los |= dc_claimed;
|
|
461 return true;
|
|
462 }
|
|
463 return false;
|
|
464 }
|
|
465
|
|
466 inline void ParallelCompactData::ChunkData::add_live_obj(size_t words)
|
|
467 {
|
|
468 assert(words <= (size_t)los_mask - live_obj_size(), "overflow");
|
|
469 Atomic::add((int) words, (volatile int*) &_dc_and_los);
|
|
470 }
|
|
471
|
|
472 inline void ParallelCompactData::ChunkData::set_highest_ref(HeapWord* addr)
|
|
473 {
|
|
474 #ifdef ASSERT
|
|
475 HeapWord* tmp = _highest_ref;
|
|
476 while (addr > tmp) {
|
|
477 tmp = (HeapWord*)Atomic::cmpxchg_ptr(addr, &_highest_ref, tmp);
|
|
478 }
|
|
479 #endif // #ifdef ASSERT
|
|
480 }
|
|
481
|
|
482 inline bool ParallelCompactData::ChunkData::claim()
|
|
483 {
|
|
484 const int los = (int) live_obj_size();
|
|
485 const int old = Atomic::cmpxchg(dc_claimed | los,
|
|
486 (volatile int*) &_dc_and_los, los);
|
|
487 return old == los;
|
|
488 }
|
|
489
|
|
490 inline ParallelCompactData::ChunkData*
|
|
491 ParallelCompactData::chunk(size_t chunk_idx) const
|
|
492 {
|
|
493 assert(chunk_idx <= chunk_count(), "bad arg");
|
|
494 return _chunk_data + chunk_idx;
|
|
495 }
|
|
496
|
|
497 inline size_t
|
|
498 ParallelCompactData::chunk(const ChunkData* const chunk_ptr) const
|
|
499 {
|
|
500 assert(chunk_ptr >= _chunk_data, "bad arg");
|
|
501 assert(chunk_ptr <= _chunk_data + chunk_count(), "bad arg");
|
|
502 return pointer_delta(chunk_ptr, _chunk_data, sizeof(ChunkData));
|
|
503 }
|
|
504
|
|
505 inline ParallelCompactData::BlockData*
|
|
506 ParallelCompactData::block(size_t n) const {
|
|
507 assert(n < block_count(), "bad arg");
|
|
508 return _block_data + n;
|
|
509 }
|
|
510
|
|
511 inline size_t
|
|
512 ParallelCompactData::chunk_offset(const HeapWord* addr) const
|
|
513 {
|
|
514 assert(addr >= _region_start, "bad addr");
|
|
515 assert(addr <= _region_end, "bad addr");
|
|
516 return (size_t(addr) & ChunkAddrOffsetMask) >> LogHeapWordSize;
|
|
517 }
|
|
518
|
|
519 inline size_t
|
|
520 ParallelCompactData::addr_to_chunk_idx(const HeapWord* addr) const
|
|
521 {
|
|
522 assert(addr >= _region_start, "bad addr");
|
|
523 assert(addr <= _region_end, "bad addr");
|
|
524 return pointer_delta(addr, _region_start) >> Log2ChunkSize;
|
|
525 }
|
|
526
|
|
527 inline ParallelCompactData::ChunkData*
|
|
528 ParallelCompactData::addr_to_chunk_ptr(const HeapWord* addr) const
|
|
529 {
|
|
530 return chunk(addr_to_chunk_idx(addr));
|
|
531 }
|
|
532
|
|
533 inline HeapWord*
|
|
534 ParallelCompactData::chunk_to_addr(size_t chunk) const
|
|
535 {
|
|
536 assert(chunk <= _chunk_count, "chunk out of range");
|
|
537 return _region_start + (chunk << Log2ChunkSize);
|
|
538 }
|
|
539
|
|
540 inline HeapWord*
|
|
541 ParallelCompactData::chunk_to_addr(const ChunkData* chunk) const
|
|
542 {
|
|
543 return chunk_to_addr(pointer_delta(chunk, _chunk_data, sizeof(ChunkData)));
|
|
544 }
|
|
545
|
|
546 inline HeapWord*
|
|
547 ParallelCompactData::chunk_to_addr(size_t chunk, size_t offset) const
|
|
548 {
|
|
549 assert(chunk <= _chunk_count, "chunk out of range");
|
|
550 assert(offset < ChunkSize, "offset too big"); // This may be too strict.
|
|
551 return chunk_to_addr(chunk) + offset;
|
|
552 }
|
|
553
|
|
554 inline HeapWord*
|
|
555 ParallelCompactData::chunk_align_down(HeapWord* addr) const
|
|
556 {
|
|
557 assert(addr >= _region_start, "bad addr");
|
|
558 assert(addr < _region_end + ChunkSize, "bad addr");
|
|
559 return (HeapWord*)(size_t(addr) & ChunkAddrMask);
|
|
560 }
|
|
561
|
|
562 inline HeapWord*
|
|
563 ParallelCompactData::chunk_align_up(HeapWord* addr) const
|
|
564 {
|
|
565 assert(addr >= _region_start, "bad addr");
|
|
566 assert(addr <= _region_end, "bad addr");
|
|
567 return chunk_align_down(addr + ChunkSizeOffsetMask);
|
|
568 }
|
|
569
|
|
570 inline bool
|
|
571 ParallelCompactData::is_chunk_aligned(HeapWord* addr) const
|
|
572 {
|
|
573 return chunk_offset(addr) == 0;
|
|
574 }
|
|
575
|
|
576 inline size_t
|
|
577 ParallelCompactData::block_offset(const HeapWord* addr) const
|
|
578 {
|
|
579 assert(addr >= _region_start, "bad addr");
|
|
580 assert(addr <= _region_end, "bad addr");
|
|
581 return pointer_delta(addr, _region_start) & BlockOffsetMask;
|
|
582 }
|
|
583
|
|
584 inline size_t
|
|
585 ParallelCompactData::addr_to_block_idx(const HeapWord* addr) const
|
|
586 {
|
|
587 assert(addr >= _region_start, "bad addr");
|
|
588 assert(addr <= _region_end, "bad addr");
|
|
589 return pointer_delta(addr, _region_start) >> Log2BlockSize;
|
|
590 }
|
|
591
|
|
592 inline ParallelCompactData::BlockData*
|
|
593 ParallelCompactData::addr_to_block_ptr(const HeapWord* addr) const
|
|
594 {
|
|
595 return block(addr_to_block_idx(addr));
|
|
596 }
|
|
597
|
|
598 inline HeapWord*
|
|
599 ParallelCompactData::block_to_addr(size_t block) const
|
|
600 {
|
|
601 assert(block < _block_count, "block out of range");
|
|
602 return _region_start + (block << Log2BlockSize);
|
|
603 }
|
|
604
|
|
605 // Abstract closure for use with ParMarkBitMap::iterate(), which will invoke the
|
|
606 // do_addr() method.
|
|
607 //
|
|
608 // The closure is initialized with the number of heap words to process
|
|
609 // (words_remaining()), and becomes 'full' when it reaches 0. The do_addr()
|
|
610 // methods in subclasses should update the total as words are processed. Since
|
|
611 // only one subclass actually uses this mechanism to terminate iteration, the
|
|
612 // default initial value is > 0. The implementation is here and not in the
|
|
613 // single subclass that uses it to avoid making is_full() virtual, and thus
|
|
614 // adding a virtual call per live object.
|
|
615
|
|
616 class ParMarkBitMapClosure: public StackObj {
|
|
617 public:
|
|
618 typedef ParMarkBitMap::idx_t idx_t;
|
|
619 typedef ParMarkBitMap::IterationStatus IterationStatus;
|
|
620
|
|
621 public:
|
|
622 inline ParMarkBitMapClosure(ParMarkBitMap* mbm, ParCompactionManager* cm,
|
|
623 size_t words = max_uintx);
|
|
624
|
|
625 inline ParCompactionManager* compaction_manager() const;
|
|
626 inline ParMarkBitMap* bitmap() const;
|
|
627 inline size_t words_remaining() const;
|
|
628 inline bool is_full() const;
|
|
629 inline HeapWord* source() const;
|
|
630
|
|
631 inline void set_source(HeapWord* addr);
|
|
632
|
|
633 virtual IterationStatus do_addr(HeapWord* addr, size_t words) = 0;
|
|
634
|
|
635 protected:
|
|
636 inline void decrement_words_remaining(size_t words);
|
|
637
|
|
638 private:
|
|
639 ParMarkBitMap* const _bitmap;
|
|
640 ParCompactionManager* const _compaction_manager;
|
|
641 DEBUG_ONLY(const size_t _initial_words_remaining;) // Useful in debugger.
|
|
642 size_t _words_remaining; // Words left to copy.
|
|
643
|
|
644 protected:
|
|
645 HeapWord* _source; // Next addr that would be read.
|
|
646 };
|
|
647
|
|
648 inline
|
|
649 ParMarkBitMapClosure::ParMarkBitMapClosure(ParMarkBitMap* bitmap,
|
|
650 ParCompactionManager* cm,
|
|
651 size_t words):
|
|
652 _bitmap(bitmap), _compaction_manager(cm)
|
|
653 #ifdef ASSERT
|
|
654 , _initial_words_remaining(words)
|
|
655 #endif
|
|
656 {
|
|
657 _words_remaining = words;
|
|
658 _source = NULL;
|
|
659 }
|
|
660
|
|
661 inline ParCompactionManager* ParMarkBitMapClosure::compaction_manager() const {
|
|
662 return _compaction_manager;
|
|
663 }
|
|
664
|
|
665 inline ParMarkBitMap* ParMarkBitMapClosure::bitmap() const {
|
|
666 return _bitmap;
|
|
667 }
|
|
668
|
|
669 inline size_t ParMarkBitMapClosure::words_remaining() const {
|
|
670 return _words_remaining;
|
|
671 }
|
|
672
|
|
673 inline bool ParMarkBitMapClosure::is_full() const {
|
|
674 return words_remaining() == 0;
|
|
675 }
|
|
676
|
|
677 inline HeapWord* ParMarkBitMapClosure::source() const {
|
|
678 return _source;
|
|
679 }
|
|
680
|
|
681 inline void ParMarkBitMapClosure::set_source(HeapWord* addr) {
|
|
682 _source = addr;
|
|
683 }
|
|
684
|
|
685 inline void ParMarkBitMapClosure::decrement_words_remaining(size_t words) {
|
|
686 assert(_words_remaining >= words, "processed too many words");
|
|
687 _words_remaining -= words;
|
|
688 }
|
|
689
|
|
690 // Closure for updating the block data during the summary phase.
|
|
691 class BitBlockUpdateClosure: public ParMarkBitMapClosure {
|
|
692 // ParallelCompactData::BlockData::blk_ofs_t _live_data_left;
|
|
693 size_t _live_data_left;
|
|
694 size_t _cur_block;
|
|
695 HeapWord* _chunk_start;
|
|
696 HeapWord* _chunk_end;
|
|
697 size_t _chunk_index;
|
|
698
|
|
699 public:
|
|
700 BitBlockUpdateClosure(ParMarkBitMap* mbm,
|
|
701 ParCompactionManager* cm,
|
|
702 size_t chunk_index);
|
|
703
|
|
704 size_t cur_block() { return _cur_block; }
|
|
705 size_t chunk_index() { return _chunk_index; }
|
|
706 size_t live_data_left() { return _live_data_left; }
|
|
707 // Returns true the first bit in the current block (cur_block) is
|
|
708 // a start bit.
|
|
709 // Returns true if the current block is within the chunk for the closure;
|
|
710 bool chunk_contains_cur_block();
|
|
711
|
|
712 // Set the chunk index and related chunk values for
|
|
713 // a new chunk.
|
|
714 void reset_chunk(size_t chunk_index);
|
|
715
|
|
716 virtual IterationStatus do_addr(HeapWord* addr, size_t words);
|
|
717 };
|
|
718
|
|
719 class PSParallelCompact : AllStatic {
|
|
720 public:
|
|
721 // Convenient access to type names.
|
|
722 typedef ParMarkBitMap::idx_t idx_t;
|
|
723 typedef ParallelCompactData::ChunkData ChunkData;
|
|
724 typedef ParallelCompactData::BlockData BlockData;
|
|
725
|
|
726 typedef enum {
|
|
727 perm_space_id, old_space_id, eden_space_id,
|
|
728 from_space_id, to_space_id, last_space_id
|
|
729 } SpaceId;
|
|
730
|
|
731 public:
|
|
732 // In line closure decls
|
|
733 //
|
|
734
|
|
735 class IsAliveClosure: public BoolObjectClosure {
|
|
736 public:
|
|
737 void do_object(oop p) { assert(false, "don't call"); }
|
|
738 bool do_object_b(oop p) { return mark_bitmap()->is_marked(p); }
|
|
739 };
|
|
740
|
|
741 class KeepAliveClosure: public OopClosure {
|
|
742 ParCompactionManager* _compaction_manager;
|
|
743 public:
|
|
744 KeepAliveClosure(ParCompactionManager* cm) {
|
|
745 _compaction_manager = cm;
|
|
746 }
|
|
747 void do_oop(oop* p);
|
|
748 };
|
|
749
|
|
750 class FollowRootClosure: public OopsInGenClosure{
|
|
751 ParCompactionManager* _compaction_manager;
|
|
752 public:
|
|
753 FollowRootClosure(ParCompactionManager* cm) {
|
|
754 _compaction_manager = cm;
|
|
755 }
|
|
756 void do_oop(oop* p) { follow_root(_compaction_manager, p); }
|
|
757 virtual const bool do_nmethods() const { return true; }
|
|
758 };
|
|
759
|
|
760 class FollowStackClosure: public VoidClosure {
|
|
761 ParCompactionManager* _compaction_manager;
|
|
762 public:
|
|
763 FollowStackClosure(ParCompactionManager* cm) {
|
|
764 _compaction_manager = cm;
|
|
765 }
|
|
766 void do_void() { follow_stack(_compaction_manager); }
|
|
767 };
|
|
768
|
|
769 class AdjustPointerClosure: public OopsInGenClosure {
|
|
770 bool _is_root;
|
|
771 public:
|
|
772 AdjustPointerClosure(bool is_root) : _is_root(is_root) {}
|
|
773 void do_oop(oop* p) { adjust_pointer(p, _is_root); }
|
|
774 };
|
|
775
|
|
776 // Closure for verifying update of pointers. Does not
|
|
777 // have any side effects.
|
|
778 class VerifyUpdateClosure: public ParMarkBitMapClosure {
|
|
779 const MutableSpace* _space; // Is this ever used?
|
|
780
|
|
781 public:
|
|
782 VerifyUpdateClosure(ParCompactionManager* cm, const MutableSpace* sp) :
|
|
783 ParMarkBitMapClosure(PSParallelCompact::mark_bitmap(), cm), _space(sp)
|
|
784 { }
|
|
785
|
|
786 virtual IterationStatus do_addr(HeapWord* addr, size_t words);
|
|
787
|
|
788 const MutableSpace* space() { return _space; }
|
|
789 };
|
|
790
|
|
791 // Closure for updating objects altered for debug checking
|
|
792 class ResetObjectsClosure: public ParMarkBitMapClosure {
|
|
793 public:
|
|
794 ResetObjectsClosure(ParCompactionManager* cm):
|
|
795 ParMarkBitMapClosure(PSParallelCompact::mark_bitmap(), cm)
|
|
796 { }
|
|
797
|
|
798 virtual IterationStatus do_addr(HeapWord* addr, size_t words);
|
|
799 };
|
|
800
|
|
801 friend class KeepAliveClosure;
|
|
802 friend class FollowStackClosure;
|
|
803 friend class AdjustPointerClosure;
|
|
804 friend class FollowRootClosure;
|
|
805 friend class instanceKlassKlass;
|
|
806 friend class RefProcTaskProxy;
|
|
807
|
|
808 static void mark_and_push_internal(ParCompactionManager* cm, oop* p);
|
|
809
|
|
810 private:
|
|
811 static elapsedTimer _accumulated_time;
|
|
812 static unsigned int _total_invocations;
|
|
813 static unsigned int _maximum_compaction_gc_num;
|
|
814 static jlong _time_of_last_gc; // ms
|
|
815 static CollectorCounters* _counters;
|
|
816 static ParMarkBitMap _mark_bitmap;
|
|
817 static ParallelCompactData _summary_data;
|
|
818 static IsAliveClosure _is_alive_closure;
|
|
819 static SpaceInfo _space_info[last_space_id];
|
|
820 static bool _print_phases;
|
|
821 static AdjustPointerClosure _adjust_root_pointer_closure;
|
|
822 static AdjustPointerClosure _adjust_pointer_closure;
|
|
823
|
|
824 // Reference processing (used in ...follow_contents)
|
|
825 static ReferenceProcessor* _ref_processor;
|
|
826
|
|
827 // Updated location of intArrayKlassObj.
|
|
828 static klassOop _updated_int_array_klass_obj;
|
|
829
|
|
830 // Values computed at initialization and used by dead_wood_limiter().
|
|
831 static double _dwl_mean;
|
|
832 static double _dwl_std_dev;
|
|
833 static double _dwl_first_term;
|
|
834 static double _dwl_adjustment;
|
|
835 #ifdef ASSERT
|
|
836 static bool _dwl_initialized;
|
|
837 #endif // #ifdef ASSERT
|
|
838
|
|
839 private:
|
|
840 // Closure accessors
|
|
841 static OopClosure* adjust_pointer_closure() { return (OopClosure*)&_adjust_pointer_closure; }
|
|
842 static OopClosure* adjust_root_pointer_closure() { return (OopClosure*)&_adjust_root_pointer_closure; }
|
|
843 static BoolObjectClosure* is_alive_closure() { return (BoolObjectClosure*)&_is_alive_closure; }
|
|
844
|
|
845 static void initialize_space_info();
|
|
846
|
|
847 // Return true if details about individual phases should be printed.
|
|
848 static inline bool print_phases();
|
|
849
|
|
850 // Clear the marking bitmap and summary data that cover the specified space.
|
|
851 static void clear_data_covering_space(SpaceId id);
|
|
852
|
|
853 static void pre_compact(PreGCValues* pre_gc_values);
|
|
854 static void post_compact();
|
|
855
|
|
856 // Mark live objects
|
|
857 static void marking_phase(ParCompactionManager* cm,
|
|
858 bool maximum_heap_compaction);
|
|
859 static void follow_stack(ParCompactionManager* cm);
|
|
860 static void follow_weak_klass_links(ParCompactionManager* cm);
|
|
861
|
|
862 static void adjust_pointer(oop* p, bool is_root);
|
|
863 static void adjust_root_pointer(oop* p) { adjust_pointer(p, true); }
|
|
864
|
|
865 static void follow_root(ParCompactionManager* cm, oop* p);
|
|
866
|
|
867 // Compute the dense prefix for the designated space. This is an experimental
|
|
868 // implementation currently not used in production.
|
|
869 static HeapWord* compute_dense_prefix_via_density(const SpaceId id,
|
|
870 bool maximum_compaction);
|
|
871
|
|
872 // Methods used to compute the dense prefix.
|
|
873
|
|
874 // Compute the value of the normal distribution at x = density. The mean and
|
|
875 // standard deviation are values saved by initialize_dead_wood_limiter().
|
|
876 static inline double normal_distribution(double density);
|
|
877
|
|
878 // Initialize the static vars used by dead_wood_limiter().
|
|
879 static void initialize_dead_wood_limiter();
|
|
880
|
|
881 // Return the percentage of space that can be treated as "dead wood" (i.e.,
|
|
882 // not reclaimed).
|
|
883 static double dead_wood_limiter(double density, size_t min_percent);
|
|
884
|
|
885 // Find the first (left-most) chunk in the range [beg, end) that has at least
|
|
886 // dead_words of dead space to the left. The argument beg must be the first
|
|
887 // chunk in the space that is not completely live.
|
|
888 static ChunkData* dead_wood_limit_chunk(const ChunkData* beg,
|
|
889 const ChunkData* end,
|
|
890 size_t dead_words);
|
|
891
|
|
892 // Return a pointer to the first chunk in the range [beg, end) that is not
|
|
893 // completely full.
|
|
894 static ChunkData* first_dead_space_chunk(const ChunkData* beg,
|
|
895 const ChunkData* end);
|
|
896
|
|
897 // Return a value indicating the benefit or 'yield' if the compacted region
|
|
898 // were to start (or equivalently if the dense prefix were to end) at the
|
|
899 // candidate chunk. Higher values are better.
|
|
900 //
|
|
901 // The value is based on the amount of space reclaimed vs. the costs of (a)
|
|
902 // updating references in the dense prefix plus (b) copying objects and
|
|
903 // updating references in the compacted region.
|
|
904 static inline double reclaimed_ratio(const ChunkData* const candidate,
|
|
905 HeapWord* const bottom,
|
|
906 HeapWord* const top,
|
|
907 HeapWord* const new_top);
|
|
908
|
|
909 // Compute the dense prefix for the designated space.
|
|
910 static HeapWord* compute_dense_prefix(const SpaceId id,
|
|
911 bool maximum_compaction);
|
|
912
|
|
913 // Return true if dead space crosses onto the specified Chunk; bit must be the
|
|
914 // bit index corresponding to the first word of the Chunk.
|
|
915 static inline bool dead_space_crosses_boundary(const ChunkData* chunk,
|
|
916 idx_t bit);
|
|
917
|
|
918 // Summary phase utility routine to fill dead space (if any) at the dense
|
|
919 // prefix boundary. Should only be called if the the dense prefix is
|
|
920 // non-empty.
|
|
921 static void fill_dense_prefix_end(SpaceId id);
|
|
922
|
|
923 static void summarize_spaces_quick();
|
|
924 static void summarize_space(SpaceId id, bool maximum_compaction);
|
|
925 static void summary_phase(ParCompactionManager* cm, bool maximum_compaction);
|
|
926
|
|
927 static bool block_first_offset(size_t block_index, idx_t* block_offset_ptr);
|
|
928
|
|
929 // Fill in the BlockData
|
|
930 static void summarize_blocks(ParCompactionManager* cm,
|
|
931 SpaceId first_compaction_space_id);
|
|
932
|
|
933 // The space that is compacted after space_id.
|
|
934 static SpaceId next_compaction_space_id(SpaceId space_id);
|
|
935
|
|
936 // Adjust addresses in roots. Does not adjust addresses in heap.
|
|
937 static void adjust_roots();
|
|
938
|
|
939 // Serial code executed in preparation for the compaction phase.
|
|
940 static void compact_prologue();
|
|
941
|
|
942 // Move objects to new locations.
|
|
943 static void compact_perm(ParCompactionManager* cm);
|
|
944 static void compact();
|
|
945
|
|
946 // Add available chunks to the stack and draining tasks to the task queue.
|
|
947 static void enqueue_chunk_draining_tasks(GCTaskQueue* q,
|
|
948 uint parallel_gc_threads);
|
|
949
|
|
950 // Add dense prefix update tasks to the task queue.
|
|
951 static void enqueue_dense_prefix_tasks(GCTaskQueue* q,
|
|
952 uint parallel_gc_threads);
|
|
953
|
|
954 // Add chunk stealing tasks to the task queue.
|
|
955 static void enqueue_chunk_stealing_tasks(
|
|
956 GCTaskQueue* q,
|
|
957 ParallelTaskTerminator* terminator_ptr,
|
|
958 uint parallel_gc_threads);
|
|
959
|
|
960 // For debugging only - compacts the old gen serially
|
|
961 static void compact_serial(ParCompactionManager* cm);
|
|
962
|
|
963 // If objects are left in eden after a collection, try to move the boundary
|
|
964 // and absorb them into the old gen. Returns true if eden was emptied.
|
|
965 static bool absorb_live_data_from_eden(PSAdaptiveSizePolicy* size_policy,
|
|
966 PSYoungGen* young_gen,
|
|
967 PSOldGen* old_gen);
|
|
968
|
|
969 // Reset time since last full gc
|
|
970 static void reset_millis_since_last_gc();
|
|
971
|
|
972 protected:
|
|
973 #ifdef VALIDATE_MARK_SWEEP
|
|
974 static GrowableArray<oop*>* _root_refs_stack;
|
|
975 static GrowableArray<oop> * _live_oops;
|
|
976 static GrowableArray<oop> * _live_oops_moved_to;
|
|
977 static GrowableArray<size_t>* _live_oops_size;
|
|
978 static size_t _live_oops_index;
|
|
979 static size_t _live_oops_index_at_perm;
|
|
980 static GrowableArray<oop*>* _other_refs_stack;
|
|
981 static GrowableArray<oop*>* _adjusted_pointers;
|
|
982 static bool _pointer_tracking;
|
|
983 static bool _root_tracking;
|
|
984
|
|
985 // The following arrays are saved since the time of the last GC and
|
|
986 // assist in tracking down problems where someone has done an errant
|
|
987 // store into the heap, usually to an oop that wasn't properly
|
|
988 // handleized across a GC. If we crash or otherwise fail before the
|
|
989 // next GC, we can query these arrays to find out the object we had
|
|
990 // intended to do the store to (assuming it is still alive) and the
|
|
991 // offset within that object. Covered under RecordMarkSweepCompaction.
|
|
992 static GrowableArray<HeapWord*> * _cur_gc_live_oops;
|
|
993 static GrowableArray<HeapWord*> * _cur_gc_live_oops_moved_to;
|
|
994 static GrowableArray<size_t>* _cur_gc_live_oops_size;
|
|
995 static GrowableArray<HeapWord*> * _last_gc_live_oops;
|
|
996 static GrowableArray<HeapWord*> * _last_gc_live_oops_moved_to;
|
|
997 static GrowableArray<size_t>* _last_gc_live_oops_size;
|
|
998 #endif
|
|
999
|
|
1000 public:
|
|
1001 class MarkAndPushClosure: public OopClosure {
|
|
1002 ParCompactionManager* _compaction_manager;
|
|
1003 public:
|
|
1004 MarkAndPushClosure(ParCompactionManager* cm) {
|
|
1005 _compaction_manager = cm;
|
|
1006 }
|
|
1007 void do_oop(oop* p) { mark_and_push(_compaction_manager, p); }
|
|
1008 virtual const bool do_nmethods() const { return true; }
|
|
1009 };
|
|
1010
|
|
1011 PSParallelCompact();
|
|
1012
|
|
1013 // Convenient accessor for Universe::heap().
|
|
1014 static ParallelScavengeHeap* gc_heap() {
|
|
1015 return (ParallelScavengeHeap*)Universe::heap();
|
|
1016 }
|
|
1017
|
|
1018 static void invoke(bool maximum_heap_compaction);
|
|
1019 static void invoke_no_policy(bool maximum_heap_compaction);
|
|
1020
|
|
1021 static void post_initialize();
|
|
1022 // Perform initialization for PSParallelCompact that requires
|
|
1023 // allocations. This should be called during the VM initialization
|
|
1024 // at a pointer where it would be appropriate to return a JNI_ENOMEM
|
|
1025 // in the event of a failure.
|
|
1026 static bool initialize();
|
|
1027
|
|
1028 // Public accessors
|
|
1029 static elapsedTimer* accumulated_time() { return &_accumulated_time; }
|
|
1030 static unsigned int total_invocations() { return _total_invocations; }
|
|
1031 static CollectorCounters* counters() { return _counters; }
|
|
1032
|
|
1033 // Used to add tasks
|
|
1034 static GCTaskManager* const gc_task_manager();
|
|
1035 static klassOop updated_int_array_klass_obj() {
|
|
1036 return _updated_int_array_klass_obj;
|
|
1037 }
|
|
1038
|
|
1039 // Marking support
|
|
1040 static inline bool mark_obj(oop obj);
|
|
1041 static bool mark_obj(oop* p) {
|
|
1042 if (*p != NULL) {
|
|
1043 return mark_obj(*p);
|
|
1044 } else {
|
|
1045 return false;
|
|
1046 }
|
|
1047 }
|
|
1048 static void mark_and_push(ParCompactionManager* cm, oop* p) {
|
|
1049 // Check mark and maybe push on
|
|
1050 // marking stack
|
|
1051 oop m = *p;
|
|
1052 if (m != NULL && mark_bitmap()->is_unmarked(m)) {
|
|
1053 mark_and_push_internal(cm, p);
|
|
1054 }
|
|
1055 }
|
|
1056
|
|
1057 // Compaction support.
|
|
1058 // Return true if p is in the range [beg_addr, end_addr).
|
|
1059 static inline bool is_in(HeapWord* p, HeapWord* beg_addr, HeapWord* end_addr);
|
|
1060 static inline bool is_in(oop* p, HeapWord* beg_addr, HeapWord* end_addr);
|
|
1061
|
|
1062 // Convenience wrappers for per-space data kept in _space_info.
|
|
1063 static inline MutableSpace* space(SpaceId space_id);
|
|
1064 static inline HeapWord* new_top(SpaceId space_id);
|
|
1065 static inline HeapWord* dense_prefix(SpaceId space_id);
|
|
1066 static inline ObjectStartArray* start_array(SpaceId space_id);
|
|
1067
|
|
1068 // Return true if the klass should be updated.
|
|
1069 static inline bool should_update_klass(klassOop k);
|
|
1070
|
|
1071 // Move and update the live objects in the specified space.
|
|
1072 static void move_and_update(ParCompactionManager* cm, SpaceId space_id);
|
|
1073
|
|
1074 // Process the end of the given chunk range in the dense prefix.
|
|
1075 // This includes saving any object not updated.
|
|
1076 static void dense_prefix_chunks_epilogue(ParCompactionManager* cm,
|
|
1077 size_t chunk_start_index,
|
|
1078 size_t chunk_end_index,
|
|
1079 idx_t exiting_object_offset,
|
|
1080 idx_t chunk_offset_start,
|
|
1081 idx_t chunk_offset_end);
|
|
1082
|
|
1083 // Update a chunk in the dense prefix. For each live object
|
|
1084 // in the chunk, update it's interior references. For each
|
|
1085 // dead object, fill it with deadwood. Dead space at the end
|
|
1086 // of a chunk range will be filled to the start of the next
|
|
1087 // live object regardless of the chunk_index_end. None of the
|
|
1088 // objects in the dense prefix move and dead space is dead
|
|
1089 // (holds only dead objects that don't need any processing), so
|
|
1090 // dead space can be filled in any order.
|
|
1091 static void update_and_deadwood_in_dense_prefix(ParCompactionManager* cm,
|
|
1092 SpaceId space_id,
|
|
1093 size_t chunk_index_start,
|
|
1094 size_t chunk_index_end);
|
|
1095
|
|
1096 // Return the address of the count + 1st live word in the range [beg, end).
|
|
1097 static HeapWord* skip_live_words(HeapWord* beg, HeapWord* end, size_t count);
|
|
1098
|
|
1099 // Return the address of the word to be copied to dest_addr, which must be
|
|
1100 // aligned to a chunk boundary.
|
|
1101 static HeapWord* first_src_addr(HeapWord* const dest_addr,
|
|
1102 size_t src_chunk_idx);
|
|
1103
|
|
1104 // Determine the next source chunk, set closure.source() to the start of the
|
|
1105 // new chunk return the chunk index. Parameter end_addr is the address one
|
|
1106 // beyond the end of source range just processed. If necessary, switch to a
|
|
1107 // new source space and set src_space_id (in-out parameter) and src_space_top
|
|
1108 // (out parameter) accordingly.
|
|
1109 static size_t next_src_chunk(MoveAndUpdateClosure& closure,
|
|
1110 SpaceId& src_space_id,
|
|
1111 HeapWord*& src_space_top,
|
|
1112 HeapWord* end_addr);
|
|
1113
|
|
1114 // Decrement the destination count for each non-empty source chunk in the
|
|
1115 // range [beg_chunk, chunk(chunk_align_up(end_addr))).
|
|
1116 static void decrement_destination_counts(ParCompactionManager* cm,
|
|
1117 size_t beg_chunk,
|
|
1118 HeapWord* end_addr);
|
|
1119
|
|
1120 // Fill a chunk, copying objects from one or more source chunks.
|
|
1121 static void fill_chunk(ParCompactionManager* cm, size_t chunk_idx);
|
|
1122 static void fill_and_update_chunk(ParCompactionManager* cm, size_t chunk) {
|
|
1123 fill_chunk(cm, chunk);
|
|
1124 }
|
|
1125
|
|
1126 // Update the deferred objects in the space.
|
|
1127 static void update_deferred_objects(ParCompactionManager* cm, SpaceId id);
|
|
1128
|
|
1129 // Mark pointer and follow contents.
|
|
1130 static void mark_and_follow(ParCompactionManager* cm, oop* p);
|
|
1131
|
|
1132 static ParMarkBitMap* mark_bitmap() { return &_mark_bitmap; }
|
|
1133 static ParallelCompactData& summary_data() { return _summary_data; }
|
|
1134
|
|
1135 static inline void adjust_pointer(oop* p) { adjust_pointer(p, false); }
|
|
1136 static inline void adjust_pointer(oop* p,
|
|
1137 HeapWord* beg_addr,
|
|
1138 HeapWord* end_addr);
|
|
1139
|
|
1140 // Reference Processing
|
|
1141 static ReferenceProcessor* const ref_processor() { return _ref_processor; }
|
|
1142
|
|
1143 // Return the SpaceId for the given address.
|
|
1144 static SpaceId space_id(HeapWord* addr);
|
|
1145
|
|
1146 // Time since last full gc (in milliseconds).
|
|
1147 static jlong millis_since_last_gc();
|
|
1148
|
|
1149 #ifdef VALIDATE_MARK_SWEEP
|
|
1150 static void track_adjusted_pointer(oop* p, oop newobj, bool isroot);
|
|
1151 static void check_adjust_pointer(oop* p); // Adjust this pointer
|
|
1152 static void track_interior_pointers(oop obj);
|
|
1153 static void check_interior_pointers();
|
|
1154
|
|
1155 static void reset_live_oop_tracking(bool at_perm);
|
|
1156 static void register_live_oop(oop p, size_t size);
|
|
1157 static void validate_live_oop(oop p, size_t size);
|
|
1158 static void live_oop_moved_to(HeapWord* q, size_t size, HeapWord* compaction_top);
|
|
1159 static void compaction_complete();
|
|
1160
|
|
1161 // Querying operation of RecordMarkSweepCompaction results.
|
|
1162 // Finds and prints the current base oop and offset for a word
|
|
1163 // within an oop that was live during the last GC. Helpful for
|
|
1164 // tracking down heap stomps.
|
|
1165 static void print_new_location_of_heap_address(HeapWord* q);
|
|
1166 #endif // #ifdef VALIDATE_MARK_SWEEP
|
|
1167
|
|
1168 // Call backs for class unloading
|
|
1169 // Update subklass/sibling/implementor links at end of marking.
|
|
1170 static void revisit_weak_klass_link(ParCompactionManager* cm, Klass* k);
|
|
1171
|
|
1172 #ifndef PRODUCT
|
|
1173 // Debugging support.
|
|
1174 static const char* space_names[last_space_id];
|
|
1175 static void print_chunk_ranges();
|
|
1176 static void print_dense_prefix_stats(const char* const algorithm,
|
|
1177 const SpaceId id,
|
|
1178 const bool maximum_compaction,
|
|
1179 HeapWord* const addr);
|
|
1180 #endif // #ifndef PRODUCT
|
|
1181
|
|
1182 #ifdef ASSERT
|
|
1183 // Verify that all the chunks have been emptied.
|
|
1184 static void verify_complete(SpaceId space_id);
|
|
1185 #endif // #ifdef ASSERT
|
|
1186 };
|
|
1187
|
|
1188 bool PSParallelCompact::mark_obj(oop obj) {
|
|
1189 const int obj_size = obj->size();
|
|
1190 if (mark_bitmap()->mark_obj(obj, obj_size)) {
|
|
1191 _summary_data.add_obj(obj, obj_size);
|
|
1192 return true;
|
|
1193 } else {
|
|
1194 return false;
|
|
1195 }
|
|
1196 }
|
|
1197
|
|
1198 inline bool PSParallelCompact::print_phases()
|
|
1199 {
|
|
1200 return _print_phases;
|
|
1201 }
|
|
1202
|
|
1203 inline double PSParallelCompact::normal_distribution(double density)
|
|
1204 {
|
|
1205 assert(_dwl_initialized, "uninitialized");
|
|
1206 const double squared_term = (density - _dwl_mean) / _dwl_std_dev;
|
|
1207 return _dwl_first_term * exp(-0.5 * squared_term * squared_term);
|
|
1208 }
|
|
1209
|
|
1210 inline bool
|
|
1211 PSParallelCompact::dead_space_crosses_boundary(const ChunkData* chunk,
|
|
1212 idx_t bit)
|
|
1213 {
|
|
1214 assert(bit > 0, "cannot call this for the first bit/chunk");
|
|
1215 assert(_summary_data.chunk_to_addr(chunk) == _mark_bitmap.bit_to_addr(bit),
|
|
1216 "sanity check");
|
|
1217
|
|
1218 // Dead space crosses the boundary if (1) a partial object does not extend
|
|
1219 // onto the chunk, (2) an object does not start at the beginning of the chunk,
|
|
1220 // and (3) an object does not end at the end of the prior chunk.
|
|
1221 return chunk->partial_obj_size() == 0 &&
|
|
1222 !_mark_bitmap.is_obj_beg(bit) &&
|
|
1223 !_mark_bitmap.is_obj_end(bit - 1);
|
|
1224 }
|
|
1225
|
|
1226 inline bool
|
|
1227 PSParallelCompact::is_in(HeapWord* p, HeapWord* beg_addr, HeapWord* end_addr) {
|
|
1228 return p >= beg_addr && p < end_addr;
|
|
1229 }
|
|
1230
|
|
1231 inline bool
|
|
1232 PSParallelCompact::is_in(oop* p, HeapWord* beg_addr, HeapWord* end_addr) {
|
|
1233 return is_in((HeapWord*)p, beg_addr, end_addr);
|
|
1234 }
|
|
1235
|
|
1236 inline MutableSpace* PSParallelCompact::space(SpaceId id) {
|
|
1237 assert(id < last_space_id, "id out of range");
|
|
1238 return _space_info[id].space();
|
|
1239 }
|
|
1240
|
|
1241 inline HeapWord* PSParallelCompact::new_top(SpaceId id) {
|
|
1242 assert(id < last_space_id, "id out of range");
|
|
1243 return _space_info[id].new_top();
|
|
1244 }
|
|
1245
|
|
1246 inline HeapWord* PSParallelCompact::dense_prefix(SpaceId id) {
|
|
1247 assert(id < last_space_id, "id out of range");
|
|
1248 return _space_info[id].dense_prefix();
|
|
1249 }
|
|
1250
|
|
1251 inline ObjectStartArray* PSParallelCompact::start_array(SpaceId id) {
|
|
1252 assert(id < last_space_id, "id out of range");
|
|
1253 return _space_info[id].start_array();
|
|
1254 }
|
|
1255
|
|
1256 inline bool PSParallelCompact::should_update_klass(klassOop k) {
|
|
1257 return ((HeapWord*) k) >= dense_prefix(perm_space_id);
|
|
1258 }
|
|
1259
|
|
1260 inline void PSParallelCompact::adjust_pointer(oop* p,
|
|
1261 HeapWord* beg_addr,
|
|
1262 HeapWord* end_addr) {
|
|
1263 if (is_in(p, beg_addr, end_addr)) {
|
|
1264 adjust_pointer(p);
|
|
1265 }
|
|
1266 }
|
|
1267
|
|
1268 class MoveAndUpdateClosure: public ParMarkBitMapClosure {
|
|
1269 public:
|
|
1270 inline MoveAndUpdateClosure(ParMarkBitMap* bitmap, ParCompactionManager* cm,
|
|
1271 ObjectStartArray* start_array,
|
|
1272 HeapWord* destination, size_t words);
|
|
1273
|
|
1274 // Accessors.
|
|
1275 HeapWord* destination() const { return _destination; }
|
|
1276
|
|
1277 // If the object will fit (size <= words_remaining()), copy it to the current
|
|
1278 // destination, update the interior oops and the start array and return either
|
|
1279 // full (if the closure is full) or incomplete. If the object will not fit,
|
|
1280 // return would_overflow.
|
|
1281 virtual IterationStatus do_addr(HeapWord* addr, size_t size);
|
|
1282
|
|
1283 // Copy enough words to fill this closure, starting at source(). Interior
|
|
1284 // oops and the start array are not updated. Return full.
|
|
1285 IterationStatus copy_until_full();
|
|
1286
|
|
1287 // Copy enough words to fill this closure or to the end of an object,
|
|
1288 // whichever is smaller, starting at source(). Interior oops and the start
|
|
1289 // array are not updated.
|
|
1290 void copy_partial_obj();
|
|
1291
|
|
1292 protected:
|
|
1293 // Update variables to indicate that word_count words were processed.
|
|
1294 inline void update_state(size_t word_count);
|
|
1295
|
|
1296 protected:
|
|
1297 ObjectStartArray* const _start_array;
|
|
1298 HeapWord* _destination; // Next addr to be written.
|
|
1299 };
|
|
1300
|
|
1301 inline
|
|
1302 MoveAndUpdateClosure::MoveAndUpdateClosure(ParMarkBitMap* bitmap,
|
|
1303 ParCompactionManager* cm,
|
|
1304 ObjectStartArray* start_array,
|
|
1305 HeapWord* destination,
|
|
1306 size_t words) :
|
|
1307 ParMarkBitMapClosure(bitmap, cm, words), _start_array(start_array)
|
|
1308 {
|
|
1309 _destination = destination;
|
|
1310 }
|
|
1311
|
|
1312 inline void MoveAndUpdateClosure::update_state(size_t words)
|
|
1313 {
|
|
1314 decrement_words_remaining(words);
|
|
1315 _source += words;
|
|
1316 _destination += words;
|
|
1317 }
|
|
1318
|
|
1319 class UpdateOnlyClosure: public ParMarkBitMapClosure {
|
|
1320 private:
|
|
1321 const PSParallelCompact::SpaceId _space_id;
|
|
1322 ObjectStartArray* const _start_array;
|
|
1323
|
|
1324 public:
|
|
1325 UpdateOnlyClosure(ParMarkBitMap* mbm,
|
|
1326 ParCompactionManager* cm,
|
|
1327 PSParallelCompact::SpaceId space_id);
|
|
1328
|
|
1329 // Update the object.
|
|
1330 virtual IterationStatus do_addr(HeapWord* addr, size_t words);
|
|
1331
|
|
1332 inline void do_addr(HeapWord* addr);
|
|
1333 };
|
|
1334
|
|
1335 inline void UpdateOnlyClosure::do_addr(HeapWord* addr) {
|
|
1336 _start_array->allocate_block(addr);
|
|
1337 oop(addr)->update_contents(compaction_manager());
|
|
1338 }
|
|
1339
|
|
1340 class FillClosure: public ParMarkBitMapClosure {
|
|
1341 public:
|
|
1342 FillClosure(ParCompactionManager* cm, PSParallelCompact::SpaceId space_id):
|
|
1343 ParMarkBitMapClosure(PSParallelCompact::mark_bitmap(), cm),
|
|
1344 _space_id(space_id),
|
|
1345 _start_array(PSParallelCompact::start_array(space_id))
|
|
1346 {
|
|
1347 assert(_space_id == PSParallelCompact::perm_space_id ||
|
|
1348 _space_id == PSParallelCompact::old_space_id,
|
|
1349 "cannot use FillClosure in the young gen");
|
|
1350 assert(bitmap() != NULL, "need a bitmap");
|
|
1351 assert(_start_array != NULL, "need a start array");
|
|
1352 }
|
|
1353
|
|
1354 void fill_region(HeapWord* addr, size_t size) {
|
|
1355 MemRegion region(addr, size);
|
|
1356 SharedHeap::fill_region_with_object(region);
|
|
1357 _start_array->allocate_block(addr);
|
|
1358 }
|
|
1359
|
|
1360 virtual IterationStatus do_addr(HeapWord* addr, size_t size) {
|
|
1361 fill_region(addr, size);
|
|
1362 return ParMarkBitMap::incomplete;
|
|
1363 }
|
|
1364
|
|
1365 private:
|
|
1366 const PSParallelCompact::SpaceId _space_id;
|
|
1367 ObjectStartArray* const _start_array;
|
|
1368 };
|