1 /*
2 * Copyright (c) 2013, 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 ASSERT
30 const jlong Ticks::invalid_time_stamp = -2; // 0xFFFF FFFF`FFFF FFFE
31 #endif
32
33 void Ticks::stamp() {
34 _stamp_ticks = os::elapsed_counter();
35 }
36
37 const Ticks Ticks::now() {
38 Ticks t;
39 t.stamp();
40 return t;
41 }
42
43 Tickspan::Tickspan(const Ticks& end, const Ticks& start) {
44 assert(end.value() != Ticks::invalid_time_stamp, "end is unstamped!");
45 assert(start.value() != Ticks::invalid_time_stamp, "start is unstamped!");
46
47 assert(end >= start, "negative time!");
48
49 _span_ticks = end.value() - start.value();
50 }
51
52 template <typename ReturnType>
53 static ReturnType time_conversion(const Tickspan& span, TicksToTimeHelper::Unit unit) {
54 assert(TicksToTimeHelper::SECONDS == unit ||
55 TicksToTimeHelper::MILLISECONDS == unit, "invalid unit!");
56
57 ReturnType frequency_per_unit = (ReturnType)os::elapsed_frequency() / (ReturnType)unit;
58
59 return (ReturnType) ((ReturnType)span.value() / frequency_per_unit);
60 }
61
62 double TicksToTimeHelper::seconds(const Tickspan& span) {
63 return time_conversion<double>(span, SECONDS);
64 }
65
66 jlong TicksToTimeHelper::milliseconds(const Tickspan& span) {
67 return time_conversion<jlong>(span, MILLISECONDS);
68 }
|
1 /*
2 * Copyright (c) 2013, 2019, 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 #ifdef TARGET_OS_ARCH_linux_x86
34 # include "os_linux_x86.hpp"
35 #endif
36 #ifdef TARGET_OS_ARCH_linux_sparc
37 # include "os_linux_sparc.hpp"
38 #endif
39 #ifdef TARGET_OS_ARCH_linux_zero
40 # include "os_linux_zero.hpp"
41 #endif
42 #ifdef TARGET_OS_ARCH_solaris_x86
43 # include "os_solaris_x86.hpp"
44 #endif
45 #ifdef TARGET_OS_ARCH_solaris_sparc
46 # include "os_solaris_sparc.hpp"
47 #endif
48 #ifdef TARGET_OS_ARCH_windows_x86
49 # include "os_windows_x86.hpp"
50 #endif
51 #ifdef TARGET_OS_ARCH_linux_arm
52 # include "os_linux_arm.hpp"
53 #endif
54 #ifdef TARGET_OS_ARCH_linux_ppc
55 # include "os_linux_ppc.hpp"
56 #endif
57 #ifdef TARGET_OS_ARCH_aix_ppc
58 # include "os_aix_ppc.hpp"
59 #endif
60 #ifdef TARGET_OS_ARCH_bsd_x86
61 # include "os_bsd_x86.hpp"
62 #endif
63 #ifdef TARGET_OS_ARCH_bsd_zero
64 # include "os_bsd_zero.hpp"
65 #endif
66
67 ElapsedCounterStamped::ElapsedCounterStamped() : ElapsedCounter(os::elapsed_counter()) {}
68
69 void ElapsedCounter::stamp() {
70 _instant = now().value();
71 }
72
73 ElapsedCounter ElapsedCounter::now() {
74 return ElapsedCounterStamped();
75 }
76
77 #ifdef X86
78 FastElapsedCounterStamped::FastElapsedCounterStamped() : FastElapsedCounter(Rdtsc::elapsed_counter()) {}
79 #else
80 FastElapsedCounterStamped::FastElapsedCounterStamped() : FastElapsedCounter(os::elapsed_counter()) {}
81 #endif
82
83 void FastElapsedCounter::stamp() {
84 _instant = now().value();
85 }
86
87 FastElapsedCounter FastElapsedCounter::now() {
88 return FastElapsedCounterStamped();
89 }
90
91 TraceElapsedInterval::TraceElapsedInterval(const TraceElapsedCounter& end, const TraceElapsedCounter& start) :
92 _elapsed_interval(end.value() - start.value())
93 #ifdef X86
94 , _ft_elapsed_interval(end.ft_value() - start.ft_value())
95 #endif
96 {}
97
98 TraceElapsedInterval::TraceElapsedInterval(jlong interval) :
99 _elapsed_interval(interval)
100 #ifdef X86
101 , _ft_elapsed_interval(interval)
102 #endif
103 {}
104
105 TraceElapsedInterval& TraceElapsedInterval::operator+=(const TraceElapsedInterval& rhs) {
106 _elapsed_interval += rhs._elapsed_interval;
107 X86_ONLY(_ft_elapsed_interval += rhs._ft_elapsed_interval;)
108 return *this;
109 }
110
111 TraceElapsedInterval& TraceElapsedInterval::operator-=(const TraceElapsedInterval& rhs) {
112 _elapsed_interval -= rhs._elapsed_interval;
113 X86_ONLY(_ft_elapsed_interval -= rhs._ft_elapsed_interval;)
114 return *this;
115 }
116
117 jlong TraceElapsedInterval::ft_value() const {
118 #ifdef X86
119 return _ft_elapsed_interval.value();
120 #else
121 return _elapsed_interval.value();
122 #endif
123 }
124
125 TraceElapsedCounter::TraceElapsedCounter(jlong stamp) :
126 _elapsed(stamp)
127 #ifdef X86
128 , _ft_elapsed(stamp)
129 #endif
130 {}
131
132 TraceElapsedCounter TraceElapsedCounter::now() {
133 TraceElapsedCounterStamped dec;
134 return dec;
135 }
136
137 TraceElapsedCounter& TraceElapsedCounter::operator+=(const TraceElapsedInterval& rhs) {
138 _elapsed += rhs.value();
139 X86_ONLY(_ft_elapsed += rhs.ft_value();)
140 return *this;
141 }
142
143 TraceElapsedCounter& TraceElapsedCounter::operator-=(const TraceElapsedInterval& rhs) {
144 _elapsed -= rhs.value();
145 X86_ONLY(_ft_elapsed -= rhs.ft_value();)
146 return *this;
147 }
148
149 void TraceElapsedCounter::stamp() {
150 _elapsed.stamp();
151 X86_ONLY(_ft_elapsed.stamp();)
152 }
153
154 jlong TraceElapsedCounter::ft_value() const {
155 #ifdef X86
156 return _ft_elapsed.value();
157 #else
158 return _elapsed.value();
159 #endif
160 }
161
162 TraceElapsedCounterStamped::TraceElapsedCounterStamped() : TraceElapsedCounter() {
163 _elapsed.stamp();
164 X86_ONLY(_ft_elapsed.stamp());
165 }
|