src/share/vm/runtime/fprofiler.hpp

Tue, 27 Nov 2012 14:20:21 +0100

author
stefank
date
Tue, 27 Nov 2012 14:20:21 +0100
changeset 4299
f34d701e952e
parent 4165
fb19af007ffc
child 4542
db9981fd3124
permissions
-rw-r--r--

8003935: Simplify the needed includes for using Thread::current()
Reviewed-by: dholmes, rbackman, coleenp

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

mercurial