Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/jfr/utilities/jfrTimeConverter.cpp
38920 views
/*1* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "jfr/utilities/jfrTimeConverter.hpp"26#include "jfr/utilities/jfrTime.hpp"27#include "runtime/os.hpp"2829static double ft_counter_to_nanos_factor = .0;30static double nanos_to_ft_counter_factor = .0;31static double os_counter_to_nanos_factor = .0;32static double nanos_to_os_counter_factor = .0;3334const double JfrTimeConverter::NANOS_PER_SEC = 1000000000.0;35const double JfrTimeConverter::NANOS_PER_MILLISEC = 1000000.0;36const double JfrTimeConverter::NANOS_PER_MICROSEC = 1000.0;3738static bool initialized = false;3940void JfrTimeConverter::initialize() {41if (!initialized) {42nanos_to_os_counter_factor = (double)os::elapsed_frequency() / NANOS_PER_SEC;43assert(nanos_to_os_counter_factor != .0, "error in conversion!");44os_counter_to_nanos_factor = (double)1.0 / nanos_to_os_counter_factor;45assert(os_counter_to_nanos_factor != .0, "error in conversion!");46if (JfrTime::is_ft_enabled()) {47nanos_to_ft_counter_factor = (double)JfrTime::frequency() / NANOS_PER_SEC;48assert(nanos_to_ft_counter_factor != .0, "error in conversion!");49ft_counter_to_nanos_factor = (double)1.0 / nanos_to_ft_counter_factor;50assert(ft_counter_to_nanos_factor != .0, "error in conversion!");51}52initialized = true;53}54}5556double JfrTimeConverter::counter_to_nano_multiplier(bool is_os_time) {57if (!initialized) {58initialize();59}60return JfrTime::is_ft_enabled() && !is_os_time ? ft_counter_to_nanos_factor : os_counter_to_nanos_factor;61}6263double JfrTimeConverter::nano_to_counter_multiplier(bool is_os_time) {64if (!initialized) {65initialize();66}67return JfrTime::is_ft_enabled() && !is_os_time ? nanos_to_ft_counter_factor : nanos_to_os_counter_factor;68}6970double JfrTimeConverter::counter_to_nanos_internal(jlong c, bool is_os_time) {71return (double)c * counter_to_nano_multiplier(is_os_time);72}7374double JfrTimeConverter::counter_to_millis_internal(jlong c, bool is_os_time) {75return (counter_to_nanos_internal(c, is_os_time) / NANOS_PER_MILLISEC);76}7778jlong JfrTimeConverter::counter_to_nanos(jlong c, bool is_os_time) {79return (jlong)counter_to_nanos_internal(c, is_os_time);80}8182jlong JfrTimeConverter::counter_to_millis(jlong c, bool is_os_time) {83return (jlong)counter_to_millis_internal(c, is_os_time);84}8586jlong JfrTimeConverter::nanos_to_countertime(jlong nanos, bool as_os_time) {87return nanos <= 0 ? 0 : (jlong)((double)nanos * nano_to_counter_multiplier(as_os_time));88}899091