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