src/share/vm/runtime/fprofiler.cpp

Tue, 08 Aug 2017 15:57:29 +0800

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

mercurial