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_bitmap_clear(), "need clear marking bitmap"); 52 53 sh->set_bitmap_valid(false); 54 55 sh->start_concurrent_marking(); 56 } 57 58 void VM_ShenandoahFullGC::doit() { 59 ShenandoahGCPauseMark mark(_gc_id, ShenandoahPhaseTimings::full_gc, SvcGCMarker::FULL); 60 ShenandoahMarkCompact::do_mark_compact(_gc_cause); 61 } 62 63 bool VM_ShenandoahReferenceOperation::doit_prologue() { 64 Heap_lock->lock(); 65 return true; 66 } 67 68 void VM_ShenandoahReferenceOperation::doit_epilogue() { 69 if (Universe::has_reference_pending_list()) { 70 Heap_lock->notify_all(); 71 } 72 Heap_lock->unlock(); 73 } 74 75 void VM_ShenandoahFinalMarkStartEvac::doit() { 76 ShenandoahGCPauseMark mark(_gc_id, ShenandoahPhaseTimings::final_mark, SvcGCMarker::OTHER); 77 78 ShenandoahHeap *sh = ShenandoahHeap::heap(); 79 80 // It is critical that we 81 // evacuate roots right after finishing marking, so that we don't 82 // get unmarked objects in the roots. 83 // Setup workers for final marking 84 WorkGang* workers = sh->workers(); 85 uint n_workers = ShenandoahWorkerPolicy::calc_workers_for_final_marking(); 86 ShenandoahWorkerScope scope(workers, n_workers); 87 88 if (! sh->cancelled_concgc()) { 89 GCTraceTime(Info, gc) time("Pause Final Mark", sh->gc_timer(), GCCause::_no_gc, true); 90 sh->concurrentMark()->finish_mark_from_roots(); 91 sh->set_bitmap_valid(true); 92 sh->stop_concurrent_marking(); 93 94 { 95 ShenandoahGCPhase prepare_evac(ShenandoahPhaseTimings::prepare_evac); 96 sh->prepare_for_concurrent_evacuation(); 97 } 98 99 // If collection set has candidates, start evacuation. 100 // Otherwise, bypass the rest of the cycle. 101 if (!sh->collection_set()->is_empty()) { 102 sh->set_evacuation_in_progress_at_safepoint(true); 103 // From here on, we need to update references. 104 sh->set_need_update_refs(true); 105 106 ShenandoahGCPhase init_evac(ShenandoahPhaseTimings::init_evac); 107 sh->evacuate_and_update_roots(); 108 } 109 } else { 110 GCTraceTime(Info, gc) time("Cancel Concurrent Mark", sh->gc_timer(), GCCause::_no_gc, true); 111 sh->concurrentMark()->cancel(); 112 sh->stop_concurrent_marking(); 113 } 114 } 115 116 void VM_ShenandoahInitPartialGC::doit() { 117 ShenandoahGCPauseMark mark(_gc_id, ShenandoahPhaseTimings::init_partial_gc, SvcGCMarker::MINOR); 118 ShenandoahHeap::heap()->partial_gc()->init_partial_collection(); 119 } 120 121 void VM_ShenandoahFinalPartialGC::doit() { 122 ShenandoahGCPauseMark mark(_gc_id, ShenandoahPhaseTimings::final_partial_gc, SvcGCMarker::MINOR); 123 ShenandoahHeap::heap()->partial_gc()->final_partial_collection(); 124 } 125 126 void VM_ShenandoahInitUpdateRefs::doit() { 127 ShenandoahGCPauseMark mark(_gc_id, ShenandoahPhaseTimings::init_update_refs, SvcGCMarker::OTHER); 128 129 ShenandoahHeap *sh = ShenandoahHeap::heap(); 130 GCTraceTime(Info, gc) time("Pause Init Update Refs", sh->gc_timer(), GCCause::_no_gc); 131 132 sh->prepare_update_refs(); 133 } 134 135 void VM_ShenandoahFinalUpdateRefs::doit() { 136 ShenandoahGCPauseMark mark(_gc_id, ShenandoahPhaseTimings::final_update_refs, SvcGCMarker::OTHER); 137 138 ShenandoahHeap *sh = ShenandoahHeap::heap(); 139 GCTraceTime(Info, gc) time("Pause Final Update Refs", sh->gc_timer(), GCCause::_no_gc, true); 140 WorkGang* workers = sh->workers(); 141 uint n_workers = ShenandoahWorkerPolicy::calc_workers_for_final_update_ref(); 142 ShenandoahWorkerScope scope(workers, n_workers); 143 144 sh->finish_update_refs(); 145 } 146 147 void VM_ShenandoahVerifyHeapAfterEvacuation::doit() { 148 ShenandoahGCPauseMark mark(_gc_id, ShenandoahPhaseTimings::pause_other, SvcGCMarker::OTHER); 149 ShenandoahHeap::heap()->verifier()->verify_after_evacuation(); 150 }