1 /* 2 * Copyright (c) 2018, Red Hat, Inc. All rights reserved. 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 26 #include "gc/shenandoah/shenandoahHeap.hpp" 27 #include "gc/shenandoah/shenandoahPhaseTimings.hpp" 28 #include "gc/shenandoah/shenandoahTimingTracker.hpp" 29 #include "gc/shenandoah/shenandoahUtils.hpp" 30 #include "runtime/os.hpp" 31 32 33 ShenandoahPhaseTimings::Phase ShenandoahTerminationTracker::_current_termination_phase = ShenandoahPhaseTimings::_num_phases; 34 35 ShenandoahWorkerTimingsTracker::ShenandoahWorkerTimingsTracker(ShenandoahWorkerTimings* worker_times, 36 ShenandoahPhaseTimings::GCParPhases phase, uint worker_id) : 37 _phase(phase), _worker_times(worker_times), _worker_id(worker_id) { 38 if (_worker_times != NULL) { 39 _start_time = os::elapsedTime(); 40 } 41 } 42 43 ShenandoahWorkerTimingsTracker::~ShenandoahWorkerTimingsTracker() { 44 if (_worker_times != NULL) { 45 _worker_times->record_time_secs(_phase, _worker_id, os::elapsedTime() - _start_time); 46 } 47 48 // Do nothing. Per-worker events are not supported in this JDK. 49 } 50 51 ShenandoahTerminationTimingsTracker::ShenandoahTerminationTimingsTracker(uint worker_id) : 52 _worker_id(worker_id) { 53 if (ShenandoahTerminationTrace) { 54 _start_time = os::elapsedTime(); 55 } 56 } 57 58 ShenandoahTerminationTimingsTracker::~ShenandoahTerminationTimingsTracker() { 59 if (ShenandoahTerminationTrace) { 60 ShenandoahHeap::heap()->phase_timings()->termination_times()->record_time_secs(_worker_id, os::elapsedTime() - _start_time); 61 } 62 } 63 64 ShenandoahTerminationTracker::ShenandoahTerminationTracker(ShenandoahPhaseTimings::Phase phase) : _phase(phase) { 65 assert(_current_termination_phase == ShenandoahPhaseTimings::_num_phases, "Should be invalid"); 66 assert(phase == ShenandoahPhaseTimings::termination || 67 phase == ShenandoahPhaseTimings::final_traversal_gc_termination || 68 phase == ShenandoahPhaseTimings::full_gc_mark_termination || 69 phase == ShenandoahPhaseTimings::conc_termination || 70 phase == ShenandoahPhaseTimings::conc_traversal_termination || 71 phase == ShenandoahPhaseTimings::weakrefs_termination || 72 phase == ShenandoahPhaseTimings::full_gc_weakrefs_termination, 73 "Only these phases"); 74 75 assert(!Thread::current()->is_Worker_thread() && 76 (Thread::current()->is_VM_thread() || 77 Thread::current()->is_ConcurrentGC_thread()), 78 "Called from wrong thread"); 79 80 _current_termination_phase = phase; 81 ShenandoahHeap::heap()->phase_timings()->termination_times()->reset(); 82 } 83 84 ShenandoahTerminationTracker::~ShenandoahTerminationTracker() { 85 assert(_phase == _current_termination_phase, "Can not change phase"); 86 ShenandoahPhaseTimings* phase_times = ShenandoahHeap::heap()->phase_timings(); 87 88 double t = phase_times->termination_times()->average(); 89 phase_times->record_phase_time(_phase, t); 90 debug_only(_current_termination_phase = ShenandoahPhaseTimings::_num_phases;) 91 }