src/share/vm/runtime/fprofiler.cpp

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 6911
ce8f6bb717c9
parent 6876
710a3c8b516e
child 9637
eef07cd490d4
permissions
-rw-r--r--

merge

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

mercurial