src/share/vm/runtime/fprofiler.hpp

Wed, 23 Jan 2013 13:02:39 -0500

author
jprovino
date
Wed, 23 Jan 2013 13:02:39 -0500
changeset 4542
db9981fd3124
parent 4299
f34d701e952e
child 6198
55fb97c4c58d
permissions
-rw-r--r--

8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
Summary: Rename INCLUDE_ALTERNATE_GCS to INCLUDE_ALL_GCS and replace SERIALGC with INCLUDE_ALL_GCS.
Reviewed-by: coleenp, stefank

duke@435 1 /*
coleenp@4037 2 * Copyright (c) 1997, 2012, 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 #ifndef SHARE_VM_RUNTIME_FPROFILER_HPP
stefank@2314 26 #define SHARE_VM_RUNTIME_FPROFILER_HPP
stefank@2314 27
jprovino@4542 28 #include "utilities/macros.hpp"
stefank@2314 29 #include "runtime/timer.hpp"
stefank@2314 30
duke@435 31 // a simple flat profiler for Java
duke@435 32
duke@435 33
duke@435 34 // Forward declaration of classes defined in this header file
duke@435 35 class ThreadProfiler;
duke@435 36 class ThreadProfilerMark;
duke@435 37 class FlatProfiler;
duke@435 38 class IntervalData;
duke@435 39
duke@435 40 // Declarations of classes defined only in the implementation.
duke@435 41 class ProfilerNode;
duke@435 42 class FlatProfilerTask;
duke@435 43
duke@435 44 enum TickPosition {
duke@435 45 tp_code,
duke@435 46 tp_native
duke@435 47 };
duke@435 48
duke@435 49 // One of these guys is constructed as we enter interesting regions
duke@435 50 // and destructed as we exit the region. While we are in the region
duke@435 51 // ticks are allotted to the region.
duke@435 52 class ThreadProfilerMark: public StackObj {
duke@435 53 public:
duke@435 54 // For now, the only thread-specific region is the class loader.
duke@435 55 enum Region { noRegion, classLoaderRegion, extraRegion, maxRegion };
duke@435 56
jprovino@4165 57 ThreadProfilerMark(Region) NOT_FPROF_RETURN;
jprovino@4165 58 ~ThreadProfilerMark() NOT_FPROF_RETURN;
duke@435 59
duke@435 60 private:
duke@435 61 ThreadProfiler* _pp;
duke@435 62 Region _r;
duke@435 63 };
duke@435 64
jprovino@4165 65 #if INCLUDE_FPROF
duke@435 66
duke@435 67 class IntervalData VALUE_OBJ_CLASS_SPEC {
duke@435 68 // Just to keep these things all together
duke@435 69 private:
duke@435 70 int _interpreted;
duke@435 71 int _compiled;
duke@435 72 int _native;
duke@435 73 int _compiling;
duke@435 74 public:
duke@435 75 int interpreted() {
duke@435 76 return _interpreted;
duke@435 77 }
duke@435 78 int compiled() {
duke@435 79 return _compiled;
duke@435 80 }
duke@435 81 int native() {
duke@435 82 return _native;
duke@435 83 }
duke@435 84 int compiling() {
duke@435 85 return _compiling;
duke@435 86 }
duke@435 87 int total() {
duke@435 88 return (interpreted() + compiled() + native() + compiling());
duke@435 89 }
duke@435 90 void inc_interpreted() {
duke@435 91 _interpreted += 1;
duke@435 92 }
duke@435 93 void inc_compiled() {
duke@435 94 _compiled += 1;
duke@435 95 }
duke@435 96 void inc_native() {
duke@435 97 _native += 1;
duke@435 98 }
duke@435 99 void inc_compiling() {
duke@435 100 _compiling += 1;
duke@435 101 }
duke@435 102 void reset() {
duke@435 103 _interpreted = 0;
duke@435 104 _compiled = 0;
duke@435 105 _native = 0;
duke@435 106 _compiling = 0;
duke@435 107 }
duke@435 108 static void print_header(outputStream* st);
duke@435 109 void print_data(outputStream* st);
duke@435 110 };
jprovino@4165 111 #endif // INCLUDE_FPROF
duke@435 112
zgu@3900 113 class ThreadProfiler: public CHeapObj<mtInternal> {
duke@435 114 public:
jprovino@4165 115 ThreadProfiler() NOT_FPROF_RETURN;
jprovino@4165 116 ~ThreadProfiler() NOT_FPROF_RETURN;
duke@435 117
duke@435 118 // Resets the profiler
jprovino@4165 119 void reset() NOT_FPROF_RETURN;
duke@435 120
duke@435 121 // Activates the profiler for a certain thread
jprovino@4165 122 void engage() NOT_FPROF_RETURN;
duke@435 123
duke@435 124 // Deactivates the profiler
jprovino@4165 125 void disengage() NOT_FPROF_RETURN;
duke@435 126
duke@435 127 // Prints the collected profiling information
jprovino@4165 128 void print(const char* thread_name) NOT_FPROF_RETURN;
duke@435 129
duke@435 130 // Garbage Collection Support
jprovino@4165 131 void oops_do(OopClosure* f) NOT_FPROF_RETURN;
duke@435 132
jprovino@4165 133 #if INCLUDE_FPROF
duke@435 134 private:
duke@435 135 // for recording ticks.
duke@435 136 friend class ProfilerNode;
duke@435 137 char* area_bottom; // preallocated area for pnodes
duke@435 138 char* area_top;
duke@435 139 char* area_limit;
duke@435 140 static int table_size;
duke@435 141 ProfilerNode** table;
duke@435 142
duke@435 143 private:
sgoldman@542 144 void record_interpreted_tick(JavaThread* thread, frame fr, TickPosition where, int* ticks);
duke@435 145 void record_compiled_tick (JavaThread* thread, frame fr, TickPosition where);
coleenp@4037 146 void interpreted_update(Method* method, TickPosition where);
coleenp@4037 147 void compiled_update (Method* method, TickPosition where);
coleenp@4037 148 void stub_update (Method* method, const char* name, TickPosition where);
duke@435 149 void adapter_update (TickPosition where);
duke@435 150
duke@435 151 void runtime_stub_update(const CodeBlob* stub, const char* name, TickPosition where);
duke@435 152 void unknown_compiled_update (const CodeBlob* cb, TickPosition where);
duke@435 153
duke@435 154 void vm_update (TickPosition where);
duke@435 155 void vm_update (const char* name, TickPosition where);
duke@435 156
duke@435 157 void record_tick_for_running_frame(JavaThread* thread, frame fr);
duke@435 158 void record_tick_for_calling_frame(JavaThread* thread, frame fr);
duke@435 159
duke@435 160 void initialize();
duke@435 161
duke@435 162 static int entry(int value);
duke@435 163
duke@435 164
duke@435 165 private:
duke@435 166 friend class FlatProfiler;
duke@435 167 void record_tick(JavaThread* thread);
duke@435 168 bool engaged;
duke@435 169 // so we can do percentages for this thread, and quick checks for activity
duke@435 170 int thread_ticks;
duke@435 171 int compiler_ticks;
duke@435 172 int interpreter_ticks;
duke@435 173
duke@435 174 public:
duke@435 175 void inc_thread_ticks() { thread_ticks += 1; }
duke@435 176
duke@435 177 private:
duke@435 178 friend class ThreadProfilerMark;
duke@435 179 // counters for thread-specific regions
duke@435 180 bool region_flag[ThreadProfilerMark::maxRegion];
duke@435 181 int class_loader_ticks;
duke@435 182 int extra_ticks;
duke@435 183
duke@435 184 private:
duke@435 185 // other thread-specific regions
duke@435 186 int blocked_ticks;
duke@435 187 enum UnknownTickSites {
duke@435 188 ut_null_method,
duke@435 189 ut_vtable_stubs,
duke@435 190 ut_running_frame,
duke@435 191 ut_calling_frame,
duke@435 192 ut_no_pc,
duke@435 193 ut_no_last_Java_frame,
duke@435 194 ut_unknown_thread_state,
duke@435 195 ut_end
duke@435 196 };
duke@435 197 int unknown_ticks_array[ut_end];
duke@435 198 int unknown_ticks() {
duke@435 199 int result = 0;
duke@435 200 for (int ut = 0; ut < ut_end; ut += 1) {
duke@435 201 result += unknown_ticks_array[ut];
duke@435 202 }
duke@435 203 return result;
duke@435 204 }
duke@435 205
duke@435 206 elapsedTimer timer;
duke@435 207
duke@435 208 // For interval timing
duke@435 209 private:
duke@435 210 IntervalData _interval_data;
duke@435 211 IntervalData interval_data() {
duke@435 212 return _interval_data;
duke@435 213 }
duke@435 214 IntervalData* interval_data_ref() {
duke@435 215 return &_interval_data;
duke@435 216 }
jprovino@4165 217 #endif // INCLUDE_FPROF
duke@435 218 };
duke@435 219
duke@435 220 class FlatProfiler: AllStatic {
duke@435 221 public:
jprovino@4165 222 static void reset() NOT_FPROF_RETURN ;
jprovino@4165 223 static void engage(JavaThread* mainThread, bool fullProfile) NOT_FPROF_RETURN ;
jprovino@4165 224 static void disengage() NOT_FPROF_RETURN ;
jprovino@4165 225 static void print(int unused) NOT_FPROF_RETURN ;
jprovino@4165 226 static bool is_active() NOT_FPROF_RETURN_(false) ;
duke@435 227
duke@435 228 // This is NULL if each thread has its own thread profiler,
duke@435 229 // else this is the single thread profiler used by all threads.
duke@435 230 // In particular it makes a difference during garbage collection,
duke@435 231 // where you only want to traverse each thread profiler once.
jprovino@4165 232 static ThreadProfiler* get_thread_profiler() NOT_FPROF_RETURN_(NULL);
duke@435 233
duke@435 234 // Garbage Collection Support
jprovino@4165 235 static void oops_do(OopClosure* f) NOT_FPROF_RETURN ;
duke@435 236
duke@435 237 // Support for disassembler to inspect the PCRecorder
duke@435 238
duke@435 239 // Returns the start address for a given pc
duke@435 240 // NULL is returned if the PCRecorder is inactive
jprovino@4165 241 static address bucket_start_for(address pc) NOT_FPROF_RETURN_(NULL);
duke@435 242
duke@435 243 enum { MillisecsPerTick = 10 }; // ms per profiling ticks
duke@435 244
duke@435 245 // Returns the number of ticks recorded for the bucket
duke@435 246 // pc belongs to.
jprovino@4165 247 static int bucket_count_for(address pc) NOT_FPROF_RETURN_(0);
duke@435 248
jprovino@4165 249 #if INCLUDE_FPROF
duke@435 250
duke@435 251 private:
duke@435 252 static bool full_profile() {
duke@435 253 return full_profile_flag;
duke@435 254 }
duke@435 255
duke@435 256 friend class ThreadProfiler;
duke@435 257 // the following group of ticks cover everything that's not attributed to individual Java methods
duke@435 258 static int received_gc_ticks; // ticks during which gc was active
duke@435 259 static int vm_operation_ticks; // total ticks in vm_operations other than GC
duke@435 260 static int threads_lock_ticks; // the number of times we couldn't get the Threads_lock without blocking
duke@435 261 static int blocked_ticks; // ticks when the thread was blocked.
duke@435 262 static int class_loader_ticks; // total ticks in class loader
duke@435 263 static int extra_ticks; // total ticks an extra temporary measuring
duke@435 264 static int compiler_ticks; // total ticks in compilation
duke@435 265 static int interpreter_ticks; // ticks in unknown interpreted method
duke@435 266 static int deopt_ticks; // ticks in deoptimization
duke@435 267 static int unknown_ticks; // ticks that cannot be categorized
duke@435 268 static int received_ticks; // ticks that were received by task
duke@435 269 static int delivered_ticks; // ticks that were delivered by task
duke@435 270 static int non_method_ticks() {
duke@435 271 return
duke@435 272 ( received_gc_ticks
duke@435 273 + vm_operation_ticks
duke@435 274 + deopt_ticks
duke@435 275 + threads_lock_ticks
duke@435 276 + blocked_ticks
duke@435 277 + compiler_ticks
duke@435 278 + interpreter_ticks
duke@435 279 + unknown_ticks );
duke@435 280 }
duke@435 281 static elapsedTimer timer;
duke@435 282
duke@435 283 // Counts of each of the byte codes
duke@435 284 static int* bytecode_ticks;
duke@435 285 static int* bytecode_ticks_stub;
duke@435 286 static void print_byte_code_statistics();
duke@435 287
duke@435 288 // the ticks below are for continuous profiling (to adjust recompilation, etc.)
duke@435 289 static int all_ticks; // total count of ticks received so far
duke@435 290 static int all_int_ticks; // ticks in interpreter
duke@435 291 static int all_comp_ticks; // ticks in compiled code (+ native)
duke@435 292 static bool full_profile_flag; // collecting full profile?
duke@435 293
duke@435 294 // to accumulate thread-specific data
duke@435 295 // if we aren't profiling individual threads.
duke@435 296 static ThreadProfiler* thread_profiler;
duke@435 297 static ThreadProfiler* vm_thread_profiler;
duke@435 298
duke@435 299 static void allocate_table();
duke@435 300
duke@435 301 // The task that periodically interrupts things.
duke@435 302 friend class FlatProfilerTask;
duke@435 303 static FlatProfilerTask* task;
duke@435 304 static void record_vm_operation();
duke@435 305 static void record_vm_tick();
duke@435 306 static void record_thread_ticks();
duke@435 307
duke@435 308 // For interval analysis
duke@435 309 private:
duke@435 310 static int interval_ticks_previous; // delivered_ticks from the last interval
duke@435 311 static void interval_record_thread(ThreadProfiler* tp); // extract ticks from ThreadProfiler.
duke@435 312 static void interval_print(); // print interval data.
duke@435 313 static void interval_reset(); // reset interval data.
duke@435 314 enum {interval_print_size = 10};
duke@435 315 static IntervalData* interval_data;
jprovino@4165 316 #endif // INCLUDE_FPROF
duke@435 317 };
stefank@2314 318
stefank@2314 319 #endif // SHARE_VM_RUNTIME_FPROFILER_HPP

mercurial