src/share/vm/services/runtimeService.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "classfile/classLoader.hpp"
aoqi@0 27 #include "services/attachListener.hpp"
aoqi@0 28 #include "services/management.hpp"
aoqi@0 29 #include "services/runtimeService.hpp"
aoqi@0 30 #include "utilities/dtrace.hpp"
aoqi@0 31 #include "utilities/exceptions.hpp"
aoqi@0 32 #include "utilities/macros.hpp"
aoqi@0 33
aoqi@0 34 #ifndef USDT2
aoqi@0 35 HS_DTRACE_PROBE_DECL(hs_private, safepoint__begin);
aoqi@0 36 HS_DTRACE_PROBE_DECL(hs_private, safepoint__end);
aoqi@0 37 #endif /* !USDT2 */
aoqi@0 38
aoqi@0 39 #if INCLUDE_MANAGEMENT
aoqi@0 40 TimeStamp RuntimeService::_app_timer;
aoqi@0 41 TimeStamp RuntimeService::_safepoint_timer;
aoqi@0 42 PerfCounter* RuntimeService::_sync_time_ticks = NULL;
aoqi@0 43 PerfCounter* RuntimeService::_total_safepoints = NULL;
aoqi@0 44 PerfCounter* RuntimeService::_safepoint_time_ticks = NULL;
aoqi@0 45 PerfCounter* RuntimeService::_application_time_ticks = NULL;
aoqi@0 46 PerfCounter* RuntimeService::_thread_interrupt_signaled_count = NULL;
aoqi@0 47 PerfCounter* RuntimeService::_interrupted_before_count = NULL;
aoqi@0 48 PerfCounter* RuntimeService::_interrupted_during_count = NULL;
aoqi@0 49
aoqi@0 50 void RuntimeService::init() {
aoqi@0 51 // Make sure the VM version is initialized
aoqi@0 52 Abstract_VM_Version::initialize();
aoqi@0 53
aoqi@0 54 if (UsePerfData) {
aoqi@0 55 EXCEPTION_MARK;
aoqi@0 56
aoqi@0 57 _sync_time_ticks =
aoqi@0 58 PerfDataManager::create_counter(SUN_RT, "safepointSyncTime",
aoqi@0 59 PerfData::U_Ticks, CHECK);
aoqi@0 60
aoqi@0 61 _total_safepoints =
aoqi@0 62 PerfDataManager::create_counter(SUN_RT, "safepoints",
aoqi@0 63 PerfData::U_Events, CHECK);
aoqi@0 64
aoqi@0 65 _safepoint_time_ticks =
aoqi@0 66 PerfDataManager::create_counter(SUN_RT, "safepointTime",
aoqi@0 67 PerfData::U_Ticks, CHECK);
aoqi@0 68
aoqi@0 69 _application_time_ticks =
aoqi@0 70 PerfDataManager::create_counter(SUN_RT, "applicationTime",
aoqi@0 71 PerfData::U_Ticks, CHECK);
aoqi@0 72
aoqi@0 73
aoqi@0 74 // create performance counters for jvm_version and its capabilities
aoqi@0 75 PerfDataManager::create_constant(SUN_RT, "jvmVersion", PerfData::U_None,
aoqi@0 76 (jlong) Abstract_VM_Version::jvm_version(), CHECK);
aoqi@0 77
aoqi@0 78 // I/O interruption related counters
aoqi@0 79
aoqi@0 80 // thread signaling via os::interrupt()
aoqi@0 81
aoqi@0 82 _thread_interrupt_signaled_count =
aoqi@0 83 PerfDataManager::create_counter(SUN_RT,
aoqi@0 84 "threadInterruptSignaled", PerfData::U_Events, CHECK);
aoqi@0 85
aoqi@0 86 // OS_INTRPT via "check before" in _INTERRUPTIBLE
aoqi@0 87
aoqi@0 88 _interrupted_before_count =
aoqi@0 89 PerfDataManager::create_counter(SUN_RT, "interruptedBeforeIO",
aoqi@0 90 PerfData::U_Events, CHECK);
aoqi@0 91
aoqi@0 92 // OS_INTRPT via "check during" in _INTERRUPTIBLE
aoqi@0 93
aoqi@0 94 _interrupted_during_count =
aoqi@0 95 PerfDataManager::create_counter(SUN_RT, "interruptedDuringIO",
aoqi@0 96 PerfData::U_Events, CHECK);
aoqi@0 97
aoqi@0 98 // The capabilities counter is a binary representation of the VM capabilities in string.
aoqi@0 99 // This string respresentation simplifies the implementation of the client side
aoqi@0 100 // to parse the value.
aoqi@0 101 char capabilities[65];
aoqi@0 102 size_t len = sizeof(capabilities);
aoqi@0 103 memset((void*) capabilities, '0', len);
aoqi@0 104 capabilities[len-1] = '\0';
aoqi@0 105 capabilities[0] = AttachListener::is_attach_supported() ? '1' : '0';
aoqi@0 106 #if INCLUDE_SERVICES
aoqi@0 107 capabilities[1] = '1';
aoqi@0 108 #endif // INCLUDE_SERVICES
aoqi@0 109 PerfDataManager::create_string_constant(SUN_RT, "jvmCapabilities",
aoqi@0 110 capabilities, CHECK);
aoqi@0 111 }
aoqi@0 112 }
aoqi@0 113
aoqi@0 114 void RuntimeService::record_safepoint_begin() {
aoqi@0 115 #ifndef USDT2
aoqi@0 116 HS_DTRACE_PROBE(hs_private, safepoint__begin);
aoqi@0 117 #else /* USDT2 */
aoqi@0 118 HS_PRIVATE_SAFEPOINT_BEGIN();
aoqi@0 119 #endif /* USDT2 */
aoqi@0 120
aoqi@0 121 // Print the time interval in which the app was executing
aoqi@0 122 if (PrintGCApplicationConcurrentTime && _app_timer.is_updated()) {
aoqi@0 123 gclog_or_tty->date_stamp(PrintGCDateStamps);
aoqi@0 124 gclog_or_tty->stamp(PrintGCTimeStamps);
aoqi@0 125 gclog_or_tty->print_cr("Application time: %3.7f seconds",
aoqi@0 126 last_application_time_sec());
aoqi@0 127 }
aoqi@0 128
aoqi@0 129 // update the time stamp to begin recording safepoint time
aoqi@0 130 _safepoint_timer.update();
aoqi@0 131 if (UsePerfData) {
aoqi@0 132 _total_safepoints->inc();
aoqi@0 133 if (_app_timer.is_updated()) {
aoqi@0 134 _application_time_ticks->inc(_app_timer.ticks_since_update());
aoqi@0 135 }
aoqi@0 136 }
aoqi@0 137 }
aoqi@0 138
aoqi@0 139 void RuntimeService::record_safepoint_synchronized() {
aoqi@0 140 if (UsePerfData) {
aoqi@0 141 _sync_time_ticks->inc(_safepoint_timer.ticks_since_update());
aoqi@0 142 }
aoqi@0 143 }
aoqi@0 144
aoqi@0 145 void RuntimeService::record_safepoint_end() {
aoqi@0 146 #ifndef USDT2
aoqi@0 147 HS_DTRACE_PROBE(hs_private, safepoint__end);
aoqi@0 148 #else /* USDT2 */
aoqi@0 149 HS_PRIVATE_SAFEPOINT_END();
aoqi@0 150 #endif /* USDT2 */
aoqi@0 151
aoqi@0 152 // Print the time interval for which the app was stopped
aoqi@0 153 // during the current safepoint operation.
aoqi@0 154 if (PrintGCApplicationStoppedTime) {
aoqi@0 155 gclog_or_tty->date_stamp(PrintGCDateStamps);
aoqi@0 156 gclog_or_tty->stamp(PrintGCTimeStamps);
aoqi@0 157 gclog_or_tty->print_cr("Total time for which application threads "
aoqi@0 158 "were stopped: %3.7f seconds",
aoqi@0 159 last_safepoint_time_sec());
aoqi@0 160 }
aoqi@0 161
aoqi@0 162 // update the time stamp to begin recording app time
aoqi@0 163 _app_timer.update();
aoqi@0 164 if (UsePerfData) {
aoqi@0 165 _safepoint_time_ticks->inc(_safepoint_timer.ticks_since_update());
aoqi@0 166 }
aoqi@0 167 }
aoqi@0 168
aoqi@0 169 void RuntimeService::record_application_start() {
aoqi@0 170 // update the time stamp to begin recording app time
aoqi@0 171 _app_timer.update();
aoqi@0 172 }
aoqi@0 173
aoqi@0 174 // Don't need to record application end because we currently
aoqi@0 175 // exit at a safepoint and record_safepoint_begin() handles updating
aoqi@0 176 // the application time counter at VM exit.
aoqi@0 177
aoqi@0 178 jlong RuntimeService::safepoint_sync_time_ms() {
aoqi@0 179 return UsePerfData ?
aoqi@0 180 Management::ticks_to_ms(_sync_time_ticks->get_value()) : -1;
aoqi@0 181 }
aoqi@0 182
aoqi@0 183 jlong RuntimeService::safepoint_count() {
aoqi@0 184 return UsePerfData ?
aoqi@0 185 _total_safepoints->get_value() : -1;
aoqi@0 186 }
aoqi@0 187 jlong RuntimeService::safepoint_time_ms() {
aoqi@0 188 return UsePerfData ?
aoqi@0 189 Management::ticks_to_ms(_safepoint_time_ticks->get_value()) : -1;
aoqi@0 190 }
aoqi@0 191
aoqi@0 192 jlong RuntimeService::application_time_ms() {
aoqi@0 193 return UsePerfData ?
aoqi@0 194 Management::ticks_to_ms(_application_time_ticks->get_value()) : -1;
aoqi@0 195 }
aoqi@0 196
aoqi@0 197 void RuntimeService::record_interrupted_before_count() {
aoqi@0 198 if (UsePerfData) {
aoqi@0 199 _interrupted_before_count->inc();
aoqi@0 200 }
aoqi@0 201 }
aoqi@0 202
aoqi@0 203 void RuntimeService::record_interrupted_during_count() {
aoqi@0 204 if (UsePerfData) {
aoqi@0 205 _interrupted_during_count->inc();
aoqi@0 206 }
aoqi@0 207 }
aoqi@0 208
aoqi@0 209 void RuntimeService::record_thread_interrupt_signaled_count() {
aoqi@0 210 if (UsePerfData) {
aoqi@0 211 _thread_interrupt_signaled_count->inc();
aoqi@0 212 }
aoqi@0 213 }
aoqi@0 214
aoqi@0 215 #endif // INCLUDE_MANAGEMENT

mercurial