< prev index next >

src/share/vm/utilities/ticks.cpp

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
  * 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.

@@ -22,47 +22,115 @@
  *
  */
 
 #include "precompiled.hpp"
 #include "runtime/os.hpp"
-#include "utilities/ticks.inline.hpp"
+#include "utilities/ticks.hpp"
 
-#ifdef ASSERT
- const jlong Ticks::invalid_time_stamp = -2; // 0xFFFF FFFF`FFFF FFFE
+#if defined(X86) && !defined(ZERO)
+#include "rdtsc_x86.hpp"
 #endif
 
-void Ticks::stamp() {
-  _stamp_ticks = os::elapsed_counter();
+template <typename TimeSource, const int unit>
+inline double conversion(typename TimeSource::Type& value) {
+  return (double)value * ((double)unit / (double)TimeSource::frequency());
 }
 
-const Ticks Ticks::now() {
-  Ticks t;
-  t.stamp();
-  return t;
+uint64_t ElapsedCounterSource::frequency() {
+  static const uint64_t freq = (uint64_t)os::elapsed_frequency();
+  return freq;
 }
 
-Tickspan::Tickspan(const Ticks& end, const Ticks& start) {
-  assert(end.value() != Ticks::invalid_time_stamp, "end is unstamped!");
-  assert(start.value() != Ticks::invalid_time_stamp, "start is unstamped!");
+ElapsedCounterSource::Type ElapsedCounterSource::now() {
+  return os::elapsed_counter();
+}
+
+double ElapsedCounterSource::seconds(Type value) {
+  return conversion<ElapsedCounterSource, 1>(value);
+}
 
-  assert(end >= start, "negative time!");
+uint64_t ElapsedCounterSource::milliseconds(Type value) {
+  return (uint64_t)conversion<ElapsedCounterSource, MILLIUNITS>(value);
+}
 
-  _span_ticks = end.value() - start.value();
+uint64_t ElapsedCounterSource::microseconds(Type value) {
+  return (uint64_t)conversion<ElapsedCounterSource, MICROUNITS>(value);
 }
 
-template <typename ReturnType>
-static ReturnType time_conversion(const Tickspan& span, TicksToTimeHelper::Unit unit) {
-  assert(TicksToTimeHelper::SECONDS == unit ||
-         TicksToTimeHelper::MILLISECONDS == unit, "invalid unit!");
+uint64_t ElapsedCounterSource::nanoseconds(Type value) {
+  return (uint64_t)conversion<ElapsedCounterSource, NANOUNITS>(value);
+}
+
+uint64_t FastUnorderedElapsedCounterSource::frequency() {
+#if defined(X86) && !defined(ZERO)
+  static bool valid_rdtsc = Rdtsc::initialize();
+  if (valid_rdtsc) {
+    static const uint64_t freq = (uint64_t)Rdtsc::frequency();
+    return freq;
+  }
+#endif
+  static const uint64_t freq = (uint64_t)os::elapsed_frequency();
+  return freq;
+}
+
+FastUnorderedElapsedCounterSource::Type FastUnorderedElapsedCounterSource::now() {
+#if defined(X86) && !defined(ZERO)
+  static bool valid_rdtsc = Rdtsc::initialize();
+  if (valid_rdtsc) {
+    return Rdtsc::elapsed_counter();
+  }
+#endif
+  return os::elapsed_counter();
+}
+
+double FastUnorderedElapsedCounterSource::seconds(Type value) {
+  return conversion<FastUnorderedElapsedCounterSource, 1>(value);
+}
 
-  ReturnType frequency_per_unit = (ReturnType)os::elapsed_frequency() / (ReturnType)unit;
+uint64_t FastUnorderedElapsedCounterSource::milliseconds(Type value) {
+  return (uint64_t)conversion<FastUnorderedElapsedCounterSource, MILLIUNITS>(value);
+}
+
+uint64_t FastUnorderedElapsedCounterSource::microseconds(Type value) {
+  return (uint64_t)conversion<FastUnorderedElapsedCounterSource, MICROUNITS>(value);
+}
+
+uint64_t FastUnorderedElapsedCounterSource::nanoseconds(Type value) {
+  return (uint64_t)conversion<FastUnorderedElapsedCounterSource, NANOUNITS>(value);
+}
+
+uint64_t CompositeElapsedCounterSource::frequency() {
+  return ElapsedCounterSource::frequency();
+}
+
+CompositeElapsedCounterSource::Type CompositeElapsedCounterSource::now() {
+  CompositeTime ct;
+  ct.val1 = ElapsedCounterSource::now();
+#if defined(X86) && !defined(ZERO)
+  static bool initialized = false;
+  static bool valid_rdtsc = false;
+  if (!initialized) {
+    valid_rdtsc = Rdtsc::initialize();
+    initialized = true;
+  }
+  if (valid_rdtsc) {
+    ct.val2 = Rdtsc::elapsed_counter();
+  }
+#endif
+  return ct;
+}
+
+double CompositeElapsedCounterSource::seconds(Type value) {
+  return conversion<ElapsedCounterSource, 1>(value.val1);
+}
 
-  return (ReturnType) ((ReturnType)span.value() / frequency_per_unit);
+uint64_t CompositeElapsedCounterSource::milliseconds(Type value) {
+  return (uint64_t)conversion<ElapsedCounterSource, MILLIUNITS>(value.val1);
 }
 
-double TicksToTimeHelper::seconds(const Tickspan& span) {
-  return time_conversion<double>(span, SECONDS);
+uint64_t CompositeElapsedCounterSource::microseconds(Type value) {
+  return (uint64_t)conversion<ElapsedCounterSource, MICROUNITS>(value.val1);
 }
 
-jlong TicksToTimeHelper::milliseconds(const Tickspan& span) {
-  return time_conversion<jlong>(span, MILLISECONDS);
+uint64_t CompositeElapsedCounterSource::nanoseconds(Type value) {
+  return (uint64_t)conversion<ElapsedCounterSource, NANOUNITS>(value.val1);
 }
< prev index next >