< prev index next >

src/hotspot/share/runtime/timer.cpp

Print this page
rev 47591 : Add Thread Local handshakes and thread local polling
   1 /*
   2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "logging/log.hpp"
  27 #include "oops/oop.inline.hpp"
  28 #include "runtime/timer.hpp"
  29 #include "utilities/ostream.hpp"
  30 
  31 double TimeHelper::counter_to_seconds(jlong counter) {
  32   double freq  = (double) os::elapsed_frequency();
  33   return counter / freq;
  34 }
  35 
  36 double TimeHelper::counter_to_millis(jlong counter) {
  37   return counter_to_seconds(counter) * 1000.0;





  38 }
  39 
  40 elapsedTimer::elapsedTimer(jlong time, jlong timeUnitsPerSecond) {
  41   _active = false;
  42   jlong osTimeUnitsPerSecond = os::elapsed_frequency();
  43   assert(osTimeUnitsPerSecond % 1000 == 0, "must be");
  44   assert(timeUnitsPerSecond % 1000 == 0, "must be");
  45   while (osTimeUnitsPerSecond < timeUnitsPerSecond) {
  46     timeUnitsPerSecond /= 1000;
  47     time *= 1000;
  48   }
  49   while (osTimeUnitsPerSecond > timeUnitsPerSecond) {
  50     timeUnitsPerSecond *= 1000;
  51     time /= 1000;
  52   }
  53   _counter = time;
  54 }
  55 
  56 void elapsedTimer::add(elapsedTimer t) {
  57   _counter += t._counter;


   1 /*
   2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "logging/log.hpp"
  27 #include "oops/oop.inline.hpp"
  28 #include "runtime/timer.hpp"
  29 #include "utilities/ostream.hpp"
  30 
  31 double TimeHelper::counter_to_seconds(jlong counter) {
  32   double freq  = (double) os::elapsed_frequency();
  33   return counter / freq;
  34 }
  35 
  36 double TimeHelper::counter_to_millis(jlong counter) {
  37   return counter_to_seconds(counter) * 1000.0;
  38 }
  39 
  40 jlong TimeHelper::millis_to_counter(jlong millis) {
  41   jlong freq = os::elapsed_frequency() / MILLIUNITS;
  42   return millis * freq;
  43 }
  44 
  45 elapsedTimer::elapsedTimer(jlong time, jlong timeUnitsPerSecond) {
  46   _active = false;
  47   jlong osTimeUnitsPerSecond = os::elapsed_frequency();
  48   assert(osTimeUnitsPerSecond % 1000 == 0, "must be");
  49   assert(timeUnitsPerSecond % 1000 == 0, "must be");
  50   while (osTimeUnitsPerSecond < timeUnitsPerSecond) {
  51     timeUnitsPerSecond /= 1000;
  52     time *= 1000;
  53   }
  54   while (osTimeUnitsPerSecond > timeUnitsPerSecond) {
  55     timeUnitsPerSecond *= 1000;
  56     time /= 1000;
  57   }
  58   _counter = time;
  59 }
  60 
  61 void elapsedTimer::add(elapsedTimer t) {
  62   _counter += t._counter;


< prev index next >