3737
3738 // this operation was quite expensive, so decrease the limits
3739 decrease_limits();
3740 }
3741
3742 void CMTask::drain_local_queue(bool partially) {
3743 if (has_aborted()) return;
3744
3745 // Decide what the target size is, depending whether we're going to
3746 // drain it partially (so that other tasks can steal if they run out
3747 // of things to do) or totally (at the very end).
3748 size_t target_size;
3749 if (partially) {
3750 target_size = MIN2((size_t)_task_queue->max_elems()/3, GCDrainStackTargetSize);
3751 } else {
3752 target_size = 0;
3753 }
3754
3755 if (_task_queue->size() > target_size) {
3756 if (_cm->verbose_high()) {
3757 gclog_or_tty->print_cr("[%u] draining local queue, target size = %d",
3758 _worker_id, target_size);
3759 }
3760
3761 oop obj;
3762 bool ret = _task_queue->pop_local(obj);
3763 while (ret) {
3764 statsOnly( ++_local_pops );
3765
3766 if (_cm->verbose_high()) {
3767 gclog_or_tty->print_cr("[%u] popped "PTR_FORMAT, _worker_id,
3768 (void*) obj);
3769 }
3770
3771 assert(_g1h->is_in_g1_reserved((HeapWord*) obj), "invariant" );
3772 assert(!_g1h->is_on_master_free_list(
3773 _g1h->heap_region_containing((HeapWord*) obj)), "invariant");
3774
3775 scan_object(obj);
3776
3777 if (_task_queue->size() <= target_size || has_aborted()) {
3778 ret = false;
3779 } else {
3780 ret = _task_queue->pop_local(obj);
3781 }
3782 }
3783
3784 if (_cm->verbose_high()) {
3785 gclog_or_tty->print_cr("[%u] drained local queue, size = %d",
3786 _worker_id, _task_queue->size());
3787 }
3788 }
3789 }
3790
3791 void CMTask::drain_global_stack(bool partially) {
3792 if (has_aborted()) return;
3793
3794 // We have a policy to drain the local queue before we attempt to
3795 // drain the global stack.
3796 assert(partially || _task_queue->size() == 0, "invariant");
3797
3798 // Decide what the target size is, depending whether we're going to
3799 // drain it partially (so that other tasks can steal if they run out
3800 // of things to do) or totally (at the very end). Notice that,
3801 // because we move entries from the global stack in chunks or
3802 // because another task might be doing the same, we might in fact
3803 // drop below the target. But, this is not a problem.
3804 size_t target_size;
3805 if (partially) {
3806 target_size = _cm->partial_mark_stack_size_target();
3807 } else {
3808 target_size = 0;
3809 }
3810
3811 if (_cm->mark_stack_size() > target_size) {
3812 if (_cm->verbose_low()) {
3813 gclog_or_tty->print_cr("[%u] draining global_stack, target size %d",
3814 _worker_id, target_size);
3815 }
3816
3817 while (!has_aborted() && _cm->mark_stack_size() > target_size) {
3818 get_entries_from_global_stack();
3819 drain_local_queue(partially);
3820 }
3821
3822 if (_cm->verbose_low()) {
3823 gclog_or_tty->print_cr("[%u] drained global stack, size = %d",
3824 _worker_id, _cm->mark_stack_size());
3825 }
3826 }
3827 }
3828
3829 // SATB Queue has several assumptions on whether to call the par or
3830 // non-par versions of the methods. this is why some of the code is
3831 // replicated. We should really get rid of the single-threaded version
3832 // of the code to simplify things.
3833 void CMTask::drain_satb_buffers() {
3834 if (has_aborted()) return;
3835
3836 // We set this so that the regular clock knows that we're in the
3837 // middle of draining buffers and doesn't set the abort flag when it
3838 // notices that SATB buffers are available for draining. It'd be
3839 // very counter productive if it did that. :-)
3840 _draining_satb_buffers = true;
3841
3842 CMObjectClosure oc(this);
3843 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set();
|
3737
3738 // this operation was quite expensive, so decrease the limits
3739 decrease_limits();
3740 }
3741
3742 void CMTask::drain_local_queue(bool partially) {
3743 if (has_aborted()) return;
3744
3745 // Decide what the target size is, depending whether we're going to
3746 // drain it partially (so that other tasks can steal if they run out
3747 // of things to do) or totally (at the very end).
3748 size_t target_size;
3749 if (partially) {
3750 target_size = MIN2((size_t)_task_queue->max_elems()/3, GCDrainStackTargetSize);
3751 } else {
3752 target_size = 0;
3753 }
3754
3755 if (_task_queue->size() > target_size) {
3756 if (_cm->verbose_high()) {
3757 gclog_or_tty->print_cr("[%u] draining local queue, target size = " SIZE_FORMAT,
3758 _worker_id, target_size);
3759 }
3760
3761 oop obj;
3762 bool ret = _task_queue->pop_local(obj);
3763 while (ret) {
3764 statsOnly( ++_local_pops );
3765
3766 if (_cm->verbose_high()) {
3767 gclog_or_tty->print_cr("[%u] popped "PTR_FORMAT, _worker_id,
3768 (void*) obj);
3769 }
3770
3771 assert(_g1h->is_in_g1_reserved((HeapWord*) obj), "invariant" );
3772 assert(!_g1h->is_on_master_free_list(
3773 _g1h->heap_region_containing((HeapWord*) obj)), "invariant");
3774
3775 scan_object(obj);
3776
3777 if (_task_queue->size() <= target_size || has_aborted()) {
3778 ret = false;
3779 } else {
3780 ret = _task_queue->pop_local(obj);
3781 }
3782 }
3783
3784 if (_cm->verbose_high()) {
3785 gclog_or_tty->print_cr("[%u] drained local queue, size = %u",
3786 _worker_id, _task_queue->size());
3787 }
3788 }
3789 }
3790
3791 void CMTask::drain_global_stack(bool partially) {
3792 if (has_aborted()) return;
3793
3794 // We have a policy to drain the local queue before we attempt to
3795 // drain the global stack.
3796 assert(partially || _task_queue->size() == 0, "invariant");
3797
3798 // Decide what the target size is, depending whether we're going to
3799 // drain it partially (so that other tasks can steal if they run out
3800 // of things to do) or totally (at the very end). Notice that,
3801 // because we move entries from the global stack in chunks or
3802 // because another task might be doing the same, we might in fact
3803 // drop below the target. But, this is not a problem.
3804 size_t target_size;
3805 if (partially) {
3806 target_size = _cm->partial_mark_stack_size_target();
3807 } else {
3808 target_size = 0;
3809 }
3810
3811 if (_cm->mark_stack_size() > target_size) {
3812 if (_cm->verbose_low()) {
3813 gclog_or_tty->print_cr("[%u] draining global_stack, target size " SIZE_FORMAT,
3814 _worker_id, target_size);
3815 }
3816
3817 while (!has_aborted() && _cm->mark_stack_size() > target_size) {
3818 get_entries_from_global_stack();
3819 drain_local_queue(partially);
3820 }
3821
3822 if (_cm->verbose_low()) {
3823 gclog_or_tty->print_cr("[%u] drained global stack, size = " SIZE_FORMAT,
3824 _worker_id, _cm->mark_stack_size());
3825 }
3826 }
3827 }
3828
3829 // SATB Queue has several assumptions on whether to call the par or
3830 // non-par versions of the methods. this is why some of the code is
3831 // replicated. We should really get rid of the single-threaded version
3832 // of the code to simplify things.
3833 void CMTask::drain_satb_buffers() {
3834 if (has_aborted()) return;
3835
3836 // We set this so that the regular clock knows that we're in the
3837 // middle of draining buffers and doesn't set the abort flag when it
3838 // notices that SATB buffers are available for draining. It'd be
3839 // very counter productive if it did that. :-)
3840 _draining_satb_buffers = true;
3841
3842 CMObjectClosure oc(this);
3843 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set();
|