0N/A/*
4170N/A * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "classfile/classLoader.hpp"
1879N/A#include "services/attachListener.hpp"
1879N/A#include "services/management.hpp"
1879N/A#include "services/runtimeService.hpp"
1879N/A#include "utilities/dtrace.hpp"
1879N/A#include "utilities/exceptions.hpp"
0N/A
2842N/A#ifndef USDT2
0N/AHS_DTRACE_PROBE_DECL(hs_private, safepoint__begin);
0N/AHS_DTRACE_PROBE_DECL(hs_private, safepoint__end);
2842N/A#endif /* !USDT2 */
0N/A
0N/ATimeStamp RuntimeService::_app_timer;
0N/ATimeStamp RuntimeService::_safepoint_timer;
0N/APerfCounter* RuntimeService::_sync_time_ticks = NULL;
0N/APerfCounter* RuntimeService::_total_safepoints = NULL;
0N/APerfCounter* RuntimeService::_safepoint_time_ticks = NULL;
0N/APerfCounter* RuntimeService::_application_time_ticks = NULL;
0N/APerfCounter* RuntimeService::_thread_interrupt_signaled_count = NULL;
0N/APerfCounter* RuntimeService::_interrupted_before_count = NULL;
0N/APerfCounter* RuntimeService::_interrupted_during_count = NULL;
0N/A
0N/Avoid RuntimeService::init() {
0N/A // Make sure the VM version is initialized
0N/A Abstract_VM_Version::initialize();
0N/A
0N/A if (UsePerfData) {
0N/A EXCEPTION_MARK;
0N/A
0N/A _sync_time_ticks =
0N/A PerfDataManager::create_counter(SUN_RT, "safepointSyncTime",
0N/A PerfData::U_Ticks, CHECK);
0N/A
0N/A _total_safepoints =
0N/A PerfDataManager::create_counter(SUN_RT, "safepoints",
0N/A PerfData::U_Events, CHECK);
0N/A
0N/A _safepoint_time_ticks =
0N/A PerfDataManager::create_counter(SUN_RT, "safepointTime",
0N/A PerfData::U_Ticks, CHECK);
0N/A
0N/A _application_time_ticks =
0N/A PerfDataManager::create_counter(SUN_RT, "applicationTime",
0N/A PerfData::U_Ticks, CHECK);
0N/A
0N/A
0N/A // create performance counters for jvm_version and its capabilities
0N/A PerfDataManager::create_constant(SUN_RT, "jvmVersion", PerfData::U_None,
0N/A (jlong) Abstract_VM_Version::jvm_version(), CHECK);
0N/A
0N/A // I/O interruption related counters
0N/A
0N/A // thread signaling via os::interrupt()
0N/A
0N/A _thread_interrupt_signaled_count =
0N/A PerfDataManager::create_counter(SUN_RT,
0N/A "threadInterruptSignaled", PerfData::U_Events, CHECK);
0N/A
0N/A // OS_INTRPT via "check before" in _INTERRUPTIBLE
0N/A
0N/A _interrupted_before_count =
0N/A PerfDataManager::create_counter(SUN_RT, "interruptedBeforeIO",
0N/A PerfData::U_Events, CHECK);
0N/A
0N/A // OS_INTRPT via "check during" in _INTERRUPTIBLE
0N/A
0N/A _interrupted_during_count =
0N/A PerfDataManager::create_counter(SUN_RT, "interruptedDuringIO",
0N/A PerfData::U_Events, CHECK);
0N/A
0N/A // The capabilities counter is a binary representation of the VM capabilities in string.
0N/A // This string respresentation simplifies the implementation of the client side
0N/A // to parse the value.
0N/A char capabilities[65];
0N/A size_t len = sizeof(capabilities);
0N/A memset((void*) capabilities, '0', len);
0N/A capabilities[len-1] = '\0';
0N/A capabilities[0] = AttachListener::is_attach_supported() ? '1' : '0';
0N/A PerfDataManager::create_string_constant(SUN_RT, "jvmCapabilities",
0N/A capabilities, CHECK);
0N/A }
0N/A}
0N/A
0N/Avoid RuntimeService::record_safepoint_begin() {
2842N/A#ifndef USDT2
0N/A HS_DTRACE_PROBE(hs_private, safepoint__begin);
2842N/A#else /* USDT2 */
2842N/A HS_PRIVATE_SAFEPOINT_BEGIN();
2842N/A#endif /* USDT2 */
1260N/A
1260N/A // Print the time interval in which the app was executing
1260N/A if (PrintGCApplicationConcurrentTime) {
4430N/A gclog_or_tty->date_stamp(PrintGCDateStamps);
4430N/A gclog_or_tty->stamp(PrintGCTimeStamps);
1260N/A gclog_or_tty->print_cr("Application time: %3.7f seconds",
1260N/A last_application_time_sec());
1260N/A }
1260N/A
0N/A // update the time stamp to begin recording safepoint time
0N/A _safepoint_timer.update();
0N/A if (UsePerfData) {
0N/A _total_safepoints->inc();
0N/A if (_app_timer.is_updated()) {
0N/A _application_time_ticks->inc(_app_timer.ticks_since_update());
0N/A }
0N/A }
0N/A}
0N/A
0N/Avoid RuntimeService::record_safepoint_synchronized() {
0N/A if (UsePerfData) {
0N/A _sync_time_ticks->inc(_safepoint_timer.ticks_since_update());
0N/A }
0N/A}
0N/A
0N/Avoid RuntimeService::record_safepoint_end() {
2842N/A#ifndef USDT2
0N/A HS_DTRACE_PROBE(hs_private, safepoint__end);
2842N/A#else /* USDT2 */
2842N/A HS_PRIVATE_SAFEPOINT_END();
2842N/A#endif /* USDT2 */
1260N/A
1260N/A // Print the time interval for which the app was stopped
1260N/A // during the current safepoint operation.
1260N/A if (PrintGCApplicationStoppedTime) {
4430N/A gclog_or_tty->date_stamp(PrintGCDateStamps);
4430N/A gclog_or_tty->stamp(PrintGCTimeStamps);
1260N/A gclog_or_tty->print_cr("Total time for which application threads "
1260N/A "were stopped: %3.7f seconds",
1260N/A last_safepoint_time_sec());
1260N/A }
1260N/A
0N/A // update the time stamp to begin recording app time
0N/A _app_timer.update();
0N/A if (UsePerfData) {
0N/A _safepoint_time_ticks->inc(_safepoint_timer.ticks_since_update());
0N/A }
0N/A}
0N/A
0N/Avoid RuntimeService::record_application_start() {
0N/A // update the time stamp to begin recording app time
0N/A _app_timer.update();
0N/A}
0N/A
0N/A// Don't need to record application end because we currently
0N/A// exit at a safepoint and record_safepoint_begin() handles updating
0N/A// the application time counter at VM exit.
0N/A
0N/Ajlong RuntimeService::safepoint_sync_time_ms() {
0N/A return UsePerfData ?
0N/A Management::ticks_to_ms(_sync_time_ticks->get_value()) : -1;
0N/A}
0N/A
0N/Ajlong RuntimeService::safepoint_count() {
0N/A return UsePerfData ?
0N/A _total_safepoints->get_value() : -1;
0N/A}
0N/Ajlong RuntimeService::safepoint_time_ms() {
0N/A return UsePerfData ?
0N/A Management::ticks_to_ms(_safepoint_time_ticks->get_value()) : -1;
0N/A}
0N/A
0N/Ajlong RuntimeService::application_time_ms() {
0N/A return UsePerfData ?
0N/A Management::ticks_to_ms(_application_time_ticks->get_value()) : -1;
0N/A}
0N/A
0N/Avoid RuntimeService::record_interrupted_before_count() {
0N/A if (UsePerfData) {
0N/A _interrupted_before_count->inc();
0N/A }
0N/A}
0N/A
0N/Avoid RuntimeService::record_interrupted_during_count() {
0N/A if (UsePerfData) {
0N/A _interrupted_during_count->inc();
0N/A }
0N/A}
0N/A
0N/Avoid RuntimeService::record_thread_interrupt_signaled_count() {
0N/A if (UsePerfData) {
0N/A _thread_interrupt_signaled_count->inc();
0N/A }
0N/A}