src/share/vm/runtime/fprofiler.cpp

Thu, 11 Jul 2013 01:11:52 -0700

author
roland
date
Thu, 11 Jul 2013 01:11:52 -0700
changeset 5385
ec173c8f3739
parent 4936
aeaca88565e6
child 5614
9758d9f36299
child 5616
522d69638aa8
permissions
-rw-r--r--

Merge

duke@435 1 /*
jiangli@4936 2 * Copyright (c) 1997, 2013, 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);
jiangli@4936 424 MethodCounters* mcs = method()->method_counters();
jiangli@4936 425 if (Verbose && mcs != NULL) mcs->invocation_counter()->print_short();
duke@435 426 }
duke@435 427 };
duke@435 428
duke@435 429 class compiledNode : public ProfilerNode {
duke@435 430 private:
coleenp@4037 431 Method* _method;
coleenp@4037 432 oop _class_loader; // needed to keep metadata for the method alive
duke@435 433 public:
coleenp@4037 434 compiledNode(Method* method, TickPosition where) : ProfilerNode() {
duke@435 435 _method = method;
coleenp@4037 436 _class_loader = method->method_holder()->class_loader();
duke@435 437 update(where);
duke@435 438 }
duke@435 439 bool is_compiled() const { return true; }
duke@435 440
coleenp@4037 441 bool compiled_match(Method* m) const {
duke@435 442 return _method == m;
duke@435 443 }
duke@435 444
coleenp@4037 445 Method* method() { return _method; }
duke@435 446
duke@435 447 void oops_do(OopClosure* f) {
coleenp@4037 448 f->do_oop(&_class_loader);
duke@435 449 }
duke@435 450
duke@435 451 static void print_title(outputStream* st) {
duke@435 452 st->fill_to(col1);
duke@435 453 st->print("%11s", "Compiled");
duke@435 454 ProfilerNode::print_title(st);
duke@435 455 }
duke@435 456
duke@435 457 void print(outputStream* st, int total_ticks) {
duke@435 458 ProfilerNode::print(st, total_ticks);
duke@435 459 }
duke@435 460
duke@435 461 void print_method_on(outputStream* st) {
duke@435 462 ProfilerNode::print_method_on(st);
duke@435 463 }
duke@435 464 };
duke@435 465
duke@435 466 class stubNode : public ProfilerNode {
duke@435 467 private:
coleenp@4037 468 Method* _method;
coleenp@4037 469 oop _class_loader; // needed to keep metadata for the method alive
duke@435 470 const char* _symbol; // The name of the nearest VM symbol (for +ProfileVM). Points to a unique string
duke@435 471 public:
coleenp@4037 472 stubNode(Method* method, const char* name, TickPosition where) : ProfilerNode() {
duke@435 473 _method = method;
coleenp@4037 474 _class_loader = method->method_holder()->class_loader();
duke@435 475 _symbol = name;
duke@435 476 update(where);
duke@435 477 }
duke@435 478
duke@435 479 bool is_stub() const { return true; }
duke@435 480
coleenp@4037 481 void oops_do(OopClosure* f) {
coleenp@4037 482 f->do_oop(&_class_loader);
coleenp@4037 483 }
coleenp@4037 484
coleenp@4037 485 bool stub_match(Method* m, const char* name) const {
duke@435 486 return (_method == m) && (_symbol == name);
duke@435 487 }
duke@435 488
coleenp@4037 489 Method* method() { return _method; }
duke@435 490
duke@435 491 static void print_title(outputStream* st) {
duke@435 492 st->fill_to(col1);
duke@435 493 st->print("%11s", "Stub");
duke@435 494 ProfilerNode::print_title(st);
duke@435 495 }
duke@435 496
duke@435 497 void print(outputStream* st, int total_ticks) {
duke@435 498 ProfilerNode::print(st, total_ticks);
duke@435 499 }
duke@435 500
duke@435 501 void print_method_on(outputStream* st) {
duke@435 502 ProfilerNode::print_method_on(st);
duke@435 503 print_symbol_on(st);
duke@435 504 }
duke@435 505
duke@435 506 void print_symbol_on(outputStream* st) {
duke@435 507 if(_symbol) {
duke@435 508 st->print(" (%s)", _symbol);
duke@435 509 }
duke@435 510 }
duke@435 511 };
duke@435 512
duke@435 513 class adapterNode : public ProfilerNode {
duke@435 514 public:
duke@435 515 adapterNode(TickPosition where) : ProfilerNode() {
duke@435 516 update(where);
duke@435 517 }
duke@435 518 bool is_compiled() const { return true; }
duke@435 519
duke@435 520 bool adapter_match() const { return true; }
duke@435 521
coleenp@4037 522 Method* method() { return NULL; }
duke@435 523
duke@435 524 void oops_do(OopClosure* f) {
duke@435 525 ;
duke@435 526 }
duke@435 527
duke@435 528 void print(outputStream* st, int total_ticks) {
duke@435 529 ProfilerNode::print(st, total_ticks);
duke@435 530 }
duke@435 531
duke@435 532 void print_method_on(outputStream* st) {
duke@435 533 st->print("%s", "adapters");
duke@435 534 }
duke@435 535 };
duke@435 536
duke@435 537 class runtimeStubNode : public ProfilerNode {
duke@435 538 private:
duke@435 539 const CodeBlob* _stub;
duke@435 540 const char* _symbol; // The name of the nearest VM symbol when ProfileVM is on. Points to a unique string.
duke@435 541 public:
duke@435 542 runtimeStubNode(const CodeBlob* stub, const char* name, TickPosition where) : ProfilerNode(), _stub(stub), _symbol(name) {
duke@435 543 assert(stub->is_runtime_stub(), "wrong code blob");
duke@435 544 update(where);
duke@435 545 }
duke@435 546
duke@435 547 bool is_runtime_stub() const { return true; }
duke@435 548
duke@435 549 bool runtimeStub_match(const CodeBlob* stub, const char* name) const {
duke@435 550 assert(stub->is_runtime_stub(), "wrong code blob");
duke@435 551 return ((RuntimeStub*)_stub)->entry_point() == ((RuntimeStub*)stub)->entry_point() &&
duke@435 552 (_symbol == name);
duke@435 553 }
duke@435 554
coleenp@4037 555 Method* method() { return NULL; }
duke@435 556
duke@435 557 static void print_title(outputStream* st) {
duke@435 558 st->fill_to(col1);
duke@435 559 st->print("%11s", "Runtime stub");
duke@435 560 ProfilerNode::print_title(st);
duke@435 561 }
duke@435 562
duke@435 563 void oops_do(OopClosure* f) {
duke@435 564 ;
duke@435 565 }
duke@435 566
duke@435 567 void print(outputStream* st, int total_ticks) {
duke@435 568 ProfilerNode::print(st, total_ticks);
duke@435 569 }
duke@435 570
duke@435 571 void print_method_on(outputStream* st) {
duke@435 572 st->print("%s", ((RuntimeStub*)_stub)->name());
duke@435 573 print_symbol_on(st);
duke@435 574 }
duke@435 575
duke@435 576 void print_symbol_on(outputStream* st) {
duke@435 577 if(_symbol) {
duke@435 578 st->print(" (%s)", _symbol);
duke@435 579 }
duke@435 580 }
duke@435 581 };
duke@435 582
duke@435 583
duke@435 584 class unknown_compiledNode : public ProfilerNode {
duke@435 585 const char *_name;
duke@435 586 public:
duke@435 587 unknown_compiledNode(const CodeBlob* cb, TickPosition where) : ProfilerNode() {
duke@435 588 if ( cb->is_buffer_blob() )
duke@435 589 _name = ((BufferBlob*)cb)->name();
duke@435 590 else
duke@435 591 _name = ((SingletonBlob*)cb)->name();
duke@435 592 update(where);
duke@435 593 }
duke@435 594 bool is_compiled() const { return true; }
duke@435 595
duke@435 596 bool unknown_compiled_match(const CodeBlob* cb) const {
duke@435 597 if ( cb->is_buffer_blob() )
duke@435 598 return !strcmp(((BufferBlob*)cb)->name(), _name);
duke@435 599 else
duke@435 600 return !strcmp(((SingletonBlob*)cb)->name(), _name);
duke@435 601 }
duke@435 602
coleenp@4037 603 Method* method() { return NULL; }
duke@435 604
duke@435 605 void oops_do(OopClosure* f) {
duke@435 606 ;
duke@435 607 }
duke@435 608
duke@435 609 void print(outputStream* st, int total_ticks) {
duke@435 610 ProfilerNode::print(st, total_ticks);
duke@435 611 }
duke@435 612
duke@435 613 void print_method_on(outputStream* st) {
duke@435 614 st->print("%s", _name);
duke@435 615 }
duke@435 616 };
duke@435 617
duke@435 618 class vmNode : public ProfilerNode {
duke@435 619 private:
duke@435 620 const char* _name; // "optional" name obtained by os means such as dll lookup
duke@435 621 public:
duke@435 622 vmNode(const TickPosition where) : ProfilerNode() {
duke@435 623 _name = NULL;
duke@435 624 update(where);
duke@435 625 }
duke@435 626
duke@435 627 vmNode(const char* name, const TickPosition where) : ProfilerNode() {
duke@435 628 _name = name;
duke@435 629 update(where);
duke@435 630 }
duke@435 631
duke@435 632 const char *name() const { return _name; }
duke@435 633 bool is_compiled() const { return true; }
duke@435 634
duke@435 635 bool vm_match(const char* name) const { return strcmp(name, _name) == 0; }
duke@435 636
coleenp@4037 637 Method* method() { return NULL; }
duke@435 638
duke@435 639 static int hash(const char* name){
duke@435 640 // Compute a simple hash
duke@435 641 const char* cp = name;
duke@435 642 int h = 0;
duke@435 643
duke@435 644 if(name != NULL){
duke@435 645 while(*cp != '\0'){
duke@435 646 h = (h << 1) ^ *cp;
duke@435 647 cp++;
duke@435 648 }
duke@435 649 }
duke@435 650 return h;
duke@435 651 }
duke@435 652
duke@435 653 void oops_do(OopClosure* f) {
duke@435 654 ;
duke@435 655 }
duke@435 656
duke@435 657 void print(outputStream* st, int total_ticks) {
duke@435 658 ProfilerNode::print(st, total_ticks);
duke@435 659 }
duke@435 660
duke@435 661 void print_method_on(outputStream* st) {
duke@435 662 if(_name==NULL){
duke@435 663 st->print("%s", "unknown code");
duke@435 664 }
duke@435 665 else {
duke@435 666 st->print("%s", _name);
duke@435 667 }
duke@435 668 }
duke@435 669 };
duke@435 670
coleenp@4037 671 void ThreadProfiler::interpreted_update(Method* method, TickPosition where) {
duke@435 672 int index = entry(ProfilerNode::hash(method));
duke@435 673 if (!table[index]) {
duke@435 674 table[index] = new (this) interpretedNode(method, where);
duke@435 675 } else {
duke@435 676 ProfilerNode* prev = table[index];
duke@435 677 for(ProfilerNode* node = prev; node; node = node->next()) {
duke@435 678 if (node->interpreted_match(method)) {
duke@435 679 node->update(where);
duke@435 680 return;
duke@435 681 }
duke@435 682 prev = node;
duke@435 683 }
duke@435 684 prev->set_next(new (this) interpretedNode(method, where));
duke@435 685 }
duke@435 686 }
duke@435 687
coleenp@4037 688 void ThreadProfiler::compiled_update(Method* method, TickPosition where) {
duke@435 689 int index = entry(ProfilerNode::hash(method));
duke@435 690 if (!table[index]) {
duke@435 691 table[index] = new (this) compiledNode(method, where);
duke@435 692 } else {
duke@435 693 ProfilerNode* prev = table[index];
duke@435 694 for(ProfilerNode* node = prev; node; node = node->next()) {
duke@435 695 if (node->compiled_match(method)) {
duke@435 696 node->update(where);
duke@435 697 return;
duke@435 698 }
duke@435 699 prev = node;
duke@435 700 }
duke@435 701 prev->set_next(new (this) compiledNode(method, where));
duke@435 702 }
duke@435 703 }
duke@435 704
coleenp@4037 705 void ThreadProfiler::stub_update(Method* method, const char* name, TickPosition where) {
duke@435 706 int index = entry(ProfilerNode::hash(method));
duke@435 707 if (!table[index]) {
duke@435 708 table[index] = new (this) stubNode(method, name, where);
duke@435 709 } else {
duke@435 710 ProfilerNode* prev = table[index];
duke@435 711 for(ProfilerNode* node = prev; node; node = node->next()) {
duke@435 712 if (node->stub_match(method, name)) {
duke@435 713 node->update(where);
duke@435 714 return;
duke@435 715 }
duke@435 716 prev = node;
duke@435 717 }
duke@435 718 prev->set_next(new (this) stubNode(method, name, where));
duke@435 719 }
duke@435 720 }
duke@435 721
duke@435 722 void ThreadProfiler::adapter_update(TickPosition where) {
duke@435 723 int index = 0;
duke@435 724 if (!table[index]) {
duke@435 725 table[index] = new (this) adapterNode(where);
duke@435 726 } else {
duke@435 727 ProfilerNode* prev = table[index];
duke@435 728 for(ProfilerNode* node = prev; node; node = node->next()) {
duke@435 729 if (node->adapter_match()) {
duke@435 730 node->update(where);
duke@435 731 return;
duke@435 732 }
duke@435 733 prev = node;
duke@435 734 }
duke@435 735 prev->set_next(new (this) adapterNode(where));
duke@435 736 }
duke@435 737 }
duke@435 738
duke@435 739 void ThreadProfiler::runtime_stub_update(const CodeBlob* stub, const char* name, TickPosition where) {
duke@435 740 int index = 0;
duke@435 741 if (!table[index]) {
duke@435 742 table[index] = new (this) runtimeStubNode(stub, name, where);
duke@435 743 } else {
duke@435 744 ProfilerNode* prev = table[index];
duke@435 745 for(ProfilerNode* node = prev; node; node = node->next()) {
duke@435 746 if (node->runtimeStub_match(stub, name)) {
duke@435 747 node->update(where);
duke@435 748 return;
duke@435 749 }
duke@435 750 prev = node;
duke@435 751 }
duke@435 752 prev->set_next(new (this) runtimeStubNode(stub, name, where));
duke@435 753 }
duke@435 754 }
duke@435 755
duke@435 756
duke@435 757 void ThreadProfiler::unknown_compiled_update(const CodeBlob* cb, TickPosition where) {
duke@435 758 int index = 0;
duke@435 759 if (!table[index]) {
duke@435 760 table[index] = new (this) unknown_compiledNode(cb, where);
duke@435 761 } else {
duke@435 762 ProfilerNode* prev = table[index];
duke@435 763 for(ProfilerNode* node = prev; node; node = node->next()) {
duke@435 764 if (node->unknown_compiled_match(cb)) {
duke@435 765 node->update(where);
duke@435 766 return;
duke@435 767 }
duke@435 768 prev = node;
duke@435 769 }
duke@435 770 prev->set_next(new (this) unknown_compiledNode(cb, where));
duke@435 771 }
duke@435 772 }
duke@435 773
duke@435 774 void ThreadProfiler::vm_update(TickPosition where) {
duke@435 775 vm_update(NULL, where);
duke@435 776 }
duke@435 777
duke@435 778 void ThreadProfiler::vm_update(const char* name, TickPosition where) {
duke@435 779 int index = entry(vmNode::hash(name));
duke@435 780 assert(index >= 0, "Must be positive");
duke@435 781 // Note that we call strdup below since the symbol may be resource allocated
duke@435 782 if (!table[index]) {
duke@435 783 table[index] = new (this) vmNode(os::strdup(name), where);
duke@435 784 } else {
duke@435 785 ProfilerNode* prev = table[index];
duke@435 786 for(ProfilerNode* node = prev; node; node = node->next()) {
duke@435 787 if (((vmNode *)node)->vm_match(name)) {
duke@435 788 node->update(where);
duke@435 789 return;
duke@435 790 }
duke@435 791 prev = node;
duke@435 792 }
duke@435 793 prev->set_next(new (this) vmNode(os::strdup(name), where));
duke@435 794 }
duke@435 795 }
duke@435 796
duke@435 797
duke@435 798 class FlatProfilerTask : public PeriodicTask {
duke@435 799 public:
duke@435 800 FlatProfilerTask(int interval_time) : PeriodicTask(interval_time) {}
duke@435 801 void task();
duke@435 802 };
duke@435 803
duke@435 804 void FlatProfiler::record_vm_operation() {
duke@435 805 if (Universe::heap()->is_gc_active()) {
duke@435 806 FlatProfiler::received_gc_ticks += 1;
duke@435 807 return;
duke@435 808 }
duke@435 809
duke@435 810 if (DeoptimizationMarker::is_active()) {
duke@435 811 FlatProfiler::deopt_ticks += 1;
duke@435 812 return;
duke@435 813 }
duke@435 814
duke@435 815 FlatProfiler::vm_operation_ticks += 1;
duke@435 816 }
duke@435 817
duke@435 818 void FlatProfiler::record_vm_tick() {
duke@435 819 // Profile the VM Thread itself if needed
duke@435 820 // This is done without getting the Threads_lock and we can go deep
duke@435 821 // inside Safepoint, etc.
duke@435 822 if( ProfileVM ) {
duke@435 823 ResourceMark rm;
duke@435 824 ExtendedPC epc;
duke@435 825 const char *name = NULL;
duke@435 826 char buf[256];
duke@435 827 buf[0] = '\0';
duke@435 828
duke@435 829 vm_thread_profiler->inc_thread_ticks();
duke@435 830
duke@435 831 // Get a snapshot of a current VMThread pc (and leave it running!)
duke@435 832 // The call may fail if, for instance the VM thread is interrupted while
duke@435 833 // holding the Interrupt_lock or for other reasons.
duke@435 834 epc = os::get_thread_pc(VMThread::vm_thread());
duke@435 835 if(epc.pc() != NULL) {
duke@435 836 if (os::dll_address_to_function_name(epc.pc(), buf, sizeof(buf), NULL)) {
duke@435 837 name = buf;
duke@435 838 }
duke@435 839 }
duke@435 840 if (name != NULL) {
duke@435 841 vm_thread_profiler->vm_update(name, tp_native);
duke@435 842 }
duke@435 843 }
duke@435 844 }
duke@435 845
duke@435 846 void FlatProfiler::record_thread_ticks() {
duke@435 847
duke@435 848 int maxthreads, suspendedthreadcount;
duke@435 849 JavaThread** threadsList;
duke@435 850 bool interval_expired = false;
duke@435 851
duke@435 852 if (ProfileIntervals &&
duke@435 853 (FlatProfiler::received_ticks >= interval_ticks_previous + ProfileIntervalsTicks)) {
duke@435 854 interval_expired = true;
duke@435 855 interval_ticks_previous = FlatProfiler::received_ticks;
duke@435 856 }
duke@435 857
duke@435 858 // Try not to wait for the Threads_lock
duke@435 859 if (Threads_lock->try_lock()) {
duke@435 860 { // Threads_lock scope
duke@435 861 maxthreads = Threads::number_of_threads();
zgu@3900 862 threadsList = NEW_C_HEAP_ARRAY(JavaThread *, maxthreads, mtInternal);
duke@435 863 suspendedthreadcount = 0;
duke@435 864 for (JavaThread* tp = Threads::first(); tp != NULL; tp = tp->next()) {
duke@435 865 if (tp->is_Compiler_thread()) {
duke@435 866 // Only record ticks for active compiler threads
duke@435 867 CompilerThread* cthread = (CompilerThread*)tp;
duke@435 868 if (cthread->task() != NULL) {
duke@435 869 // The compiler is active. If we need to access any of the fields
duke@435 870 // of the compiler task we should suspend the CompilerThread first.
duke@435 871 FlatProfiler::compiler_ticks += 1;
duke@435 872 continue;
duke@435 873 }
duke@435 874 }
duke@435 875
duke@435 876 // First externally suspend all threads by marking each for
duke@435 877 // external suspension - so it will stop at its next transition
duke@435 878 // Then do a safepoint
duke@435 879 ThreadProfiler* pp = tp->get_thread_profiler();
duke@435 880 if (pp != NULL && pp->engaged) {
duke@435 881 MutexLockerEx ml(tp->SR_lock(), Mutex::_no_safepoint_check_flag);
duke@435 882 if (!tp->is_external_suspend() && !tp->is_exiting()) {
duke@435 883 tp->set_external_suspend();
duke@435 884 threadsList[suspendedthreadcount++] = tp;
duke@435 885 }
duke@435 886 }
duke@435 887 }
duke@435 888 Threads_lock->unlock();
duke@435 889 }
duke@435 890 // Suspend each thread. This call should just return
duke@435 891 // for any threads that have already self-suspended
duke@435 892 // Net result should be one safepoint
duke@435 893 for (int j = 0; j < suspendedthreadcount; j++) {
duke@435 894 JavaThread *tp = threadsList[j];
duke@435 895 if (tp) {
duke@435 896 tp->java_suspend();
duke@435 897 }
duke@435 898 }
duke@435 899
duke@435 900 // We are responsible for resuming any thread on this list
duke@435 901 for (int i = 0; i < suspendedthreadcount; i++) {
duke@435 902 JavaThread *tp = threadsList[i];
duke@435 903 if (tp) {
duke@435 904 ThreadProfiler* pp = tp->get_thread_profiler();
duke@435 905 if (pp != NULL && pp->engaged) {
duke@435 906 HandleMark hm;
duke@435 907 FlatProfiler::delivered_ticks += 1;
duke@435 908 if (interval_expired) {
duke@435 909 FlatProfiler::interval_record_thread(pp);
duke@435 910 }
duke@435 911 // This is the place where we check to see if a user thread is
duke@435 912 // blocked waiting for compilation.
duke@435 913 if (tp->blocked_on_compilation()) {
duke@435 914 pp->compiler_ticks += 1;
duke@435 915 pp->interval_data_ref()->inc_compiling();
duke@435 916 } else {
duke@435 917 pp->record_tick(tp);
duke@435 918 }
duke@435 919 }
duke@435 920 MutexLocker ml(Threads_lock);
duke@435 921 tp->java_resume();
duke@435 922 }
duke@435 923 }
duke@435 924 if (interval_expired) {
duke@435 925 FlatProfiler::interval_print();
duke@435 926 FlatProfiler::interval_reset();
duke@435 927 }
duke@435 928 } else {
duke@435 929 // Couldn't get the threads lock, just record that rather than blocking
duke@435 930 FlatProfiler::threads_lock_ticks += 1;
duke@435 931 }
duke@435 932
duke@435 933 }
duke@435 934
duke@435 935 void FlatProfilerTask::task() {
duke@435 936 FlatProfiler::received_ticks += 1;
duke@435 937
duke@435 938 if (ProfileVM) {
duke@435 939 FlatProfiler::record_vm_tick();
duke@435 940 }
duke@435 941
duke@435 942 VM_Operation* op = VMThread::vm_operation();
duke@435 943 if (op != NULL) {
duke@435 944 FlatProfiler::record_vm_operation();
duke@435 945 if (SafepointSynchronize::is_at_safepoint()) {
duke@435 946 return;
duke@435 947 }
duke@435 948 }
duke@435 949 FlatProfiler::record_thread_ticks();
duke@435 950 }
duke@435 951
sgoldman@542 952 void ThreadProfiler::record_interpreted_tick(JavaThread* thread, frame fr, TickPosition where, int* ticks) {
duke@435 953 FlatProfiler::all_int_ticks++;
duke@435 954 if (!FlatProfiler::full_profile()) {
duke@435 955 return;
duke@435 956 }
duke@435 957
sgoldman@542 958 if (!fr.is_interpreted_frame_valid(thread)) {
duke@435 959 // tick came at a bad time
duke@435 960 interpreter_ticks += 1;
duke@435 961 FlatProfiler::interpreter_ticks += 1;
duke@435 962 return;
duke@435 963 }
duke@435 964
sgoldman@542 965 // The frame has been fully validated so we can trust the method and bci
sgoldman@542 966
coleenp@4037 967 Method* method = *fr.interpreter_frame_method_addr();
sgoldman@542 968
duke@435 969 interpreted_update(method, where);
duke@435 970
duke@435 971 // update byte code table
duke@435 972 InterpreterCodelet* desc = Interpreter::codelet_containing(fr.pc());
duke@435 973 if (desc != NULL && desc->bytecode() >= 0) {
duke@435 974 ticks[desc->bytecode()]++;
duke@435 975 }
duke@435 976 }
duke@435 977
duke@435 978 void ThreadProfiler::record_compiled_tick(JavaThread* thread, frame fr, TickPosition where) {
duke@435 979 const char *name = NULL;
duke@435 980 TickPosition localwhere = where;
duke@435 981
duke@435 982 FlatProfiler::all_comp_ticks++;
duke@435 983 if (!FlatProfiler::full_profile()) return;
duke@435 984
duke@435 985 CodeBlob* cb = fr.cb();
duke@435 986
duke@435 987 // For runtime stubs, record as native rather than as compiled
duke@435 988 if (cb->is_runtime_stub()) {
duke@435 989 RegisterMap map(thread, false);
duke@435 990 fr = fr.sender(&map);
duke@435 991 cb = fr.cb();
duke@435 992 localwhere = tp_native;
duke@435 993 }
coleenp@4037 994 Method* method = (cb->is_nmethod()) ? ((nmethod *)cb)->method() :
coleenp@4037 995 (Method*)NULL;
duke@435 996
duke@435 997 if (method == NULL) {
duke@435 998 if (cb->is_runtime_stub())
duke@435 999 runtime_stub_update(cb, name, localwhere);
duke@435 1000 else
duke@435 1001 unknown_compiled_update(cb, localwhere);
duke@435 1002 }
duke@435 1003 else {
duke@435 1004 if (method->is_native()) {
duke@435 1005 stub_update(method, name, localwhere);
duke@435 1006 } else {
duke@435 1007 compiled_update(method, localwhere);
duke@435 1008 }
duke@435 1009 }
duke@435 1010 }
duke@435 1011
duke@435 1012 extern "C" void find(int x);
duke@435 1013
duke@435 1014
duke@435 1015 void ThreadProfiler::record_tick_for_running_frame(JavaThread* thread, frame fr) {
twisti@1040 1016 // The tick happened in real code -> non VM code
duke@435 1017 if (fr.is_interpreted_frame()) {
duke@435 1018 interval_data_ref()->inc_interpreted();
sgoldman@542 1019 record_interpreted_tick(thread, fr, tp_code, FlatProfiler::bytecode_ticks);
duke@435 1020 return;
duke@435 1021 }
duke@435 1022
duke@435 1023 if (CodeCache::contains(fr.pc())) {
duke@435 1024 interval_data_ref()->inc_compiled();
duke@435 1025 PCRecorder::record(fr.pc());
duke@435 1026 record_compiled_tick(thread, fr, tp_code);
duke@435 1027 return;
duke@435 1028 }
duke@435 1029
duke@435 1030 if (VtableStubs::stub_containing(fr.pc()) != NULL) {
duke@435 1031 unknown_ticks_array[ut_vtable_stubs] += 1;
duke@435 1032 return;
duke@435 1033 }
duke@435 1034
duke@435 1035 frame caller = fr.profile_find_Java_sender_frame(thread);
duke@435 1036
duke@435 1037 if (caller.sp() != NULL && caller.pc() != NULL) {
duke@435 1038 record_tick_for_calling_frame(thread, caller);
duke@435 1039 return;
duke@435 1040 }
duke@435 1041
duke@435 1042 unknown_ticks_array[ut_running_frame] += 1;
duke@435 1043 FlatProfiler::unknown_ticks += 1;
duke@435 1044 }
duke@435 1045
duke@435 1046 void ThreadProfiler::record_tick_for_calling_frame(JavaThread* thread, frame fr) {
twisti@1040 1047 // The tick happened in VM code
duke@435 1048 interval_data_ref()->inc_native();
duke@435 1049 if (fr.is_interpreted_frame()) {
sgoldman@542 1050 record_interpreted_tick(thread, fr, tp_native, FlatProfiler::bytecode_ticks_stub);
duke@435 1051 return;
duke@435 1052 }
duke@435 1053 if (CodeCache::contains(fr.pc())) {
duke@435 1054 record_compiled_tick(thread, fr, tp_native);
duke@435 1055 return;
duke@435 1056 }
duke@435 1057
duke@435 1058 frame caller = fr.profile_find_Java_sender_frame(thread);
duke@435 1059
duke@435 1060 if (caller.sp() != NULL && caller.pc() != NULL) {
duke@435 1061 record_tick_for_calling_frame(thread, caller);
duke@435 1062 return;
duke@435 1063 }
duke@435 1064
duke@435 1065 unknown_ticks_array[ut_calling_frame] += 1;
duke@435 1066 FlatProfiler::unknown_ticks += 1;
duke@435 1067 }
duke@435 1068
duke@435 1069 void ThreadProfiler::record_tick(JavaThread* thread) {
duke@435 1070 FlatProfiler::all_ticks++;
duke@435 1071 thread_ticks += 1;
duke@435 1072
duke@435 1073 // Here's another way to track global state changes.
duke@435 1074 // When the class loader starts it marks the ThreadProfiler to tell it it is in the class loader
duke@435 1075 // and we check that here.
duke@435 1076 // This is more direct, and more than one thread can be in the class loader at a time,
duke@435 1077 // but it does mean the class loader has to know about the profiler.
duke@435 1078 if (region_flag[ThreadProfilerMark::classLoaderRegion]) {
duke@435 1079 class_loader_ticks += 1;
duke@435 1080 FlatProfiler::class_loader_ticks += 1;
duke@435 1081 return;
duke@435 1082 } else if (region_flag[ThreadProfilerMark::extraRegion]) {
duke@435 1083 extra_ticks += 1;
duke@435 1084 FlatProfiler::extra_ticks += 1;
duke@435 1085 return;
duke@435 1086 }
duke@435 1087 // Note that the WatcherThread can now stop for safepoints
duke@435 1088 uint32_t debug_bits = 0;
duke@435 1089 if (!thread->wait_for_ext_suspend_completion(SuspendRetryCount,
duke@435 1090 SuspendRetryDelay, &debug_bits)) {
duke@435 1091 unknown_ticks_array[ut_unknown_thread_state] += 1;
duke@435 1092 FlatProfiler::unknown_ticks += 1;
duke@435 1093 return;
duke@435 1094 }
duke@435 1095
duke@435 1096 frame fr;
duke@435 1097
duke@435 1098 switch (thread->thread_state()) {
duke@435 1099 case _thread_in_native:
duke@435 1100 case _thread_in_native_trans:
duke@435 1101 case _thread_in_vm:
duke@435 1102 case _thread_in_vm_trans:
duke@435 1103 if (thread->profile_last_Java_frame(&fr)) {
duke@435 1104 if (fr.is_runtime_frame()) {
duke@435 1105 RegisterMap map(thread, false);
duke@435 1106 fr = fr.sender(&map);
duke@435 1107 }
duke@435 1108 record_tick_for_calling_frame(thread, fr);
duke@435 1109 } else {
duke@435 1110 unknown_ticks_array[ut_no_last_Java_frame] += 1;
duke@435 1111 FlatProfiler::unknown_ticks += 1;
duke@435 1112 }
duke@435 1113 break;
duke@435 1114 // handle_special_runtime_exit_condition self-suspends threads in Java
duke@435 1115 case _thread_in_Java:
duke@435 1116 case _thread_in_Java_trans:
duke@435 1117 if (thread->profile_last_Java_frame(&fr)) {
duke@435 1118 if (fr.is_safepoint_blob_frame()) {
duke@435 1119 RegisterMap map(thread, false);
duke@435 1120 fr = fr.sender(&map);
duke@435 1121 }
duke@435 1122 record_tick_for_running_frame(thread, fr);
duke@435 1123 } else {
duke@435 1124 unknown_ticks_array[ut_no_last_Java_frame] += 1;
duke@435 1125 FlatProfiler::unknown_ticks += 1;
duke@435 1126 }
duke@435 1127 break;
duke@435 1128 case _thread_blocked:
duke@435 1129 case _thread_blocked_trans:
duke@435 1130 if (thread->osthread() && thread->osthread()->get_state() == RUNNABLE) {
duke@435 1131 if (thread->profile_last_Java_frame(&fr)) {
duke@435 1132 if (fr.is_safepoint_blob_frame()) {
duke@435 1133 RegisterMap map(thread, false);
duke@435 1134 fr = fr.sender(&map);
duke@435 1135 record_tick_for_running_frame(thread, fr);
duke@435 1136 } else {
duke@435 1137 record_tick_for_calling_frame(thread, fr);
duke@435 1138 }
duke@435 1139 } else {
duke@435 1140 unknown_ticks_array[ut_no_last_Java_frame] += 1;
duke@435 1141 FlatProfiler::unknown_ticks += 1;
duke@435 1142 }
duke@435 1143 } else {
duke@435 1144 blocked_ticks += 1;
duke@435 1145 FlatProfiler::blocked_ticks += 1;
duke@435 1146 }
duke@435 1147 break;
duke@435 1148 case _thread_uninitialized:
duke@435 1149 case _thread_new:
duke@435 1150 // not used, included for completeness
duke@435 1151 case _thread_new_trans:
duke@435 1152 unknown_ticks_array[ut_no_last_Java_frame] += 1;
duke@435 1153 FlatProfiler::unknown_ticks += 1;
duke@435 1154 break;
duke@435 1155 default:
duke@435 1156 unknown_ticks_array[ut_unknown_thread_state] += 1;
duke@435 1157 FlatProfiler::unknown_ticks += 1;
duke@435 1158 break;
duke@435 1159 }
duke@435 1160 return;
duke@435 1161 }
duke@435 1162
duke@435 1163 void ThreadProfiler::engage() {
duke@435 1164 engaged = true;
duke@435 1165 timer.start();
duke@435 1166 }
duke@435 1167
duke@435 1168 void ThreadProfiler::disengage() {
duke@435 1169 engaged = false;
duke@435 1170 timer.stop();
duke@435 1171 }
duke@435 1172
duke@435 1173 void ThreadProfiler::initialize() {
duke@435 1174 for (int index = 0; index < table_size; index++) {
duke@435 1175 table[index] = NULL;
duke@435 1176 }
duke@435 1177 thread_ticks = 0;
duke@435 1178 blocked_ticks = 0;
duke@435 1179 compiler_ticks = 0;
duke@435 1180 interpreter_ticks = 0;
duke@435 1181 for (int ut = 0; ut < ut_end; ut += 1) {
duke@435 1182 unknown_ticks_array[ut] = 0;
duke@435 1183 }
duke@435 1184 region_flag[ThreadProfilerMark::classLoaderRegion] = false;
duke@435 1185 class_loader_ticks = 0;
duke@435 1186 region_flag[ThreadProfilerMark::extraRegion] = false;
duke@435 1187 extra_ticks = 0;
duke@435 1188 timer.start();
duke@435 1189 interval_data_ref()->reset();
duke@435 1190 }
duke@435 1191
duke@435 1192 void ThreadProfiler::reset() {
duke@435 1193 timer.stop();
duke@435 1194 if (table != NULL) {
duke@435 1195 for (int index = 0; index < table_size; index++) {
duke@435 1196 ProfilerNode* n = table[index];
duke@435 1197 if (n != NULL) {
duke@435 1198 delete n;
duke@435 1199 }
duke@435 1200 }
duke@435 1201 }
duke@435 1202 initialize();
duke@435 1203 }
duke@435 1204
duke@435 1205 void FlatProfiler::allocate_table() {
duke@435 1206 { // Bytecode table
zgu@3900 1207 bytecode_ticks = NEW_C_HEAP_ARRAY(int, Bytecodes::number_of_codes, mtInternal);
zgu@3900 1208 bytecode_ticks_stub = NEW_C_HEAP_ARRAY(int, Bytecodes::number_of_codes, mtInternal);
duke@435 1209 for(int index = 0; index < Bytecodes::number_of_codes; index++) {
duke@435 1210 bytecode_ticks[index] = 0;
duke@435 1211 bytecode_ticks_stub[index] = 0;
duke@435 1212 }
duke@435 1213 }
duke@435 1214
duke@435 1215 if (ProfilerRecordPC) PCRecorder::init();
duke@435 1216
zgu@3900 1217 interval_data = NEW_C_HEAP_ARRAY(IntervalData, interval_print_size, mtInternal);
duke@435 1218 FlatProfiler::interval_reset();
duke@435 1219 }
duke@435 1220
duke@435 1221 void FlatProfiler::engage(JavaThread* mainThread, bool fullProfile) {
duke@435 1222 full_profile_flag = fullProfile;
duke@435 1223 if (bytecode_ticks == NULL) {
duke@435 1224 allocate_table();
duke@435 1225 }
duke@435 1226 if(ProfileVM && (vm_thread_profiler == NULL)){
duke@435 1227 vm_thread_profiler = new ThreadProfiler();
duke@435 1228 }
duke@435 1229 if (task == NULL) {
duke@435 1230 task = new FlatProfilerTask(WatcherThread::delay_interval);
duke@435 1231 task->enroll();
duke@435 1232 }
duke@435 1233 timer.start();
duke@435 1234 if (mainThread != NULL) {
duke@435 1235 // When mainThread was created, it might not have a ThreadProfiler
duke@435 1236 ThreadProfiler* pp = mainThread->get_thread_profiler();
duke@435 1237 if (pp == NULL) {
duke@435 1238 mainThread->set_thread_profiler(new ThreadProfiler());
duke@435 1239 } else {
duke@435 1240 pp->reset();
duke@435 1241 }
duke@435 1242 mainThread->get_thread_profiler()->engage();
duke@435 1243 }
duke@435 1244 // This is where we would assign thread_profiler
duke@435 1245 // if we wanted only one thread_profiler for all threads.
duke@435 1246 thread_profiler = NULL;
duke@435 1247 }
duke@435 1248
duke@435 1249 void FlatProfiler::disengage() {
duke@435 1250 if (!task) {
duke@435 1251 return;
duke@435 1252 }
duke@435 1253 timer.stop();
duke@435 1254 task->disenroll();
duke@435 1255 delete task;
duke@435 1256 task = NULL;
duke@435 1257 if (thread_profiler != NULL) {
duke@435 1258 thread_profiler->disengage();
duke@435 1259 } else {
duke@435 1260 MutexLocker tl(Threads_lock);
duke@435 1261 for (JavaThread* tp = Threads::first(); tp != NULL; tp = tp->next()) {
duke@435 1262 ThreadProfiler* pp = tp->get_thread_profiler();
duke@435 1263 if (pp != NULL) {
duke@435 1264 pp->disengage();
duke@435 1265 }
duke@435 1266 }
duke@435 1267 }
duke@435 1268 }
duke@435 1269
duke@435 1270 void FlatProfiler::reset() {
duke@435 1271 if (task) {
duke@435 1272 disengage();
duke@435 1273 }
duke@435 1274
duke@435 1275 class_loader_ticks = 0;
duke@435 1276 extra_ticks = 0;
duke@435 1277 received_gc_ticks = 0;
duke@435 1278 vm_operation_ticks = 0;
duke@435 1279 compiler_ticks = 0;
duke@435 1280 deopt_ticks = 0;
duke@435 1281 interpreter_ticks = 0;
duke@435 1282 blocked_ticks = 0;
duke@435 1283 unknown_ticks = 0;
duke@435 1284 received_ticks = 0;
duke@435 1285 delivered_ticks = 0;
duke@435 1286 timer.stop();
duke@435 1287 }
duke@435 1288
duke@435 1289 bool FlatProfiler::is_active() {
duke@435 1290 return task != NULL;
duke@435 1291 }
duke@435 1292
duke@435 1293 void FlatProfiler::print_byte_code_statistics() {
duke@435 1294 GrowableArray <ProfilerNode*>* array = new GrowableArray<ProfilerNode*>(200);
duke@435 1295
duke@435 1296 tty->print_cr(" Bytecode ticks:");
duke@435 1297 for (int index = 0; index < Bytecodes::number_of_codes; index++) {
duke@435 1298 if (FlatProfiler::bytecode_ticks[index] > 0 || FlatProfiler::bytecode_ticks_stub[index] > 0) {
duke@435 1299 tty->print_cr(" %4d %4d = %s",
duke@435 1300 FlatProfiler::bytecode_ticks[index],
duke@435 1301 FlatProfiler::bytecode_ticks_stub[index],
duke@435 1302 Bytecodes::name( (Bytecodes::Code) index));
duke@435 1303 }
duke@435 1304 }
duke@435 1305 tty->cr();
duke@435 1306 }
duke@435 1307
duke@435 1308 void print_ticks(const char* title, int ticks, int total) {
duke@435 1309 if (ticks > 0) {
duke@435 1310 tty->print("%5.1f%% %5d", ticks * 100.0 / total, ticks);
duke@435 1311 tty->fill_to(col3);
duke@435 1312 tty->print("%s", title);
duke@435 1313 tty->cr();
duke@435 1314 }
duke@435 1315 }
duke@435 1316
duke@435 1317 void ThreadProfiler::print(const char* thread_name) {
duke@435 1318 ResourceMark rm;
duke@435 1319 MutexLocker ppl(ProfilePrint_lock);
duke@435 1320 int index = 0; // Declared outside for loops for portability
duke@435 1321
duke@435 1322 if (table == NULL) {
duke@435 1323 return;
duke@435 1324 }
duke@435 1325
duke@435 1326 if (thread_ticks <= 0) {
duke@435 1327 return;
duke@435 1328 }
duke@435 1329
duke@435 1330 const char* title = "too soon to tell";
duke@435 1331 double secs = timer.seconds();
duke@435 1332
duke@435 1333 GrowableArray <ProfilerNode*>* array = new GrowableArray<ProfilerNode*>(200);
duke@435 1334 for(index = 0; index < table_size; index++) {
duke@435 1335 for(ProfilerNode* node = table[index]; node; node = node->next())
duke@435 1336 array->append(node);
duke@435 1337 }
duke@435 1338
duke@435 1339 array->sort(&ProfilerNode::compare);
duke@435 1340
duke@435 1341 // compute total (sanity check)
duke@435 1342 int active =
duke@435 1343 class_loader_ticks +
duke@435 1344 compiler_ticks +
duke@435 1345 interpreter_ticks +
duke@435 1346 unknown_ticks();
duke@435 1347 for (index = 0; index < array->length(); index++) {
duke@435 1348 active += array->at(index)->ticks.total();
duke@435 1349 }
duke@435 1350 int total = active + blocked_ticks;
duke@435 1351
duke@435 1352 tty->cr();
duke@435 1353 tty->print_cr("Flat profile of %3.2f secs (%d total ticks): %s", secs, total, thread_name);
duke@435 1354 if (total != thread_ticks) {
duke@435 1355 print_ticks("Lost ticks", thread_ticks-total, thread_ticks);
duke@435 1356 }
duke@435 1357 tty->cr();
duke@435 1358
duke@435 1359 // print interpreted methods
duke@435 1360 tick_counter interpreted_ticks;
duke@435 1361 bool has_interpreted_ticks = false;
duke@435 1362 int print_count = 0;
duke@435 1363 for (index = 0; index < array->length(); index++) {
duke@435 1364 ProfilerNode* n = array->at(index);
duke@435 1365 if (n->is_interpreted()) {
duke@435 1366 interpreted_ticks.add(&n->ticks);
duke@435 1367 if (!has_interpreted_ticks) {
duke@435 1368 interpretedNode::print_title(tty);
duke@435 1369 has_interpreted_ticks = true;
duke@435 1370 }
duke@435 1371 if (print_count++ < ProfilerNumberOfInterpretedMethods) {
duke@435 1372 n->print(tty, active);
duke@435 1373 }
duke@435 1374 }
duke@435 1375 }
duke@435 1376 if (has_interpreted_ticks) {
duke@435 1377 if (print_count <= ProfilerNumberOfInterpretedMethods) {
duke@435 1378 title = "Total interpreted";
duke@435 1379 } else {
duke@435 1380 title = "Total interpreted (including elided)";
duke@435 1381 }
duke@435 1382 interpretedNode::print_total(tty, &interpreted_ticks, active, title);
duke@435 1383 tty->cr();
duke@435 1384 }
duke@435 1385
duke@435 1386 // print compiled methods
duke@435 1387 tick_counter compiled_ticks;
duke@435 1388 bool has_compiled_ticks = false;
duke@435 1389 print_count = 0;
duke@435 1390 for (index = 0; index < array->length(); index++) {
duke@435 1391 ProfilerNode* n = array->at(index);
duke@435 1392 if (n->is_compiled()) {
duke@435 1393 compiled_ticks.add(&n->ticks);
duke@435 1394 if (!has_compiled_ticks) {
duke@435 1395 compiledNode::print_title(tty);
duke@435 1396 has_compiled_ticks = true;
duke@435 1397 }
duke@435 1398 if (print_count++ < ProfilerNumberOfCompiledMethods) {
duke@435 1399 n->print(tty, active);
duke@435 1400 }
duke@435 1401 }
duke@435 1402 }
duke@435 1403 if (has_compiled_ticks) {
duke@435 1404 if (print_count <= ProfilerNumberOfCompiledMethods) {
duke@435 1405 title = "Total compiled";
duke@435 1406 } else {
duke@435 1407 title = "Total compiled (including elided)";
duke@435 1408 }
duke@435 1409 compiledNode::print_total(tty, &compiled_ticks, active, title);
duke@435 1410 tty->cr();
duke@435 1411 }
duke@435 1412
duke@435 1413 // print stub methods
duke@435 1414 tick_counter stub_ticks;
duke@435 1415 bool has_stub_ticks = false;
duke@435 1416 print_count = 0;
duke@435 1417 for (index = 0; index < array->length(); index++) {
duke@435 1418 ProfilerNode* n = array->at(index);
duke@435 1419 if (n->is_stub()) {
duke@435 1420 stub_ticks.add(&n->ticks);
duke@435 1421 if (!has_stub_ticks) {
duke@435 1422 stubNode::print_title(tty);
duke@435 1423 has_stub_ticks = true;
duke@435 1424 }
duke@435 1425 if (print_count++ < ProfilerNumberOfStubMethods) {
duke@435 1426 n->print(tty, active);
duke@435 1427 }
duke@435 1428 }
duke@435 1429 }
duke@435 1430 if (has_stub_ticks) {
duke@435 1431 if (print_count <= ProfilerNumberOfStubMethods) {
duke@435 1432 title = "Total stub";
duke@435 1433 } else {
duke@435 1434 title = "Total stub (including elided)";
duke@435 1435 }
duke@435 1436 stubNode::print_total(tty, &stub_ticks, active, title);
duke@435 1437 tty->cr();
duke@435 1438 }
duke@435 1439
duke@435 1440 // print runtime stubs
duke@435 1441 tick_counter runtime_stub_ticks;
duke@435 1442 bool has_runtime_stub_ticks = false;
duke@435 1443 print_count = 0;
duke@435 1444 for (index = 0; index < array->length(); index++) {
duke@435 1445 ProfilerNode* n = array->at(index);
duke@435 1446 if (n->is_runtime_stub()) {
duke@435 1447 runtime_stub_ticks.add(&n->ticks);
duke@435 1448 if (!has_runtime_stub_ticks) {
duke@435 1449 runtimeStubNode::print_title(tty);
duke@435 1450 has_runtime_stub_ticks = true;
duke@435 1451 }
duke@435 1452 if (print_count++ < ProfilerNumberOfRuntimeStubNodes) {
duke@435 1453 n->print(tty, active);
duke@435 1454 }
duke@435 1455 }
duke@435 1456 }
duke@435 1457 if (has_runtime_stub_ticks) {
duke@435 1458 if (print_count <= ProfilerNumberOfRuntimeStubNodes) {
duke@435 1459 title = "Total runtime stubs";
duke@435 1460 } else {
duke@435 1461 title = "Total runtime stubs (including elided)";
duke@435 1462 }
duke@435 1463 runtimeStubNode::print_total(tty, &runtime_stub_ticks, active, title);
duke@435 1464 tty->cr();
duke@435 1465 }
duke@435 1466
duke@435 1467 if (blocked_ticks + class_loader_ticks + interpreter_ticks + compiler_ticks + unknown_ticks() != 0) {
duke@435 1468 tty->fill_to(col1);
duke@435 1469 tty->print_cr("Thread-local ticks:");
duke@435 1470 print_ticks("Blocked (of total)", blocked_ticks, total);
duke@435 1471 print_ticks("Class loader", class_loader_ticks, active);
duke@435 1472 print_ticks("Extra", extra_ticks, active);
duke@435 1473 print_ticks("Interpreter", interpreter_ticks, active);
duke@435 1474 print_ticks("Compilation", compiler_ticks, active);
duke@435 1475 print_ticks("Unknown: vtable stubs", unknown_ticks_array[ut_vtable_stubs], active);
duke@435 1476 print_ticks("Unknown: null method", unknown_ticks_array[ut_null_method], active);
duke@435 1477 print_ticks("Unknown: running frame", unknown_ticks_array[ut_running_frame], active);
duke@435 1478 print_ticks("Unknown: calling frame", unknown_ticks_array[ut_calling_frame], active);
duke@435 1479 print_ticks("Unknown: no pc", unknown_ticks_array[ut_no_pc], active);
duke@435 1480 print_ticks("Unknown: no last frame", unknown_ticks_array[ut_no_last_Java_frame], active);
duke@435 1481 print_ticks("Unknown: thread_state", unknown_ticks_array[ut_unknown_thread_state], active);
duke@435 1482 tty->cr();
duke@435 1483 }
duke@435 1484
duke@435 1485 if (WizardMode) {
duke@435 1486 tty->print_cr("Node area used: %dKb", (area_top - area_bottom) / 1024);
duke@435 1487 }
duke@435 1488 reset();
duke@435 1489 }
duke@435 1490
duke@435 1491 /*
duke@435 1492 ThreadProfiler::print_unknown(){
duke@435 1493 if (table == NULL) {
duke@435 1494 return;
duke@435 1495 }
duke@435 1496
duke@435 1497 if (thread_ticks <= 0) {
duke@435 1498 return;
duke@435 1499 }
duke@435 1500 } */
duke@435 1501
duke@435 1502 void FlatProfiler::print(int unused) {
duke@435 1503 ResourceMark rm;
duke@435 1504 if (thread_profiler != NULL) {
duke@435 1505 thread_profiler->print("All threads");
duke@435 1506 } else {
duke@435 1507 MutexLocker tl(Threads_lock);
duke@435 1508 for (JavaThread* tp = Threads::first(); tp != NULL; tp = tp->next()) {
duke@435 1509 ThreadProfiler* pp = tp->get_thread_profiler();
duke@435 1510 if (pp != NULL) {
duke@435 1511 pp->print(tp->get_thread_name());
duke@435 1512 }
duke@435 1513 }
duke@435 1514 }
duke@435 1515
duke@435 1516 if (ProfilerPrintByteCodeStatistics) {
duke@435 1517 print_byte_code_statistics();
duke@435 1518 }
duke@435 1519
duke@435 1520 if (non_method_ticks() > 0) {
duke@435 1521 tty->cr();
duke@435 1522 tty->print_cr("Global summary of %3.2f seconds:", timer.seconds());
duke@435 1523 print_ticks("Received ticks", received_ticks, received_ticks);
duke@435 1524 print_ticks("Received GC ticks", received_gc_ticks, received_ticks);
duke@435 1525 print_ticks("Compilation", compiler_ticks, received_ticks);
duke@435 1526 print_ticks("Deoptimization", deopt_ticks, received_ticks);
duke@435 1527 print_ticks("Other VM operations", vm_operation_ticks, received_ticks);
duke@435 1528 #ifndef PRODUCT
duke@435 1529 print_ticks("Blocked ticks", blocked_ticks, received_ticks);
duke@435 1530 print_ticks("Threads_lock blocks", threads_lock_ticks, received_ticks);
duke@435 1531 print_ticks("Delivered ticks", delivered_ticks, received_ticks);
duke@435 1532 print_ticks("All ticks", all_ticks, received_ticks);
duke@435 1533 #endif
duke@435 1534 print_ticks("Class loader", class_loader_ticks, received_ticks);
duke@435 1535 print_ticks("Extra ", extra_ticks, received_ticks);
duke@435 1536 print_ticks("Interpreter", interpreter_ticks, received_ticks);
duke@435 1537 print_ticks("Unknown code", unknown_ticks, received_ticks);
duke@435 1538 }
duke@435 1539
duke@435 1540 PCRecorder::print();
duke@435 1541
duke@435 1542 if(ProfileVM){
duke@435 1543 tty->cr();
duke@435 1544 vm_thread_profiler->print("VM Thread");
duke@435 1545 }
duke@435 1546 }
duke@435 1547
duke@435 1548 void IntervalData::print_header(outputStream* st) {
duke@435 1549 st->print("i/c/n/g");
duke@435 1550 }
duke@435 1551
duke@435 1552 void IntervalData::print_data(outputStream* st) {
duke@435 1553 st->print("%d/%d/%d/%d", interpreted(), compiled(), native(), compiling());
duke@435 1554 }
duke@435 1555
duke@435 1556 void FlatProfiler::interval_record_thread(ThreadProfiler* tp) {
duke@435 1557 IntervalData id = tp->interval_data();
duke@435 1558 int total = id.total();
duke@435 1559 tp->interval_data_ref()->reset();
duke@435 1560
duke@435 1561 // Insertion sort the data, if it's relevant.
duke@435 1562 for (int i = 0; i < interval_print_size; i += 1) {
duke@435 1563 if (total > interval_data[i].total()) {
duke@435 1564 for (int j = interval_print_size - 1; j > i; j -= 1) {
duke@435 1565 interval_data[j] = interval_data[j-1];
duke@435 1566 }
duke@435 1567 interval_data[i] = id;
duke@435 1568 break;
duke@435 1569 }
duke@435 1570 }
duke@435 1571 }
duke@435 1572
duke@435 1573 void FlatProfiler::interval_print() {
duke@435 1574 if ((interval_data[0].total() > 0)) {
duke@435 1575 tty->stamp();
duke@435 1576 tty->print("\t");
duke@435 1577 IntervalData::print_header(tty);
duke@435 1578 for (int i = 0; i < interval_print_size; i += 1) {
duke@435 1579 if (interval_data[i].total() > 0) {
duke@435 1580 tty->print("\t");
duke@435 1581 interval_data[i].print_data(tty);
duke@435 1582 }
duke@435 1583 }
duke@435 1584 tty->cr();
duke@435 1585 }
duke@435 1586 }
duke@435 1587
duke@435 1588 void FlatProfiler::interval_reset() {
duke@435 1589 for (int i = 0; i < interval_print_size; i += 1) {
duke@435 1590 interval_data[i].reset();
duke@435 1591 }
duke@435 1592 }
duke@435 1593
duke@435 1594 void ThreadProfiler::oops_do(OopClosure* f) {
duke@435 1595 if (table == NULL) return;
duke@435 1596
duke@435 1597 for(int index = 0; index < table_size; index++) {
duke@435 1598 for(ProfilerNode* node = table[index]; node; node = node->next())
duke@435 1599 node->oops_do(f);
duke@435 1600 }
duke@435 1601 }
duke@435 1602
duke@435 1603 void FlatProfiler::oops_do(OopClosure* f) {
duke@435 1604 if (thread_profiler != NULL) {
duke@435 1605 thread_profiler->oops_do(f);
duke@435 1606 } else {
duke@435 1607 for (JavaThread* tp = Threads::first(); tp != NULL; tp = tp->next()) {
duke@435 1608 ThreadProfiler* pp = tp->get_thread_profiler();
duke@435 1609 if (pp != NULL) {
duke@435 1610 pp->oops_do(f);
duke@435 1611 }
duke@435 1612 }
duke@435 1613 }
duke@435 1614 }

mercurial