src/share/vm/runtime/fprofiler.cpp

Wed, 21 Nov 2012 05:57:12 -0800

author
vlivanov
date
Wed, 21 Nov 2012 05:57:12 -0800
changeset 4312
ee32440febeb
parent 4037
da91efe96a93
child 4936
aeaca88565e6
permissions
-rw-r--r--

8001538: hs_err file does not list anymore compiled methods in compilation events
Summary: Fixed message buffer size calculation.
Reviewed-by: kvn, twisti

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

mercurial