src/hotspot/share/utilities/ticks.cpp
author sgehwolf
Wed, 16 May 2018 15:25:51 +0200
changeset 50174 78d9ffb8146f
parent 50113 caf115bb98ad
permissions -rw-r--r--
8203287: Zero fails to build after JDK-8199712 (Flight Recorder) Reviewed-by: shade, mdoerr
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: 47216
diff changeset
     2
 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
     4
 *
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
     8
 *
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
    13
 * accompanied this code).
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
    14
 *
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
    18
 *
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
    21
 * questions.
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
    22
 *
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
    23
 */
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
#include "precompiled.hpp"
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
    26
#include "runtime/os.hpp"
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    27
#include "utilities/ticks.hpp"
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
    28
50174
78d9ffb8146f 8203287: Zero fails to build after JDK-8199712 (Flight Recorder)
sgehwolf
parents: 50113
diff changeset
    29
#if defined(X86) && !defined(ZERO)
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    30
#include "rdtsc_x86.hpp"
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
    31
#endif
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
    32
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    33
#include OS_CPU_HEADER(os)
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    34
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    35
template <typename TimeSource, const int unit>
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    36
inline double conversion(typename TimeSource::Type& value) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    37
  return (double)value * ((double)unit / (double)TimeSource::frequency());
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    38
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    39
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    40
uint64_t ElapsedCounterSource::frequency() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    41
  static const uint64_t freq = (uint64_t)os::elapsed_frequency();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    42
  return freq;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    43
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    44
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    45
ElapsedCounterSource::Type ElapsedCounterSource::now() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    46
  return os::elapsed_counter();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    47
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    48
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    49
double ElapsedCounterSource::seconds(Type value) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    50
  return conversion<ElapsedCounterSource, 1>(value);
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
    51
}
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
    52
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    53
uint64_t ElapsedCounterSource::milliseconds(Type value) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    54
  return (uint64_t)conversion<ElapsedCounterSource, MILLIUNITS>(value);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    55
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    56
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    57
uint64_t ElapsedCounterSource::microseconds(Type value) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    58
  return (uint64_t)conversion<ElapsedCounterSource, MICROUNITS>(value);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    59
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    60
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    61
uint64_t ElapsedCounterSource::nanoseconds(Type value) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    62
  return (uint64_t)conversion<ElapsedCounterSource, NANOUNITS>(value);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    63
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    64
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    65
uint64_t FastUnorderedElapsedCounterSource::frequency() {
50174
78d9ffb8146f 8203287: Zero fails to build after JDK-8199712 (Flight Recorder)
sgehwolf
parents: 50113
diff changeset
    66
#if defined(X86) && !defined(ZERO)
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    67
  static bool valid_rdtsc = Rdtsc::initialize();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    68
  if (valid_rdtsc) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    69
    static const uint64_t freq = (uint64_t)Rdtsc::frequency();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    70
    return freq;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    71
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    72
#endif
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    73
  static const uint64_t freq = (uint64_t)os::elapsed_frequency();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    74
  return freq;
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
    75
}
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
    76
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    77
FastUnorderedElapsedCounterSource::Type FastUnorderedElapsedCounterSource::now() {
50174
78d9ffb8146f 8203287: Zero fails to build after JDK-8199712 (Flight Recorder)
sgehwolf
parents: 50113
diff changeset
    78
#if defined(X86) && !defined(ZERO)
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    79
  static bool valid_rdtsc = Rdtsc::initialize();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    80
  if (valid_rdtsc) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    81
    return Rdtsc::elapsed_counter();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    82
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    83
#endif
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    84
  return os::elapsed_counter();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    85
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    86
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    87
double FastUnorderedElapsedCounterSource::seconds(Type value) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    88
  return conversion<FastUnorderedElapsedCounterSource, 1>(value);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    89
}
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
    90
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    91
uint64_t FastUnorderedElapsedCounterSource::milliseconds(Type value) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    92
  return (uint64_t)conversion<FastUnorderedElapsedCounterSource, MILLIUNITS>(value);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    93
}
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
    94
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    95
uint64_t FastUnorderedElapsedCounterSource::microseconds(Type value) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    96
  return (uint64_t)conversion<FastUnorderedElapsedCounterSource, MICROUNITS>(value);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    97
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    98
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
    99
uint64_t FastUnorderedElapsedCounterSource::nanoseconds(Type value) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   100
  return (uint64_t)conversion<FastUnorderedElapsedCounterSource, NANOUNITS>(value);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   101
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   102
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   103
uint64_t CompositeElapsedCounterSource::frequency() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   104
  return ElapsedCounterSource::frequency();
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
   105
}
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
   106
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   107
CompositeElapsedCounterSource::Type CompositeElapsedCounterSource::now() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   108
  CompositeTime ct;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   109
  ct.val1 = ElapsedCounterSource::now();
50174
78d9ffb8146f 8203287: Zero fails to build after JDK-8199712 (Flight Recorder)
sgehwolf
parents: 50113
diff changeset
   110
#if defined(X86) && !defined(ZERO)
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   111
  static bool initialized = false;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   112
  static bool valid_rdtsc = false;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   113
  if (!initialized) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   114
    valid_rdtsc = Rdtsc::initialize();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   115
    initialized = true;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   116
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   117
  if (valid_rdtsc) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   118
    ct.val2 = Rdtsc::elapsed_counter();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   119
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   120
#endif
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   121
  return ct;
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
   122
}
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
   123
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   124
double CompositeElapsedCounterSource::seconds(Type value) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   125
  return conversion<ElapsedCounterSource, 1>(value.val1);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   126
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   127
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   128
uint64_t CompositeElapsedCounterSource::milliseconds(Type value) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   129
  return (uint64_t)conversion<ElapsedCounterSource, MILLIUNITS>(value.val1);
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
   130
}
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
   131
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   132
uint64_t CompositeElapsedCounterSource::microseconds(Type value) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   133
  return (uint64_t)conversion<ElapsedCounterSource, MICROUNITS>(value.val1);
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff changeset
   134
}
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   135
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   136
uint64_t CompositeElapsedCounterSource::nanoseconds(Type value) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   137
  return (uint64_t)conversion<ElapsedCounterSource, NANOUNITS>(value.val1);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47216
diff changeset
   138
}