# HG changeset patch # User brutisso # Date 1431073816 -7200 # Node ID d79880a5cf2f9da03133aa2b1c57a00fbe58025b # Parent 23e6e981e89c93be34cf125112fd9e60ae4ecf6f 8079561: Add a method to convert counters to milliseconds Reviewed-by: mgerdin, ehelin diff -r 23e6e981e89c -r d79880a5cf2f hotspot/src/share/vm/runtime/task.cpp --- a/hotspot/src/share/vm/runtime/task.cpp Thu May 07 10:32:42 2015 +0200 +++ b/hotspot/src/share/vm/runtime/task.cpp Fri May 08 10:30:16 2015 +0200 @@ -53,7 +53,7 @@ if (ProfilerCheckIntervals) { _ticks++; _timer.stop(); - int ms = (int)(_timer.seconds() * 1000.0); + int ms = (int)_timer.milliseconds(); _timer.reset(); _timer.start(); if (ms >= PeriodicTask::max_interval) ms = PeriodicTask::max_interval - 1; diff -r 23e6e981e89c -r d79880a5cf2f hotspot/src/share/vm/runtime/timer.cpp --- a/hotspot/src/share/vm/runtime/timer.cpp Thu May 07 10:32:42 2015 +0200 +++ b/hotspot/src/share/vm/runtime/timer.cpp Fri May 08 10:30:16 2015 +0200 @@ -28,9 +28,12 @@ #include "utilities/ostream.hpp" double TimeHelper::counter_to_seconds(jlong counter) { - double count = (double) counter; double freq = (double) os::elapsed_frequency(); - return counter/freq; + return counter / freq; +} + +double TimeHelper::counter_to_millis(jlong counter) { + return counter_to_seconds(counter) * 1000.0; } void elapsedTimer::add(elapsedTimer t) { @@ -56,8 +59,7 @@ } jlong elapsedTimer::milliseconds() const { - jlong ticks_per_ms = os::elapsed_frequency() / 1000; - return _counter / ticks_per_ms; + return TimeHelper::counter_to_millis(_counter); } jlong elapsedTimer::active_ticks() const { @@ -86,11 +88,8 @@ jlong TimeStamp::milliseconds() const { assert(is_updated(), "must not be clear"); - jlong new_count = os::elapsed_counter(); - jlong count = new_count - _counter; - jlong ticks_per_ms = os::elapsed_frequency() / 1000; - return count / ticks_per_ms; + return TimeHelper::counter_to_millis(new_count - _counter); } jlong TimeStamp::ticks_since_update() const { diff -r 23e6e981e89c -r d79880a5cf2f hotspot/src/share/vm/runtime/timer.hpp --- a/hotspot/src/share/vm/runtime/timer.hpp Thu May 07 10:32:42 2015 +0200 +++ b/hotspot/src/share/vm/runtime/timer.hpp Fri May 08 10:30:16 2015 +0200 @@ -123,6 +123,7 @@ class TimeHelper { public: static double counter_to_seconds(jlong counter); + static double counter_to_millis(jlong counter); }; #endif // SHARE_VM_RUNTIME_TIMER_HPP