src/share/vm/services/runtimeService.cpp

Wed, 03 Jul 2019 20:42:37 +0800

author
aoqi
date
Wed, 03 Jul 2019 20:42:37 +0800
changeset 9637
eef07cd490d4
parent 7535
7ae4e26cb1e0
permissions
-rw-r--r--

Merge

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;
vkempik@7326 49 double RuntimeService::_last_safepoint_sync_time_sec = 0.0;
aoqi@0 50
aoqi@0 51 void RuntimeService::init() {
aoqi@0 52 // Make sure the VM version is initialized
aoqi@0 53 Abstract_VM_Version::initialize();
aoqi@0 54
aoqi@0 55 if (UsePerfData) {
aoqi@0 56 EXCEPTION_MARK;
aoqi@0 57
aoqi@0 58 _sync_time_ticks =
aoqi@0 59 PerfDataManager::create_counter(SUN_RT, "safepointSyncTime",
aoqi@0 60 PerfData::U_Ticks, CHECK);
aoqi@0 61
aoqi@0 62 _total_safepoints =
aoqi@0 63 PerfDataManager::create_counter(SUN_RT, "safepoints",
aoqi@0 64 PerfData::U_Events, CHECK);
aoqi@0 65
aoqi@0 66 _safepoint_time_ticks =
aoqi@0 67 PerfDataManager::create_counter(SUN_RT, "safepointTime",
aoqi@0 68 PerfData::U_Ticks, CHECK);
aoqi@0 69
aoqi@0 70 _application_time_ticks =
aoqi@0 71 PerfDataManager::create_counter(SUN_RT, "applicationTime",
aoqi@0 72 PerfData::U_Ticks, CHECK);
aoqi@0 73
aoqi@0 74
aoqi@0 75 // create performance counters for jvm_version and its capabilities
aoqi@0 76 PerfDataManager::create_constant(SUN_RT, "jvmVersion", PerfData::U_None,
aoqi@0 77 (jlong) Abstract_VM_Version::jvm_version(), CHECK);
aoqi@0 78
aoqi@0 79 // I/O interruption related counters
aoqi@0 80
aoqi@0 81 // thread signaling via os::interrupt()
aoqi@0 82
aoqi@0 83 _thread_interrupt_signaled_count =
aoqi@0 84 PerfDataManager::create_counter(SUN_RT,
aoqi@0 85 "threadInterruptSignaled", PerfData::U_Events, CHECK);
aoqi@0 86
aoqi@0 87 // OS_INTRPT via "check before" in _INTERRUPTIBLE
aoqi@0 88
aoqi@0 89 _interrupted_before_count =
aoqi@0 90 PerfDataManager::create_counter(SUN_RT, "interruptedBeforeIO",
aoqi@0 91 PerfData::U_Events, CHECK);
aoqi@0 92
aoqi@0 93 // OS_INTRPT via "check during" in _INTERRUPTIBLE
aoqi@0 94
aoqi@0 95 _interrupted_during_count =
aoqi@0 96 PerfDataManager::create_counter(SUN_RT, "interruptedDuringIO",
aoqi@0 97 PerfData::U_Events, CHECK);
aoqi@0 98
aoqi@0 99 // The capabilities counter is a binary representation of the VM capabilities in string.
aoqi@0 100 // This string respresentation simplifies the implementation of the client side
aoqi@0 101 // to parse the value.
aoqi@0 102 char capabilities[65];
aoqi@0 103 size_t len = sizeof(capabilities);
aoqi@0 104 memset((void*) capabilities, '0', len);
aoqi@0 105 capabilities[len-1] = '\0';
aoqi@0 106 capabilities[0] = AttachListener::is_attach_supported() ? '1' : '0';
aoqi@0 107 #if INCLUDE_SERVICES
aoqi@0 108 capabilities[1] = '1';
aoqi@0 109 #endif // INCLUDE_SERVICES
aoqi@0 110 PerfDataManager::create_string_constant(SUN_RT, "jvmCapabilities",
aoqi@0 111 capabilities, CHECK);
aoqi@0 112 }
aoqi@0 113 }
aoqi@0 114
aoqi@0 115 void RuntimeService::record_safepoint_begin() {
aoqi@0 116 #ifndef USDT2
aoqi@0 117 HS_DTRACE_PROBE(hs_private, safepoint__begin);
aoqi@0 118 #else /* USDT2 */
aoqi@0 119 HS_PRIVATE_SAFEPOINT_BEGIN();
aoqi@0 120 #endif /* USDT2 */
aoqi@0 121
aoqi@0 122 // Print the time interval in which the app was executing
aoqi@0 123 if (PrintGCApplicationConcurrentTime && _app_timer.is_updated()) {
aoqi@0 124 gclog_or_tty->date_stamp(PrintGCDateStamps);
aoqi@0 125 gclog_or_tty->stamp(PrintGCTimeStamps);
aoqi@0 126 gclog_or_tty->print_cr("Application time: %3.7f seconds",
aoqi@0 127 last_application_time_sec());
aoqi@0 128 }
aoqi@0 129
aoqi@0 130 // update the time stamp to begin recording safepoint time
aoqi@0 131 _safepoint_timer.update();
vkempik@7326 132 _last_safepoint_sync_time_sec = 0.0;
aoqi@0 133 if (UsePerfData) {
aoqi@0 134 _total_safepoints->inc();
aoqi@0 135 if (_app_timer.is_updated()) {
aoqi@0 136 _application_time_ticks->inc(_app_timer.ticks_since_update());
aoqi@0 137 }
aoqi@0 138 }
aoqi@0 139 }
aoqi@0 140
aoqi@0 141 void RuntimeService::record_safepoint_synchronized() {
aoqi@0 142 if (UsePerfData) {
aoqi@0 143 _sync_time_ticks->inc(_safepoint_timer.ticks_since_update());
aoqi@0 144 }
vkempik@7326 145 if (PrintGCApplicationStoppedTime) {
vkempik@7326 146 _last_safepoint_sync_time_sec = last_safepoint_time_sec();
vkempik@7326 147 }
aoqi@0 148 }
aoqi@0 149
aoqi@0 150 void RuntimeService::record_safepoint_end() {
aoqi@0 151 #ifndef USDT2
aoqi@0 152 HS_DTRACE_PROBE(hs_private, safepoint__end);
aoqi@0 153 #else /* USDT2 */
aoqi@0 154 HS_PRIVATE_SAFEPOINT_END();
aoqi@0 155 #endif /* USDT2 */
aoqi@0 156
aoqi@0 157 // Print the time interval for which the app was stopped
aoqi@0 158 // during the current safepoint operation.
aoqi@0 159 if (PrintGCApplicationStoppedTime) {
aoqi@0 160 gclog_or_tty->date_stamp(PrintGCDateStamps);
aoqi@0 161 gclog_or_tty->stamp(PrintGCTimeStamps);
aoqi@0 162 gclog_or_tty->print_cr("Total time for which application threads "
vkempik@7326 163 "were stopped: %3.7f seconds, "
vkempik@7326 164 "Stopping threads took: %3.7f seconds",
vkempik@7326 165 last_safepoint_time_sec(),
vkempik@7326 166 _last_safepoint_sync_time_sec);
aoqi@0 167 }
aoqi@0 168
aoqi@0 169 // update the time stamp to begin recording app time
aoqi@0 170 _app_timer.update();
aoqi@0 171 if (UsePerfData) {
aoqi@0 172 _safepoint_time_ticks->inc(_safepoint_timer.ticks_since_update());
aoqi@0 173 }
aoqi@0 174 }
aoqi@0 175
aoqi@0 176 void RuntimeService::record_application_start() {
aoqi@0 177 // update the time stamp to begin recording app time
aoqi@0 178 _app_timer.update();
aoqi@0 179 }
aoqi@0 180
aoqi@0 181 // Don't need to record application end because we currently
aoqi@0 182 // exit at a safepoint and record_safepoint_begin() handles updating
aoqi@0 183 // the application time counter at VM exit.
aoqi@0 184
aoqi@0 185 jlong RuntimeService::safepoint_sync_time_ms() {
aoqi@0 186 return UsePerfData ?
aoqi@0 187 Management::ticks_to_ms(_sync_time_ticks->get_value()) : -1;
aoqi@0 188 }
aoqi@0 189
aoqi@0 190 jlong RuntimeService::safepoint_count() {
aoqi@0 191 return UsePerfData ?
aoqi@0 192 _total_safepoints->get_value() : -1;
aoqi@0 193 }
aoqi@0 194 jlong RuntimeService::safepoint_time_ms() {
aoqi@0 195 return UsePerfData ?
aoqi@0 196 Management::ticks_to_ms(_safepoint_time_ticks->get_value()) : -1;
aoqi@0 197 }
aoqi@0 198
aoqi@0 199 jlong RuntimeService::application_time_ms() {
aoqi@0 200 return UsePerfData ?
aoqi@0 201 Management::ticks_to_ms(_application_time_ticks->get_value()) : -1;
aoqi@0 202 }
aoqi@0 203
aoqi@0 204 void RuntimeService::record_interrupted_before_count() {
aoqi@0 205 if (UsePerfData) {
aoqi@0 206 _interrupted_before_count->inc();
aoqi@0 207 }
aoqi@0 208 }
aoqi@0 209
aoqi@0 210 void RuntimeService::record_interrupted_during_count() {
aoqi@0 211 if (UsePerfData) {
aoqi@0 212 _interrupted_during_count->inc();
aoqi@0 213 }
aoqi@0 214 }
aoqi@0 215
aoqi@0 216 void RuntimeService::record_thread_interrupt_signaled_count() {
aoqi@0 217 if (UsePerfData) {
aoqi@0 218 _thread_interrupt_signaled_count->inc();
aoqi@0 219 }
aoqi@0 220 }
aoqi@0 221
aoqi@0 222 #endif // INCLUDE_MANAGEMENT

mercurial