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