src/share/vm/runtime/fprofiler.cpp

Mon, 12 Aug 2019 18:30:40 +0300

author
apetushkov
date
Mon, 12 Aug 2019 18:30:40 +0300
changeset 9858
b985cbb00e68
parent 9607
a9ab35a0f5cb
child 9637
eef07cd490d4
permissions
-rw-r--r--

8223147: JFR Backport
8199712: Flight Recorder
8203346: JFR: Inconsistent signature of jfr_add_string_constant
8195817: JFR.stop should require name of recording
8195818: JFR.start should increase autogenerated name by one
8195819: Remove recording=x from jcmd JFR.check output
8203921: JFR thread sampling is missing fixes from JDK-8194552
8203929: Limit amount of data for JFR.dump
8203664: JFR start failure after AppCDS archive created with JFR StartFlightRecording
8003209: JFR events for network utilization
8207392: [PPC64] Implement JFR profiling
8202835: jfr/event/os/TestSystemProcess.java fails on missing events
Summary: Backport JFR from JDK11. Initial integration
Reviewed-by: neugens

duke@435 1 /*
drchase@6680 2 * Copyright (c) 1997, 2014, 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 #include "precompiled.hpp"
stefank@2314 26 #include "classfile/classLoader.hpp"
stefank@2314 27 #include "code/vtableStubs.hpp"
stefank@2314 28 #include "gc_interface/collectedHeap.inline.hpp"
stefank@2314 29 #include "interpreter/interpreter.hpp"
stefank@2314 30 #include "memory/allocation.inline.hpp"
stefank@2314 31 #include "memory/universe.inline.hpp"
stefank@2314 32 #include "oops/oop.inline.hpp"
stefank@2314 33 #include "oops/oop.inline2.hpp"
coleenp@2497 34 #include "oops/symbol.hpp"
stefank@2314 35 #include "runtime/deoptimization.hpp"
stefank@2314 36 #include "runtime/fprofiler.hpp"
stefank@2314 37 #include "runtime/mutexLocker.hpp"
stefank@2314 38 #include "runtime/stubCodeGenerator.hpp"
stefank@2314 39 #include "runtime/stubRoutines.hpp"
stefank@2314 40 #include "runtime/task.hpp"
goetz@6911 41 #include "runtime/thread.inline.hpp"
stefank@2314 42 #include "runtime/vframe.hpp"
stefank@2314 43 #include "utilities/macros.hpp"
duke@435 44
drchase@6680 45 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
drchase@6680 46
duke@435 47 // Static fields of FlatProfiler
duke@435 48 int FlatProfiler::received_gc_ticks = 0;
duke@435 49 int FlatProfiler::vm_operation_ticks = 0;
duke@435 50 int FlatProfiler::threads_lock_ticks = 0;
duke@435 51 int FlatProfiler::class_loader_ticks = 0;
duke@435 52 int FlatProfiler::extra_ticks = 0;
duke@435 53 int FlatProfiler::blocked_ticks = 0;
duke@435 54 int FlatProfiler::deopt_ticks = 0;
duke@435 55 int FlatProfiler::unknown_ticks = 0;
duke@435 56 int FlatProfiler::interpreter_ticks = 0;
duke@435 57 int FlatProfiler::compiler_ticks = 0;
duke@435 58 int FlatProfiler::received_ticks = 0;
duke@435 59 int FlatProfiler::delivered_ticks = 0;
duke@435 60 int* FlatProfiler::bytecode_ticks = NULL;
duke@435 61 int* FlatProfiler::bytecode_ticks_stub = NULL;
duke@435 62 int FlatProfiler::all_int_ticks = 0;
duke@435 63 int FlatProfiler::all_comp_ticks = 0;
duke@435 64 int FlatProfiler::all_ticks = 0;
duke@435 65 bool FlatProfiler::full_profile_flag = false;
duke@435 66 ThreadProfiler* FlatProfiler::thread_profiler = NULL;
duke@435 67 ThreadProfiler* FlatProfiler::vm_thread_profiler = NULL;
duke@435 68 FlatProfilerTask* FlatProfiler::task = NULL;
duke@435 69 elapsedTimer FlatProfiler::timer;
duke@435 70 int FlatProfiler::interval_ticks_previous = 0;
duke@435 71 IntervalData* FlatProfiler::interval_data = NULL;
duke@435 72
duke@435 73 ThreadProfiler::ThreadProfiler() {
duke@435 74 // Space for the ProfilerNodes
duke@435 75 const int area_size = 1 * ProfilerNodeSize * 1024;
zgu@3900 76 area_bottom = AllocateHeap(area_size, mtInternal);
duke@435 77 area_top = area_bottom;
duke@435 78 area_limit = area_bottom + area_size;
duke@435 79
duke@435 80 // ProfilerNode pointer table
zgu@3900 81 table = NEW_C_HEAP_ARRAY(ProfilerNode*, table_size, mtInternal);
duke@435 82 initialize();
duke@435 83 engaged = false;
duke@435 84 }
duke@435 85
duke@435 86 ThreadProfiler::~ThreadProfiler() {
duke@435 87 FreeHeap(area_bottom);
duke@435 88 area_bottom = NULL;
duke@435 89 area_top = NULL;
duke@435 90 area_limit = NULL;
duke@435 91 FreeHeap(table);
duke@435 92 table = NULL;
duke@435 93 }
duke@435 94
duke@435 95 // Statics for ThreadProfiler
duke@435 96 int ThreadProfiler::table_size = 1024;
duke@435 97
duke@435 98 int ThreadProfiler::entry(int value) {
duke@435 99 value = (value > 0) ? value : -value;
duke@435 100 return value % table_size;
duke@435 101 }
duke@435 102
duke@435 103 ThreadProfilerMark::ThreadProfilerMark(ThreadProfilerMark::Region r) {
duke@435 104 _r = r;
duke@435 105 _pp = NULL;
duke@435 106 assert(((r > ThreadProfilerMark::noRegion) && (r < ThreadProfilerMark::maxRegion)), "ThreadProfilerMark::Region out of bounds");
duke@435 107 Thread* tp = Thread::current();
duke@435 108 if (tp != NULL && tp->is_Java_thread()) {
duke@435 109 JavaThread* jtp = (JavaThread*) tp;
duke@435 110 ThreadProfiler* pp = jtp->get_thread_profiler();
duke@435 111 _pp = pp;
duke@435 112 if (pp != NULL) {
duke@435 113 pp->region_flag[r] = true;
duke@435 114 }
duke@435 115 }
duke@435 116 }
duke@435 117
duke@435 118 ThreadProfilerMark::~ThreadProfilerMark() {
duke@435 119 if (_pp != NULL) {
duke@435 120 _pp->region_flag[_r] = false;
duke@435 121 }
duke@435 122 _pp = NULL;
duke@435 123 }
duke@435 124
duke@435 125 // Random other statics
duke@435 126 static const int col1 = 2; // position of output column 1
duke@435 127 static const int col2 = 11; // position of output column 2
duke@435 128 static const int col3 = 25; // position of output column 3
duke@435 129 static const int col4 = 55; // position of output column 4
duke@435 130
duke@435 131
duke@435 132 // Used for detailed profiling of nmethods.
duke@435 133 class PCRecorder : AllStatic {
duke@435 134 private:
duke@435 135 static int* counters;
duke@435 136 static address base;
duke@435 137 enum {
duke@435 138 bucket_size = 16
duke@435 139 };
duke@435 140 static int index_for(address pc) { return (pc - base)/bucket_size; }
duke@435 141 static address pc_for(int index) { return base + (index * bucket_size); }
duke@435 142 static int size() {
duke@435 143 return ((int)CodeCache::max_capacity())/bucket_size * BytesPerWord;
duke@435 144 }
duke@435 145 public:
duke@435 146 static address bucket_start_for(address pc) {
duke@435 147 if (counters == NULL) return NULL;
duke@435 148 return pc_for(index_for(pc));
duke@435 149 }
duke@435 150 static int bucket_count_for(address pc) { return counters[index_for(pc)]; }
duke@435 151 static void init();
duke@435 152 static void record(address pc);
duke@435 153 static void print();
duke@435 154 static void print_blobs(CodeBlob* cb);
duke@435 155 };
duke@435 156
duke@435 157 int* PCRecorder::counters = NULL;
duke@435 158 address PCRecorder::base = NULL;
duke@435 159
duke@435 160 void PCRecorder::init() {
duke@435 161 MutexLockerEx lm(CodeCache_lock, Mutex::_no_safepoint_check_flag);
duke@435 162 int s = size();
zgu@3900 163 counters = NEW_C_HEAP_ARRAY(int, s, mtInternal);
duke@435 164 for (int index = 0; index < s; index++) {
duke@435 165 counters[index] = 0;
duke@435 166 }
duke@435 167 base = CodeCache::first_address();
duke@435 168 }
duke@435 169
duke@435 170 void PCRecorder::record(address pc) {
duke@435 171 if (counters == NULL) return;
duke@435 172 assert(CodeCache::contains(pc), "must be in CodeCache");
duke@435 173 counters[index_for(pc)]++;
duke@435 174 }
duke@435 175
duke@435 176
duke@435 177 address FlatProfiler::bucket_start_for(address pc) {
duke@435 178 return PCRecorder::bucket_start_for(pc);
duke@435 179 }
duke@435 180
duke@435 181 int FlatProfiler::bucket_count_for(address pc) {
duke@435 182 return PCRecorder::bucket_count_for(pc);
duke@435 183 }
duke@435 184
duke@435 185 void PCRecorder::print() {
duke@435 186 if (counters == NULL) return;
duke@435 187
duke@435 188 tty->cr();
duke@435 189 tty->print_cr("Printing compiled methods with PC buckets having more than %d ticks", ProfilerPCTickThreshold);
duke@435 190 tty->print_cr("===================================================================");
duke@435 191 tty->cr();
duke@435 192
duke@435 193 GrowableArray<CodeBlob*>* candidates = new GrowableArray<CodeBlob*>(20);
duke@435 194
duke@435 195
duke@435 196 int s;
duke@435 197 {
duke@435 198 MutexLockerEx lm(CodeCache_lock, Mutex::_no_safepoint_check_flag);
duke@435 199 s = size();
duke@435 200 }
duke@435 201
duke@435 202 for (int index = 0; index < s; index++) {
duke@435 203 int count = counters[index];
duke@435 204 if (count > ProfilerPCTickThreshold) {
duke@435 205 address pc = pc_for(index);
duke@435 206 CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
duke@435 207 if (cb != NULL && candidates->find(cb) < 0) {
duke@435 208 candidates->push(cb);
duke@435 209 }
duke@435 210 }
duke@435 211 }
duke@435 212 for (int i = 0; i < candidates->length(); i++) {
duke@435 213 print_blobs(candidates->at(i));
duke@435 214 }
duke@435 215 }
duke@435 216
duke@435 217 void PCRecorder::print_blobs(CodeBlob* cb) {
duke@435 218 if (cb != NULL) {
duke@435 219 cb->print();
duke@435 220 if (cb->is_nmethod()) {
duke@435 221 ((nmethod*)cb)->print_code();
duke@435 222 }
duke@435 223 tty->cr();
duke@435 224 } else {
duke@435 225 tty->print_cr("stub code");
duke@435 226 }
duke@435 227 }
duke@435 228
duke@435 229 class tick_counter { // holds tick info for one node
duke@435 230 public:
duke@435 231 int ticks_in_code;
duke@435 232 int ticks_in_native;
duke@435 233
duke@435 234 tick_counter() { ticks_in_code = ticks_in_native = 0; }
duke@435 235 tick_counter(int code, int native) { ticks_in_code = code; ticks_in_native = native; }
duke@435 236
duke@435 237 int total() const {
duke@435 238 return (ticks_in_code + ticks_in_native);
duke@435 239 }
duke@435 240
duke@435 241 void add(tick_counter* a) {
duke@435 242 ticks_in_code += a->ticks_in_code;
duke@435 243 ticks_in_native += a->ticks_in_native;
duke@435 244 }
duke@435 245
duke@435 246 void update(TickPosition where) {
duke@435 247 switch(where) {
duke@435 248 case tp_code: ticks_in_code++; break;
duke@435 249 case tp_native: ticks_in_native++; break;
duke@435 250 }
duke@435 251 }
duke@435 252
duke@435 253 void print_code(outputStream* st, int total_ticks) {
duke@435 254 st->print("%5.1f%% %5d ", total() * 100.0 / total_ticks, ticks_in_code);
duke@435 255 }
duke@435 256
duke@435 257 void print_native(outputStream* st) {
duke@435 258 st->print(" + %5d ", ticks_in_native);
duke@435 259 }
duke@435 260 };
duke@435 261
duke@435 262 class ProfilerNode {
duke@435 263 private:
duke@435 264 ProfilerNode* _next;
duke@435 265 public:
duke@435 266 tick_counter ticks;
duke@435 267
duke@435 268 public:
duke@435 269
coleenp@5614 270 void* operator new(size_t size, ThreadProfiler* tp) throw();
duke@435 271 void operator delete(void* p);
duke@435 272
duke@435 273 ProfilerNode() {
duke@435 274 _next = NULL;
duke@435 275 }
duke@435 276
duke@435 277 virtual ~ProfilerNode() {
duke@435 278 if (_next)
duke@435 279 delete _next;
duke@435 280 }
duke@435 281
duke@435 282 void set_next(ProfilerNode* n) { _next = n; }
duke@435 283 ProfilerNode* next() { return _next; }
duke@435 284
duke@435 285 void update(TickPosition where) { ticks.update(where);}
duke@435 286 int total_ticks() { return ticks.total(); }
duke@435 287
duke@435 288 virtual bool is_interpreted() const { return false; }
duke@435 289 virtual bool is_compiled() const { return false; }
duke@435 290 virtual bool is_stub() const { return false; }
duke@435 291 virtual bool is_runtime_stub() const{ return false; }
duke@435 292 virtual void oops_do(OopClosure* f) = 0;
duke@435 293
coleenp@4037 294 virtual bool interpreted_match(Method* m) const { return false; }
coleenp@4037 295 virtual bool compiled_match(Method* m ) const { return false; }
coleenp@4037 296 virtual bool stub_match(Method* m, const char* name) const { return false; }
duke@435 297 virtual bool adapter_match() const { return false; }
duke@435 298 virtual bool runtimeStub_match(const CodeBlob* stub, const char* name) const { return false; }
duke@435 299 virtual bool unknown_compiled_match(const CodeBlob* cb) const { return false; }
duke@435 300
duke@435 301 static void print_title(outputStream* st) {
duke@435 302 st->print(" + native");
duke@435 303 st->fill_to(col3);
duke@435 304 st->print("Method");
duke@435 305 st->fill_to(col4);
duke@435 306 st->cr();
duke@435 307 }
duke@435 308
duke@435 309 static void print_total(outputStream* st, tick_counter* t, int total, const char* msg) {
duke@435 310 t->print_code(st, total);
duke@435 311 st->fill_to(col2);
duke@435 312 t->print_native(st);
duke@435 313 st->fill_to(col3);
drchase@6680 314 st->print("%s", msg);
duke@435 315 st->cr();
duke@435 316 }
duke@435 317
coleenp@4037 318 virtual Method* method() = 0;
duke@435 319
duke@435 320 virtual void print_method_on(outputStream* st) {
duke@435 321 int limit;
duke@435 322 int i;
coleenp@4037 323 Method* m = method();
coleenp@2497 324 Symbol* k = m->klass_name();
duke@435 325 // Print the class name with dots instead of slashes
duke@435 326 limit = k->utf8_length();
duke@435 327 for (i = 0 ; i < limit ; i += 1) {
duke@435 328 char c = (char) k->byte_at(i);
duke@435 329 if (c == '/') {
duke@435 330 c = '.';
duke@435 331 }
duke@435 332 st->print("%c", c);
duke@435 333 }
duke@435 334 if (limit > 0) {
duke@435 335 st->print(".");
duke@435 336 }
coleenp@2497 337 Symbol* n = m->name();
duke@435 338 limit = n->utf8_length();
duke@435 339 for (i = 0 ; i < limit ; i += 1) {
duke@435 340 char c = (char) n->byte_at(i);
duke@435 341 st->print("%c", c);
duke@435 342 }
twisti@3969 343 if (Verbose || WizardMode) {
duke@435 344 // Disambiguate overloaded methods
coleenp@2497 345 Symbol* sig = m->signature();
duke@435 346 sig->print_symbol_on(st);
twisti@3969 347 } else if (MethodHandles::is_signature_polymorphic(m->intrinsic_id()))
coleenp@4037 348 // compare with Method::print_short_name
twisti@3969 349 MethodHandles::print_as_basic_type_signature_on(st, m->signature(), true);
duke@435 350 }
duke@435 351
duke@435 352 virtual void print(outputStream* st, int total_ticks) {
duke@435 353 ticks.print_code(st, total_ticks);
duke@435 354 st->fill_to(col2);
duke@435 355 ticks.print_native(st);
duke@435 356 st->fill_to(col3);
duke@435 357 print_method_on(st);
duke@435 358 st->cr();
duke@435 359 }
duke@435 360
duke@435 361 // for hashing into the table
coleenp@4037 362 static int hash(Method* method) {
duke@435 363 // The point here is to try to make something fairly unique
duke@435 364 // out of the fields we can read without grabbing any locks
duke@435 365 // since the method may be locked when we need the hash.
duke@435 366 return (
duke@435 367 method->code_size() ^
duke@435 368 method->max_stack() ^
duke@435 369 method->max_locals() ^
duke@435 370 method->size_of_parameters());
duke@435 371 }
duke@435 372
duke@435 373 // for sorting
duke@435 374 static int compare(ProfilerNode** a, ProfilerNode** b) {
duke@435 375 return (*b)->total_ticks() - (*a)->total_ticks();
duke@435 376 }
duke@435 377 };
duke@435 378
coleenp@5614 379 void* ProfilerNode::operator new(size_t size, ThreadProfiler* tp) throw() {
duke@435 380 void* result = (void*) tp->area_top;
duke@435 381 tp->area_top += size;
duke@435 382
duke@435 383 if (tp->area_top > tp->area_limit) {
duke@435 384 fatal("flat profiler buffer overflow");
duke@435 385 }
duke@435 386 return result;
duke@435 387 }
duke@435 388
duke@435 389 void ProfilerNode::operator delete(void* p){
duke@435 390 }
duke@435 391
duke@435 392 class interpretedNode : public ProfilerNode {
duke@435 393 private:
coleenp@4037 394 Method* _method;
coleenp@4037 395 oop _class_loader; // needed to keep metadata for the method alive
duke@435 396 public:
coleenp@4037 397 interpretedNode(Method* method, TickPosition where) : ProfilerNode() {
duke@435 398 _method = method;
coleenp@4037 399 _class_loader = method->method_holder()->class_loader();
duke@435 400 update(where);
duke@435 401 }
duke@435 402
duke@435 403 bool is_interpreted() const { return true; }
duke@435 404
coleenp@4037 405 bool interpreted_match(Method* m) const {
duke@435 406 return _method == m;
duke@435 407 }
duke@435 408
duke@435 409 void oops_do(OopClosure* f) {
coleenp@4037 410 f->do_oop(&_class_loader);
duke@435 411 }
duke@435 412
coleenp@4037 413 Method* method() { return _method; }
duke@435 414
duke@435 415 static void print_title(outputStream* st) {
duke@435 416 st->fill_to(col1);
duke@435 417 st->print("%11s", "Interpreted");
duke@435 418 ProfilerNode::print_title(st);
duke@435 419 }
duke@435 420
duke@435 421 void print(outputStream* st, int total_ticks) {
duke@435 422 ProfilerNode::print(st, total_ticks);
duke@435 423 }
duke@435 424
duke@435 425 void print_method_on(outputStream* st) {
duke@435 426 ProfilerNode::print_method_on(st);
jiangli@4936 427 MethodCounters* mcs = method()->method_counters();
jiangli@4936 428 if (Verbose && mcs != NULL) mcs->invocation_counter()->print_short();
duke@435 429 }
duke@435 430 };
duke@435 431
duke@435 432 class compiledNode : public ProfilerNode {
duke@435 433 private:
coleenp@4037 434 Method* _method;
coleenp@4037 435 oop _class_loader; // needed to keep metadata for the method alive
duke@435 436 public:
coleenp@4037 437 compiledNode(Method* method, TickPosition where) : ProfilerNode() {
duke@435 438 _method = method;
coleenp@4037 439 _class_loader = method->method_holder()->class_loader();
duke@435 440 update(where);
duke@435 441 }
duke@435 442 bool is_compiled() const { return true; }
duke@435 443
coleenp@4037 444 bool compiled_match(Method* m) const {
duke@435 445 return _method == m;
duke@435 446 }
duke@435 447
coleenp@4037 448 Method* method() { return _method; }
duke@435 449
duke@435 450 void oops_do(OopClosure* f) {
coleenp@4037 451 f->do_oop(&_class_loader);
duke@435 452 }
duke@435 453
duke@435 454 static void print_title(outputStream* st) {
duke@435 455 st->fill_to(col1);
duke@435 456 st->print("%11s", "Compiled");
duke@435 457 ProfilerNode::print_title(st);
duke@435 458 }
duke@435 459
duke@435 460 void print(outputStream* st, int total_ticks) {
duke@435 461 ProfilerNode::print(st, total_ticks);
duke@435 462 }
duke@435 463
duke@435 464 void print_method_on(outputStream* st) {
duke@435 465 ProfilerNode::print_method_on(st);
duke@435 466 }
duke@435 467 };
duke@435 468
duke@435 469 class stubNode : public ProfilerNode {
duke@435 470 private:
coleenp@4037 471 Method* _method;
coleenp@4037 472 oop _class_loader; // needed to keep metadata for the method alive
duke@435 473 const char* _symbol; // The name of the nearest VM symbol (for +ProfileVM). Points to a unique string
duke@435 474 public:
coleenp@4037 475 stubNode(Method* method, const char* name, TickPosition where) : ProfilerNode() {
duke@435 476 _method = method;
coleenp@4037 477 _class_loader = method->method_holder()->class_loader();
duke@435 478 _symbol = name;
duke@435 479 update(where);
duke@435 480 }
duke@435 481
duke@435 482 bool is_stub() const { return true; }
duke@435 483
coleenp@4037 484 void oops_do(OopClosure* f) {
coleenp@4037 485 f->do_oop(&_class_loader);
coleenp@4037 486 }
coleenp@4037 487
coleenp@4037 488 bool stub_match(Method* m, const char* name) const {
duke@435 489 return (_method == m) && (_symbol == name);
duke@435 490 }
duke@435 491
coleenp@4037 492 Method* method() { return _method; }
duke@435 493
duke@435 494 static void print_title(outputStream* st) {
duke@435 495 st->fill_to(col1);
duke@435 496 st->print("%11s", "Stub");
duke@435 497 ProfilerNode::print_title(st);
duke@435 498 }
duke@435 499
duke@435 500 void print(outputStream* st, int total_ticks) {
duke@435 501 ProfilerNode::print(st, total_ticks);
duke@435 502 }
duke@435 503
duke@435 504 void print_method_on(outputStream* st) {
duke@435 505 ProfilerNode::print_method_on(st);
duke@435 506 print_symbol_on(st);
duke@435 507 }
duke@435 508
duke@435 509 void print_symbol_on(outputStream* st) {
duke@435 510 if(_symbol) {
duke@435 511 st->print(" (%s)", _symbol);
duke@435 512 }
duke@435 513 }
duke@435 514 };
duke@435 515
duke@435 516 class adapterNode : public ProfilerNode {
duke@435 517 public:
duke@435 518 adapterNode(TickPosition where) : ProfilerNode() {
duke@435 519 update(where);
duke@435 520 }
duke@435 521 bool is_compiled() const { return true; }
duke@435 522
duke@435 523 bool adapter_match() const { return true; }
duke@435 524
coleenp@4037 525 Method* method() { return NULL; }
duke@435 526
duke@435 527 void oops_do(OopClosure* f) {
duke@435 528 ;
duke@435 529 }
duke@435 530
duke@435 531 void print(outputStream* st, int total_ticks) {
duke@435 532 ProfilerNode::print(st, total_ticks);
duke@435 533 }
duke@435 534
duke@435 535 void print_method_on(outputStream* st) {
duke@435 536 st->print("%s", "adapters");
duke@435 537 }
duke@435 538 };
duke@435 539
duke@435 540 class runtimeStubNode : public ProfilerNode {
duke@435 541 private:
duke@435 542 const CodeBlob* _stub;
duke@435 543 const char* _symbol; // The name of the nearest VM symbol when ProfileVM is on. Points to a unique string.
duke@435 544 public:
duke@435 545 runtimeStubNode(const CodeBlob* stub, const char* name, TickPosition where) : ProfilerNode(), _stub(stub), _symbol(name) {
duke@435 546 assert(stub->is_runtime_stub(), "wrong code blob");
duke@435 547 update(where);
duke@435 548 }
duke@435 549
duke@435 550 bool is_runtime_stub() const { return true; }
duke@435 551
duke@435 552 bool runtimeStub_match(const CodeBlob* stub, const char* name) const {
duke@435 553 assert(stub->is_runtime_stub(), "wrong code blob");
duke@435 554 return ((RuntimeStub*)_stub)->entry_point() == ((RuntimeStub*)stub)->entry_point() &&
duke@435 555 (_symbol == name);
duke@435 556 }
duke@435 557
coleenp@4037 558 Method* method() { return NULL; }
duke@435 559
duke@435 560 static void print_title(outputStream* st) {
duke@435 561 st->fill_to(col1);
duke@435 562 st->print("%11s", "Runtime stub");
duke@435 563 ProfilerNode::print_title(st);
duke@435 564 }
duke@435 565
duke@435 566 void oops_do(OopClosure* f) {
duke@435 567 ;
duke@435 568 }
duke@435 569
duke@435 570 void print(outputStream* st, int total_ticks) {
duke@435 571 ProfilerNode::print(st, total_ticks);
duke@435 572 }
duke@435 573
duke@435 574 void print_method_on(outputStream* st) {
duke@435 575 st->print("%s", ((RuntimeStub*)_stub)->name());
duke@435 576 print_symbol_on(st);
duke@435 577 }
duke@435 578
duke@435 579 void print_symbol_on(outputStream* st) {
duke@435 580 if(_symbol) {
duke@435 581 st->print(" (%s)", _symbol);
duke@435 582 }
duke@435 583 }
duke@435 584 };
duke@435 585
duke@435 586
duke@435 587 class unknown_compiledNode : public ProfilerNode {
duke@435 588 const char *_name;
duke@435 589 public:
duke@435 590 unknown_compiledNode(const CodeBlob* cb, TickPosition where) : ProfilerNode() {
duke@435 591 if ( cb->is_buffer_blob() )
duke@435 592 _name = ((BufferBlob*)cb)->name();
duke@435 593 else
duke@435 594 _name = ((SingletonBlob*)cb)->name();
duke@435 595 update(where);
duke@435 596 }
duke@435 597 bool is_compiled() const { return true; }
duke@435 598
duke@435 599 bool unknown_compiled_match(const CodeBlob* cb) const {
duke@435 600 if ( cb->is_buffer_blob() )
duke@435 601 return !strcmp(((BufferBlob*)cb)->name(), _name);
duke@435 602 else
duke@435 603 return !strcmp(((SingletonBlob*)cb)->name(), _name);
duke@435 604 }
duke@435 605
coleenp@4037 606 Method* method() { return NULL; }
duke@435 607
duke@435 608 void oops_do(OopClosure* f) {
duke@435 609 ;
duke@435 610 }
duke@435 611
duke@435 612 void print(outputStream* st, int total_ticks) {
duke@435 613 ProfilerNode::print(st, total_ticks);
duke@435 614 }
duke@435 615
duke@435 616 void print_method_on(outputStream* st) {
duke@435 617 st->print("%s", _name);
duke@435 618 }
duke@435 619 };
duke@435 620
duke@435 621 class vmNode : public ProfilerNode {
duke@435 622 private:
duke@435 623 const char* _name; // "optional" name obtained by os means such as dll lookup
duke@435 624 public:
duke@435 625 vmNode(const TickPosition where) : ProfilerNode() {
duke@435 626 _name = NULL;
duke@435 627 update(where);
duke@435 628 }
duke@435 629
duke@435 630 vmNode(const char* name, const TickPosition where) : ProfilerNode() {
duke@435 631 _name = name;
duke@435 632 update(where);
duke@435 633 }
duke@435 634
duke@435 635 const char *name() const { return _name; }
duke@435 636 bool is_compiled() const { return true; }
duke@435 637
duke@435 638 bool vm_match(const char* name) const { return strcmp(name, _name) == 0; }
duke@435 639
coleenp@4037 640 Method* method() { return NULL; }
duke@435 641
duke@435 642 static int hash(const char* name){
duke@435 643 // Compute a simple hash
duke@435 644 const char* cp = name;
duke@435 645 int h = 0;
duke@435 646
duke@435 647 if(name != NULL){
duke@435 648 while(*cp != '\0'){
duke@435 649 h = (h << 1) ^ *cp;
duke@435 650 cp++;
duke@435 651 }
duke@435 652 }
duke@435 653 return h;
duke@435 654 }
duke@435 655
duke@435 656 void oops_do(OopClosure* f) {
duke@435 657 ;
duke@435 658 }
duke@435 659
duke@435 660 void print(outputStream* st, int total_ticks) {
duke@435 661 ProfilerNode::print(st, total_ticks);
duke@435 662 }
duke@435 663
duke@435 664 void print_method_on(outputStream* st) {
duke@435 665 if(_name==NULL){
duke@435 666 st->print("%s", "unknown code");
duke@435 667 }
duke@435 668 else {
duke@435 669 st->print("%s", _name);
duke@435 670 }
duke@435 671 }
duke@435 672 };
duke@435 673
coleenp@4037 674 void ThreadProfiler::interpreted_update(Method* method, TickPosition where) {
duke@435 675 int index = entry(ProfilerNode::hash(method));
duke@435 676 if (!table[index]) {
duke@435 677 table[index] = new (this) interpretedNode(method, where);
duke@435 678 } else {
duke@435 679 ProfilerNode* prev = table[index];
duke@435 680 for(ProfilerNode* node = prev; node; node = node->next()) {
duke@435 681 if (node->interpreted_match(method)) {
duke@435 682 node->update(where);
duke@435 683 return;
duke@435 684 }
duke@435 685 prev = node;
duke@435 686 }
duke@435 687 prev->set_next(new (this) interpretedNode(method, where));
duke@435 688 }
duke@435 689 }
duke@435 690
coleenp@4037 691 void ThreadProfiler::compiled_update(Method* method, TickPosition where) {
duke@435 692 int index = entry(ProfilerNode::hash(method));
duke@435 693 if (!table[index]) {
duke@435 694 table[index] = new (this) compiledNode(method, where);
duke@435 695 } else {
duke@435 696 ProfilerNode* prev = table[index];
duke@435 697 for(ProfilerNode* node = prev; node; node = node->next()) {
duke@435 698 if (node->compiled_match(method)) {
duke@435 699 node->update(where);
duke@435 700 return;
duke@435 701 }
duke@435 702 prev = node;
duke@435 703 }
duke@435 704 prev->set_next(new (this) compiledNode(method, where));
duke@435 705 }
duke@435 706 }
duke@435 707
coleenp@4037 708 void ThreadProfiler::stub_update(Method* method, const char* name, TickPosition where) {
duke@435 709 int index = entry(ProfilerNode::hash(method));
duke@435 710 if (!table[index]) {
duke@435 711 table[index] = new (this) stubNode(method, name, where);
duke@435 712 } else {
duke@435 713 ProfilerNode* prev = table[index];
duke@435 714 for(ProfilerNode* node = prev; node; node = node->next()) {
duke@435 715 if (node->stub_match(method, name)) {
duke@435 716 node->update(where);
duke@435 717 return;
duke@435 718 }
duke@435 719 prev = node;
duke@435 720 }
duke@435 721 prev->set_next(new (this) stubNode(method, name, where));
duke@435 722 }
duke@435 723 }
duke@435 724
duke@435 725 void ThreadProfiler::adapter_update(TickPosition where) {
duke@435 726 int index = 0;
duke@435 727 if (!table[index]) {
duke@435 728 table[index] = new (this) adapterNode(where);
duke@435 729 } else {
duke@435 730 ProfilerNode* prev = table[index];
duke@435 731 for(ProfilerNode* node = prev; node; node = node->next()) {
duke@435 732 if (node->adapter_match()) {
duke@435 733 node->update(where);
duke@435 734 return;
duke@435 735 }
duke@435 736 prev = node;
duke@435 737 }
duke@435 738 prev->set_next(new (this) adapterNode(where));
duke@435 739 }
duke@435 740 }
duke@435 741
duke@435 742 void ThreadProfiler::runtime_stub_update(const CodeBlob* stub, const char* name, TickPosition where) {
duke@435 743 int index = 0;
duke@435 744 if (!table[index]) {
duke@435 745 table[index] = new (this) runtimeStubNode(stub, name, where);
duke@435 746 } else {
duke@435 747 ProfilerNode* prev = table[index];
duke@435 748 for(ProfilerNode* node = prev; node; node = node->next()) {
duke@435 749 if (node->runtimeStub_match(stub, name)) {
duke@435 750 node->update(where);
duke@435 751 return;
duke@435 752 }
duke@435 753 prev = node;
duke@435 754 }
duke@435 755 prev->set_next(new (this) runtimeStubNode(stub, name, where));
duke@435 756 }
duke@435 757 }
duke@435 758
duke@435 759
duke@435 760 void ThreadProfiler::unknown_compiled_update(const CodeBlob* cb, TickPosition where) {
duke@435 761 int index = 0;
duke@435 762 if (!table[index]) {
duke@435 763 table[index] = new (this) unknown_compiledNode(cb, where);
duke@435 764 } else {
duke@435 765 ProfilerNode* prev = table[index];
duke@435 766 for(ProfilerNode* node = prev; node; node = node->next()) {
duke@435 767 if (node->unknown_compiled_match(cb)) {
duke@435 768 node->update(where);
duke@435 769 return;
duke@435 770 }
duke@435 771 prev = node;
duke@435 772 }
duke@435 773 prev->set_next(new (this) unknown_compiledNode(cb, where));
duke@435 774 }
duke@435 775 }
duke@435 776
duke@435 777 void ThreadProfiler::vm_update(TickPosition where) {
andrew@9607 778 vm_update("", where);
duke@435 779 }
duke@435 780
duke@435 781 void ThreadProfiler::vm_update(const char* name, TickPosition where) {
duke@435 782 int index = entry(vmNode::hash(name));
duke@435 783 assert(index >= 0, "Must be positive");
duke@435 784 // Note that we call strdup below since the symbol may be resource allocated
duke@435 785 if (!table[index]) {
duke@435 786 table[index] = new (this) vmNode(os::strdup(name), where);
duke@435 787 } else {
duke@435 788 ProfilerNode* prev = table[index];
duke@435 789 for(ProfilerNode* node = prev; node; node = node->next()) {
duke@435 790 if (((vmNode *)node)->vm_match(name)) {
duke@435 791 node->update(where);
duke@435 792 return;
duke@435 793 }
duke@435 794 prev = node;
duke@435 795 }
duke@435 796 prev->set_next(new (this) vmNode(os::strdup(name), where));
duke@435 797 }
duke@435 798 }
duke@435 799
duke@435 800
duke@435 801 class FlatProfilerTask : public PeriodicTask {
duke@435 802 public:
duke@435 803 FlatProfilerTask(int interval_time) : PeriodicTask(interval_time) {}
duke@435 804 void task();
duke@435 805 };
duke@435 806
duke@435 807 void FlatProfiler::record_vm_operation() {
duke@435 808 if (Universe::heap()->is_gc_active()) {
duke@435 809 FlatProfiler::received_gc_ticks += 1;
duke@435 810 return;
duke@435 811 }
duke@435 812
duke@435 813 if (DeoptimizationMarker::is_active()) {
duke@435 814 FlatProfiler::deopt_ticks += 1;
duke@435 815 return;
duke@435 816 }
duke@435 817
duke@435 818 FlatProfiler::vm_operation_ticks += 1;
duke@435 819 }
duke@435 820
duke@435 821 void FlatProfiler::record_vm_tick() {
duke@435 822 // Profile the VM Thread itself if needed
duke@435 823 // This is done without getting the Threads_lock and we can go deep
duke@435 824 // inside Safepoint, etc.
duke@435 825 if( ProfileVM ) {
duke@435 826 ResourceMark rm;
duke@435 827 ExtendedPC epc;
duke@435 828 const char *name = NULL;
duke@435 829 char buf[256];
duke@435 830 buf[0] = '\0';
duke@435 831
duke@435 832 vm_thread_profiler->inc_thread_ticks();
duke@435 833
duke@435 834 // Get a snapshot of a current VMThread pc (and leave it running!)
duke@435 835 // The call may fail if, for instance the VM thread is interrupted while
duke@435 836 // holding the Interrupt_lock or for other reasons.
duke@435 837 epc = os::get_thread_pc(VMThread::vm_thread());
duke@435 838 if(epc.pc() != NULL) {
duke@435 839 if (os::dll_address_to_function_name(epc.pc(), buf, sizeof(buf), NULL)) {
duke@435 840 name = buf;
duke@435 841 }
duke@435 842 }
duke@435 843 if (name != NULL) {
duke@435 844 vm_thread_profiler->vm_update(name, tp_native);
duke@435 845 }
duke@435 846 }
duke@435 847 }
duke@435 848
duke@435 849 void FlatProfiler::record_thread_ticks() {
duke@435 850
duke@435 851 int maxthreads, suspendedthreadcount;
duke@435 852 JavaThread** threadsList;
duke@435 853 bool interval_expired = false;
duke@435 854
duke@435 855 if (ProfileIntervals &&
duke@435 856 (FlatProfiler::received_ticks >= interval_ticks_previous + ProfileIntervalsTicks)) {
duke@435 857 interval_expired = true;
duke@435 858 interval_ticks_previous = FlatProfiler::received_ticks;
duke@435 859 }
duke@435 860
duke@435 861 // Try not to wait for the Threads_lock
duke@435 862 if (Threads_lock->try_lock()) {
duke@435 863 { // Threads_lock scope
duke@435 864 maxthreads = Threads::number_of_threads();
zgu@3900 865 threadsList = NEW_C_HEAP_ARRAY(JavaThread *, maxthreads, mtInternal);
duke@435 866 suspendedthreadcount = 0;
duke@435 867 for (JavaThread* tp = Threads::first(); tp != NULL; tp = tp->next()) {
duke@435 868 if (tp->is_Compiler_thread()) {
duke@435 869 // Only record ticks for active compiler threads
duke@435 870 CompilerThread* cthread = (CompilerThread*)tp;
duke@435 871 if (cthread->task() != NULL) {
duke@435 872 // The compiler is active. If we need to access any of the fields
duke@435 873 // of the compiler task we should suspend the CompilerThread first.
duke@435 874 FlatProfiler::compiler_ticks += 1;
duke@435 875 continue;
duke@435 876 }
duke@435 877 }
duke@435 878
duke@435 879 // First externally suspend all threads by marking each for
duke@435 880 // external suspension - so it will stop at its next transition
duke@435 881 // Then do a safepoint
duke@435 882 ThreadProfiler* pp = tp->get_thread_profiler();
duke@435 883 if (pp != NULL && pp->engaged) {
duke@435 884 MutexLockerEx ml(tp->SR_lock(), Mutex::_no_safepoint_check_flag);
duke@435 885 if (!tp->is_external_suspend() && !tp->is_exiting()) {
duke@435 886 tp->set_external_suspend();
duke@435 887 threadsList[suspendedthreadcount++] = tp;
duke@435 888 }
duke@435 889 }
duke@435 890 }
duke@435 891 Threads_lock->unlock();
duke@435 892 }
duke@435 893 // Suspend each thread. This call should just return
duke@435 894 // for any threads that have already self-suspended
duke@435 895 // Net result should be one safepoint
duke@435 896 for (int j = 0; j < suspendedthreadcount; j++) {
duke@435 897 JavaThread *tp = threadsList[j];
duke@435 898 if (tp) {
duke@435 899 tp->java_suspend();
duke@435 900 }
duke@435 901 }
duke@435 902
duke@435 903 // We are responsible for resuming any thread on this list
duke@435 904 for (int i = 0; i < suspendedthreadcount; i++) {
duke@435 905 JavaThread *tp = threadsList[i];
duke@435 906 if (tp) {
duke@435 907 ThreadProfiler* pp = tp->get_thread_profiler();
duke@435 908 if (pp != NULL && pp->engaged) {
duke@435 909 HandleMark hm;
duke@435 910 FlatProfiler::delivered_ticks += 1;
duke@435 911 if (interval_expired) {
duke@435 912 FlatProfiler::interval_record_thread(pp);
duke@435 913 }
duke@435 914 // This is the place where we check to see if a user thread is
duke@435 915 // blocked waiting for compilation.
duke@435 916 if (tp->blocked_on_compilation()) {
duke@435 917 pp->compiler_ticks += 1;
duke@435 918 pp->interval_data_ref()->inc_compiling();
duke@435 919 } else {
duke@435 920 pp->record_tick(tp);
duke@435 921 }
duke@435 922 }
duke@435 923 MutexLocker ml(Threads_lock);
duke@435 924 tp->java_resume();
duke@435 925 }
duke@435 926 }
duke@435 927 if (interval_expired) {
duke@435 928 FlatProfiler::interval_print();
duke@435 929 FlatProfiler::interval_reset();
duke@435 930 }
zgu@5616 931
zgu@5616 932 FREE_C_HEAP_ARRAY(JavaThread *, threadsList, mtInternal);
duke@435 933 } else {
duke@435 934 // Couldn't get the threads lock, just record that rather than blocking
duke@435 935 FlatProfiler::threads_lock_ticks += 1;
duke@435 936 }
duke@435 937
duke@435 938 }
duke@435 939
duke@435 940 void FlatProfilerTask::task() {
duke@435 941 FlatProfiler::received_ticks += 1;
duke@435 942
duke@435 943 if (ProfileVM) {
duke@435 944 FlatProfiler::record_vm_tick();
duke@435 945 }
duke@435 946
duke@435 947 VM_Operation* op = VMThread::vm_operation();
duke@435 948 if (op != NULL) {
duke@435 949 FlatProfiler::record_vm_operation();
duke@435 950 if (SafepointSynchronize::is_at_safepoint()) {
duke@435 951 return;
duke@435 952 }
duke@435 953 }
duke@435 954 FlatProfiler::record_thread_ticks();
duke@435 955 }
duke@435 956
sgoldman@542 957 void ThreadProfiler::record_interpreted_tick(JavaThread* thread, frame fr, TickPosition where, int* ticks) {
duke@435 958 FlatProfiler::all_int_ticks++;
duke@435 959 if (!FlatProfiler::full_profile()) {
duke@435 960 return;
duke@435 961 }
duke@435 962
sgoldman@542 963 if (!fr.is_interpreted_frame_valid(thread)) {
duke@435 964 // tick came at a bad time
duke@435 965 interpreter_ticks += 1;
duke@435 966 FlatProfiler::interpreter_ticks += 1;
duke@435 967 return;
duke@435 968 }
duke@435 969
sgoldman@542 970 // The frame has been fully validated so we can trust the method and bci
sgoldman@542 971
coleenp@4037 972 Method* method = *fr.interpreter_frame_method_addr();
sgoldman@542 973
duke@435 974 interpreted_update(method, where);
duke@435 975
duke@435 976 // update byte code table
duke@435 977 InterpreterCodelet* desc = Interpreter::codelet_containing(fr.pc());
duke@435 978 if (desc != NULL && desc->bytecode() >= 0) {
duke@435 979 ticks[desc->bytecode()]++;
duke@435 980 }
duke@435 981 }
duke@435 982
duke@435 983 void ThreadProfiler::record_compiled_tick(JavaThread* thread, frame fr, TickPosition where) {
duke@435 984 const char *name = NULL;
duke@435 985 TickPosition localwhere = where;
duke@435 986
duke@435 987 FlatProfiler::all_comp_ticks++;
duke@435 988 if (!FlatProfiler::full_profile()) return;
duke@435 989
duke@435 990 CodeBlob* cb = fr.cb();
duke@435 991
duke@435 992 // For runtime stubs, record as native rather than as compiled
duke@435 993 if (cb->is_runtime_stub()) {
duke@435 994 RegisterMap map(thread, false);
duke@435 995 fr = fr.sender(&map);
duke@435 996 cb = fr.cb();
duke@435 997 localwhere = tp_native;
duke@435 998 }
coleenp@4037 999 Method* method = (cb->is_nmethod()) ? ((nmethod *)cb)->method() :
coleenp@4037 1000 (Method*)NULL;
duke@435 1001
duke@435 1002 if (method == NULL) {
duke@435 1003 if (cb->is_runtime_stub())
duke@435 1004 runtime_stub_update(cb, name, localwhere);
duke@435 1005 else
duke@435 1006 unknown_compiled_update(cb, localwhere);
duke@435 1007 }
duke@435 1008 else {
duke@435 1009 if (method->is_native()) {
duke@435 1010 stub_update(method, name, localwhere);
duke@435 1011 } else {
duke@435 1012 compiled_update(method, localwhere);
duke@435 1013 }
duke@435 1014 }
duke@435 1015 }
duke@435 1016
duke@435 1017 extern "C" void find(int x);
duke@435 1018
duke@435 1019
duke@435 1020 void ThreadProfiler::record_tick_for_running_frame(JavaThread* thread, frame fr) {
twisti@1040 1021 // The tick happened in real code -> non VM code
duke@435 1022 if (fr.is_interpreted_frame()) {
duke@435 1023 interval_data_ref()->inc_interpreted();
sgoldman@542 1024 record_interpreted_tick(thread, fr, tp_code, FlatProfiler::bytecode_ticks);
duke@435 1025 return;
duke@435 1026 }
duke@435 1027
duke@435 1028 if (CodeCache::contains(fr.pc())) {
duke@435 1029 interval_data_ref()->inc_compiled();
duke@435 1030 PCRecorder::record(fr.pc());
duke@435 1031 record_compiled_tick(thread, fr, tp_code);
duke@435 1032 return;
duke@435 1033 }
duke@435 1034
duke@435 1035 if (VtableStubs::stub_containing(fr.pc()) != NULL) {
duke@435 1036 unknown_ticks_array[ut_vtable_stubs] += 1;
duke@435 1037 return;
duke@435 1038 }
duke@435 1039
duke@435 1040 frame caller = fr.profile_find_Java_sender_frame(thread);
duke@435 1041
duke@435 1042 if (caller.sp() != NULL && caller.pc() != NULL) {
duke@435 1043 record_tick_for_calling_frame(thread, caller);
duke@435 1044 return;
duke@435 1045 }
duke@435 1046
duke@435 1047 unknown_ticks_array[ut_running_frame] += 1;
duke@435 1048 FlatProfiler::unknown_ticks += 1;
duke@435 1049 }
duke@435 1050
duke@435 1051 void ThreadProfiler::record_tick_for_calling_frame(JavaThread* thread, frame fr) {
twisti@1040 1052 // The tick happened in VM code
duke@435 1053 interval_data_ref()->inc_native();
duke@435 1054 if (fr.is_interpreted_frame()) {
sgoldman@542 1055 record_interpreted_tick(thread, fr, tp_native, FlatProfiler::bytecode_ticks_stub);
duke@435 1056 return;
duke@435 1057 }
duke@435 1058 if (CodeCache::contains(fr.pc())) {
duke@435 1059 record_compiled_tick(thread, fr, tp_native);
duke@435 1060 return;
duke@435 1061 }
duke@435 1062
duke@435 1063 frame caller = fr.profile_find_Java_sender_frame(thread);
duke@435 1064
duke@435 1065 if (caller.sp() != NULL && caller.pc() != NULL) {
duke@435 1066 record_tick_for_calling_frame(thread, caller);
duke@435 1067 return;
duke@435 1068 }
duke@435 1069
duke@435 1070 unknown_ticks_array[ut_calling_frame] += 1;
duke@435 1071 FlatProfiler::unknown_ticks += 1;
duke@435 1072 }
duke@435 1073
duke@435 1074 void ThreadProfiler::record_tick(JavaThread* thread) {
duke@435 1075 FlatProfiler::all_ticks++;
duke@435 1076 thread_ticks += 1;
duke@435 1077
duke@435 1078 // Here's another way to track global state changes.
duke@435 1079 // When the class loader starts it marks the ThreadProfiler to tell it it is in the class loader
duke@435 1080 // and we check that here.
duke@435 1081 // This is more direct, and more than one thread can be in the class loader at a time,
duke@435 1082 // but it does mean the class loader has to know about the profiler.
duke@435 1083 if (region_flag[ThreadProfilerMark::classLoaderRegion]) {
duke@435 1084 class_loader_ticks += 1;
duke@435 1085 FlatProfiler::class_loader_ticks += 1;
duke@435 1086 return;
duke@435 1087 } else if (region_flag[ThreadProfilerMark::extraRegion]) {
duke@435 1088 extra_ticks += 1;
duke@435 1089 FlatProfiler::extra_ticks += 1;
duke@435 1090 return;
duke@435 1091 }
duke@435 1092 // Note that the WatcherThread can now stop for safepoints
duke@435 1093 uint32_t debug_bits = 0;
duke@435 1094 if (!thread->wait_for_ext_suspend_completion(SuspendRetryCount,
duke@435 1095 SuspendRetryDelay, &debug_bits)) {
duke@435 1096 unknown_ticks_array[ut_unknown_thread_state] += 1;
duke@435 1097 FlatProfiler::unknown_ticks += 1;
duke@435 1098 return;
duke@435 1099 }
duke@435 1100
duke@435 1101 frame fr;
duke@435 1102
duke@435 1103 switch (thread->thread_state()) {
duke@435 1104 case _thread_in_native:
duke@435 1105 case _thread_in_native_trans:
duke@435 1106 case _thread_in_vm:
duke@435 1107 case _thread_in_vm_trans:
duke@435 1108 if (thread->profile_last_Java_frame(&fr)) {
duke@435 1109 if (fr.is_runtime_frame()) {
duke@435 1110 RegisterMap map(thread, false);
duke@435 1111 fr = fr.sender(&map);
duke@435 1112 }
duke@435 1113 record_tick_for_calling_frame(thread, fr);
duke@435 1114 } else {
duke@435 1115 unknown_ticks_array[ut_no_last_Java_frame] += 1;
duke@435 1116 FlatProfiler::unknown_ticks += 1;
duke@435 1117 }
duke@435 1118 break;
duke@435 1119 // handle_special_runtime_exit_condition self-suspends threads in Java
duke@435 1120 case _thread_in_Java:
duke@435 1121 case _thread_in_Java_trans:
duke@435 1122 if (thread->profile_last_Java_frame(&fr)) {
duke@435 1123 if (fr.is_safepoint_blob_frame()) {
duke@435 1124 RegisterMap map(thread, false);
duke@435 1125 fr = fr.sender(&map);
duke@435 1126 }
duke@435 1127 record_tick_for_running_frame(thread, fr);
duke@435 1128 } else {
duke@435 1129 unknown_ticks_array[ut_no_last_Java_frame] += 1;
duke@435 1130 FlatProfiler::unknown_ticks += 1;
duke@435 1131 }
duke@435 1132 break;
duke@435 1133 case _thread_blocked:
duke@435 1134 case _thread_blocked_trans:
duke@435 1135 if (thread->osthread() && thread->osthread()->get_state() == RUNNABLE) {
duke@435 1136 if (thread->profile_last_Java_frame(&fr)) {
duke@435 1137 if (fr.is_safepoint_blob_frame()) {
duke@435 1138 RegisterMap map(thread, false);
duke@435 1139 fr = fr.sender(&map);
duke@435 1140 record_tick_for_running_frame(thread, fr);
duke@435 1141 } else {
duke@435 1142 record_tick_for_calling_frame(thread, fr);
duke@435 1143 }
duke@435 1144 } else {
duke@435 1145 unknown_ticks_array[ut_no_last_Java_frame] += 1;
duke@435 1146 FlatProfiler::unknown_ticks += 1;
duke@435 1147 }
duke@435 1148 } else {
duke@435 1149 blocked_ticks += 1;
duke@435 1150 FlatProfiler::blocked_ticks += 1;
duke@435 1151 }
duke@435 1152 break;
duke@435 1153 case _thread_uninitialized:
duke@435 1154 case _thread_new:
duke@435 1155 // not used, included for completeness
duke@435 1156 case _thread_new_trans:
duke@435 1157 unknown_ticks_array[ut_no_last_Java_frame] += 1;
duke@435 1158 FlatProfiler::unknown_ticks += 1;
duke@435 1159 break;
duke@435 1160 default:
duke@435 1161 unknown_ticks_array[ut_unknown_thread_state] += 1;
duke@435 1162 FlatProfiler::unknown_ticks += 1;
duke@435 1163 break;
duke@435 1164 }
duke@435 1165 return;
duke@435 1166 }
duke@435 1167
duke@435 1168 void ThreadProfiler::engage() {
duke@435 1169 engaged = true;
duke@435 1170 timer.start();
duke@435 1171 }
duke@435 1172
duke@435 1173 void ThreadProfiler::disengage() {
duke@435 1174 engaged = false;
duke@435 1175 timer.stop();
duke@435 1176 }
duke@435 1177
duke@435 1178 void ThreadProfiler::initialize() {
duke@435 1179 for (int index = 0; index < table_size; index++) {
duke@435 1180 table[index] = NULL;
duke@435 1181 }
duke@435 1182 thread_ticks = 0;
duke@435 1183 blocked_ticks = 0;
duke@435 1184 compiler_ticks = 0;
duke@435 1185 interpreter_ticks = 0;
duke@435 1186 for (int ut = 0; ut < ut_end; ut += 1) {
duke@435 1187 unknown_ticks_array[ut] = 0;
duke@435 1188 }
duke@435 1189 region_flag[ThreadProfilerMark::classLoaderRegion] = false;
duke@435 1190 class_loader_ticks = 0;
duke@435 1191 region_flag[ThreadProfilerMark::extraRegion] = false;
duke@435 1192 extra_ticks = 0;
duke@435 1193 timer.start();
duke@435 1194 interval_data_ref()->reset();
duke@435 1195 }
duke@435 1196
duke@435 1197 void ThreadProfiler::reset() {
duke@435 1198 timer.stop();
duke@435 1199 if (table != NULL) {
duke@435 1200 for (int index = 0; index < table_size; index++) {
duke@435 1201 ProfilerNode* n = table[index];
duke@435 1202 if (n != NULL) {
duke@435 1203 delete n;
duke@435 1204 }
duke@435 1205 }
duke@435 1206 }
duke@435 1207 initialize();
duke@435 1208 }
duke@435 1209
duke@435 1210 void FlatProfiler::allocate_table() {
duke@435 1211 { // Bytecode table
zgu@3900 1212 bytecode_ticks = NEW_C_HEAP_ARRAY(int, Bytecodes::number_of_codes, mtInternal);
zgu@3900 1213 bytecode_ticks_stub = NEW_C_HEAP_ARRAY(int, Bytecodes::number_of_codes, mtInternal);
duke@435 1214 for(int index = 0; index < Bytecodes::number_of_codes; index++) {
duke@435 1215 bytecode_ticks[index] = 0;
duke@435 1216 bytecode_ticks_stub[index] = 0;
duke@435 1217 }
duke@435 1218 }
duke@435 1219
duke@435 1220 if (ProfilerRecordPC) PCRecorder::init();
duke@435 1221
zgu@3900 1222 interval_data = NEW_C_HEAP_ARRAY(IntervalData, interval_print_size, mtInternal);
duke@435 1223 FlatProfiler::interval_reset();
duke@435 1224 }
duke@435 1225
duke@435 1226 void FlatProfiler::engage(JavaThread* mainThread, bool fullProfile) {
duke@435 1227 full_profile_flag = fullProfile;
duke@435 1228 if (bytecode_ticks == NULL) {
duke@435 1229 allocate_table();
duke@435 1230 }
duke@435 1231 if(ProfileVM && (vm_thread_profiler == NULL)){
duke@435 1232 vm_thread_profiler = new ThreadProfiler();
duke@435 1233 }
duke@435 1234 if (task == NULL) {
duke@435 1235 task = new FlatProfilerTask(WatcherThread::delay_interval);
duke@435 1236 task->enroll();
duke@435 1237 }
duke@435 1238 timer.start();
duke@435 1239 if (mainThread != NULL) {
duke@435 1240 // When mainThread was created, it might not have a ThreadProfiler
duke@435 1241 ThreadProfiler* pp = mainThread->get_thread_profiler();
duke@435 1242 if (pp == NULL) {
duke@435 1243 mainThread->set_thread_profiler(new ThreadProfiler());
duke@435 1244 } else {
duke@435 1245 pp->reset();
duke@435 1246 }
duke@435 1247 mainThread->get_thread_profiler()->engage();
duke@435 1248 }
duke@435 1249 // This is where we would assign thread_profiler
duke@435 1250 // if we wanted only one thread_profiler for all threads.
duke@435 1251 thread_profiler = NULL;
duke@435 1252 }
duke@435 1253
duke@435 1254 void FlatProfiler::disengage() {
duke@435 1255 if (!task) {
duke@435 1256 return;
duke@435 1257 }
duke@435 1258 timer.stop();
duke@435 1259 task->disenroll();
duke@435 1260 delete task;
duke@435 1261 task = NULL;
duke@435 1262 if (thread_profiler != NULL) {
duke@435 1263 thread_profiler->disengage();
duke@435 1264 } else {
duke@435 1265 MutexLocker tl(Threads_lock);
duke@435 1266 for (JavaThread* tp = Threads::first(); tp != NULL; tp = tp->next()) {
duke@435 1267 ThreadProfiler* pp = tp->get_thread_profiler();
duke@435 1268 if (pp != NULL) {
duke@435 1269 pp->disengage();
duke@435 1270 }
duke@435 1271 }
duke@435 1272 }
duke@435 1273 }
duke@435 1274
duke@435 1275 void FlatProfiler::reset() {
duke@435 1276 if (task) {
duke@435 1277 disengage();
duke@435 1278 }
duke@435 1279
duke@435 1280 class_loader_ticks = 0;
duke@435 1281 extra_ticks = 0;
duke@435 1282 received_gc_ticks = 0;
duke@435 1283 vm_operation_ticks = 0;
duke@435 1284 compiler_ticks = 0;
duke@435 1285 deopt_ticks = 0;
duke@435 1286 interpreter_ticks = 0;
duke@435 1287 blocked_ticks = 0;
duke@435 1288 unknown_ticks = 0;
duke@435 1289 received_ticks = 0;
duke@435 1290 delivered_ticks = 0;
duke@435 1291 timer.stop();
duke@435 1292 }
duke@435 1293
duke@435 1294 bool FlatProfiler::is_active() {
duke@435 1295 return task != NULL;
duke@435 1296 }
duke@435 1297
duke@435 1298 void FlatProfiler::print_byte_code_statistics() {
duke@435 1299 GrowableArray <ProfilerNode*>* array = new GrowableArray<ProfilerNode*>(200);
duke@435 1300
duke@435 1301 tty->print_cr(" Bytecode ticks:");
duke@435 1302 for (int index = 0; index < Bytecodes::number_of_codes; index++) {
duke@435 1303 if (FlatProfiler::bytecode_ticks[index] > 0 || FlatProfiler::bytecode_ticks_stub[index] > 0) {
duke@435 1304 tty->print_cr(" %4d %4d = %s",
duke@435 1305 FlatProfiler::bytecode_ticks[index],
duke@435 1306 FlatProfiler::bytecode_ticks_stub[index],
duke@435 1307 Bytecodes::name( (Bytecodes::Code) index));
duke@435 1308 }
duke@435 1309 }
duke@435 1310 tty->cr();
duke@435 1311 }
duke@435 1312
duke@435 1313 void print_ticks(const char* title, int ticks, int total) {
duke@435 1314 if (ticks > 0) {
duke@435 1315 tty->print("%5.1f%% %5d", ticks * 100.0 / total, ticks);
duke@435 1316 tty->fill_to(col3);
duke@435 1317 tty->print("%s", title);
duke@435 1318 tty->cr();
duke@435 1319 }
duke@435 1320 }
duke@435 1321
duke@435 1322 void ThreadProfiler::print(const char* thread_name) {
duke@435 1323 ResourceMark rm;
duke@435 1324 MutexLocker ppl(ProfilePrint_lock);
duke@435 1325 int index = 0; // Declared outside for loops for portability
duke@435 1326
duke@435 1327 if (table == NULL) {
duke@435 1328 return;
duke@435 1329 }
duke@435 1330
duke@435 1331 if (thread_ticks <= 0) {
duke@435 1332 return;
duke@435 1333 }
duke@435 1334
duke@435 1335 const char* title = "too soon to tell";
duke@435 1336 double secs = timer.seconds();
duke@435 1337
duke@435 1338 GrowableArray <ProfilerNode*>* array = new GrowableArray<ProfilerNode*>(200);
duke@435 1339 for(index = 0; index < table_size; index++) {
duke@435 1340 for(ProfilerNode* node = table[index]; node; node = node->next())
duke@435 1341 array->append(node);
duke@435 1342 }
duke@435 1343
duke@435 1344 array->sort(&ProfilerNode::compare);
duke@435 1345
duke@435 1346 // compute total (sanity check)
duke@435 1347 int active =
duke@435 1348 class_loader_ticks +
duke@435 1349 compiler_ticks +
duke@435 1350 interpreter_ticks +
duke@435 1351 unknown_ticks();
duke@435 1352 for (index = 0; index < array->length(); index++) {
duke@435 1353 active += array->at(index)->ticks.total();
duke@435 1354 }
duke@435 1355 int total = active + blocked_ticks;
duke@435 1356
duke@435 1357 tty->cr();
duke@435 1358 tty->print_cr("Flat profile of %3.2f secs (%d total ticks): %s", secs, total, thread_name);
duke@435 1359 if (total != thread_ticks) {
duke@435 1360 print_ticks("Lost ticks", thread_ticks-total, thread_ticks);
duke@435 1361 }
duke@435 1362 tty->cr();
duke@435 1363
duke@435 1364 // print interpreted methods
duke@435 1365 tick_counter interpreted_ticks;
duke@435 1366 bool has_interpreted_ticks = false;
duke@435 1367 int print_count = 0;
duke@435 1368 for (index = 0; index < array->length(); index++) {
duke@435 1369 ProfilerNode* n = array->at(index);
duke@435 1370 if (n->is_interpreted()) {
duke@435 1371 interpreted_ticks.add(&n->ticks);
duke@435 1372 if (!has_interpreted_ticks) {
duke@435 1373 interpretedNode::print_title(tty);
duke@435 1374 has_interpreted_ticks = true;
duke@435 1375 }
duke@435 1376 if (print_count++ < ProfilerNumberOfInterpretedMethods) {
duke@435 1377 n->print(tty, active);
duke@435 1378 }
duke@435 1379 }
duke@435 1380 }
duke@435 1381 if (has_interpreted_ticks) {
duke@435 1382 if (print_count <= ProfilerNumberOfInterpretedMethods) {
duke@435 1383 title = "Total interpreted";
duke@435 1384 } else {
duke@435 1385 title = "Total interpreted (including elided)";
duke@435 1386 }
duke@435 1387 interpretedNode::print_total(tty, &interpreted_ticks, active, title);
duke@435 1388 tty->cr();
duke@435 1389 }
duke@435 1390
duke@435 1391 // print compiled methods
duke@435 1392 tick_counter compiled_ticks;
duke@435 1393 bool has_compiled_ticks = false;
duke@435 1394 print_count = 0;
duke@435 1395 for (index = 0; index < array->length(); index++) {
duke@435 1396 ProfilerNode* n = array->at(index);
duke@435 1397 if (n->is_compiled()) {
duke@435 1398 compiled_ticks.add(&n->ticks);
duke@435 1399 if (!has_compiled_ticks) {
duke@435 1400 compiledNode::print_title(tty);
duke@435 1401 has_compiled_ticks = true;
duke@435 1402 }
duke@435 1403 if (print_count++ < ProfilerNumberOfCompiledMethods) {
duke@435 1404 n->print(tty, active);
duke@435 1405 }
duke@435 1406 }
duke@435 1407 }
duke@435 1408 if (has_compiled_ticks) {
duke@435 1409 if (print_count <= ProfilerNumberOfCompiledMethods) {
duke@435 1410 title = "Total compiled";
duke@435 1411 } else {
duke@435 1412 title = "Total compiled (including elided)";
duke@435 1413 }
duke@435 1414 compiledNode::print_total(tty, &compiled_ticks, active, title);
duke@435 1415 tty->cr();
duke@435 1416 }
duke@435 1417
duke@435 1418 // print stub methods
duke@435 1419 tick_counter stub_ticks;
duke@435 1420 bool has_stub_ticks = false;
duke@435 1421 print_count = 0;
duke@435 1422 for (index = 0; index < array->length(); index++) {
duke@435 1423 ProfilerNode* n = array->at(index);
duke@435 1424 if (n->is_stub()) {
duke@435 1425 stub_ticks.add(&n->ticks);
duke@435 1426 if (!has_stub_ticks) {
duke@435 1427 stubNode::print_title(tty);
duke@435 1428 has_stub_ticks = true;
duke@435 1429 }
duke@435 1430 if (print_count++ < ProfilerNumberOfStubMethods) {
duke@435 1431 n->print(tty, active);
duke@435 1432 }
duke@435 1433 }
duke@435 1434 }
duke@435 1435 if (has_stub_ticks) {
duke@435 1436 if (print_count <= ProfilerNumberOfStubMethods) {
duke@435 1437 title = "Total stub";
duke@435 1438 } else {
duke@435 1439 title = "Total stub (including elided)";
duke@435 1440 }
duke@435 1441 stubNode::print_total(tty, &stub_ticks, active, title);
duke@435 1442 tty->cr();
duke@435 1443 }
duke@435 1444
duke@435 1445 // print runtime stubs
duke@435 1446 tick_counter runtime_stub_ticks;
duke@435 1447 bool has_runtime_stub_ticks = false;
duke@435 1448 print_count = 0;
duke@435 1449 for (index = 0; index < array->length(); index++) {
duke@435 1450 ProfilerNode* n = array->at(index);
duke@435 1451 if (n->is_runtime_stub()) {
duke@435 1452 runtime_stub_ticks.add(&n->ticks);
duke@435 1453 if (!has_runtime_stub_ticks) {
duke@435 1454 runtimeStubNode::print_title(tty);
duke@435 1455 has_runtime_stub_ticks = true;
duke@435 1456 }
duke@435 1457 if (print_count++ < ProfilerNumberOfRuntimeStubNodes) {
duke@435 1458 n->print(tty, active);
duke@435 1459 }
duke@435 1460 }
duke@435 1461 }
duke@435 1462 if (has_runtime_stub_ticks) {
duke@435 1463 if (print_count <= ProfilerNumberOfRuntimeStubNodes) {
duke@435 1464 title = "Total runtime stubs";
duke@435 1465 } else {
duke@435 1466 title = "Total runtime stubs (including elided)";
duke@435 1467 }
duke@435 1468 runtimeStubNode::print_total(tty, &runtime_stub_ticks, active, title);
duke@435 1469 tty->cr();
duke@435 1470 }
duke@435 1471
duke@435 1472 if (blocked_ticks + class_loader_ticks + interpreter_ticks + compiler_ticks + unknown_ticks() != 0) {
duke@435 1473 tty->fill_to(col1);
duke@435 1474 tty->print_cr("Thread-local ticks:");
duke@435 1475 print_ticks("Blocked (of total)", blocked_ticks, total);
duke@435 1476 print_ticks("Class loader", class_loader_ticks, active);
duke@435 1477 print_ticks("Extra", extra_ticks, active);
duke@435 1478 print_ticks("Interpreter", interpreter_ticks, active);
duke@435 1479 print_ticks("Compilation", compiler_ticks, active);
duke@435 1480 print_ticks("Unknown: vtable stubs", unknown_ticks_array[ut_vtable_stubs], active);
duke@435 1481 print_ticks("Unknown: null method", unknown_ticks_array[ut_null_method], active);
duke@435 1482 print_ticks("Unknown: running frame", unknown_ticks_array[ut_running_frame], active);
duke@435 1483 print_ticks("Unknown: calling frame", unknown_ticks_array[ut_calling_frame], active);
duke@435 1484 print_ticks("Unknown: no pc", unknown_ticks_array[ut_no_pc], active);
duke@435 1485 print_ticks("Unknown: no last frame", unknown_ticks_array[ut_no_last_Java_frame], active);
duke@435 1486 print_ticks("Unknown: thread_state", unknown_ticks_array[ut_unknown_thread_state], active);
duke@435 1487 tty->cr();
duke@435 1488 }
duke@435 1489
duke@435 1490 if (WizardMode) {
duke@435 1491 tty->print_cr("Node area used: %dKb", (area_top - area_bottom) / 1024);
duke@435 1492 }
duke@435 1493 reset();
duke@435 1494 }
duke@435 1495
duke@435 1496 /*
duke@435 1497 ThreadProfiler::print_unknown(){
duke@435 1498 if (table == NULL) {
duke@435 1499 return;
duke@435 1500 }
duke@435 1501
duke@435 1502 if (thread_ticks <= 0) {
duke@435 1503 return;
duke@435 1504 }
duke@435 1505 } */
duke@435 1506
duke@435 1507 void FlatProfiler::print(int unused) {
duke@435 1508 ResourceMark rm;
duke@435 1509 if (thread_profiler != NULL) {
duke@435 1510 thread_profiler->print("All threads");
duke@435 1511 } else {
duke@435 1512 MutexLocker tl(Threads_lock);
duke@435 1513 for (JavaThread* tp = Threads::first(); tp != NULL; tp = tp->next()) {
duke@435 1514 ThreadProfiler* pp = tp->get_thread_profiler();
duke@435 1515 if (pp != NULL) {
duke@435 1516 pp->print(tp->get_thread_name());
duke@435 1517 }
duke@435 1518 }
duke@435 1519 }
duke@435 1520
duke@435 1521 if (ProfilerPrintByteCodeStatistics) {
duke@435 1522 print_byte_code_statistics();
duke@435 1523 }
duke@435 1524
duke@435 1525 if (non_method_ticks() > 0) {
duke@435 1526 tty->cr();
duke@435 1527 tty->print_cr("Global summary of %3.2f seconds:", timer.seconds());
duke@435 1528 print_ticks("Received ticks", received_ticks, received_ticks);
duke@435 1529 print_ticks("Received GC ticks", received_gc_ticks, received_ticks);
duke@435 1530 print_ticks("Compilation", compiler_ticks, received_ticks);
duke@435 1531 print_ticks("Deoptimization", deopt_ticks, received_ticks);
duke@435 1532 print_ticks("Other VM operations", vm_operation_ticks, received_ticks);
duke@435 1533 #ifndef PRODUCT
duke@435 1534 print_ticks("Blocked ticks", blocked_ticks, received_ticks);
duke@435 1535 print_ticks("Threads_lock blocks", threads_lock_ticks, received_ticks);
duke@435 1536 print_ticks("Delivered ticks", delivered_ticks, received_ticks);
duke@435 1537 print_ticks("All ticks", all_ticks, received_ticks);
duke@435 1538 #endif
duke@435 1539 print_ticks("Class loader", class_loader_ticks, received_ticks);
duke@435 1540 print_ticks("Extra ", extra_ticks, received_ticks);
duke@435 1541 print_ticks("Interpreter", interpreter_ticks, received_ticks);
duke@435 1542 print_ticks("Unknown code", unknown_ticks, received_ticks);
duke@435 1543 }
duke@435 1544
duke@435 1545 PCRecorder::print();
duke@435 1546
duke@435 1547 if(ProfileVM){
duke@435 1548 tty->cr();
duke@435 1549 vm_thread_profiler->print("VM Thread");
duke@435 1550 }
duke@435 1551 }
duke@435 1552
duke@435 1553 void IntervalData::print_header(outputStream* st) {
duke@435 1554 st->print("i/c/n/g");
duke@435 1555 }
duke@435 1556
duke@435 1557 void IntervalData::print_data(outputStream* st) {
duke@435 1558 st->print("%d/%d/%d/%d", interpreted(), compiled(), native(), compiling());
duke@435 1559 }
duke@435 1560
duke@435 1561 void FlatProfiler::interval_record_thread(ThreadProfiler* tp) {
duke@435 1562 IntervalData id = tp->interval_data();
duke@435 1563 int total = id.total();
duke@435 1564 tp->interval_data_ref()->reset();
duke@435 1565
duke@435 1566 // Insertion sort the data, if it's relevant.
duke@435 1567 for (int i = 0; i < interval_print_size; i += 1) {
duke@435 1568 if (total > interval_data[i].total()) {
duke@435 1569 for (int j = interval_print_size - 1; j > i; j -= 1) {
duke@435 1570 interval_data[j] = interval_data[j-1];
duke@435 1571 }
duke@435 1572 interval_data[i] = id;
duke@435 1573 break;
duke@435 1574 }
duke@435 1575 }
duke@435 1576 }
duke@435 1577
duke@435 1578 void FlatProfiler::interval_print() {
duke@435 1579 if ((interval_data[0].total() > 0)) {
duke@435 1580 tty->stamp();
duke@435 1581 tty->print("\t");
duke@435 1582 IntervalData::print_header(tty);
duke@435 1583 for (int i = 0; i < interval_print_size; i += 1) {
duke@435 1584 if (interval_data[i].total() > 0) {
duke@435 1585 tty->print("\t");
duke@435 1586 interval_data[i].print_data(tty);
duke@435 1587 }
duke@435 1588 }
duke@435 1589 tty->cr();
duke@435 1590 }
duke@435 1591 }
duke@435 1592
duke@435 1593 void FlatProfiler::interval_reset() {
duke@435 1594 for (int i = 0; i < interval_print_size; i += 1) {
duke@435 1595 interval_data[i].reset();
duke@435 1596 }
duke@435 1597 }
duke@435 1598
duke@435 1599 void ThreadProfiler::oops_do(OopClosure* f) {
duke@435 1600 if (table == NULL) return;
duke@435 1601
duke@435 1602 for(int index = 0; index < table_size; index++) {
duke@435 1603 for(ProfilerNode* node = table[index]; node; node = node->next())
duke@435 1604 node->oops_do(f);
duke@435 1605 }
duke@435 1606 }
duke@435 1607
duke@435 1608 void FlatProfiler::oops_do(OopClosure* f) {
duke@435 1609 if (thread_profiler != NULL) {
duke@435 1610 thread_profiler->oops_do(f);
duke@435 1611 } else {
duke@435 1612 for (JavaThread* tp = Threads::first(); tp != NULL; tp = tp->next()) {
duke@435 1613 ThreadProfiler* pp = tp->get_thread_profiler();
duke@435 1614 if (pp != NULL) {
duke@435 1615 pp->oops_do(f);
duke@435 1616 }
duke@435 1617 }
duke@435 1618 }
duke@435 1619 }

mercurial