/* * Copyright (c) 2013, 2015, Red Hat, Inc. and/or its affiliates. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. * */ #include "gc/shared/gcTraceTime.inline.hpp" #include "gc/shenandoah/shenandoahCollectorPolicy.hpp" #include "gc/shenandoah/shenandoahMarkCompact.hpp" #include "gc/shenandoah/shenandoahConcurrentMark.inline.hpp" #include "gc/shenandoah/shenandoahHeap.inline.hpp" #include "gc/shenandoah/shenandoahPartialGC.hpp" #include "gc/shenandoah/shenandoahWorkGroup.hpp" #include "gc/shenandoah/vm_operations_shenandoah.hpp" void VM_ShenandoahInitMark::doit() { GCIdMark gc_id_mark(_gc_id); ShenandoahHeap *sh = (ShenandoahHeap*) Universe::heap(); WorkGang* workers = sh->workers(); // Calculate workers for initial marking uint nworkers = ShenandoahCollectorPolicy::calc_workers_for_init_marking( workers->active_workers(), Threads::number_of_non_daemon_threads()); ShenandoahWorkerScope scope(workers, nworkers); GCTraceTime(Info, gc) time("Pause Init Mark", sh->gc_timer()); sh->shenandoahPolicy()->record_phase_start(ShenandoahCollectorPolicy::total_pause); sh->shenandoahPolicy()->record_phase_start(ShenandoahCollectorPolicy::init_mark); assert(sh->is_next_bitmap_clear(), "need clear marking bitmap"); sh->start_concurrent_marking(); if (UseTLAB) { sh->shenandoahPolicy()->record_phase_start(ShenandoahCollectorPolicy::resize_tlabs); sh->resize_all_tlabs(); sh->shenandoahPolicy()->record_phase_end(ShenandoahCollectorPolicy::resize_tlabs); } sh->shenandoahPolicy()->record_phase_end(ShenandoahCollectorPolicy::init_mark); sh->shenandoahPolicy()->record_phase_end(ShenandoahCollectorPolicy::total_pause); } void VM_ShenandoahFullGC::doit() { GCIdMark gc_id_mark(_gc_id); ShenandoahHeap *sh = ShenandoahHeap::heap(); sh->shenandoahPolicy()->record_gc_start(); ShenandoahMarkCompact::do_mark_compact(_gc_cause); if (UseTLAB) { sh->shenandoahPolicy()->record_phase_start(ShenandoahCollectorPolicy::resize_tlabs); sh->resize_all_tlabs(); sh->shenandoahPolicy()->record_phase_end(ShenandoahCollectorPolicy::resize_tlabs); } sh->shenandoahPolicy()->record_gc_end(); } bool VM_ShenandoahReferenceOperation::doit_prologue() { Heap_lock->lock(); return true; } void VM_ShenandoahReferenceOperation::doit_epilogue() { if (Universe::has_reference_pending_list()) { Heap_lock->notify_all(); } Heap_lock->unlock(); } void VM_ShenandoahStartEvacuation::doit() { GCIdMark gc_id_mark(_gc_id); ShenandoahHeap *sh = ShenandoahHeap::heap(); sh->shenandoahPolicy()->record_gc_start(); // It is critical that we // evacuate roots right after finishing marking, so that we don't // get unmarked objects in the roots. // Setup workers for final marking WorkGang* workers = sh->workers(); uint n_workers = ShenandoahCollectorPolicy::calc_workers_for_final_marking(workers->active_workers(), Threads::number_of_non_daemon_threads()); ShenandoahWorkerScope scope(workers, n_workers); if (! sh->cancelled_concgc()) { GCTraceTime(Info, gc) time("Pause Final Mark", sh->gc_timer(), GCCause::_no_gc, true); sh->shenandoahPolicy()->record_phase_start(ShenandoahCollectorPolicy::total_pause); sh->shenandoahPolicy()->record_phase_start(ShenandoahCollectorPolicy::final_mark); sh->concurrentMark()->finish_mark_from_roots(); sh->stop_concurrent_marking(); sh->shenandoahPolicy()->record_phase_end(ShenandoahCollectorPolicy::final_mark); sh->shenandoahPolicy()->record_phase_end(ShenandoahCollectorPolicy::total_pause); sh->shenandoahPolicy()->record_phase_start(ShenandoahCollectorPolicy::prepare_evac); sh->prepare_for_concurrent_evacuation(); sh->shenandoahPolicy()->record_phase_end(ShenandoahCollectorPolicy::prepare_evac); sh->set_evacuation_in_progress_at_safepoint(true); // From here on, we need to update references. sh->set_need_update_refs(true); sh->shenandoahPolicy()->record_phase_start(ShenandoahCollectorPolicy::init_evac); sh->evacuate_and_update_roots(); sh->shenandoahPolicy()->record_phase_end(ShenandoahCollectorPolicy::init_evac); } else { GCTraceTime(Info, gc) time("Cancel Concurrent Mark", sh->gc_timer(), GCCause::_no_gc, true); sh->concurrentMark()->cancel(); sh->stop_concurrent_marking(); } sh->shenandoahPolicy()->record_gc_end(); } void VM_ShenandoahPartialGC::doit() { GCIdMark gc_id_mark(_gc_id); ShenandoahHeap *sh = ShenandoahHeap::heap(); sh->shenandoahPolicy()->record_gc_start(); ShenandoahHeap::heap()->do_partial_collection(); sh->shenandoahPolicy()->record_gc_end(); } void VM_ShenandoahVerifyHeapAfterEvacuation::doit() { GCIdMark gc_id_mark(_gc_id); ShenandoahHeap *sh = ShenandoahHeap::heap(); sh->verify_heap_after_evacuation(); }