runtimeService.cpp revision 0:a61af66fc99e
144743Smarkm/* 244743Smarkm * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved. 344743Smarkm * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 444743Smarkm * 544743Smarkm * This code is free software; you can redistribute it and/or modify it 644743Smarkm * under the terms of the GNU General Public License version 2 only, as 744743Smarkm * published by the Free Software Foundation. 844743Smarkm * 944743Smarkm * This code is distributed in the hope that it will be useful, but WITHOUT 1044743Smarkm * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1144743Smarkm * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1244743Smarkm * version 2 for more details (a copy is included in the LICENSE file that 1344743Smarkm * accompanied this code). 1444743Smarkm * 1544743Smarkm * You should have received a copy of the GNU General Public License version 1644743Smarkm * 2 along with this work; if not, write to the Free Software Foundation, 1744743Smarkm * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1844743Smarkm * 1944743Smarkm * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 2044743Smarkm * CA 95054 USA or visit www.sun.com if you need additional information or 2144743Smarkm * have any questions. 2244743Smarkm * 2344743Smarkm */ 2444743Smarkm 2544743Smarkm# include "incls/_precompiled.incl" 2644743Smarkm# include "incls/_runtimeService.cpp.incl" 2744743Smarkm 2844743SmarkmHS_DTRACE_PROBE_DECL(hs_private, safepoint__begin); 2944743SmarkmHS_DTRACE_PROBE_DECL(hs_private, safepoint__end); 3044743Smarkm 3144743SmarkmTimeStamp RuntimeService::_app_timer; 3244743SmarkmTimeStamp RuntimeService::_safepoint_timer; 3344743SmarkmPerfCounter* RuntimeService::_sync_time_ticks = NULL; 3444743SmarkmPerfCounter* RuntimeService::_total_safepoints = NULL; 35PerfCounter* RuntimeService::_safepoint_time_ticks = NULL; 36PerfCounter* RuntimeService::_application_time_ticks = NULL; 37PerfCounter* RuntimeService::_thread_interrupt_signaled_count = NULL; 38PerfCounter* RuntimeService::_interrupted_before_count = NULL; 39PerfCounter* RuntimeService::_interrupted_during_count = NULL; 40 41void RuntimeService::init() { 42 // Make sure the VM version is initialized 43 Abstract_VM_Version::initialize(); 44 45 if (UsePerfData) { 46 EXCEPTION_MARK; 47 48 _sync_time_ticks = 49 PerfDataManager::create_counter(SUN_RT, "safepointSyncTime", 50 PerfData::U_Ticks, CHECK); 51 52 _total_safepoints = 53 PerfDataManager::create_counter(SUN_RT, "safepoints", 54 PerfData::U_Events, CHECK); 55 56 _safepoint_time_ticks = 57 PerfDataManager::create_counter(SUN_RT, "safepointTime", 58 PerfData::U_Ticks, CHECK); 59 60 _application_time_ticks = 61 PerfDataManager::create_counter(SUN_RT, "applicationTime", 62 PerfData::U_Ticks, CHECK); 63 64 65 // create performance counters for jvm_version and its capabilities 66 PerfDataManager::create_constant(SUN_RT, "jvmVersion", PerfData::U_None, 67 (jlong) Abstract_VM_Version::jvm_version(), CHECK); 68 69 // I/O interruption related counters 70 71 // thread signaling via os::interrupt() 72 73 _thread_interrupt_signaled_count = 74 PerfDataManager::create_counter(SUN_RT, 75 "threadInterruptSignaled", PerfData::U_Events, CHECK); 76 77 // OS_INTRPT via "check before" in _INTERRUPTIBLE 78 79 _interrupted_before_count = 80 PerfDataManager::create_counter(SUN_RT, "interruptedBeforeIO", 81 PerfData::U_Events, CHECK); 82 83 // OS_INTRPT via "check during" in _INTERRUPTIBLE 84 85 _interrupted_during_count = 86 PerfDataManager::create_counter(SUN_RT, "interruptedDuringIO", 87 PerfData::U_Events, CHECK); 88 89 // The capabilities counter is a binary representation of the VM capabilities in string. 90 // This string respresentation simplifies the implementation of the client side 91 // to parse the value. 92 char capabilities[65]; 93 size_t len = sizeof(capabilities); 94 memset((void*) capabilities, '0', len); 95 capabilities[len-1] = '\0'; 96 capabilities[0] = AttachListener::is_attach_supported() ? '1' : '0'; 97#ifdef KERNEL 98 capabilities[1] = '1'; 99#endif // KERNEL 100 PerfDataManager::create_string_constant(SUN_RT, "jvmCapabilities", 101 capabilities, CHECK); 102 } 103} 104 105void RuntimeService::record_safepoint_begin() { 106 HS_DTRACE_PROBE(hs_private, safepoint__begin); 107 // update the time stamp to begin recording safepoint time 108 _safepoint_timer.update(); 109 if (UsePerfData) { 110 _total_safepoints->inc(); 111 if (_app_timer.is_updated()) { 112 _application_time_ticks->inc(_app_timer.ticks_since_update()); 113 } 114 } 115} 116 117void RuntimeService::record_safepoint_synchronized() { 118 if (UsePerfData) { 119 _sync_time_ticks->inc(_safepoint_timer.ticks_since_update()); 120 } 121} 122 123void RuntimeService::record_safepoint_end() { 124 HS_DTRACE_PROBE(hs_private, safepoint__end); 125 // update the time stamp to begin recording app time 126 _app_timer.update(); 127 if (UsePerfData) { 128 _safepoint_time_ticks->inc(_safepoint_timer.ticks_since_update()); 129 } 130} 131 132void RuntimeService::record_application_start() { 133 // update the time stamp to begin recording app time 134 _app_timer.update(); 135} 136 137// Don't need to record application end because we currently 138// exit at a safepoint and record_safepoint_begin() handles updating 139// the application time counter at VM exit. 140 141jlong RuntimeService::safepoint_sync_time_ms() { 142 return UsePerfData ? 143 Management::ticks_to_ms(_sync_time_ticks->get_value()) : -1; 144} 145 146jlong RuntimeService::safepoint_count() { 147 return UsePerfData ? 148 _total_safepoints->get_value() : -1; 149} 150jlong RuntimeService::safepoint_time_ms() { 151 return UsePerfData ? 152 Management::ticks_to_ms(_safepoint_time_ticks->get_value()) : -1; 153} 154 155jlong RuntimeService::application_time_ms() { 156 return UsePerfData ? 157 Management::ticks_to_ms(_application_time_ticks->get_value()) : -1; 158} 159 160void RuntimeService::record_interrupted_before_count() { 161 if (UsePerfData) { 162 _interrupted_before_count->inc(); 163 } 164} 165 166void RuntimeService::record_interrupted_during_count() { 167 if (UsePerfData) { 168 _interrupted_during_count->inc(); 169 } 170} 171 172void RuntimeService::record_thread_interrupt_signaled_count() { 173 if (UsePerfData) { 174 _thread_interrupt_signaled_count->inc(); 175 } 176} 177