519 _objarray_stack.clear(true); 520 } 521 522 void PSMarkSweep::mark_sweep_phase1(bool clear_all_softrefs) { 523 // Recursively traverse all live objects and mark them 524 GCTraceTime tm("phase 1", PrintGCDetails && Verbose, true, _gc_timer, _gc_tracer->gc_id()); 525 trace(" 1"); 526 527 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); 528 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); 529 530 // Need to clear claim bits before the tracing starts. 531 ClassLoaderDataGraph::clear_claimed_marks(); 532 533 // General strong roots. 534 { 535 ParallelScavengeHeap::ParStrongRootsScope psrs; 536 Universe::oops_do(mark_and_push_closure()); 537 JNIHandles::oops_do(mark_and_push_closure()); // Global (strong) JNI handles 538 CLDToOopClosure mark_and_push_from_cld(mark_and_push_closure()); 539 CodeBlobToOopClosure each_active_code_blob(mark_and_push_closure(), /*do_marking=*/ true); 540 Threads::oops_do(mark_and_push_closure(), &mark_and_push_from_cld, &each_active_code_blob); 541 ObjectSynchronizer::oops_do(mark_and_push_closure()); 542 FlatProfiler::oops_do(mark_and_push_closure()); 543 Management::oops_do(mark_and_push_closure()); 544 JvmtiExport::oops_do(mark_and_push_closure()); 545 SystemDictionary::always_strong_oops_do(mark_and_push_closure()); 546 ClassLoaderDataGraph::always_strong_oops_do(mark_and_push_closure(), follow_klass_closure(), true); 547 // Do not treat nmethods as strong roots for mark/sweep, since we can unload them. 548 //CodeCache::scavenge_root_nmethods_do(CodeBlobToOopClosure(mark_and_push_closure())); 549 } 550 551 // Flush marking stack. 552 follow_stack(); 553 554 // Process reference objects found during marking 555 { 556 ref_processor()->setup_policy(clear_all_softrefs); 557 const ReferenceProcessorStats& stats = 558 ref_processor()->process_discovered_references( 559 is_alive_closure(), mark_and_push_closure(), follow_stack_closure(), NULL, _gc_timer, _gc_tracer->gc_id()); 560 gc_tracer()->report_gc_reference_stats(stats); 561 } 562 563 // This is the point where the entire marking should have completed. 564 assert(_marking_stack.is_empty(), "Marking should have completed"); 565 566 // Unload classes and purge the SystemDictionary. 616 trace("3"); 617 618 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); 619 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); 620 621 PSYoungGen* young_gen = heap->young_gen(); 622 PSOldGen* old_gen = heap->old_gen(); 623 624 // Need to clear claim bits before the tracing starts. 625 ClassLoaderDataGraph::clear_claimed_marks(); 626 627 // General strong roots. 628 Universe::oops_do(adjust_pointer_closure()); 629 JNIHandles::oops_do(adjust_pointer_closure()); // Global (strong) JNI handles 630 CLDToOopClosure adjust_from_cld(adjust_pointer_closure()); 631 Threads::oops_do(adjust_pointer_closure(), &adjust_from_cld, NULL); 632 ObjectSynchronizer::oops_do(adjust_pointer_closure()); 633 FlatProfiler::oops_do(adjust_pointer_closure()); 634 Management::oops_do(adjust_pointer_closure()); 635 JvmtiExport::oops_do(adjust_pointer_closure()); 636 // SO_AllClasses 637 SystemDictionary::oops_do(adjust_pointer_closure()); 638 ClassLoaderDataGraph::oops_do(adjust_pointer_closure(), adjust_klass_closure(), true); 639 640 // Now adjust pointers in remaining weak roots. (All of which should 641 // have been cleared if they pointed to non-surviving objects.) 642 // Global (weak) JNI handles 643 JNIHandles::weak_oops_do(&always_true, adjust_pointer_closure()); 644 645 CodeCache::oops_do(adjust_pointer_closure()); 646 StringTable::oops_do(adjust_pointer_closure()); 647 ref_processor()->weak_oops_do(adjust_pointer_closure()); 648 PSScavenge::reference_processor()->weak_oops_do(adjust_pointer_closure()); 649 650 adjust_marks(); 651 652 young_gen->adjust_pointers(); 653 old_gen->adjust_pointers(); 654 } 655 656 void PSMarkSweep::mark_sweep_phase4() { 657 EventMark m("4 compact heap"); 658 GCTraceTime tm("phase 4", PrintGCDetails && Verbose, true, _gc_timer, _gc_tracer->gc_id()); 659 trace("4"); 660 661 // All pointers are now adjusted, move objects accordingly 662 663 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); 664 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); 665 | 519 _objarray_stack.clear(true); 520 } 521 522 void PSMarkSweep::mark_sweep_phase1(bool clear_all_softrefs) { 523 // Recursively traverse all live objects and mark them 524 GCTraceTime tm("phase 1", PrintGCDetails && Verbose, true, _gc_timer, _gc_tracer->gc_id()); 525 trace(" 1"); 526 527 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); 528 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); 529 530 // Need to clear claim bits before the tracing starts. 531 ClassLoaderDataGraph::clear_claimed_marks(); 532 533 // General strong roots. 534 { 535 ParallelScavengeHeap::ParStrongRootsScope psrs; 536 Universe::oops_do(mark_and_push_closure()); 537 JNIHandles::oops_do(mark_and_push_closure()); // Global (strong) JNI handles 538 CLDToOopClosure mark_and_push_from_cld(mark_and_push_closure()); 539 MarkingCodeBlobClosure each_active_code_blob(mark_and_push_closure(), !CodeBlobToOopClosure::FixRelocations); 540 Threads::oops_do(mark_and_push_closure(), &mark_and_push_from_cld, &each_active_code_blob); 541 ObjectSynchronizer::oops_do(mark_and_push_closure()); 542 FlatProfiler::oops_do(mark_and_push_closure()); 543 Management::oops_do(mark_and_push_closure()); 544 JvmtiExport::oops_do(mark_and_push_closure()); 545 SystemDictionary::always_strong_oops_do(mark_and_push_closure()); 546 ClassLoaderDataGraph::always_strong_cld_do(follow_cld_closure()); 547 // Do not treat nmethods as strong roots for mark/sweep, since we can unload them. 548 //CodeCache::scavenge_root_nmethods_do(CodeBlobToOopClosure(mark_and_push_closure())); 549 } 550 551 // Flush marking stack. 552 follow_stack(); 553 554 // Process reference objects found during marking 555 { 556 ref_processor()->setup_policy(clear_all_softrefs); 557 const ReferenceProcessorStats& stats = 558 ref_processor()->process_discovered_references( 559 is_alive_closure(), mark_and_push_closure(), follow_stack_closure(), NULL, _gc_timer, _gc_tracer->gc_id()); 560 gc_tracer()->report_gc_reference_stats(stats); 561 } 562 563 // This is the point where the entire marking should have completed. 564 assert(_marking_stack.is_empty(), "Marking should have completed"); 565 566 // Unload classes and purge the SystemDictionary. 616 trace("3"); 617 618 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); 619 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); 620 621 PSYoungGen* young_gen = heap->young_gen(); 622 PSOldGen* old_gen = heap->old_gen(); 623 624 // Need to clear claim bits before the tracing starts. 625 ClassLoaderDataGraph::clear_claimed_marks(); 626 627 // General strong roots. 628 Universe::oops_do(adjust_pointer_closure()); 629 JNIHandles::oops_do(adjust_pointer_closure()); // Global (strong) JNI handles 630 CLDToOopClosure adjust_from_cld(adjust_pointer_closure()); 631 Threads::oops_do(adjust_pointer_closure(), &adjust_from_cld, NULL); 632 ObjectSynchronizer::oops_do(adjust_pointer_closure()); 633 FlatProfiler::oops_do(adjust_pointer_closure()); 634 Management::oops_do(adjust_pointer_closure()); 635 JvmtiExport::oops_do(adjust_pointer_closure()); 636 SystemDictionary::oops_do(adjust_pointer_closure()); 637 ClassLoaderDataGraph::cld_do(adjust_cld_closure()); 638 639 // Now adjust pointers in remaining weak roots. (All of which should 640 // have been cleared if they pointed to non-surviving objects.) 641 // Global (weak) JNI handles 642 JNIHandles::weak_oops_do(&always_true, adjust_pointer_closure()); 643 644 CodeBlobToOopClosure adjust_from_blobs(adjust_pointer_closure(), CodeBlobToOopClosure::FixRelocations); 645 CodeCache::blobs_do(&adjust_from_blobs); 646 StringTable::oops_do(adjust_pointer_closure()); 647 ref_processor()->weak_oops_do(adjust_pointer_closure()); 648 PSScavenge::reference_processor()->weak_oops_do(adjust_pointer_closure()); 649 650 adjust_marks(); 651 652 young_gen->adjust_pointers(); 653 old_gen->adjust_pointers(); 654 } 655 656 void PSMarkSweep::mark_sweep_phase4() { 657 EventMark m("4 compact heap"); 658 GCTraceTime tm("phase 4", PrintGCDetails && Verbose, true, _gc_timer, _gc_tracer->gc_id()); 659 trace("4"); 660 661 // All pointers are now adjusted, move objects accordingly 662 663 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); 664 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); 665 |