1 /* 2 * Copyright (c) 2017, 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 26 #include "gc_implementation/shenandoah/shenandoahAllocTracker.hpp" 27 #include "gc_implementation/shenandoah/shenandoahCollectorPolicy.hpp" 28 #include "gc_implementation/shenandoah/shenandoahMarkCompact.hpp" 29 #include "gc_implementation/shenandoah/shenandoahHeap.hpp" 30 #include "gc_implementation/shenandoah/shenandoahUtils.hpp" 31 #include "gc_implementation/shenandoah/shenandoahLogging.hpp" 32 #include "gc_implementation/shared/gcTimer.hpp" 33 34 35 ShenandoahGCSession::ShenandoahGCSession() { 36 ShenandoahHeap* sh = ShenandoahHeap::heap(); 37 _timer = sh->gc_timer(); 38 _timer->register_gc_start(); 39 sh->shenandoahPolicy()->record_cycle_start(); 40 _trace_cycle.initialize(false, sh->gc_cause(), 41 /* recordGCBeginTime = */ true, 42 /* recordPreGCUsage = */ true, 43 /* recordPeakUsage = */ true, 44 /* recordPostGCUsage = */ true, 45 /* recordAccumulatedGCTime = */ true, 46 /* recordGCEndTime = */ true, 47 /* countCollection = */ true 48 ); 49 } 50 51 ShenandoahGCSession::~ShenandoahGCSession() { 52 ShenandoahHeap::heap()->shenandoahPolicy()->record_cycle_end(); 53 _timer->register_gc_end(); 54 } 55 56 ShenandoahGCPauseMark::ShenandoahGCPauseMark(SvcGCMarker::reason_type type) : 57 _svc_gc_mark(type), _is_gc_active_mark() { 58 ShenandoahHeap* sh = ShenandoahHeap::heap(); 59 sh->shenandoahPolicy()->record_gc_start(); 60 61 _trace_pause.initialize(true, sh->gc_cause(), 62 /* recordGCBeginTime = */ true, 63 /* recordPreGCUsage = */ false, 64 /* recordPeakUsage = */ false, 65 /* recordPostGCUsage = */ false, 66 /* recordAccumulatedGCTime = */ true, 67 /* recordGCEndTime = */ true, 68 /* countCollection = */ true 69 ); 70 } 71 72 ShenandoahGCPauseMark::~ShenandoahGCPauseMark() { 73 ShenandoahHeap* sh = ShenandoahHeap::heap(); 74 sh->shenandoahPolicy()->record_gc_end(); 75 } 76 77 ShenandoahGCPhase::ShenandoahGCPhase(const ShenandoahPhaseTimings::Phase phase) : 78 _phase(phase) { 79 ShenandoahHeap::heap()->phase_timings()->record_phase_start(_phase); 80 } 81 82 ShenandoahGCPhase::~ShenandoahGCPhase() { 83 ShenandoahHeap::heap()->phase_timings()->record_phase_end(_phase); 84 } 85 86 ShenandoahAllocTrace::ShenandoahAllocTrace(size_t words_size, ShenandoahHeap::AllocType alloc_type) { 87 if (ShenandoahAllocationTrace) { 88 _start = os::elapsedTime(); 89 _size = words_size; 90 _alloc_type = alloc_type; 91 } else { 92 _start = 0; 93 _size = 0; 94 _alloc_type = ShenandoahHeap::AllocType(0); 95 } 96 } 97 98 ShenandoahAllocTrace::~ShenandoahAllocTrace() { 99 if (ShenandoahAllocationTrace) { 100 double stop = os::elapsedTime(); 101 double duration_sec = stop - _start; 102 double duration_us = duration_sec * 1000000; 103 ShenandoahAllocTracker* tracker = ShenandoahHeap::heap()->alloc_tracker(); 104 assert(tracker != NULL, "Must be"); 105 tracker->record_alloc_latency(_size, _alloc_type, duration_us); 106 if (duration_us > ShenandoahAllocationStallThreshold) { 107 log_warning(gc)("Allocation stall: %.0f us (threshold: " INTX_FORMAT " us)", 108 duration_us, ShenandoahAllocationStallThreshold); 109 } 110 } 111 }