src/share/vm/runtime/fprofiler.cpp

Fri, 11 Apr 2014 12:29:24 +0200

author
pliden
date
Fri, 11 Apr 2014 12:29:24 +0200
changeset 6906
581e70386ec9
parent 6680
78bbf4d43a14
child 6876
710a3c8b516e
child 6911
ce8f6bb717c9
permissions
-rw-r--r--

8039147: Cleanup SuspendibleThreadSet
Reviewed-by: brutisso, tschatzl, mgerdin

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

mercurial