author | sgehwolf |
Wed, 16 May 2018 15:25:51 +0200 | |
changeset 50174 | 78d9ffb8146f |
parent 50113 | caf115bb98ad |
permissions | -rw-r--r-- |
21767
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
1 |
/* |
50113 | 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 | 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 | 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 | 33 |
#include OS_CPU_HEADER(os) |
34 |
||
35 |
template <typename TimeSource, const int unit> |
|
36 |
inline double conversion(typename TimeSource::Type& value) { |
|
37 |
return (double)value * ((double)unit / (double)TimeSource::frequency()); |
|
38 |
} |
|
39 |
||
40 |
uint64_t ElapsedCounterSource::frequency() { |
|
41 |
static const uint64_t freq = (uint64_t)os::elapsed_frequency(); |
|
42 |
return freq; |
|
43 |
} |
|
44 |
||
45 |
ElapsedCounterSource::Type ElapsedCounterSource::now() { |
|
46 |
return os::elapsed_counter(); |
|
47 |
} |
|
48 |
||
49 |
double ElapsedCounterSource::seconds(Type value) { |
|
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 | 53 |
uint64_t ElapsedCounterSource::milliseconds(Type value) { |
54 |
return (uint64_t)conversion<ElapsedCounterSource, MILLIUNITS>(value); |
|
55 |
} |
|
56 |
||
57 |
uint64_t ElapsedCounterSource::microseconds(Type value) { |
|
58 |
return (uint64_t)conversion<ElapsedCounterSource, MICROUNITS>(value); |
|
59 |
} |
|
60 |
||
61 |
uint64_t ElapsedCounterSource::nanoseconds(Type value) { |
|
62 |
return (uint64_t)conversion<ElapsedCounterSource, NANOUNITS>(value); |
|
63 |
} |
|
64 |
||
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 | 67 |
static bool valid_rdtsc = Rdtsc::initialize(); |
68 |
if (valid_rdtsc) { |
|
69 |
static const uint64_t freq = (uint64_t)Rdtsc::frequency(); |
|
70 |
return freq; |
|
71 |
} |
|
72 |
#endif |
|
73 |
static const uint64_t freq = (uint64_t)os::elapsed_frequency(); |
|
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 | 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 | 79 |
static bool valid_rdtsc = Rdtsc::initialize(); |
80 |
if (valid_rdtsc) { |
|
81 |
return Rdtsc::elapsed_counter(); |
|
82 |
} |
|
83 |
#endif |
|
84 |
return os::elapsed_counter(); |
|
85 |
} |
|
86 |
||
87 |
double FastUnorderedElapsedCounterSource::seconds(Type value) { |
|
88 |
return conversion<FastUnorderedElapsedCounterSource, 1>(value); |
|
89 |
} |
|
21767
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
90 |
|
50113 | 91 |
uint64_t FastUnorderedElapsedCounterSource::milliseconds(Type value) { |
92 |
return (uint64_t)conversion<FastUnorderedElapsedCounterSource, MILLIUNITS>(value); |
|
93 |
} |
|
21767
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
94 |
|
50113 | 95 |
uint64_t FastUnorderedElapsedCounterSource::microseconds(Type value) { |
96 |
return (uint64_t)conversion<FastUnorderedElapsedCounterSource, MICROUNITS>(value); |
|
97 |
} |
|
98 |
||
99 |
uint64_t FastUnorderedElapsedCounterSource::nanoseconds(Type value) { |
|
100 |
return (uint64_t)conversion<FastUnorderedElapsedCounterSource, NANOUNITS>(value); |
|
101 |
} |
|
102 |
||
103 |
uint64_t CompositeElapsedCounterSource::frequency() { |
|
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 | 107 |
CompositeElapsedCounterSource::Type CompositeElapsedCounterSource::now() { |
108 |
CompositeTime ct; |
|
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 | 111 |
static bool initialized = false; |
112 |
static bool valid_rdtsc = false; |
|
113 |
if (!initialized) { |
|
114 |
valid_rdtsc = Rdtsc::initialize(); |
|
115 |
initialized = true; |
|
116 |
} |
|
117 |
if (valid_rdtsc) { |
|
118 |
ct.val2 = Rdtsc::elapsed_counter(); |
|
119 |
} |
|
120 |
#endif |
|
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 | 124 |
double CompositeElapsedCounterSource::seconds(Type value) { |
125 |
return conversion<ElapsedCounterSource, 1>(value.val1); |
|
126 |
} |
|
127 |
||
128 |
uint64_t CompositeElapsedCounterSource::milliseconds(Type value) { |
|
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 | 132 |
uint64_t CompositeElapsedCounterSource::microseconds(Type value) { |
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 | 135 |
|
136 |
uint64_t CompositeElapsedCounterSource::nanoseconds(Type value) { |
|
137 |
return (uint64_t)conversion<ElapsedCounterSource, NANOUNITS>(value.val1); |
|
138 |
} |