src/share/vm/utilities/ticks.hpp

Mon, 12 Aug 2019 18:30:40 +0300

author
apetushkov
date
Mon, 12 Aug 2019 18:30:40 +0300
changeset 9858
b985cbb00e68
parent 0
f90c822e73f8
permissions
-rw-r--r--

8223147: JFR Backport
8199712: Flight Recorder
8203346: JFR: Inconsistent signature of jfr_add_string_constant
8195817: JFR.stop should require name of recording
8195818: JFR.start should increase autogenerated name by one
8195819: Remove recording=x from jcmd JFR.check output
8203921: JFR thread sampling is missing fixes from JDK-8194552
8203929: Limit amount of data for JFR.dump
8203664: JFR start failure after AppCDS archive created with JFR StartFlightRecording
8003209: JFR events for network utilization
8207392: [PPC64] Implement JFR profiling
8202835: jfr/event/os/TestSystemProcess.java fails on missing events
Summary: Backport JFR from JDK11. Initial integration
Reviewed-by: neugens

aoqi@0 1 /*
apetushkov@9858 2 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
apetushkov@9858 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
apetushkov@9858 4 *
apetushkov@9858 5 * This code is free software; you can redistribute it and/or modify it
apetushkov@9858 6 * under the terms of the GNU General Public License version 2 only, as
apetushkov@9858 7 * published by the Free Software Foundation.
apetushkov@9858 8 *
apetushkov@9858 9 * This code is distributed in the hope that it will be useful, but WITHOUT
apetushkov@9858 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
apetushkov@9858 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
apetushkov@9858 12 * version 2 for more details (a copy is included in the LICENSE file that
apetushkov@9858 13 * accompanied this code).
apetushkov@9858 14 *
apetushkov@9858 15 * You should have received a copy of the GNU General Public License version
apetushkov@9858 16 * 2 along with this work; if not, write to the Free Software Foundation,
apetushkov@9858 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
apetushkov@9858 18 *
apetushkov@9858 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
apetushkov@9858 20 * or visit www.oracle.com if you need additional information or have any
apetushkov@9858 21 * questions.
apetushkov@9858 22 *
apetushkov@9858 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_UTILITIES_TICKS_HPP
aoqi@0 26 #define SHARE_VM_UTILITIES_TICKS_HPP
aoqi@0 27
apetushkov@9858 28 #include "jni.h"
aoqi@0 29 #include "memory/allocation.hpp"
apetushkov@9858 30 #include "utilities/macros.hpp"
aoqi@0 31
apetushkov@9858 32 // Time sources
apetushkov@9858 33 class ElapsedCounterSource {
apetushkov@9858 34 public:
apetushkov@9858 35 typedef jlong Type;
apetushkov@9858 36 static uint64_t frequency();
apetushkov@9858 37 static Type now();
apetushkov@9858 38 static double seconds(Type value);
apetushkov@9858 39 static uint64_t milliseconds(Type value);
apetushkov@9858 40 static uint64_t microseconds(Type value);
apetushkov@9858 41 static uint64_t nanoseconds(Type value);
apetushkov@9858 42 };
aoqi@0 43
apetushkov@9858 44 // Not guaranteed to be synchronized across hardware threads and
apetushkov@9858 45 // therefore software threads, and can be updated asynchronously
apetushkov@9858 46 // by software. now() can jump backwards as well as jump forward
apetushkov@9858 47 // when threads query different cores/sockets.
apetushkov@9858 48 // Very much not recommended for general use. Caveat emptor.
apetushkov@9858 49 class FastUnorderedElapsedCounterSource {
apetushkov@9858 50 public:
apetushkov@9858 51 typedef jlong Type;
apetushkov@9858 52 static uint64_t frequency();
apetushkov@9858 53 static Type now();
apetushkov@9858 54 static double seconds(Type value);
apetushkov@9858 55 static uint64_t milliseconds(Type value);
apetushkov@9858 56 static uint64_t microseconds(Type value);
apetushkov@9858 57 static uint64_t nanoseconds(Type value);
apetushkov@9858 58 };
aoqi@0 59
apetushkov@9858 60 template <typename T1, typename T2>
apetushkov@9858 61 class PairRep {
apetushkov@9858 62 public:
apetushkov@9858 63 T1 val1;
apetushkov@9858 64 T2 val2;
aoqi@0 65
apetushkov@9858 66 PairRep() : val1((T1)0), val2((T2)0) {}
apetushkov@9858 67 void operator+=(const PairRep& rhs) {
apetushkov@9858 68 val1 += rhs.val1;
apetushkov@9858 69 val2 += rhs.val2;
apetushkov@9858 70 }
apetushkov@9858 71 void operator-=(const PairRep& rhs) {
apetushkov@9858 72 val1 -= rhs.val1;
apetushkov@9858 73 val2 -= rhs.val2;
apetushkov@9858 74 }
apetushkov@9858 75 bool operator==(const PairRep& rhs) const {
apetushkov@9858 76 return val1 == rhs.val1;
apetushkov@9858 77 }
apetushkov@9858 78 bool operator!=(const PairRep& rhs) const {
apetushkov@9858 79 return !operator==(rhs);
apetushkov@9858 80 }
apetushkov@9858 81 bool operator<(const PairRep& rhs) const {
apetushkov@9858 82 return val1 < rhs.val1;
apetushkov@9858 83 }
apetushkov@9858 84 bool operator>(const PairRep& rhs) const {
apetushkov@9858 85 return val1 > rhs.val1;
apetushkov@9858 86 }
apetushkov@9858 87 };
aoqi@0 88
apetushkov@9858 89 template <typename T1, typename T2>
apetushkov@9858 90 PairRep<T1, T2> operator-(const PairRep<T1, T2>& lhs, const PairRep<T1, T2>& rhs) {
apetushkov@9858 91 PairRep<T1, T2> temp(lhs);
apetushkov@9858 92 temp -= rhs;
apetushkov@9858 93 return temp;
apetushkov@9858 94 }
apetushkov@9858 95
apetushkov@9858 96 typedef PairRep<ElapsedCounterSource::Type, FastUnorderedElapsedCounterSource::Type> CompositeTime;
apetushkov@9858 97
apetushkov@9858 98 class CompositeElapsedCounterSource {
aoqi@0 99 public:
apetushkov@9858 100 typedef CompositeTime Type;
apetushkov@9858 101 static uint64_t frequency();
apetushkov@9858 102 static Type now();
apetushkov@9858 103 static double seconds(Type value);
apetushkov@9858 104 static uint64_t milliseconds(Type value);
apetushkov@9858 105 static uint64_t microseconds(Type value);
apetushkov@9858 106 static uint64_t nanoseconds(Type value);
apetushkov@9858 107 };
aoqi@0 108
apetushkov@9858 109 template <typename TimeSource>
apetushkov@9858 110 class Representation {
apetushkov@9858 111 public:
apetushkov@9858 112 typedef typename TimeSource::Type Type;
apetushkov@9858 113 protected:
apetushkov@9858 114 Type _rep;
apetushkov@9858 115 Representation(const Representation<TimeSource>& end, const Representation<TimeSource>& start) : _rep(end._rep - start._rep) {}
apetushkov@9858 116 Representation() : _rep() {}
apetushkov@9858 117 public:
apetushkov@9858 118 void operator+=(const Representation<TimeSource>& rhs) {
apetushkov@9858 119 _rep += rhs._rep;
apetushkov@9858 120 }
apetushkov@9858 121 void operator-=(const Representation<TimeSource>& rhs) {
apetushkov@9858 122 _rep -= rhs._rep;
apetushkov@9858 123 }
apetushkov@9858 124 bool operator==(const Representation<TimeSource>& rhs) const {
apetushkov@9858 125 return _rep == rhs._rep;
apetushkov@9858 126 }
apetushkov@9858 127 bool operator!=(const Representation<TimeSource>& rhs) const {
apetushkov@9858 128 return !operator==(rhs);
apetushkov@9858 129 }
apetushkov@9858 130 bool operator<(const Representation<TimeSource>& rhs) const {
apetushkov@9858 131 return _rep < rhs._rep;
apetushkov@9858 132 }
apetushkov@9858 133 bool operator>(const Representation<TimeSource>& rhs) const {
apetushkov@9858 134 return _rep > rhs._rep;
apetushkov@9858 135 }
apetushkov@9858 136 bool operator<=(const Representation<TimeSource>& rhs) const {
apetushkov@9858 137 return !operator>(rhs);
apetushkov@9858 138 }
apetushkov@9858 139 bool operator>=(const Representation<TimeSource>& rhs) const {
apetushkov@9858 140 return !operator<(rhs);
apetushkov@9858 141 }
apetushkov@9858 142 double seconds() const {
apetushkov@9858 143 return TimeSource::seconds(_rep);
apetushkov@9858 144 }
apetushkov@9858 145 uint64_t milliseconds() const {
apetushkov@9858 146 return TimeSource::milliseconds(_rep);
apetushkov@9858 147 }
apetushkov@9858 148 uint64_t microseconds() const {
apetushkov@9858 149 return TimeSource::microseconds(_rep);
apetushkov@9858 150 }
apetushkov@9858 151 uint64_t nanoseconds() const {
apetushkov@9858 152 return TimeSource::nanoseconds(_rep);
apetushkov@9858 153 }
apetushkov@9858 154 };
apetushkov@9858 155
apetushkov@9858 156 template <typename TimeSource>
apetushkov@9858 157 class CounterRepresentation : public Representation<TimeSource> {
apetushkov@9858 158 protected:
apetushkov@9858 159 CounterRepresentation(const CounterRepresentation& end, const CounterRepresentation& start) : Representation<TimeSource>(end, start) {}
apetushkov@9858 160 explicit CounterRepresentation(jlong value) : Representation<TimeSource>() {
apetushkov@9858 161 this->_rep = value;
apetushkov@9858 162 }
apetushkov@9858 163 public:
apetushkov@9858 164 CounterRepresentation() : Representation<TimeSource>() {}
apetushkov@9858 165 typename TimeSource::Type value() const { return this->_rep; }
apetushkov@9858 166 operator typename TimeSource::Type() { return value(); }
apetushkov@9858 167 };
apetushkov@9858 168
apetushkov@9858 169 template <typename TimeSource>
apetushkov@9858 170 class CompositeCounterRepresentation : public Representation<TimeSource> {
apetushkov@9858 171 protected:
apetushkov@9858 172 CompositeCounterRepresentation(const CompositeCounterRepresentation& end, const CompositeCounterRepresentation& start) :
apetushkov@9858 173 Representation<TimeSource>(end, start) {}
apetushkov@9858 174 explicit CompositeCounterRepresentation(jlong value) : Representation<TimeSource>() {
apetushkov@9858 175 this->_rep.val1 = value;
apetushkov@9858 176 this->_rep.val2 = value;
apetushkov@9858 177 }
apetushkov@9858 178 public:
apetushkov@9858 179 CompositeCounterRepresentation() : Representation<TimeSource>() {}
apetushkov@9858 180 ElapsedCounterSource::Type value() const { return this->_rep.val1; }
apetushkov@9858 181 FastUnorderedElapsedCounterSource::Type ft_value() const { return this->_rep.val2; }
apetushkov@9858 182 };
apetushkov@9858 183
apetushkov@9858 184 template <template <typename> class, typename>
apetushkov@9858 185 class TimeInstant;
apetushkov@9858 186
apetushkov@9858 187 template <template <typename> class Rep, typename TimeSource>
apetushkov@9858 188 class TimeInterval : public Rep<TimeSource> {
apetushkov@9858 189 template <template <typename> class, typename>
apetushkov@9858 190 friend class TimeInstant;
apetushkov@9858 191 TimeInterval(const TimeInstant<Rep, TimeSource>& end, const TimeInstant<Rep, TimeSource>& start) : Rep<TimeSource>(end, start) {}
apetushkov@9858 192 public:
apetushkov@9858 193 TimeInterval() : Rep<TimeSource>() {}
apetushkov@9858 194 TimeInterval<Rep, TimeSource> operator+(const TimeInterval<Rep, TimeSource>& rhs) const {
apetushkov@9858 195 TimeInterval<Rep, TimeSource> temp(*this);
apetushkov@9858 196 temp += rhs;
apetushkov@9858 197 return temp;
apetushkov@9858 198 }
apetushkov@9858 199 TimeInterval<Rep, TimeSource> operator-(const TimeInterval<Rep, TimeSource>& rhs) const {
apetushkov@9858 200 TimeInterval<Rep, TimeSource> temp(*this);
apetushkov@9858 201 temp -= rhs;
apetushkov@9858 202 return temp;
apetushkov@9858 203 }
apetushkov@9858 204 };
apetushkov@9858 205
apetushkov@9858 206 template <template <typename> class Rep, typename TimeSource>
apetushkov@9858 207 class TimeInstant : public Rep<TimeSource> {
apetushkov@9858 208 public:
apetushkov@9858 209 TimeInstant() : Rep<TimeSource>() {}
apetushkov@9858 210 TimeInstant<Rep, TimeSource>& operator+=(const TimeInterval<Rep, TimeSource>& rhs) {
apetushkov@9858 211 Rep<TimeSource>::operator+=(rhs);
aoqi@0 212 return *this;
aoqi@0 213 }
apetushkov@9858 214 TimeInstant<Rep, TimeSource>& operator-=(const TimeInterval<Rep, TimeSource>& rhs) {
apetushkov@9858 215 Rep<TimeSource>::operator-=(rhs);
apetushkov@9858 216 return *this;
aoqi@0 217 }
apetushkov@9858 218 TimeInterval<Rep, TimeSource> operator+(const TimeInstant<Rep, TimeSource>& end) const {
apetushkov@9858 219 return TimeInterval<Rep, TimeSource>(end, *this);
apetushkov@9858 220 }
apetushkov@9858 221 TimeInterval<Rep, TimeSource> operator-(const TimeInstant<Rep, TimeSource>& start) const {
apetushkov@9858 222 return TimeInterval<Rep, TimeSource>(*this, start);
apetushkov@9858 223 }
apetushkov@9858 224 void stamp() {
apetushkov@9858 225 this->_rep = TimeSource::now();
apetushkov@9858 226 }
apetushkov@9858 227 static TimeInstant<Rep, TimeSource> now() {
apetushkov@9858 228 TimeInstant<Rep, TimeSource> temp;
apetushkov@9858 229 temp.stamp();
apetushkov@9858 230 return temp;
apetushkov@9858 231 }
apetushkov@9858 232 private:
apetushkov@9858 233 TimeInstant(jlong ticks) : Rep<TimeSource>(ticks) {}
apetushkov@9858 234 friend class GranularTimer;
apetushkov@9858 235 friend class ObjectSample;
apetushkov@9858 236 // GC VM tests
apetushkov@9858 237 friend class TimePartitionPhasesIteratorTest;
apetushkov@9858 238 friend class GCTimerTest;
aoqi@0 239 };
aoqi@0 240
apetushkov@9858 241 #if INCLUDE_JFR
apetushkov@9858 242 typedef TimeInstant<CompositeCounterRepresentation, CompositeElapsedCounterSource> Ticks;
apetushkov@9858 243 typedef TimeInterval<CompositeCounterRepresentation, CompositeElapsedCounterSource> Tickspan;
apetushkov@9858 244 #else
apetushkov@9858 245 typedef TimeInstant<CounterRepresentation, ElapsedCounterSource> Ticks;
apetushkov@9858 246 typedef TimeInterval<CounterRepresentation, ElapsedCounterSource> Tickspan;
aoqi@0 247 #endif
aoqi@0 248
aoqi@0 249 #endif // SHARE_VM_UTILITIES_TICKS_HPP

mercurial