1 /*
2 * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
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 "gc/g1/dirtyCardQueue.hpp"
27 #include "gc/g1/g1BarrierSet.hpp"
28 #include "gc/g1/g1BlockOffsetTable.inline.hpp"
29 #include "gc/g1/g1CardTable.inline.hpp"
30 #include "gc/g1/g1CollectedHeap.inline.hpp"
31 #include "gc/g1/g1ConcurrentRefine.hpp"
32 #include "gc/g1/g1FromCardCache.hpp"
33 #include "gc/g1/g1GCPhaseTimes.hpp"
34 #include "gc/g1/g1HotCardCache.hpp"
35 #include "gc/g1/g1OopClosures.inline.hpp"
36 #include "gc/g1/g1RootClosures.hpp"
37 #include "gc/g1/g1RemSet.hpp"
38 #include "gc/g1/heapRegion.inline.hpp"
39 #include "gc/g1/heapRegionManager.inline.hpp"
40 #include "gc/g1/heapRegionRemSet.hpp"
41 #include "gc/shared/gcTraceTime.inline.hpp"
42 #include "gc/shared/suspendibleThreadSet.hpp"
43 #include "jfr/jfrEvents.hpp"
44 #include "memory/iterator.hpp"
45 #include "memory/resourceArea.hpp"
46 #include "oops/access.inline.hpp"
47 #include "oops/oop.inline.hpp"
48 #include "runtime/os.hpp"
49 #include "utilities/align.hpp"
50 #include "utilities/globalDefinitions.hpp"
51 #include "utilities/intHisto.hpp"
283
284 G1RemSet::G1RemSet(G1CollectedHeap* g1h,
285 G1CardTable* ct,
286 G1HotCardCache* hot_card_cache) :
287 _scan_state(new G1RemSetScanState()),
288 _prev_period_summary(),
289 _g1h(g1h),
290 _num_conc_refined_cards(0),
291 _ct(ct),
292 _g1p(_g1h->g1_policy()),
293 _hot_card_cache(hot_card_cache) {
294 }
295
296 G1RemSet::~G1RemSet() {
297 if (_scan_state != NULL) {
298 delete _scan_state;
299 }
300 }
301
302 uint G1RemSet::num_par_rem_sets() {
303 return DirtyCardQueueSet::num_par_ids() + G1ConcurrentRefine::max_num_threads() + MAX2(ConcGCThreads, ParallelGCThreads);
304 }
305
306 void G1RemSet::initialize(size_t capacity, uint max_regions) {
307 G1FromCardCache::initialize(num_par_rem_sets(), max_regions);
308 _scan_state->initialize(max_regions);
309 }
310
311 G1ScanRSForRegionClosure::G1ScanRSForRegionClosure(G1RemSetScanState* scan_state,
312 G1ScanObjsDuringScanRSClosure* scan_obj_on_card,
313 G1ParScanThreadState* pss,
314 G1GCPhaseTimes::GCParPhases phase,
315 uint worker_i) :
316 _g1h(G1CollectedHeap::heap()),
317 _ct(_g1h->card_table()),
318 _pss(pss),
319 _scan_objs_on_card_cl(scan_obj_on_card),
320 _scan_state(scan_state),
321 _phase(phase),
322 _worker_i(worker_i),
323 _cards_scanned(0),
439
440 void G1RemSet::scan_rem_set(G1ParScanThreadState* pss, uint worker_i) {
441 G1ScanObjsDuringScanRSClosure scan_cl(_g1h, pss);
442 G1ScanRSForRegionClosure cl(_scan_state, &scan_cl, pss, G1GCPhaseTimes::ScanRS, worker_i);
443 _g1h->collection_set_iterate_from(&cl, worker_i);
444
445 G1GCPhaseTimes* p = _g1p->phase_times();
446
447 p->record_time_secs(G1GCPhaseTimes::ScanRS, worker_i, cl.rem_set_root_scan_time().seconds());
448 p->add_time_secs(G1GCPhaseTimes::ObjCopy, worker_i, cl.rem_set_trim_partially_time().seconds());
449
450 p->record_thread_work_item(G1GCPhaseTimes::ScanRS, worker_i, cl.cards_scanned(), G1GCPhaseTimes::ScanRSScannedCards);
451 p->record_thread_work_item(G1GCPhaseTimes::ScanRS, worker_i, cl.cards_claimed(), G1GCPhaseTimes::ScanRSClaimedCards);
452 p->record_thread_work_item(G1GCPhaseTimes::ScanRS, worker_i, cl.cards_skipped(), G1GCPhaseTimes::ScanRSSkippedCards);
453
454 p->record_time_secs(G1GCPhaseTimes::CodeRoots, worker_i, cl.strong_code_root_scan_time().seconds());
455 p->add_time_secs(G1GCPhaseTimes::ObjCopy, worker_i, cl.strong_code_root_trim_partially_time().seconds());
456 }
457
458 // Closure used for updating rem sets. Only called during an evacuation pause.
459 class G1RefineCardClosure: public CardTableEntryClosure {
460 G1RemSet* _g1rs;
461 G1ScanObjsDuringUpdateRSClosure* _update_rs_cl;
462
463 size_t _cards_scanned;
464 size_t _cards_skipped;
465 public:
466 G1RefineCardClosure(G1CollectedHeap* g1h, G1ScanObjsDuringUpdateRSClosure* update_rs_cl) :
467 _g1rs(g1h->g1_rem_set()), _update_rs_cl(update_rs_cl), _cards_scanned(0), _cards_skipped(0)
468 {}
469
470 bool do_card_ptr(jbyte* card_ptr, uint worker_i) {
471 // The only time we care about recording cards that
472 // contain references that point into the collection set
473 // is during RSet updating within an evacuation pause.
474 // In this case worker_i should be the id of a GC worker thread.
475 assert(SafepointSynchronize::is_at_safepoint(), "not during an evacuation pause");
476
477 bool card_scanned = _g1rs->refine_card_during_gc(card_ptr, _update_rs_cl);
478
479 if (card_scanned) {
503
504 // Now apply the closure to all remaining log entries.
505 {
506 G1EvacPhaseTimesTracker x(p, pss, G1GCPhaseTimes::UpdateRS, worker_i);
507
508 G1ScanObjsDuringUpdateRSClosure update_rs_cl(_g1h, pss);
509 G1RefineCardClosure refine_card_cl(_g1h, &update_rs_cl);
510 _g1h->iterate_dirty_card_closure(&refine_card_cl, worker_i);
511
512 p->record_thread_work_item(G1GCPhaseTimes::UpdateRS, worker_i, refine_card_cl.cards_scanned(), G1GCPhaseTimes::UpdateRSScannedCards);
513 p->record_thread_work_item(G1GCPhaseTimes::UpdateRS, worker_i, refine_card_cl.cards_skipped(), G1GCPhaseTimes::UpdateRSSkippedCards);
514 }
515 }
516
517 void G1RemSet::oops_into_collection_set_do(G1ParScanThreadState* pss, uint worker_i) {
518 update_rem_set(pss, worker_i);
519 scan_rem_set(pss, worker_i);;
520 }
521
522 void G1RemSet::prepare_for_oops_into_collection_set_do() {
523 DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
524 dcqs.concatenate_logs();
525
526 _scan_state->reset();
527 }
528
529 void G1RemSet::cleanup_after_oops_into_collection_set_do() {
530 G1GCPhaseTimes* phase_times = _g1h->g1_policy()->phase_times();
531
532 // Set all cards back to clean.
533 double start = os::elapsedTime();
534 _scan_state->clear_card_table(_g1h->workers());
535 phase_times->record_clear_ct_time((os::elapsedTime() - start) * 1000.0);
536 }
537
538 inline void check_card_ptr(jbyte* card_ptr, G1CardTable* ct) {
539 #ifdef ASSERT
540 G1CollectedHeap* g1h = G1CollectedHeap::heap();
541 assert(g1h->is_in_exact(ct->addr_for(card_ptr)),
542 "Card at " PTR_FORMAT " index " SIZE_FORMAT " representing heap at " PTR_FORMAT " (%u) must be in committed heap",
543 p2i(card_ptr),
660 MemRegion dirty_region(start, MIN2(scan_limit, end));
661 assert(!dirty_region.is_empty(), "sanity");
662
663 G1ConcurrentRefineOopClosure conc_refine_cl(_g1h, worker_i);
664
665 bool card_processed =
666 r->oops_on_card_seq_iterate_careful<false>(dirty_region, &conc_refine_cl);
667
668 // If unable to process the card then we encountered an unparsable
669 // part of the heap (e.g. a partially allocated object) while
670 // processing a stale card. Despite the card being stale, redirty
671 // and re-enqueue, because we've already cleaned the card. Without
672 // this we could incorrectly discard a non-stale card.
673 if (!card_processed) {
674 // The card might have gotten re-dirtied and re-enqueued while we
675 // worked. (In fact, it's pretty likely.)
676 if (*card_ptr != G1CardTable::dirty_card_val()) {
677 *card_ptr = G1CardTable::dirty_card_val();
678 MutexLockerEx x(Shared_DirtyCardQ_lock,
679 Mutex::_no_safepoint_check_flag);
680 DirtyCardQueue* sdcq =
681 G1BarrierSet::dirty_card_queue_set().shared_dirty_card_queue();
682 sdcq->enqueue(card_ptr);
683 }
684 } else {
685 _num_conc_refined_cards++; // Unsynchronized update, only used for logging.
686 }
687 }
688
689 bool G1RemSet::refine_card_during_gc(jbyte* card_ptr,
690 G1ScanObjsDuringUpdateRSClosure* update_rs_cl) {
691 assert(_g1h->is_gc_active(), "Only call during GC");
692
693 // Construct the region representing the card.
694 HeapWord* card_start = _ct->addr_for(card_ptr);
695 // And find the region containing it.
696 uint const card_region_idx = _g1h->addr_to_region(card_start);
697
698 HeapWord* scan_limit = _scan_state->scan_top(card_region_idx);
699 if (scan_limit == NULL) {
700 // This is a card into an uncommitted region. We need to bail out early as we
|
1 /*
2 * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
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 "gc/g1/g1BarrierSet.hpp"
27 #include "gc/g1/g1BlockOffsetTable.inline.hpp"
28 #include "gc/g1/g1CardTable.inline.hpp"
29 #include "gc/g1/g1CollectedHeap.inline.hpp"
30 #include "gc/g1/g1ConcurrentRefine.hpp"
31 #include "gc/g1/g1DirtyCardQueue.hpp"
32 #include "gc/g1/g1FromCardCache.hpp"
33 #include "gc/g1/g1GCPhaseTimes.hpp"
34 #include "gc/g1/g1HotCardCache.hpp"
35 #include "gc/g1/g1OopClosures.inline.hpp"
36 #include "gc/g1/g1RootClosures.hpp"
37 #include "gc/g1/g1RemSet.hpp"
38 #include "gc/g1/heapRegion.inline.hpp"
39 #include "gc/g1/heapRegionManager.inline.hpp"
40 #include "gc/g1/heapRegionRemSet.hpp"
41 #include "gc/shared/gcTraceTime.inline.hpp"
42 #include "gc/shared/suspendibleThreadSet.hpp"
43 #include "jfr/jfrEvents.hpp"
44 #include "memory/iterator.hpp"
45 #include "memory/resourceArea.hpp"
46 #include "oops/access.inline.hpp"
47 #include "oops/oop.inline.hpp"
48 #include "runtime/os.hpp"
49 #include "utilities/align.hpp"
50 #include "utilities/globalDefinitions.hpp"
51 #include "utilities/intHisto.hpp"
283
284 G1RemSet::G1RemSet(G1CollectedHeap* g1h,
285 G1CardTable* ct,
286 G1HotCardCache* hot_card_cache) :
287 _scan_state(new G1RemSetScanState()),
288 _prev_period_summary(),
289 _g1h(g1h),
290 _num_conc_refined_cards(0),
291 _ct(ct),
292 _g1p(_g1h->g1_policy()),
293 _hot_card_cache(hot_card_cache) {
294 }
295
296 G1RemSet::~G1RemSet() {
297 if (_scan_state != NULL) {
298 delete _scan_state;
299 }
300 }
301
302 uint G1RemSet::num_par_rem_sets() {
303 return G1DirtyCardQueueSet::num_par_ids() + G1ConcurrentRefine::max_num_threads() + MAX2(ConcGCThreads, ParallelGCThreads);
304 }
305
306 void G1RemSet::initialize(size_t capacity, uint max_regions) {
307 G1FromCardCache::initialize(num_par_rem_sets(), max_regions);
308 _scan_state->initialize(max_regions);
309 }
310
311 G1ScanRSForRegionClosure::G1ScanRSForRegionClosure(G1RemSetScanState* scan_state,
312 G1ScanObjsDuringScanRSClosure* scan_obj_on_card,
313 G1ParScanThreadState* pss,
314 G1GCPhaseTimes::GCParPhases phase,
315 uint worker_i) :
316 _g1h(G1CollectedHeap::heap()),
317 _ct(_g1h->card_table()),
318 _pss(pss),
319 _scan_objs_on_card_cl(scan_obj_on_card),
320 _scan_state(scan_state),
321 _phase(phase),
322 _worker_i(worker_i),
323 _cards_scanned(0),
439
440 void G1RemSet::scan_rem_set(G1ParScanThreadState* pss, uint worker_i) {
441 G1ScanObjsDuringScanRSClosure scan_cl(_g1h, pss);
442 G1ScanRSForRegionClosure cl(_scan_state, &scan_cl, pss, G1GCPhaseTimes::ScanRS, worker_i);
443 _g1h->collection_set_iterate_from(&cl, worker_i);
444
445 G1GCPhaseTimes* p = _g1p->phase_times();
446
447 p->record_time_secs(G1GCPhaseTimes::ScanRS, worker_i, cl.rem_set_root_scan_time().seconds());
448 p->add_time_secs(G1GCPhaseTimes::ObjCopy, worker_i, cl.rem_set_trim_partially_time().seconds());
449
450 p->record_thread_work_item(G1GCPhaseTimes::ScanRS, worker_i, cl.cards_scanned(), G1GCPhaseTimes::ScanRSScannedCards);
451 p->record_thread_work_item(G1GCPhaseTimes::ScanRS, worker_i, cl.cards_claimed(), G1GCPhaseTimes::ScanRSClaimedCards);
452 p->record_thread_work_item(G1GCPhaseTimes::ScanRS, worker_i, cl.cards_skipped(), G1GCPhaseTimes::ScanRSSkippedCards);
453
454 p->record_time_secs(G1GCPhaseTimes::CodeRoots, worker_i, cl.strong_code_root_scan_time().seconds());
455 p->add_time_secs(G1GCPhaseTimes::ObjCopy, worker_i, cl.strong_code_root_trim_partially_time().seconds());
456 }
457
458 // Closure used for updating rem sets. Only called during an evacuation pause.
459 class G1RefineCardClosure: public G1CardTableEntryClosure {
460 G1RemSet* _g1rs;
461 G1ScanObjsDuringUpdateRSClosure* _update_rs_cl;
462
463 size_t _cards_scanned;
464 size_t _cards_skipped;
465 public:
466 G1RefineCardClosure(G1CollectedHeap* g1h, G1ScanObjsDuringUpdateRSClosure* update_rs_cl) :
467 _g1rs(g1h->g1_rem_set()), _update_rs_cl(update_rs_cl), _cards_scanned(0), _cards_skipped(0)
468 {}
469
470 bool do_card_ptr(jbyte* card_ptr, uint worker_i) {
471 // The only time we care about recording cards that
472 // contain references that point into the collection set
473 // is during RSet updating within an evacuation pause.
474 // In this case worker_i should be the id of a GC worker thread.
475 assert(SafepointSynchronize::is_at_safepoint(), "not during an evacuation pause");
476
477 bool card_scanned = _g1rs->refine_card_during_gc(card_ptr, _update_rs_cl);
478
479 if (card_scanned) {
503
504 // Now apply the closure to all remaining log entries.
505 {
506 G1EvacPhaseTimesTracker x(p, pss, G1GCPhaseTimes::UpdateRS, worker_i);
507
508 G1ScanObjsDuringUpdateRSClosure update_rs_cl(_g1h, pss);
509 G1RefineCardClosure refine_card_cl(_g1h, &update_rs_cl);
510 _g1h->iterate_dirty_card_closure(&refine_card_cl, worker_i);
511
512 p->record_thread_work_item(G1GCPhaseTimes::UpdateRS, worker_i, refine_card_cl.cards_scanned(), G1GCPhaseTimes::UpdateRSScannedCards);
513 p->record_thread_work_item(G1GCPhaseTimes::UpdateRS, worker_i, refine_card_cl.cards_skipped(), G1GCPhaseTimes::UpdateRSSkippedCards);
514 }
515 }
516
517 void G1RemSet::oops_into_collection_set_do(G1ParScanThreadState* pss, uint worker_i) {
518 update_rem_set(pss, worker_i);
519 scan_rem_set(pss, worker_i);;
520 }
521
522 void G1RemSet::prepare_for_oops_into_collection_set_do() {
523 G1DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
524 dcqs.concatenate_logs();
525
526 _scan_state->reset();
527 }
528
529 void G1RemSet::cleanup_after_oops_into_collection_set_do() {
530 G1GCPhaseTimes* phase_times = _g1h->g1_policy()->phase_times();
531
532 // Set all cards back to clean.
533 double start = os::elapsedTime();
534 _scan_state->clear_card_table(_g1h->workers());
535 phase_times->record_clear_ct_time((os::elapsedTime() - start) * 1000.0);
536 }
537
538 inline void check_card_ptr(jbyte* card_ptr, G1CardTable* ct) {
539 #ifdef ASSERT
540 G1CollectedHeap* g1h = G1CollectedHeap::heap();
541 assert(g1h->is_in_exact(ct->addr_for(card_ptr)),
542 "Card at " PTR_FORMAT " index " SIZE_FORMAT " representing heap at " PTR_FORMAT " (%u) must be in committed heap",
543 p2i(card_ptr),
660 MemRegion dirty_region(start, MIN2(scan_limit, end));
661 assert(!dirty_region.is_empty(), "sanity");
662
663 G1ConcurrentRefineOopClosure conc_refine_cl(_g1h, worker_i);
664
665 bool card_processed =
666 r->oops_on_card_seq_iterate_careful<false>(dirty_region, &conc_refine_cl);
667
668 // If unable to process the card then we encountered an unparsable
669 // part of the heap (e.g. a partially allocated object) while
670 // processing a stale card. Despite the card being stale, redirty
671 // and re-enqueue, because we've already cleaned the card. Without
672 // this we could incorrectly discard a non-stale card.
673 if (!card_processed) {
674 // The card might have gotten re-dirtied and re-enqueued while we
675 // worked. (In fact, it's pretty likely.)
676 if (*card_ptr != G1CardTable::dirty_card_val()) {
677 *card_ptr = G1CardTable::dirty_card_val();
678 MutexLockerEx x(Shared_DirtyCardQ_lock,
679 Mutex::_no_safepoint_check_flag);
680 G1DirtyCardQueue* sdcq =
681 G1BarrierSet::dirty_card_queue_set().shared_dirty_card_queue();
682 sdcq->enqueue(card_ptr);
683 }
684 } else {
685 _num_conc_refined_cards++; // Unsynchronized update, only used for logging.
686 }
687 }
688
689 bool G1RemSet::refine_card_during_gc(jbyte* card_ptr,
690 G1ScanObjsDuringUpdateRSClosure* update_rs_cl) {
691 assert(_g1h->is_gc_active(), "Only call during GC");
692
693 // Construct the region representing the card.
694 HeapWord* card_start = _ct->addr_for(card_ptr);
695 // And find the region containing it.
696 uint const card_region_idx = _g1h->addr_to_region(card_start);
697
698 HeapWord* scan_limit = _scan_state->scan_top(card_region_idx);
699 if (scan_limit == NULL) {
700 // This is a card into an uncommitted region. We need to bail out early as we
|