src/share/vm/runtime/statSampler.cpp

Thu, 21 Nov 2013 12:30:35 -0800

author
kvn
date
Thu, 21 Nov 2013 12:30:35 -0800
changeset 6485
da862781b584
parent 2708
1d1603768966
child 6876
710a3c8b516e
permissions
-rw-r--r--

Merge

duke@435 1 /*
trims@2708 2 * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "classfile/systemDictionary.hpp"
stefank@2314 27 #include "classfile/vmSymbols.hpp"
stefank@2314 28 #include "memory/allocation.inline.hpp"
stefank@2314 29 #include "memory/resourceArea.hpp"
stefank@2314 30 #include "oops/oop.inline.hpp"
stefank@2314 31 #include "runtime/arguments.hpp"
stefank@2314 32 #include "runtime/java.hpp"
stefank@2314 33 #include "runtime/javaCalls.hpp"
stefank@2314 34 #include "runtime/os.hpp"
stefank@2314 35 #include "runtime/statSampler.hpp"
stefank@2314 36 #ifdef TARGET_ARCH_x86
stefank@2314 37 # include "vm_version_x86.hpp"
stefank@2314 38 #endif
stefank@2314 39 #ifdef TARGET_ARCH_sparc
stefank@2314 40 # include "vm_version_sparc.hpp"
stefank@2314 41 #endif
stefank@2314 42 #ifdef TARGET_ARCH_zero
stefank@2314 43 # include "vm_version_zero.hpp"
stefank@2314 44 #endif
bobv@2508 45 #ifdef TARGET_ARCH_arm
bobv@2508 46 # include "vm_version_arm.hpp"
bobv@2508 47 #endif
bobv@2508 48 #ifdef TARGET_ARCH_ppc
bobv@2508 49 # include "vm_version_ppc.hpp"
bobv@2508 50 #endif
duke@435 51
duke@435 52 // --------------------------------------------------------
duke@435 53 // StatSamplerTask
duke@435 54
duke@435 55 class StatSamplerTask : public PeriodicTask {
duke@435 56 public:
duke@435 57 StatSamplerTask(int interval_time) : PeriodicTask(interval_time) {}
duke@435 58 void task() { StatSampler::collect_sample(); }
duke@435 59 };
duke@435 60
duke@435 61
duke@435 62 //----------------------------------------------------------
duke@435 63 // Implementation of StatSampler
duke@435 64
duke@435 65 StatSamplerTask* StatSampler::_task = NULL;
duke@435 66 PerfDataList* StatSampler::_sampled = NULL;
duke@435 67
duke@435 68 /*
duke@435 69 * the initialize method is called from the engage() method
duke@435 70 * and is responsible for initializing various global variables.
duke@435 71 */
duke@435 72 void StatSampler::initialize() {
duke@435 73
duke@435 74 if (!UsePerfData) return;
duke@435 75
duke@435 76 // create performance data that could not be created prior
duke@435 77 // to vm_init_globals() or otherwise have no logical home.
duke@435 78
duke@435 79 create_misc_perfdata();
duke@435 80
duke@435 81 // get copy of the sampled list
duke@435 82 _sampled = PerfDataManager::sampled();
duke@435 83
duke@435 84 }
duke@435 85
duke@435 86 /*
duke@435 87 * The engage() method is called at initialization time via
duke@435 88 * Thread::create_vm() to initialize the StatSampler and
duke@435 89 * register it with the WatcherThread as a periodic task.
duke@435 90 */
duke@435 91 void StatSampler::engage() {
duke@435 92
duke@435 93 if (!UsePerfData) return;
duke@435 94
duke@435 95 if (!is_active()) {
duke@435 96
duke@435 97 initialize();
duke@435 98
duke@435 99 // start up the periodic task
duke@435 100 _task = new StatSamplerTask(PerfDataSamplingInterval);
duke@435 101 _task->enroll();
duke@435 102 }
duke@435 103 }
duke@435 104
duke@435 105
duke@435 106 /*
duke@435 107 * the disengage() method is responsible for deactivating the periodic
duke@435 108 * task and, if logging was enabled, for logging the final sample. This
duke@435 109 * method is called from before_exit() in java.cpp and is only called
duke@435 110 * after the WatcherThread has been stopped.
duke@435 111 */
duke@435 112 void StatSampler::disengage() {
duke@435 113
duke@435 114 if (!UsePerfData) return;
duke@435 115
duke@435 116 if (!is_active())
duke@435 117 return;
duke@435 118
duke@435 119 // remove StatSamplerTask
duke@435 120 _task->disenroll();
duke@435 121 delete _task;
duke@435 122 _task = NULL;
duke@435 123
duke@435 124 // force a final sample
duke@435 125 sample_data(_sampled);
duke@435 126 }
duke@435 127
duke@435 128 /*
duke@435 129 * the destroy method is responsible for releasing any resources used by
duke@435 130 * the StatSampler prior to shutdown of the VM. this method is called from
duke@435 131 * before_exit() in java.cpp and is only called after the WatcherThread
duke@435 132 * has stopped.
duke@435 133 */
duke@435 134 void StatSampler::destroy() {
duke@435 135
duke@435 136 if (!UsePerfData) return;
duke@435 137
duke@435 138 if (_sampled != NULL) {
duke@435 139 delete(_sampled);
duke@435 140 _sampled = NULL;
duke@435 141 }
duke@435 142 }
duke@435 143
duke@435 144 /*
duke@435 145 * The sample_data() method is responsible for sampling the
duke@435 146 * the data value for each PerfData instance in the given list.
duke@435 147 */
duke@435 148 void StatSampler::sample_data(PerfDataList* list) {
duke@435 149
duke@435 150 assert(list != NULL, "null list unexpected");
duke@435 151
duke@435 152 for (int index = 0; index < list->length(); index++) {
duke@435 153 PerfData* item = list->at(index);
duke@435 154 item->sample();
duke@435 155 }
duke@435 156 }
duke@435 157
duke@435 158 /*
duke@435 159 * the collect_sample() method is the method invoked by the
duke@435 160 * WatcherThread via the PeriodicTask::task() method. This method
duke@435 161 * is responsible for collecting data samples from sampled
duke@435 162 * PerfData instances every PerfDataSamplingInterval milliseconds.
duke@435 163 * It is also responsible for logging the requested set of
duke@435 164 * PerfData instances every _sample_count milliseconds. While
duke@435 165 * logging data, it will output a column header after every _print_header
duke@435 166 * rows of data have been logged.
duke@435 167 */
duke@435 168 void StatSampler::collect_sample() {
duke@435 169
duke@435 170 // future - check for new PerfData objects. PerfData objects might
duke@435 171 // get added to the PerfDataManager lists after we have already
duke@435 172 // built our local copies.
duke@435 173 //
duke@435 174 // if (PerfDataManager::count() > previous) {
duke@435 175 // // get a new copy of the sampled list
duke@435 176 // if (_sampled != NULL) {
duke@435 177 // delete(_sampled);
duke@435 178 // _sampled = NULL;
duke@435 179 // }
duke@435 180 // _sampled = PerfDataManager::sampled();
duke@435 181 // }
duke@435 182
duke@435 183 assert(_sampled != NULL, "list not initialized");
duke@435 184
duke@435 185 sample_data(_sampled);
duke@435 186 }
duke@435 187
duke@435 188 /*
duke@435 189 * method to upcall into Java to return the value of the specified
duke@435 190 * property as a utf8 string, or NULL if does not exist. The caller
duke@435 191 * is responsible for setting a ResourceMark for proper cleanup of
duke@435 192 * the utf8 strings.
duke@435 193 */
duke@435 194 const char* StatSampler::get_system_property(const char* name, TRAPS) {
duke@435 195
duke@435 196 // setup the arguments to getProperty
duke@435 197 Handle key_str = java_lang_String::create_from_str(name, CHECK_NULL);
duke@435 198
duke@435 199 // return value
duke@435 200 JavaValue result(T_OBJECT);
duke@435 201
duke@435 202 // public static String getProperty(String key, String def);
duke@435 203 JavaCalls::call_static(&result,
never@1577 204 KlassHandle(THREAD, SystemDictionary::System_klass()),
coleenp@2497 205 vmSymbols::getProperty_name(),
coleenp@2497 206 vmSymbols::string_string_signature(),
duke@435 207 key_str,
duke@435 208 CHECK_NULL);
duke@435 209
duke@435 210 oop value_oop = (oop)result.get_jobject();
duke@435 211 if (value_oop == NULL) {
duke@435 212 return NULL;
duke@435 213 }
duke@435 214
duke@435 215 // convert Java String to utf8 string
duke@435 216 char* value = java_lang_String::as_utf8_string(value_oop);
duke@435 217
duke@435 218 return value;
duke@435 219 }
duke@435 220
duke@435 221 /*
duke@435 222 * The list of System Properties that have corresponding PerfData
duke@435 223 * string instrumentation created by retrieving the named property's
duke@435 224 * value from System.getProperty() and unconditionally creating a
duke@435 225 * PerfStringConstant object initialized to the retreived value. This
duke@435 226 * is not an exhustive list of Java properties with corresponding string
duke@435 227 * instrumentation as the create_system_property_instrumentation() method
duke@435 228 * creates other property based instrumentation conditionally.
duke@435 229 */
duke@435 230
duke@435 231 // stable interface, supported counters
duke@435 232 static const char* property_counters_ss[] = {
duke@435 233 "java.vm.specification.version",
duke@435 234 "java.vm.specification.name",
duke@435 235 "java.vm.specification.vendor",
duke@435 236 "java.vm.version",
duke@435 237 "java.vm.name",
duke@435 238 "java.vm.vendor",
duke@435 239 "java.vm.info",
duke@435 240 "java.library.path",
duke@435 241 "java.class.path",
duke@435 242 "java.endorsed.dirs",
duke@435 243 "java.ext.dirs",
thurka@714 244 "java.version",
duke@435 245 "java.home",
duke@435 246 NULL
duke@435 247 };
duke@435 248
duke@435 249 // unstable interface, supported counters
duke@435 250 static const char* property_counters_us[] = {
duke@435 251 NULL
duke@435 252 };
duke@435 253
duke@435 254 // unstable interface, unsupported counters
duke@435 255 static const char* property_counters_uu[] = {
duke@435 256 "sun.boot.class.path",
duke@435 257 "sun.boot.library.path",
duke@435 258 NULL
duke@435 259 };
duke@435 260
duke@435 261 typedef struct {
duke@435 262 const char** property_list;
duke@435 263 CounterNS name_space;
duke@435 264 } PropertyCounters;
duke@435 265
duke@435 266 static PropertyCounters property_counters[] = {
duke@435 267 { property_counters_ss, JAVA_PROPERTY },
duke@435 268 { property_counters_us, COM_PROPERTY },
duke@435 269 { property_counters_uu, SUN_PROPERTY },
duke@435 270 { NULL, SUN_PROPERTY }
duke@435 271 };
duke@435 272
duke@435 273
duke@435 274 /*
duke@435 275 * Method to create PerfData string instruments that contain the values
duke@435 276 * of various system properties. String instruments are created for each
duke@435 277 * property specified in the property lists provided in property_counters[].
duke@435 278 * Property counters have a counter name space prefix prepended to the
duke@435 279 * property name as indicated in property_counters[].
duke@435 280 */
duke@435 281 void StatSampler::create_system_property_instrumentation(TRAPS) {
duke@435 282
duke@435 283 ResourceMark rm;
duke@435 284
duke@435 285 for (int i = 0; property_counters[i].property_list != NULL; i++) {
duke@435 286
duke@435 287 for (int j = 0; property_counters[i].property_list[j] != NULL; j++) {
duke@435 288
duke@435 289 const char* property_name = property_counters[i].property_list[j];
duke@435 290 assert(property_name != NULL, "property name should not be NULL");
duke@435 291
duke@435 292 const char* value = get_system_property(property_name, CHECK);
duke@435 293
duke@435 294 // the property must exist
duke@435 295 assert(value != NULL, "property name should be valid");
duke@435 296
duke@435 297 if (value != NULL) {
duke@435 298 // create the property counter
duke@435 299 PerfDataManager::create_string_constant(property_counters[i].name_space,
duke@435 300 property_name, value, CHECK);
duke@435 301 }
duke@435 302 }
duke@435 303 }
duke@435 304 }
duke@435 305
duke@435 306 /*
duke@435 307 * The create_misc_perfdata() method provides a place to create
duke@435 308 * PerfData instances that would otherwise have no better place
duke@435 309 * to exist.
duke@435 310 */
duke@435 311 void StatSampler::create_misc_perfdata() {
duke@435 312
duke@435 313 ResourceMark rm;
duke@435 314 EXCEPTION_MARK;
duke@435 315
duke@435 316 // numeric constants
duke@435 317
duke@435 318 // frequency of the native high resolution timer
duke@435 319 PerfDataManager::create_constant(SUN_OS, "hrt.frequency",
duke@435 320 PerfData::U_Hertz, os::elapsed_frequency(),
duke@435 321 CHECK);
duke@435 322
duke@435 323 // string constants
duke@435 324
duke@435 325 // create string instrumentation for various Java properties.
duke@435 326 create_system_property_instrumentation(CHECK);
duke@435 327
duke@435 328 // hotspot flags (from .hotspotrc) and args (from command line)
duke@435 329 //
duke@435 330 PerfDataManager::create_string_constant(JAVA_RT, "vmFlags",
duke@435 331 Arguments::jvm_flags(), CHECK);
duke@435 332 PerfDataManager::create_string_constant(JAVA_RT, "vmArgs",
duke@435 333 Arguments::jvm_args(), CHECK);
duke@435 334
duke@435 335 // java class name/jar file and arguments to main class
duke@435 336 // note: name is cooridnated with launcher and Arguments.cpp
duke@435 337 PerfDataManager::create_string_constant(SUN_RT, "javaCommand",
duke@435 338 Arguments::java_command(), CHECK);
duke@435 339
duke@435 340 // the Java VM Internal version string
duke@435 341 PerfDataManager::create_string_constant(SUN_RT, "internalVersion",
duke@435 342 VM_Version::internal_vm_info_string(),
duke@435 343 CHECK);
duke@435 344
duke@435 345 // create sampled instrumentation objects
duke@435 346 create_sampled_perfdata();
duke@435 347 }
duke@435 348
duke@435 349 /*
duke@435 350 * helper class to provide for sampling of the elapsed_counter value
duke@435 351 * maintained in the OS class.
duke@435 352 */
duke@435 353 class HighResTimeSampler : public PerfSampleHelper {
duke@435 354 public:
duke@435 355 jlong take_sample() { return os::elapsed_counter(); }
duke@435 356 };
duke@435 357
duke@435 358 /*
duke@435 359 * the create_sampled_perdata() method provides a place to instantiate
duke@435 360 * sampled PerfData instances that would otherwise have no better place
duke@435 361 * to exist.
duke@435 362 */
duke@435 363 void StatSampler::create_sampled_perfdata() {
duke@435 364
duke@435 365 EXCEPTION_MARK;
duke@435 366
duke@435 367 // setup sampling of the elapsed time counter maintained in the
duke@435 368 // the os class. This counter can be used as either a time stamp
duke@435 369 // for each logged entry or as a liveness indicator for the VM.
duke@435 370 PerfSampleHelper* psh = new HighResTimeSampler();
duke@435 371 PerfDataManager::create_counter(SUN_OS, "hrt.ticks",
duke@435 372 PerfData::U_Ticks, psh, CHECK);
duke@435 373 }
duke@435 374
duke@435 375 /*
duke@435 376 * the statSampler_exit() function is called from os_init.cpp on
duke@435 377 * exit of the vm.
duke@435 378 */
duke@435 379 void statSampler_exit() {
duke@435 380
duke@435 381 if (!UsePerfData) return;
duke@435 382
duke@435 383 StatSampler::destroy();
duke@435 384 }

mercurial