hotspot/src/share/vm/services/runtimeService.cpp
author johnc
Tue, 09 Feb 2010 13:56:09 -0800
changeset 4901 304ce755c6ee
parent 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
6782663: Data produced by PrintGCApplicationConcurrentTime and PrintGCApplicationStoppedTime is not accurate. Summary: Update and display the timers associated with these flags for all safepoints. Reviewed-by: ysr, jcoomes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
4901
304ce755c6ee 6782663: Data produced by PrintGCApplicationConcurrentTime and PrintGCApplicationStoppedTime is not accurate.
johnc
parents: 1
diff changeset
     2
 * Copyright 2003-2010 Sun Microsystems, Inc.  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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_runtimeService.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
HS_DTRACE_PROBE_DECL(hs_private, safepoint__begin);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
HS_DTRACE_PROBE_DECL(hs_private, safepoint__end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
TimeStamp RuntimeService::_app_timer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
TimeStamp RuntimeService::_safepoint_timer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
PerfCounter*  RuntimeService::_sync_time_ticks = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
PerfCounter*  RuntimeService::_total_safepoints = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
PerfCounter*  RuntimeService::_safepoint_time_ticks = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
PerfCounter*  RuntimeService::_application_time_ticks = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
PerfCounter*  RuntimeService::_thread_interrupt_signaled_count = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
PerfCounter*  RuntimeService::_interrupted_before_count = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
PerfCounter*  RuntimeService::_interrupted_during_count = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
void RuntimeService::init() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  // Make sure the VM version is initialized
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  Abstract_VM_Version::initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  if (UsePerfData) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    EXCEPTION_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    _sync_time_ticks =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
              PerfDataManager::create_counter(SUN_RT, "safepointSyncTime",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
                                              PerfData::U_Ticks, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    _total_safepoints =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
              PerfDataManager::create_counter(SUN_RT, "safepoints",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
                                              PerfData::U_Events, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    _safepoint_time_ticks =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
              PerfDataManager::create_counter(SUN_RT, "safepointTime",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
                                              PerfData::U_Ticks, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    _application_time_ticks =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
              PerfDataManager::create_counter(SUN_RT, "applicationTime",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
                                              PerfData::U_Ticks, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    // create performance counters for jvm_version and its capabilities
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    PerfDataManager::create_constant(SUN_RT, "jvmVersion", PerfData::U_None,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
                                     (jlong) Abstract_VM_Version::jvm_version(), CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    // I/O interruption related counters
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    // thread signaling via os::interrupt()
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    _thread_interrupt_signaled_count =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
                PerfDataManager::create_counter(SUN_RT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
                 "threadInterruptSignaled", PerfData::U_Events, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    // OS_INTRPT via "check before" in _INTERRUPTIBLE
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    _interrupted_before_count =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
                PerfDataManager::create_counter(SUN_RT, "interruptedBeforeIO",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
                                                PerfData::U_Events, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    // OS_INTRPT via "check during" in _INTERRUPTIBLE
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    _interrupted_during_count =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
                PerfDataManager::create_counter(SUN_RT, "interruptedDuringIO",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
                                                PerfData::U_Events, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    // The capabilities counter is a binary representation of the VM capabilities in string.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    // This string respresentation simplifies the implementation of the client side
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    // to parse the value.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    char capabilities[65];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    size_t len = sizeof(capabilities);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    memset((void*) capabilities, '0', len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    capabilities[len-1] = '\0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    capabilities[0] = AttachListener::is_attach_supported() ? '1' : '0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
#ifdef KERNEL
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    capabilities[1] = '1';
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
#endif // KERNEL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    PerfDataManager::create_string_constant(SUN_RT, "jvmCapabilities",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
                                            capabilities, CHECK);
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
void RuntimeService::record_safepoint_begin() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  HS_DTRACE_PROBE(hs_private, safepoint__begin);
4901
304ce755c6ee 6782663: Data produced by PrintGCApplicationConcurrentTime and PrintGCApplicationStoppedTime is not accurate.
johnc
parents: 1
diff changeset
   107
304ce755c6ee 6782663: Data produced by PrintGCApplicationConcurrentTime and PrintGCApplicationStoppedTime is not accurate.
johnc
parents: 1
diff changeset
   108
  // Print the time interval in which the app was executing
304ce755c6ee 6782663: Data produced by PrintGCApplicationConcurrentTime and PrintGCApplicationStoppedTime is not accurate.
johnc
parents: 1
diff changeset
   109
  if (PrintGCApplicationConcurrentTime) {
304ce755c6ee 6782663: Data produced by PrintGCApplicationConcurrentTime and PrintGCApplicationStoppedTime is not accurate.
johnc
parents: 1
diff changeset
   110
    gclog_or_tty->print_cr("Application time: %3.7f seconds",
304ce755c6ee 6782663: Data produced by PrintGCApplicationConcurrentTime and PrintGCApplicationStoppedTime is not accurate.
johnc
parents: 1
diff changeset
   111
                                last_application_time_sec());
304ce755c6ee 6782663: Data produced by PrintGCApplicationConcurrentTime and PrintGCApplicationStoppedTime is not accurate.
johnc
parents: 1
diff changeset
   112
  }
304ce755c6ee 6782663: Data produced by PrintGCApplicationConcurrentTime and PrintGCApplicationStoppedTime is not accurate.
johnc
parents: 1
diff changeset
   113
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  // update the time stamp to begin recording safepoint time
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  _safepoint_timer.update();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  if (UsePerfData) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    _total_safepoints->inc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    if (_app_timer.is_updated()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
      _application_time_ticks->inc(_app_timer.ticks_since_update());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
void RuntimeService::record_safepoint_synchronized() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  if (UsePerfData) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    _sync_time_ticks->inc(_safepoint_timer.ticks_since_update());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
void RuntimeService::record_safepoint_end() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  HS_DTRACE_PROBE(hs_private, safepoint__end);
4901
304ce755c6ee 6782663: Data produced by PrintGCApplicationConcurrentTime and PrintGCApplicationStoppedTime is not accurate.
johnc
parents: 1
diff changeset
   132
304ce755c6ee 6782663: Data produced by PrintGCApplicationConcurrentTime and PrintGCApplicationStoppedTime is not accurate.
johnc
parents: 1
diff changeset
   133
  // Print the time interval for which the app was stopped
304ce755c6ee 6782663: Data produced by PrintGCApplicationConcurrentTime and PrintGCApplicationStoppedTime is not accurate.
johnc
parents: 1
diff changeset
   134
  // during the current safepoint operation.
304ce755c6ee 6782663: Data produced by PrintGCApplicationConcurrentTime and PrintGCApplicationStoppedTime is not accurate.
johnc
parents: 1
diff changeset
   135
  if (PrintGCApplicationStoppedTime) {
304ce755c6ee 6782663: Data produced by PrintGCApplicationConcurrentTime and PrintGCApplicationStoppedTime is not accurate.
johnc
parents: 1
diff changeset
   136
    gclog_or_tty->print_cr("Total time for which application threads "
304ce755c6ee 6782663: Data produced by PrintGCApplicationConcurrentTime and PrintGCApplicationStoppedTime is not accurate.
johnc
parents: 1
diff changeset
   137
                           "were stopped: %3.7f seconds",
304ce755c6ee 6782663: Data produced by PrintGCApplicationConcurrentTime and PrintGCApplicationStoppedTime is not accurate.
johnc
parents: 1
diff changeset
   138
                           last_safepoint_time_sec());
304ce755c6ee 6782663: Data produced by PrintGCApplicationConcurrentTime and PrintGCApplicationStoppedTime is not accurate.
johnc
parents: 1
diff changeset
   139
  }
304ce755c6ee 6782663: Data produced by PrintGCApplicationConcurrentTime and PrintGCApplicationStoppedTime is not accurate.
johnc
parents: 1
diff changeset
   140
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  // update the time stamp to begin recording app time
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  _app_timer.update();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  if (UsePerfData) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    _safepoint_time_ticks->inc(_safepoint_timer.ticks_since_update());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
void RuntimeService::record_application_start() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  // update the time stamp to begin recording app time
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  _app_timer.update();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
// Don't need to record application end because we currently
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
// exit at a safepoint and record_safepoint_begin() handles updating
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
// the application time counter at VM exit.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
jlong RuntimeService::safepoint_sync_time_ms() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  return UsePerfData ?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    Management::ticks_to_ms(_sync_time_ticks->get_value()) : -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
jlong RuntimeService::safepoint_count() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  return UsePerfData ?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    _total_safepoints->get_value() : -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
jlong RuntimeService::safepoint_time_ms() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  return UsePerfData ?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    Management::ticks_to_ms(_safepoint_time_ticks->get_value()) : -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
jlong RuntimeService::application_time_ms() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  return UsePerfData ?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    Management::ticks_to_ms(_application_time_ticks->get_value()) : -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
void RuntimeService::record_interrupted_before_count() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  if (UsePerfData) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    _interrupted_before_count->inc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
void RuntimeService::record_interrupted_during_count() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  if (UsePerfData) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    _interrupted_during_count->inc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
void RuntimeService::record_thread_interrupt_signaled_count() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  if (UsePerfData) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    _thread_interrupt_signaled_count->inc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
}