author | stefank |
Tue, 28 Nov 2017 21:43:45 +0100 | |
changeset 48157 | 7c4d43c26352 |
parent 47216 | 71c04702a3d5 |
child 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 |
/* |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
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" |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
27 |
#include "utilities/ticks.inline.hpp" |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
28 |
|
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
29 |
#ifdef ASSERT |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
30 |
const jlong Ticks::invalid_time_stamp = -2; // 0xFFFF FFFF`FFFF FFFE |
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 |
|
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
33 |
void Ticks::stamp() { |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
34 |
_stamp_ticks = os::elapsed_counter(); |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
35 |
} |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
36 |
|
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
37 |
const Ticks Ticks::now() { |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
38 |
Ticks t; |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
39 |
t.stamp(); |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
40 |
return t; |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
41 |
} |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
42 |
|
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
43 |
Tickspan::Tickspan(const Ticks& end, const Ticks& start) { |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
44 |
assert(end.value() != Ticks::invalid_time_stamp, "end is unstamped!"); |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
45 |
assert(start.value() != Ticks::invalid_time_stamp, "start is unstamped!"); |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
46 |
|
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
47 |
assert(end >= start, "negative time!"); |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
48 |
|
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
49 |
_span_ticks = end.value() - start.value(); |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
50 |
} |
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 |
template <typename ReturnType> |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
53 |
static ReturnType time_conversion(const Tickspan& span, TicksToTimeHelper::Unit unit) { |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
54 |
assert(TicksToTimeHelper::SECONDS == unit || |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
55 |
TicksToTimeHelper::MILLISECONDS == unit, "invalid unit!"); |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
56 |
|
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
57 |
ReturnType frequency_per_unit = (ReturnType)os::elapsed_frequency() / (ReturnType)unit; |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
58 |
|
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
59 |
return (ReturnType) ((ReturnType)span.value() / frequency_per_unit); |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
60 |
} |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
61 |
|
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
62 |
double TicksToTimeHelper::seconds(const Tickspan& span) { |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
63 |
return time_conversion<double>(span, SECONDS); |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
64 |
} |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
65 |
|
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
66 |
jlong TicksToTimeHelper::milliseconds(const Tickspan& span) { |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
67 |
return time_conversion<jlong>(span, MILLISECONDS); |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
diff
changeset
|
68 |
} |