src/share/vm/runtime/statSampler.cpp

Wed, 06 Jan 2010 14:22:39 -0800

author
never
date
Wed, 06 Jan 2010 14:22:39 -0800
changeset 1577
4ce7240d622c
parent 772
9ee9cf798b59
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6914300: ciEnv should export all well known classes
Reviewed-by: kvn, twisti

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

mercurial