1 /* 2 * Copyright (c) 2013, 2015, Red Hat, Inc. and/or its affiliates. 3 * 4 * This code is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License version 2 only, as 6 * published by the Free Software Foundation. 7 * 8 * This code is distributed in the hope that it will be useful, but WITHOUT 9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 * version 2 for more details (a copy is included in the LICENSE file that 12 * accompanied this code). 13 * 14 * You should have received a copy of the GNU General Public License version 15 * 2 along with this work; if not, write to the Free Software Foundation, 16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17 * 18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19 * or visit www.oracle.com if you need additional information or have any 20 * questions. 21 * 22 */ 23 24 #include "precompiled.hpp" 25 #include "gc/shared/gcTraceTime.inline.hpp" 26 #include "gc/shared/vmGCOperations.hpp" 27 #include "gc/shenandoah/shenandoahConcurrentMark.inline.hpp" 28 #include "gc/shenandoah/shenandoahPhaseTimings.hpp" 29 #include "gc/shenandoah/shenandoahHeap.inline.hpp" 30 #include "gc/shenandoah/shenandoahMarkCompact.hpp" 31 #include "gc/shenandoah/shenandoahPartialGC.hpp" 32 #include "gc/shenandoah/shenandoahUtils.hpp" 33 #include "gc/shenandoah/shenandoahVerifier.hpp" 34 #include "gc/shenandoah/shenandoahWorkGroup.hpp" 35 #include "gc/shenandoah/shenandoahWorkerPolicy.hpp" 36 #include "gc/shenandoah/vm_operations_shenandoah.hpp" 37 38 void VM_ShenandoahInitMark::doit() { 39 ShenandoahGCPauseMark mark(_gc_id, ShenandoahPhaseTimings::init_mark, SvcGCMarker::OTHER); 40 41 ShenandoahHeap* sh = ShenandoahHeap::heap(); 42 43 GCTraceTime(Info, gc) time("Pause Init Mark", sh->gc_timer()); 44 WorkGang* workers = sh->workers(); 45 46 // Calculate workers for initial marking 47 uint nworkers = ShenandoahWorkerPolicy::calc_workers_for_init_marking(); 48 49 ShenandoahWorkerScope scope(workers, nworkers); 50 51 assert(sh->is_next_bitmap_clear(), "need clear marking bitmap"); 52 53 sh->start_concurrent_marking(); 54 } 55 56 void VM_ShenandoahFullGC::doit() { 57 ShenandoahGCPauseMark mark(_gc_id, ShenandoahPhaseTimings::full_gc, SvcGCMarker::FULL); 58 ShenandoahMarkCompact::do_mark_compact(_gc_cause); 59 } 60 61 bool VM_ShenandoahReferenceOperation::doit_prologue() { 62 Heap_lock->lock(); 63 return true; 64 } 65 66 void VM_ShenandoahReferenceOperation::doit_epilogue() { 67 if (Universe::has_reference_pending_list()) { 68 Heap_lock->notify_all(); 69 } 70 Heap_lock->unlock(); 71 } 72 73 void VM_ShenandoahFinalMarkStartEvac::doit() { 74 ShenandoahGCPauseMark mark(_gc_id, ShenandoahPhaseTimings::final_mark, SvcGCMarker::OTHER); 75 76 ShenandoahHeap *sh = ShenandoahHeap::heap(); 77 78 // It is critical that we 79 // evacuate roots right after finishing marking, so that we don't 80 // get unmarked objects in the roots. 81 // Setup workers for final marking 82 WorkGang* workers = sh->workers(); 83 uint n_workers = ShenandoahWorkerPolicy::calc_workers_for_final_marking(); 84 ShenandoahWorkerScope scope(workers, n_workers); 85 86 if (! sh->cancelled_concgc()) { 87 GCTraceTime(Info, gc) time("Pause Final Mark", sh->gc_timer(), GCCause::_no_gc, true); 88 sh->concurrentMark()->finish_mark_from_roots(); 89 sh->stop_concurrent_marking(); 90 91 { 92 ShenandoahGCPhase prepare_evac(ShenandoahPhaseTimings::prepare_evac); 93 sh->prepare_for_concurrent_evacuation(); 94 } 95 96 // If collection set has candidates, start evacuation. 97 // Otherwise, bypass the rest of the cycle. 98 if (!sh->collection_set()->is_empty()) { 99 sh->set_evacuation_in_progress_at_safepoint(true); 100 // From here on, we need to update references. 101 sh->set_need_update_refs(true); 102 103 ShenandoahGCPhase init_evac(ShenandoahPhaseTimings::init_evac); 104 sh->evacuate_and_update_roots(); 105 } 106 } else { 107 GCTraceTime(Info, gc) time("Cancel Concurrent Mark", sh->gc_timer(), GCCause::_no_gc, true); 108 sh->concurrentMark()->cancel(); 109 sh->stop_concurrent_marking(); 110 } 111 } 112 113 void VM_ShenandoahPartialGC::doit() { 114 ShenandoahGCPauseMark mark(_gc_id, ShenandoahPhaseTimings::partial_gc, SvcGCMarker::MINOR); 115 ShenandoahHeap::heap()->do_partial_collection(); 116 } 117 118 void VM_ShenandoahInitUpdateRefs::doit() { 119 ShenandoahGCPauseMark mark(_gc_id, ShenandoahPhaseTimings::init_update_refs, SvcGCMarker::OTHER); 120 121 ShenandoahHeap *sh = ShenandoahHeap::heap(); 122 GCTraceTime(Info, gc) time("Pause Init Update Refs", sh->gc_timer(), GCCause::_no_gc); 123 124 sh->prepare_update_refs(); 125 } 126 127 void VM_ShenandoahFinalUpdateRefs::doit() { 128 ShenandoahGCPauseMark mark(_gc_id, ShenandoahPhaseTimings::final_update_refs, SvcGCMarker::OTHER); 129 130 ShenandoahHeap *sh = ShenandoahHeap::heap(); 131 GCTraceTime(Info, gc) time("Pause Final Update Refs", sh->gc_timer(), GCCause::_no_gc, true); 132 WorkGang* workers = sh->workers(); 133 uint n_workers = ShenandoahWorkerPolicy::calc_workers_for_final_update_ref(); 134 ShenandoahWorkerScope scope(workers, n_workers); 135 136 sh->finish_update_refs(); 137 } 138 139 void VM_ShenandoahVerifyHeapAfterEvacuation::doit() { 140 ShenandoahGCPauseMark mark(_gc_id, ShenandoahPhaseTimings::pause_other, SvcGCMarker::OTHER); 141 ShenandoahHeap::heap()->verifier()->verify_after_evacuation(); 142 }