src/share/vm/runtime/fprofiler.hpp

Wed, 03 Jul 2019 20:42:37 +0800

author
aoqi
date
Wed, 03 Jul 2019 20:42:37 +0800
changeset 9637
eef07cd490d4
parent 6876
710a3c8b516e
permissions
-rw-r--r--

Merge

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

mercurial