2623
2624 {
2625 G1RemarkGCTraceTime trace("Deallocate Metadata", G1Log::finest());
2626 ClassLoaderDataGraph::free_deallocate_lists();
2627 }
2628 }
2629
2630 if (G1StringDedup::is_enabled()) {
2631 G1RemarkGCTraceTime trace("String Deduplication Unlink", G1Log::finest());
2632 G1StringDedup::unlink(&g1_is_alive);
2633 }
2634 }
2635 }
2636
2637 void ConcurrentMark::swapMarkBitMaps() {
2638 CMBitMapRO* temp = _prevMarkBitMap;
2639 _prevMarkBitMap = (CMBitMapRO*)_nextMarkBitMap;
2640 _nextMarkBitMap = (CMBitMap*) temp;
2641 }
2642
2643 class CMObjectClosure;
2644
2645 // Closure for iterating over objects, currently only used for
2646 // processing SATB buffers.
2647 class CMObjectClosure : public ObjectClosure {
2648 private:
2649 CMTask* _task;
2650
2651 public:
2652 void do_object(oop obj) {
2653 _task->deal_with_reference(obj);
2654 }
2655
2656 CMObjectClosure(CMTask* task) : _task(task) { }
2657 };
2658
2659 class G1RemarkThreadsClosure : public ThreadClosure {
2660 CMObjectClosure _cm_obj;
2661 G1CMOopClosure _cm_cl;
2662 MarkingCodeBlobClosure _code_cl;
2663 int _thread_parity;
2664 bool _is_par;
2665
2666 public:
2667 G1RemarkThreadsClosure(G1CollectedHeap* g1h, CMTask* task, bool is_par) :
2668 _cm_obj(task), _cm_cl(g1h, g1h->concurrent_mark(), task), _code_cl(&_cm_cl, !CodeBlobToOopClosure::FixRelocations),
2669 _thread_parity(SharedHeap::heap()->strong_roots_parity()), _is_par(is_par) {}
2670
2671 void do_thread(Thread* thread) {
2672 if (thread->is_Java_thread()) {
2673 if (thread->claim_oops_do(_is_par, _thread_parity)) {
2674 JavaThread* jt = (JavaThread*)thread;
2675
2676 // In theory it should not be neccessary to explicitly walk the nmethods to find roots for concurrent marking
2677 // however the liveness of oops reachable from nmethods have very complex lifecycles:
2678 // * Alive if on the stack of an executing method
2679 // * Weakly reachable otherwise
2680 // Some objects reachable from nmethods, such as the class loader (or klass_holder) of the receiver should be
2681 // live by the SATB invariant but other oops recorded in nmethods may behave differently.
2682 jt->nmethods_do(&_code_cl);
2683
2684 jt->satb_mark_queue().apply_closure_and_empty(&_cm_obj);
2685 }
2686 } else if (thread->is_VM_thread()) {
2687 if (thread->claim_oops_do(_is_par, _thread_parity)) {
2688 JavaThread::satb_mark_queue_set().shared_satb_queue()->apply_closure_and_empty(&_cm_obj);
2689 }
2690 }
2691 }
2692 };
2693
2694 class CMRemarkTask: public AbstractGangTask {
2695 private:
2696 ConcurrentMark* _cm;
2697 bool _is_serial;
2698 public:
2699 void work(uint worker_id) {
2700 // Since all available tasks are actually started, we should
2701 // only proceed if we're supposed to be actived.
2702 if (worker_id < _cm->active_tasks()) {
2703 CMTask* task = _cm->task(worker_id);
2704 task->record_start_time();
2705 {
2706 ResourceMark rm;
2707 HandleMark hm;
2708
3959 if (_cm->verbose_low()) {
3960 gclog_or_tty->print_cr("[%u] drained global stack, size = " SIZE_FORMAT,
3961 _worker_id, _cm->mark_stack_size());
3962 }
3963 }
3964 }
3965
3966 // SATB Queue has several assumptions on whether to call the par or
3967 // non-par versions of the methods. this is why some of the code is
3968 // replicated. We should really get rid of the single-threaded version
3969 // of the code to simplify things.
3970 void CMTask::drain_satb_buffers() {
3971 if (has_aborted()) return;
3972
3973 // We set this so that the regular clock knows that we're in the
3974 // middle of draining buffers and doesn't set the abort flag when it
3975 // notices that SATB buffers are available for draining. It'd be
3976 // very counter productive if it did that. :-)
3977 _draining_satb_buffers = true;
3978
3979 CMObjectClosure oc(this);
3980 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set();
3981
3982 // This keeps claiming and applying the closure to completed buffers
3983 // until we run out of buffers or we need to abort.
3984 while (!has_aborted() &&
3985 satb_mq_set.apply_closure_to_completed_buffer(&oc)) {
3986 if (_cm->verbose_medium()) {
3987 gclog_or_tty->print_cr("[%u] processed an SATB buffer", _worker_id);
3988 }
3989 statsOnly( ++_satb_buffers_processed );
3990 regular_clock_call();
3991 }
3992
3993 _draining_satb_buffers = false;
3994
3995 assert(has_aborted() ||
3996 concurrent() ||
3997 satb_mq_set.completed_buffers_num() == 0, "invariant");
3998
3999 // again, this was a potentially expensive operation, decrease the
4000 // limits to get the regular clock call early
4001 decrease_limits();
4002 }
4003
4004 void CMTask::print_stats() {
4005 gclog_or_tty->print_cr("Marking Stats, task = %u, calls = %d",
|
2623
2624 {
2625 G1RemarkGCTraceTime trace("Deallocate Metadata", G1Log::finest());
2626 ClassLoaderDataGraph::free_deallocate_lists();
2627 }
2628 }
2629
2630 if (G1StringDedup::is_enabled()) {
2631 G1RemarkGCTraceTime trace("String Deduplication Unlink", G1Log::finest());
2632 G1StringDedup::unlink(&g1_is_alive);
2633 }
2634 }
2635 }
2636
2637 void ConcurrentMark::swapMarkBitMaps() {
2638 CMBitMapRO* temp = _prevMarkBitMap;
2639 _prevMarkBitMap = (CMBitMapRO*)_nextMarkBitMap;
2640 _nextMarkBitMap = (CMBitMap*) temp;
2641 }
2642
2643 // Closure for marking entries in SATB buffers.
2644 class CMSATBBufferClosure : public SATBBufferClosure {
2645 private:
2646 CMTask* _task;
2647 G1CollectedHeap* _g1h;
2648
2649 // This is very similar to CMTask::deal_with_reference, but with
2650 // more relaxed requirements for the argument, so this must be more
2651 // circumspect about treating the argument as an object.
2652 void do_entry(void* entry) const {
2653 _task->increment_refs_reached();
2654 HeapRegion* hr = _g1h->heap_region_containing_raw(entry);
2655 if (entry < hr->next_top_at_mark_start()) {
2656 // Until we get here, we don't know whether entry refers to a valid
2657 // object; it could instead have been a stale reference.
2658 oop obj = static_cast<oop>(entry);
2659 assert(obj->is_oop(true /* ignore mark word */),
2660 err_msg("Invalid oop in SATB buffer: " PTR_FORMAT, p2i(obj)));
2661 _task->make_reference_grey(obj, hr);
2662 }
2663 }
2664
2665 public:
2666 CMSATBBufferClosure(CMTask* task, G1CollectedHeap* g1h)
2667 : _task(task), _g1h(g1h) { }
2668
2669 virtual void do_buffer(void** buffer, size_t size) {
2670 for (size_t i = 0; i < size; ++i) {
2671 do_entry(buffer[i]);
2672 }
2673 }
2674 };
2675
2676 class G1RemarkThreadsClosure : public ThreadClosure {
2677 CMSATBBufferClosure _cm_satb_cl;
2678 G1CMOopClosure _cm_cl;
2679 MarkingCodeBlobClosure _code_cl;
2680 int _thread_parity;
2681 bool _is_par;
2682
2683 public:
2684 G1RemarkThreadsClosure(G1CollectedHeap* g1h, CMTask* task, bool is_par) :
2685 _cm_satb_cl(task, g1h),
2686 _cm_cl(g1h, g1h->concurrent_mark(), task),
2687 _code_cl(&_cm_cl, !CodeBlobToOopClosure::FixRelocations),
2688 _thread_parity(SharedHeap::heap()->strong_roots_parity()), _is_par(is_par) {}
2689
2690 void do_thread(Thread* thread) {
2691 if (thread->is_Java_thread()) {
2692 if (thread->claim_oops_do(_is_par, _thread_parity)) {
2693 JavaThread* jt = (JavaThread*)thread;
2694
2695 // In theory it should not be neccessary to explicitly walk the nmethods to find roots for concurrent marking
2696 // however the liveness of oops reachable from nmethods have very complex lifecycles:
2697 // * Alive if on the stack of an executing method
2698 // * Weakly reachable otherwise
2699 // Some objects reachable from nmethods, such as the class loader (or klass_holder) of the receiver should be
2700 // live by the SATB invariant but other oops recorded in nmethods may behave differently.
2701 jt->nmethods_do(&_code_cl);
2702
2703 jt->satb_mark_queue().apply_closure_and_empty(&_cm_satb_cl);
2704 }
2705 } else if (thread->is_VM_thread()) {
2706 if (thread->claim_oops_do(_is_par, _thread_parity)) {
2707 JavaThread::satb_mark_queue_set().shared_satb_queue()->apply_closure_and_empty(&_cm_satb_cl);
2708 }
2709 }
2710 }
2711 };
2712
2713 class CMRemarkTask: public AbstractGangTask {
2714 private:
2715 ConcurrentMark* _cm;
2716 bool _is_serial;
2717 public:
2718 void work(uint worker_id) {
2719 // Since all available tasks are actually started, we should
2720 // only proceed if we're supposed to be actived.
2721 if (worker_id < _cm->active_tasks()) {
2722 CMTask* task = _cm->task(worker_id);
2723 task->record_start_time();
2724 {
2725 ResourceMark rm;
2726 HandleMark hm;
2727
3978 if (_cm->verbose_low()) {
3979 gclog_or_tty->print_cr("[%u] drained global stack, size = " SIZE_FORMAT,
3980 _worker_id, _cm->mark_stack_size());
3981 }
3982 }
3983 }
3984
3985 // SATB Queue has several assumptions on whether to call the par or
3986 // non-par versions of the methods. this is why some of the code is
3987 // replicated. We should really get rid of the single-threaded version
3988 // of the code to simplify things.
3989 void CMTask::drain_satb_buffers() {
3990 if (has_aborted()) return;
3991
3992 // We set this so that the regular clock knows that we're in the
3993 // middle of draining buffers and doesn't set the abort flag when it
3994 // notices that SATB buffers are available for draining. It'd be
3995 // very counter productive if it did that. :-)
3996 _draining_satb_buffers = true;
3997
3998 CMSATBBufferClosure satb_cl(this, _g1h);
3999 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set();
4000
4001 // This keeps claiming and applying the closure to completed buffers
4002 // until we run out of buffers or we need to abort.
4003 while (!has_aborted() &&
4004 satb_mq_set.apply_closure_to_completed_buffer(&satb_cl)) {
4005 if (_cm->verbose_medium()) {
4006 gclog_or_tty->print_cr("[%u] processed an SATB buffer", _worker_id);
4007 }
4008 statsOnly( ++_satb_buffers_processed );
4009 regular_clock_call();
4010 }
4011
4012 _draining_satb_buffers = false;
4013
4014 assert(has_aborted() ||
4015 concurrent() ||
4016 satb_mq_set.completed_buffers_num() == 0, "invariant");
4017
4018 // again, this was a potentially expensive operation, decrease the
4019 // limits to get the regular clock call early
4020 decrease_limits();
4021 }
4022
4023 void CMTask::print_stats() {
4024 gclog_or_tty->print_cr("Marking Stats, task = %u, calls = %d",
|