ticks.hpp 4.0 KB
Newer Older
1
/*
卓昂 已提交
2
 * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 *
 */

#ifndef SHARE_VM_UTILITIES_TICKS_HPP
#define SHARE_VM_UTILITIES_TICKS_HPP

卓昂 已提交
28
#include "jni.h"
29
#include "memory/allocation.hpp"
卓昂 已提交
30
#include "utilities/macros.hpp"
31

卓昂 已提交
32 33 34 35
template <typename InstantType>
class TimeInterval {
  template <typename, typename>
  friend TimeInterval operator-(const InstantType& end, const InstantType& start);
36
 private:
卓昂 已提交
37 38
  jlong _interval;
  TimeInterval(const InstantType& end, const InstantType& start) : _interval(end - start) {}
39
 public:
卓昂 已提交
40 41 42 43
  TimeInterval(jlong interval = 0) : _interval(interval) {}
  TimeInterval& operator+=(const TimeInterval& rhs);
  TimeInterval& operator-=(const TimeInterval& rhs);
  jlong value() const { return _interval; }
44 45
};

卓昂 已提交
46 47 48
class TimeInstant {
 protected:
  jlong _instant;
49
 public:
卓昂 已提交
50 51 52 53 54
  TimeInstant(jlong stamp = 0) : _instant(stamp) {}
  TimeInstant& operator+=(const TimeInterval<TimeInstant>& rhs);
  TimeInstant& operator-=(const TimeInterval<TimeInstant>& rhs);
  jlong value() const { return _instant; }
};
55

卓昂 已提交
56 57 58 59 60 61
class ElapsedCounter : public TimeInstant {
 public:
  ElapsedCounter(jlong stamp = 0) : TimeInstant(stamp) {}
  static ElapsedCounter now();
  void stamp();
};
62

卓昂 已提交
63 64 65 66
class ElapsedCounterStamped : public ElapsedCounter {
 public:
  ElapsedCounterStamped();
};
67

卓昂 已提交
68 69 70 71
class FastElapsedCounter : public TimeInstant {
 public:
  FastElapsedCounter(jlong stamp = 0) : TimeInstant(stamp) {}
  static FastElapsedCounter now();
72
  void stamp();
卓昂 已提交
73
};
74

卓昂 已提交
75 76 77 78
class FastElapsedCounterStamped : public FastElapsedCounter {
 public:
  FastElapsedCounterStamped();
};
79

卓昂 已提交
80 81
typedef TimeInterval<ElapsedCounter> ElapsedCounterInterval;
typedef TimeInterval<FastElapsedCounter> FastElapsedCounterInterval;
82

卓昂 已提交
83
class TraceElapsedCounter;
84

卓昂 已提交
85 86
class TraceElapsedInterval {
  friend TraceElapsedInterval operator-(const TraceElapsedCounter& end, const TraceElapsedCounter& start);
87
 private:
卓昂 已提交
88 89 90 91 92 93 94 95 96 97
  ElapsedCounterInterval _elapsed_interval;
  FastElapsedCounterInterval _ft_elapsed_interval;
  TraceElapsedInterval(const TraceElapsedCounter& end, const TraceElapsedCounter& start);
 public:
  TraceElapsedInterval(jlong interval = 0);
  TraceElapsedInterval& operator+=(const TraceElapsedInterval& rhs);
  TraceElapsedInterval& operator-=(const TraceElapsedInterval& rhs);
  jlong value() const { return _elapsed_interval.value(); }
  jlong ft_value() const;
};
98

卓昂 已提交
99 100 101 102 103 104 105 106
class TraceElapsedCounter {
 protected:
  ElapsedCounter _elapsed;
  X86_ONLY(FastElapsedCounter _ft_elapsed;)
 public:
  TraceElapsedCounter(jlong stamp = 0);
  TraceElapsedCounter& operator+=(const TraceElapsedInterval& rhs);
  TraceElapsedCounter& operator-=(const TraceElapsedInterval& rhs);
107

卓昂 已提交
108 109 110 111
  static TraceElapsedCounter now();
  void stamp();
  jlong value() const { return _elapsed.value(); }
  jlong ft_value() const;
112 113
};

卓昂 已提交
114
class TraceElapsedCounterStamped : public TraceElapsedCounter {
115
 public:
卓昂 已提交
116
  TraceElapsedCounterStamped();
117 118
};

卓昂 已提交
119 120 121 122 123 124 125 126
#if INCLUDE_TRACE
typedef TraceElapsedCounter  Ticks;
typedef TraceElapsedInterval Tickspan;
#else
typedef ElapsedCounter       Ticks;
typedef TicksInterval<Ticks> Tickspan;
#endif

127
#endif // SHARE_VM_UTILITIES_TICKS_HPP