1 /* 2 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "runtime/os.hpp" 27 #include "utilities/ticks.inline.hpp" 28 29 #ifdef X86 30 #include "rdtsc_x86.hpp" 31 #endif 32 33 #include OS_CPU_HEADER(os) 34 35 ElapsedCounterStamped::ElapsedCounterStamped() : ElapsedCounter(os::elapsed_counter()) {} 36 37 void ElapsedCounter::stamp() { 38 _instant = now().value(); 39 } 40 41 ElapsedCounter ElapsedCounter::now() { 42 return ElapsedCounterStamped(); 43 } 44 45 #ifdef X86 46 FastElapsedCounterStamped::FastElapsedCounterStamped() : FastElapsedCounter(Rdtsc::elapsed_counter()) {} 47 #else 48 FastElapsedCounterStamped::FastElapsedCounterStamped() : FastElapsedCounter(os::elapsed_counter()) {} 49 #endif 50 51 void FastElapsedCounter::stamp() { 52 _instant = now().value(); 53 } 54 55 FastElapsedCounter FastElapsedCounter::now() { 56 return FastElapsedCounterStamped(); 57 } 58 59 TraceElapsedInterval::TraceElapsedInterval(const TraceElapsedCounter& end, const TraceElapsedCounter& start) : 60 _elapsed_interval(end.value() - start.value()) 61 #ifdef X86 62 , _ft_elapsed_interval(end.ft_value() - start.ft_value()) 63 #endif 64 {} 65 66 TraceElapsedInterval::TraceElapsedInterval(jlong interval) : 67 _elapsed_interval(interval) 68 #ifdef X86 69 , _ft_elapsed_interval(interval) 70 #endif 71 {} 72 73 TraceElapsedInterval& TraceElapsedInterval::operator+=(const TraceElapsedInterval& rhs) { 74 _elapsed_interval += rhs._elapsed_interval; 75 X86_ONLY(_ft_elapsed_interval += rhs._ft_elapsed_interval;) 76 return *this; 77 } 78 79 TraceElapsedInterval& TraceElapsedInterval::operator-=(const TraceElapsedInterval& rhs) { 80 _elapsed_interval -= rhs._elapsed_interval; 81 X86_ONLY(_ft_elapsed_interval -= rhs._ft_elapsed_interval;) 82 return *this; 83 } 84 85 jlong TraceElapsedInterval::ft_value() const { 86 #ifdef X86 87 return _ft_elapsed_interval.value(); 88 #else 89 return _elapsed_interval.value(); 90 #endif 91 } 92 93 TraceElapsedCounter::TraceElapsedCounter(jlong stamp) : 94 _elapsed(stamp) 95 #ifdef X86 96 , _ft_elapsed(stamp) 97 #endif 98 {} 99 100 TraceElapsedCounter TraceElapsedCounter::now() { 101 TraceElapsedCounterStamped dec; 102 return dec; 103 } 104 105 TraceElapsedCounter& TraceElapsedCounter::operator+=(const TraceElapsedInterval& rhs) { 106 _elapsed += rhs.value(); 107 X86_ONLY(_ft_elapsed += rhs.ft_value();) 108 return *this; 109 } 110 111 TraceElapsedCounter& TraceElapsedCounter::operator-=(const TraceElapsedInterval& rhs) { 112 _elapsed -= rhs.value(); 113 X86_ONLY(_ft_elapsed -= rhs.ft_value();) 114 return *this; 115 } 116 117 void TraceElapsedCounter::stamp() { 118 _elapsed.stamp(); 119 X86_ONLY(_ft_elapsed.stamp();) 120 } 121 122 jlong TraceElapsedCounter::ft_value() const { 123 #ifdef X86 124 return _ft_elapsed.value(); 125 #else 126 return _elapsed.value(); 127 #endif 128 } 129 130 TraceElapsedCounterStamped::TraceElapsedCounterStamped() : TraceElapsedCounter() { 131 _elapsed.stamp(); 132 X86_ONLY(_ft_elapsed.stamp()); 133 }