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/systemDictionary.hpp"
27 #include "classfile/vmSymbols.hpp"
28 #include "gc/serial/defNewGeneration.hpp"
29 #include "gc/shared/blockOffsetTable.inline.hpp"
30 #include "gc/shared/collectedHeap.inline.hpp"
31 #include "gc/shared/genCollectedHeap.hpp"
32 #include "gc/shared/genOopClosures.inline.hpp"
33 #include "gc/shared/liveRange.hpp"
34 #include "gc/shared/space.hpp"
35 #include "gc/shared/space.inline.hpp"
36 #include "gc/shared/spaceDecorator.hpp"
37 #include "memory/universe.inline.hpp"
38 #include "oops/oop.inline.hpp"
39 #include "runtime/atomic.inline.hpp"
40 #include "runtime/java.hpp"
41 #include "runtime/orderAccess.inline.hpp"
42 #include "runtime/prefetch.inline.hpp"
43 #include "runtime/safepoint.hpp"
44 #include "utilities/copy.hpp"
45 #include "utilities/globalDefinitions.hpp"
46 #include "utilities/macros.hpp"
47
48 HeapWord* DirtyCardToOopClosure::get_actual_top(HeapWord* top,
49 HeapWord* top_obj) {
50 if (top_obj != NULL) {
411 cp->space->cross_threshold(compact_top - size, compact_top);
412 return compact_top;
413 }
414
415
416 bool CompactibleSpace::insert_deadspace(size_t& allowed_deadspace_words,
417 HeapWord* q, size_t deadlength) {
418 if (allowed_deadspace_words >= deadlength) {
419 allowed_deadspace_words -= deadlength;
420 CollectedHeap::fill_with_object(q, deadlength);
421 oop(q)->set_mark(oop(q)->mark()->set_marked());
422 assert((int) deadlength == oop(q)->size(), "bad filler object size");
423 // Recall that we required "q == compaction_top".
424 return true;
425 } else {
426 allowed_deadspace_words = 0;
427 return false;
428 }
429 }
430
431 void ContiguousSpace::prepare_for_compaction(CompactPoint* cp) {
432 scan_and_forward(this, cp);
433 }
434
435 void CompactibleSpace::adjust_pointers() {
436 // Check first is there is any work to do.
437 if (used() == 0) {
438 return; // Nothing to do.
439 }
440
441 scan_and_adjust_pointers(this);
442 }
443
444 void CompactibleSpace::compact() {
445 scan_and_compact(this);
446 }
447
448 void Space::print_short() const { print_short_on(tty); }
449
450 void Space::print_short_on(outputStream* st) const {
451 st->print(" space " SIZE_FORMAT "K, %3d%% used", capacity() / K,
452 (int) ((double) used() * 100 / capacity()));
453 }
454
455 void Space::print() const { print_on(tty); }
456
457 void Space::print_on(outputStream* st) const {
458 print_short_on(st);
459 st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ")",
460 p2i(bottom()), p2i(end()));
461 }
462
463 void ContiguousSpace::print_on(outputStream* st) const {
464 print_short_on(st);
465 st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")",
|
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/systemDictionary.hpp"
27 #include "classfile/vmSymbols.hpp"
28 #include "gc/serial/defNewGeneration.hpp"
29 #include "gc/shared/blockOffsetTable.inline.hpp"
30 #include "gc/shared/collectedHeap.inline.hpp"
31 #include "gc/shared/gcTraceTime.hpp"
32 #include "gc/shared/genCollectedHeap.hpp"
33 #include "gc/shared/genOopClosures.inline.hpp"
34 #include "gc/shared/liveRange.hpp"
35 #include "gc/shared/space.hpp"
36 #include "gc/shared/space.inline.hpp"
37 #include "gc/shared/spaceDecorator.hpp"
38 #include "memory/universe.inline.hpp"
39 #include "oops/oop.inline.hpp"
40 #include "runtime/atomic.inline.hpp"
41 #include "runtime/java.hpp"
42 #include "runtime/orderAccess.inline.hpp"
43 #include "runtime/prefetch.inline.hpp"
44 #include "runtime/safepoint.hpp"
45 #include "utilities/copy.hpp"
46 #include "utilities/globalDefinitions.hpp"
47 #include "utilities/macros.hpp"
48
49 HeapWord* DirtyCardToOopClosure::get_actual_top(HeapWord* top,
50 HeapWord* top_obj) {
51 if (top_obj != NULL) {
412 cp->space->cross_threshold(compact_top - size, compact_top);
413 return compact_top;
414 }
415
416
417 bool CompactibleSpace::insert_deadspace(size_t& allowed_deadspace_words,
418 HeapWord* q, size_t deadlength) {
419 if (allowed_deadspace_words >= deadlength) {
420 allowed_deadspace_words -= deadlength;
421 CollectedHeap::fill_with_object(q, deadlength);
422 oop(q)->set_mark(oop(q)->mark()->set_marked());
423 assert((int) deadlength == oop(q)->size(), "bad filler object size");
424 // Recall that we required "q == compaction_top".
425 return true;
426 } else {
427 allowed_deadspace_words = 0;
428 return false;
429 }
430 }
431
432 #define contiguous_space_obj_size(q) oop(q)->size()
433 DECLARE_PMS_SPECIALIZED_CODE(ContiguousSpace, contiguous_space_obj_size);
434
435 void ContiguousSpace::prepare_for_compaction(CompactPoint* cp) {
436 if (!CMSParallelFullGC) {
437 scan_and_forward(this, cp);
438 } else {
439 pms_prepare_for_compaction_work(cp);
440 }
441 }
442
443 void CompactibleSpace::adjust_pointers() {
444 // Check first is there is any work to do.
445 if (used() == 0) {
446 return; // Nothing to do.
447 }
448
449 if (!CMSParallelFullGC) {
450 scan_and_adjust_pointers(this);
451 } else {
452 pms_adjust_pointers_work();
453 }
454 }
455
456 // The parallel version of adjust_pointers() for parallel mark
457 // sweep. This code is shared between ContiguousSpace (YG) and the
458 // CompactibleFreeListSpace (OG and PG).
459 void CompactibleSpace::pms_adjust_pointers_work() {
460 assert(CMSParallelFullGC, "Used only if CMSParallelFullGC");
461 if (_beginning_of_live < _end_of_live) { // Unless there is no live object
462 PMSMarkBitMap* mark_bit_map = MarkSweep::pms_mark_bit_map();
463 PMSAdjustClosure adjust_cl(mark_bit_map);
464 GenCollectedHeap* gch = GenCollectedHeap::heap();
465 PMSRegionTaskQueueSet* task_queues = MarkSweep::pms_region_task_queues();
466 WorkGang* workers = gch->workers();
467 int n_workers = workers->total_workers();
468 PMSRegionArray* regions = MarkSweep::pms_region_array_set()->region_array_for(this);
469 assert(regions != NULL && regions->space() == this, "Must be this space");
470 PMSRegion* start_r = regions->region_for_addr(_beginning_of_live);
471 PMSRegion* end_r = regions->region_for_addr(_end_of_live - 1); // _end_of_live is exclusive
472 if (LogCMSParallelFullGC) {
473 gclog_or_tty->print_cr("bottom=" PTR_FORMAT ", "
474 "end=" PTR_FORMAT ", "
475 "start_r=" PTR_FORMAT "-" PTR_FORMAT ", "
476 "end_r=" PTR_FORMAT "-" PTR_FORMAT ", "
477 "_beginning_of_live=" PTR_FORMAT ", "
478 "_end_of_live=" PTR_FORMAT "",
479 p2i(bottom()), p2i(end()),
480 p2i(start_r->start()), p2i(start_r->end()),
481 p2i(end_r->start()), p2i(end_r->end()),
482 p2i(_beginning_of_live), p2i(_end_of_live));
483 }
484 assert(start_r->start() <= _beginning_of_live &&
485 _beginning_of_live < start_r->end(), "Must include it");
486 assert(end_r->start() <= (_end_of_live - 1) &&
487 (_end_of_live - 1) < end_r->end(), "Must include it");
488 assert(bottom() <= start_r->start() &&
489 end_r->end() <= end(), "Must include it");
490 int i = 0;
491 // Push regions into the task queues in a round robin
492 // fashion. In a reverse order so that the processing happens in
493 // a forward direction (it's a LIFO stack).
494 for (PMSRegion* r = end_r; r >= start_r; r--) {
495 task_queues->queue(i)->push(r);
496 i = (i + 1) % n_workers;
497 }
498 PMSParAdjustTask tsk(n_workers, workers,
499 task_queues, &adjust_cl);
500 GCTraceTime tm1("par-adjust-pointers",
501 (PrintGC && Verbose) || LogCMSParallelFullGC,
502 true, NULL, GCId::peek());
503 if (n_workers > 1) {
504 workers->run_task(&tsk);
505 } else {
506 tsk.work(0);
507 }
508 }
509 }
510
511 void CompactibleSpace::compact() {
512 if (!CMSParallelFullGC) {
513 scan_and_compact(this);
514 } else {
515 pms_compact_work();
516 }
517 }
518
519 void Space::print_short() const { print_short_on(tty); }
520
521 void Space::print_short_on(outputStream* st) const {
522 st->print(" space " SIZE_FORMAT "K, %3d%% used", capacity() / K,
523 (int) ((double) used() * 100 / capacity()));
524 }
525
526 void Space::print() const { print_on(tty); }
527
528 void Space::print_on(outputStream* st) const {
529 print_short_on(st);
530 st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ")",
531 p2i(bottom()), p2i(end()));
532 }
533
534 void ContiguousSpace::print_on(outputStream* st) const {
535 print_short_on(st);
536 st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")",
|