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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/vmClasses.hpp"
27 #include "classfile/vmSymbols.hpp"
28 #include "gc/shared/collectedHeap.inline.hpp"
29 #include "gc/shared/genCollectedHeap.hpp"
30 #include "gc/shared/space.hpp"
31 #include "gc/shared/space.inline.hpp"
32 #include "gc/shared/spaceDecorator.inline.hpp"
33 #include "memory/iterator.inline.hpp"
34 #include "memory/universe.hpp"
35 #include "oops/oop.inline.hpp"
36 #include "runtime/atomic.hpp"
37 #include "runtime/java.hpp"
38 #include "runtime/prefetch.inline.hpp"
39 #include "runtime/safepoint.hpp"
40 #include "utilities/align.hpp"
41 #include "utilities/copy.hpp"
42 #include "utilities/globalDefinitions.hpp"
43 #include "utilities/macros.hpp"
44 #if INCLUDE_SERIALGC
45 #include "gc/serial/serialBlockOffsetTable.inline.hpp"
46 #include "gc/serial/defNewGeneration.hpp"
47 #endif
48
49 HeapWord* DirtyCardToOopClosure::get_actual_top(HeapWord* top,
252 assert(this == cp->space, "'this' should be current compaction space.");
253 size_t compaction_max_size = pointer_delta(end(), compact_top);
254 while (size > compaction_max_size) {
255 // switch to next compaction space
256 cp->space->set_compaction_top(compact_top);
257 cp->space = cp->space->next_compaction_space();
258 if (cp->space == nullptr) {
259 cp->gen = GenCollectedHeap::heap()->young_gen();
260 assert(cp->gen != nullptr, "compaction must succeed");
261 cp->space = cp->gen->first_compaction_space();
262 assert(cp->space != nullptr, "generation must have a first compaction space");
263 }
264 compact_top = cp->space->bottom();
265 cp->space->set_compaction_top(compact_top);
266 cp->space->initialize_threshold();
267 compaction_max_size = pointer_delta(cp->space->end(), compact_top);
268 }
269
270 // store the forwarding pointer into the mark word
271 if (cast_from_oop<HeapWord*>(q) != compact_top) {
272 q->forward_to(cast_to_oop(compact_top));
273 assert(q->is_gc_marked(), "encoding the pointer should preserve the mark");
274 } else {
275 // if the object isn't moving we can just set the mark to the default
276 // mark and handle it specially later on.
277 q->init_mark();
278 assert(!q->is_forwarded(), "should not be forwarded");
279 }
280
281 compact_top += size;
282
283 // We need to update the offset table so that the beginnings of objects can be
284 // found during scavenge. Note that we are updating the offset table based on
285 // where the object will be once the compaction phase finishes.
286 cp->space->alloc_block(compact_top - size, compact_top);
287 return compact_top;
288 }
289
290 #if INCLUDE_SERIALGC
291
292 void ContiguousSpace::prepare_for_compaction(CompactPoint* cp) {
293 // Compute the new addresses for the live objects and store it in the mark
294 // Used by universe::mark_sweep_phase2()
295
296 // We're sure to be here before any objects are compacted into this
297 // space, so this is a good time to initialize this:
298 set_compaction_top(bottom());
418 assert(_first_dead <= end_of_live, "Invariant. _first_dead: " PTR_FORMAT " <= end_of_live: " PTR_FORMAT, p2i(_first_dead), p2i(end_of_live));
419 if (_first_dead == end_of_live && (start == end_of_live || !cast_to_oop(start)->is_gc_marked())) {
420 // Nothing to compact. The space is either empty or all live object should be left in place.
421 clear_empty_region(this);
422 return;
423 }
424
425 const intx scan_interval = PrefetchScanIntervalInBytes;
426 const intx copy_interval = PrefetchCopyIntervalInBytes;
427
428 assert(start < end_of_live, "bottom: " PTR_FORMAT " should be < end_of_live: " PTR_FORMAT, p2i(start), p2i(end_of_live));
429 HeapWord* cur_obj = start;
430 if (_first_dead > cur_obj && !cast_to_oop(cur_obj)->is_gc_marked()) {
431 // All object before _first_dead can be skipped. They should not be moved.
432 // A pointer to the first live object is stored at the memory location for _first_dead.
433 cur_obj = *(HeapWord**)(_first_dead);
434 }
435
436 debug_only(HeapWord* prev_obj = nullptr);
437 while (cur_obj < end_of_live) {
438 if (!cast_to_oop(cur_obj)->is_forwarded()) {
439 debug_only(prev_obj = cur_obj);
440 // The first word of the dead object contains a pointer to the next live object or end of space.
441 cur_obj = *(HeapWord**)cur_obj;
442 assert(cur_obj > prev_obj, "we should be moving forward through memory");
443 } else {
444 // prefetch beyond q
445 Prefetch::read(cur_obj, scan_interval);
446
447 // size and destination
448 size_t size = cast_to_oop(cur_obj)->size();
449 HeapWord* compaction_top = cast_from_oop<HeapWord*>(cast_to_oop(cur_obj)->forwardee());
450
451 // prefetch beyond compaction_top
452 Prefetch::write(compaction_top, copy_interval);
453
454 // copy object and reinit its mark
455 assert(cur_obj != compaction_top, "everything in this pass should be moving");
456 Copy::aligned_conjoint_words(cur_obj, compaction_top, size);
457 oop new_obj = cast_to_oop(compaction_top);
458
459 ContinuationGCSupport::transform_stack_chunk(new_obj);
460
461 new_obj->init_mark();
462 assert(new_obj->klass() != nullptr, "should have a class");
463
464 debug_only(prev_obj = cur_obj);
465 cur_obj += size;
466 }
467 }
468
469 clear_empty_region(this);
|
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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/vmClasses.hpp"
27 #include "classfile/vmSymbols.hpp"
28 #include "gc/shared/collectedHeap.inline.hpp"
29 #include "gc/shared/genCollectedHeap.hpp"
30 #include "gc/shared/gcForwarding.inline.hpp"
31 #include "gc/shared/space.hpp"
32 #include "gc/shared/space.inline.hpp"
33 #include "gc/shared/spaceDecorator.inline.hpp"
34 #include "memory/iterator.inline.hpp"
35 #include "memory/universe.hpp"
36 #include "oops/oop.inline.hpp"
37 #include "runtime/atomic.hpp"
38 #include "runtime/java.hpp"
39 #include "runtime/prefetch.inline.hpp"
40 #include "runtime/safepoint.hpp"
41 #include "utilities/align.hpp"
42 #include "utilities/copy.hpp"
43 #include "utilities/globalDefinitions.hpp"
44 #include "utilities/macros.hpp"
45 #if INCLUDE_SERIALGC
46 #include "gc/serial/serialBlockOffsetTable.inline.hpp"
47 #include "gc/serial/defNewGeneration.hpp"
48 #endif
49
50 HeapWord* DirtyCardToOopClosure::get_actual_top(HeapWord* top,
253 assert(this == cp->space, "'this' should be current compaction space.");
254 size_t compaction_max_size = pointer_delta(end(), compact_top);
255 while (size > compaction_max_size) {
256 // switch to next compaction space
257 cp->space->set_compaction_top(compact_top);
258 cp->space = cp->space->next_compaction_space();
259 if (cp->space == nullptr) {
260 cp->gen = GenCollectedHeap::heap()->young_gen();
261 assert(cp->gen != nullptr, "compaction must succeed");
262 cp->space = cp->gen->first_compaction_space();
263 assert(cp->space != nullptr, "generation must have a first compaction space");
264 }
265 compact_top = cp->space->bottom();
266 cp->space->set_compaction_top(compact_top);
267 cp->space->initialize_threshold();
268 compaction_max_size = pointer_delta(cp->space->end(), compact_top);
269 }
270
271 // store the forwarding pointer into the mark word
272 if (cast_from_oop<HeapWord*>(q) != compact_top) {
273 GCForwarding::forward_to(q, cast_to_oop(compact_top));
274 assert(q->is_gc_marked(), "encoding the pointer should preserve the mark");
275 } else {
276 // if the object isn't moving we can just set the mark to the default
277 // mark and handle it specially later on.
278 q->init_mark();
279 assert(GCForwarding::is_not_forwarded(q), "should not be forwarded");
280 }
281
282 compact_top += size;
283
284 // We need to update the offset table so that the beginnings of objects can be
285 // found during scavenge. Note that we are updating the offset table based on
286 // where the object will be once the compaction phase finishes.
287 cp->space->alloc_block(compact_top - size, compact_top);
288 return compact_top;
289 }
290
291 #if INCLUDE_SERIALGC
292
293 void ContiguousSpace::prepare_for_compaction(CompactPoint* cp) {
294 // Compute the new addresses for the live objects and store it in the mark
295 // Used by universe::mark_sweep_phase2()
296
297 // We're sure to be here before any objects are compacted into this
298 // space, so this is a good time to initialize this:
299 set_compaction_top(bottom());
419 assert(_first_dead <= end_of_live, "Invariant. _first_dead: " PTR_FORMAT " <= end_of_live: " PTR_FORMAT, p2i(_first_dead), p2i(end_of_live));
420 if (_first_dead == end_of_live && (start == end_of_live || !cast_to_oop(start)->is_gc_marked())) {
421 // Nothing to compact. The space is either empty or all live object should be left in place.
422 clear_empty_region(this);
423 return;
424 }
425
426 const intx scan_interval = PrefetchScanIntervalInBytes;
427 const intx copy_interval = PrefetchCopyIntervalInBytes;
428
429 assert(start < end_of_live, "bottom: " PTR_FORMAT " should be < end_of_live: " PTR_FORMAT, p2i(start), p2i(end_of_live));
430 HeapWord* cur_obj = start;
431 if (_first_dead > cur_obj && !cast_to_oop(cur_obj)->is_gc_marked()) {
432 // All object before _first_dead can be skipped. They should not be moved.
433 // A pointer to the first live object is stored at the memory location for _first_dead.
434 cur_obj = *(HeapWord**)(_first_dead);
435 }
436
437 debug_only(HeapWord* prev_obj = nullptr);
438 while (cur_obj < end_of_live) {
439 if (GCForwarding::is_not_forwarded(cast_to_oop(cur_obj))) {
440 debug_only(prev_obj = cur_obj);
441 // The first word of the dead object contains a pointer to the next live object or end of space.
442 cur_obj = *(HeapWord**)cur_obj;
443 assert(cur_obj > prev_obj, "we should be moving forward through memory");
444 } else {
445 // prefetch beyond q
446 Prefetch::read(cur_obj, scan_interval);
447
448 // size and destination
449 size_t size = cast_to_oop(cur_obj)->size();
450 HeapWord* compaction_top = cast_from_oop<HeapWord*>(GCForwarding::forwardee(cast_to_oop(cur_obj)));
451
452 // prefetch beyond compaction_top
453 Prefetch::write(compaction_top, copy_interval);
454
455 // copy object and reinit its mark
456 assert(cur_obj != compaction_top, "everything in this pass should be moving");
457 Copy::aligned_conjoint_words(cur_obj, compaction_top, size);
458 oop new_obj = cast_to_oop(compaction_top);
459
460 ContinuationGCSupport::transform_stack_chunk(new_obj);
461
462 new_obj->init_mark();
463 assert(new_obj->klass() != nullptr, "should have a class");
464
465 debug_only(prev_obj = cur_obj);
466 cur_obj += size;
467 }
468 }
469
470 clear_empty_region(this);
|