src/share/vm/runtime/fprofiler.cpp

Wed, 18 Sep 2013 07:02:10 -0700

author
dcubed
date
Wed, 18 Sep 2013 07:02:10 -0700
changeset 5743
63147986a428
parent 5617
491de79915eb
child 6680
78bbf4d43a14
permissions
-rw-r--r--

8019835: Strings interned in different threads equal but does not ==
Summary: Add -XX:+VerifyStringTableAtExit option and code to verify StringTable invariants.
Reviewed-by: rdurbin, sspitsyn, coleenp

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
coleenp@5614 267 void* operator new(size_t size, ThreadProfiler* tp) throw();
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
coleenp@5614 376 void* ProfilerNode::operator new(size_t size, ThreadProfiler* tp) throw() {
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 }
zgu@5616 928
zgu@5616 929 FREE_C_HEAP_ARRAY(JavaThread *, threadsList, mtInternal);
duke@435 930 } else {
duke@435 931 // Couldn't get the threads lock, just record that rather than blocking
duke@435 932 FlatProfiler::threads_lock_ticks += 1;
duke@435 933 }
duke@435 934
duke@435 935 }
duke@435 936
duke@435 937 void FlatProfilerTask::task() {
duke@435 938 FlatProfiler::received_ticks += 1;
duke@435 939
duke@435 940 if (ProfileVM) {
duke@435 941 FlatProfiler::record_vm_tick();
duke@435 942 }
duke@435 943
duke@435 944 VM_Operation* op = VMThread::vm_operation();
duke@435 945 if (op != NULL) {
duke@435 946 FlatProfiler::record_vm_operation();
duke@435 947 if (SafepointSynchronize::is_at_safepoint()) {
duke@435 948 return;
duke@435 949 }
duke@435 950 }
duke@435 951 FlatProfiler::record_thread_ticks();
duke@435 952 }
duke@435 953
sgoldman@542 954 void ThreadProfiler::record_interpreted_tick(JavaThread* thread, frame fr, TickPosition where, int* ticks) {
duke@435 955 FlatProfiler::all_int_ticks++;
duke@435 956 if (!FlatProfiler::full_profile()) {
duke@435 957 return;
duke@435 958 }
duke@435 959
sgoldman@542 960 if (!fr.is_interpreted_frame_valid(thread)) {
duke@435 961 // tick came at a bad time
duke@435 962 interpreter_ticks += 1;
duke@435 963 FlatProfiler::interpreter_ticks += 1;
duke@435 964 return;
duke@435 965 }
duke@435 966
sgoldman@542 967 // The frame has been fully validated so we can trust the method and bci
sgoldman@542 968
coleenp@4037 969 Method* method = *fr.interpreter_frame_method_addr();
sgoldman@542 970
duke@435 971 interpreted_update(method, where);
duke@435 972
duke@435 973 // update byte code table
duke@435 974 InterpreterCodelet* desc = Interpreter::codelet_containing(fr.pc());
duke@435 975 if (desc != NULL && desc->bytecode() >= 0) {
duke@435 976 ticks[desc->bytecode()]++;
duke@435 977 }
duke@435 978 }
duke@435 979
duke@435 980 void ThreadProfiler::record_compiled_tick(JavaThread* thread, frame fr, TickPosition where) {
duke@435 981 const char *name = NULL;
duke@435 982 TickPosition localwhere = where;
duke@435 983
duke@435 984 FlatProfiler::all_comp_ticks++;
duke@435 985 if (!FlatProfiler::full_profile()) return;
duke@435 986
duke@435 987 CodeBlob* cb = fr.cb();
duke@435 988
duke@435 989 // For runtime stubs, record as native rather than as compiled
duke@435 990 if (cb->is_runtime_stub()) {
duke@435 991 RegisterMap map(thread, false);
duke@435 992 fr = fr.sender(&map);
duke@435 993 cb = fr.cb();
duke@435 994 localwhere = tp_native;
duke@435 995 }
coleenp@4037 996 Method* method = (cb->is_nmethod()) ? ((nmethod *)cb)->method() :
coleenp@4037 997 (Method*)NULL;
duke@435 998
duke@435 999 if (method == NULL) {
duke@435 1000 if (cb->is_runtime_stub())
duke@435 1001 runtime_stub_update(cb, name, localwhere);
duke@435 1002 else
duke@435 1003 unknown_compiled_update(cb, localwhere);
duke@435 1004 }
duke@435 1005 else {
duke@435 1006 if (method->is_native()) {
duke@435 1007 stub_update(method, name, localwhere);
duke@435 1008 } else {
duke@435 1009 compiled_update(method, localwhere);
duke@435 1010 }
duke@435 1011 }
duke@435 1012 }
duke@435 1013
duke@435 1014 extern "C" void find(int x);
duke@435 1015
duke@435 1016
duke@435 1017 void ThreadProfiler::record_tick_for_running_frame(JavaThread* thread, frame fr) {
twisti@1040 1018 // The tick happened in real code -> non VM code
duke@435 1019 if (fr.is_interpreted_frame()) {
duke@435 1020 interval_data_ref()->inc_interpreted();
sgoldman@542 1021 record_interpreted_tick(thread, fr, tp_code, FlatProfiler::bytecode_ticks);
duke@435 1022 return;
duke@435 1023 }
duke@435 1024
duke@435 1025 if (CodeCache::contains(fr.pc())) {
duke@435 1026 interval_data_ref()->inc_compiled();
duke@435 1027 PCRecorder::record(fr.pc());
duke@435 1028 record_compiled_tick(thread, fr, tp_code);
duke@435 1029 return;
duke@435 1030 }
duke@435 1031
duke@435 1032 if (VtableStubs::stub_containing(fr.pc()) != NULL) {
duke@435 1033 unknown_ticks_array[ut_vtable_stubs] += 1;
duke@435 1034 return;
duke@435 1035 }
duke@435 1036
duke@435 1037 frame caller = fr.profile_find_Java_sender_frame(thread);
duke@435 1038
duke@435 1039 if (caller.sp() != NULL && caller.pc() != NULL) {
duke@435 1040 record_tick_for_calling_frame(thread, caller);
duke@435 1041 return;
duke@435 1042 }
duke@435 1043
duke@435 1044 unknown_ticks_array[ut_running_frame] += 1;
duke@435 1045 FlatProfiler::unknown_ticks += 1;
duke@435 1046 }
duke@435 1047
duke@435 1048 void ThreadProfiler::record_tick_for_calling_frame(JavaThread* thread, frame fr) {
twisti@1040 1049 // The tick happened in VM code
duke@435 1050 interval_data_ref()->inc_native();
duke@435 1051 if (fr.is_interpreted_frame()) {
sgoldman@542 1052 record_interpreted_tick(thread, fr, tp_native, FlatProfiler::bytecode_ticks_stub);
duke@435 1053 return;
duke@435 1054 }
duke@435 1055 if (CodeCache::contains(fr.pc())) {
duke@435 1056 record_compiled_tick(thread, fr, tp_native);
duke@435 1057 return;
duke@435 1058 }
duke@435 1059
duke@435 1060 frame caller = fr.profile_find_Java_sender_frame(thread);
duke@435 1061
duke@435 1062 if (caller.sp() != NULL && caller.pc() != NULL) {
duke@435 1063 record_tick_for_calling_frame(thread, caller);
duke@435 1064 return;
duke@435 1065 }
duke@435 1066
duke@435 1067 unknown_ticks_array[ut_calling_frame] += 1;
duke@435 1068 FlatProfiler::unknown_ticks += 1;
duke@435 1069 }
duke@435 1070
duke@435 1071 void ThreadProfiler::record_tick(JavaThread* thread) {
duke@435 1072 FlatProfiler::all_ticks++;
duke@435 1073 thread_ticks += 1;
duke@435 1074
duke@435 1075 // Here's another way to track global state changes.
duke@435 1076 // When the class loader starts it marks the ThreadProfiler to tell it it is in the class loader
duke@435 1077 // and we check that here.
duke@435 1078 // This is more direct, and more than one thread can be in the class loader at a time,
duke@435 1079 // but it does mean the class loader has to know about the profiler.
duke@435 1080 if (region_flag[ThreadProfilerMark::classLoaderRegion]) {
duke@435 1081 class_loader_ticks += 1;
duke@435 1082 FlatProfiler::class_loader_ticks += 1;
duke@435 1083 return;
duke@435 1084 } else if (region_flag[ThreadProfilerMark::extraRegion]) {
duke@435 1085 extra_ticks += 1;
duke@435 1086 FlatProfiler::extra_ticks += 1;
duke@435 1087 return;
duke@435 1088 }
duke@435 1089 // Note that the WatcherThread can now stop for safepoints
duke@435 1090 uint32_t debug_bits = 0;
duke@435 1091 if (!thread->wait_for_ext_suspend_completion(SuspendRetryCount,
duke@435 1092 SuspendRetryDelay, &debug_bits)) {
duke@435 1093 unknown_ticks_array[ut_unknown_thread_state] += 1;
duke@435 1094 FlatProfiler::unknown_ticks += 1;
duke@435 1095 return;
duke@435 1096 }
duke@435 1097
duke@435 1098 frame fr;
duke@435 1099
duke@435 1100 switch (thread->thread_state()) {
duke@435 1101 case _thread_in_native:
duke@435 1102 case _thread_in_native_trans:
duke@435 1103 case _thread_in_vm:
duke@435 1104 case _thread_in_vm_trans:
duke@435 1105 if (thread->profile_last_Java_frame(&fr)) {
duke@435 1106 if (fr.is_runtime_frame()) {
duke@435 1107 RegisterMap map(thread, false);
duke@435 1108 fr = fr.sender(&map);
duke@435 1109 }
duke@435 1110 record_tick_for_calling_frame(thread, fr);
duke@435 1111 } else {
duke@435 1112 unknown_ticks_array[ut_no_last_Java_frame] += 1;
duke@435 1113 FlatProfiler::unknown_ticks += 1;
duke@435 1114 }
duke@435 1115 break;
duke@435 1116 // handle_special_runtime_exit_condition self-suspends threads in Java
duke@435 1117 case _thread_in_Java:
duke@435 1118 case _thread_in_Java_trans:
duke@435 1119 if (thread->profile_last_Java_frame(&fr)) {
duke@435 1120 if (fr.is_safepoint_blob_frame()) {
duke@435 1121 RegisterMap map(thread, false);
duke@435 1122 fr = fr.sender(&map);
duke@435 1123 }
duke@435 1124 record_tick_for_running_frame(thread, fr);
duke@435 1125 } else {
duke@435 1126 unknown_ticks_array[ut_no_last_Java_frame] += 1;
duke@435 1127 FlatProfiler::unknown_ticks += 1;
duke@435 1128 }
duke@435 1129 break;
duke@435 1130 case _thread_blocked:
duke@435 1131 case _thread_blocked_trans:
duke@435 1132 if (thread->osthread() && thread->osthread()->get_state() == RUNNABLE) {
duke@435 1133 if (thread->profile_last_Java_frame(&fr)) {
duke@435 1134 if (fr.is_safepoint_blob_frame()) {
duke@435 1135 RegisterMap map(thread, false);
duke@435 1136 fr = fr.sender(&map);
duke@435 1137 record_tick_for_running_frame(thread, fr);
duke@435 1138 } else {
duke@435 1139 record_tick_for_calling_frame(thread, fr);
duke@435 1140 }
duke@435 1141 } else {
duke@435 1142 unknown_ticks_array[ut_no_last_Java_frame] += 1;
duke@435 1143 FlatProfiler::unknown_ticks += 1;
duke@435 1144 }
duke@435 1145 } else {
duke@435 1146 blocked_ticks += 1;
duke@435 1147 FlatProfiler::blocked_ticks += 1;
duke@435 1148 }
duke@435 1149 break;
duke@435 1150 case _thread_uninitialized:
duke@435 1151 case _thread_new:
duke@435 1152 // not used, included for completeness
duke@435 1153 case _thread_new_trans:
duke@435 1154 unknown_ticks_array[ut_no_last_Java_frame] += 1;
duke@435 1155 FlatProfiler::unknown_ticks += 1;
duke@435 1156 break;
duke@435 1157 default:
duke@435 1158 unknown_ticks_array[ut_unknown_thread_state] += 1;
duke@435 1159 FlatProfiler::unknown_ticks += 1;
duke@435 1160 break;
duke@435 1161 }
duke@435 1162 return;
duke@435 1163 }
duke@435 1164
duke@435 1165 void ThreadProfiler::engage() {
duke@435 1166 engaged = true;
duke@435 1167 timer.start();
duke@435 1168 }
duke@435 1169
duke@435 1170 void ThreadProfiler::disengage() {
duke@435 1171 engaged = false;
duke@435 1172 timer.stop();
duke@435 1173 }
duke@435 1174
duke@435 1175 void ThreadProfiler::initialize() {
duke@435 1176 for (int index = 0; index < table_size; index++) {
duke@435 1177 table[index] = NULL;
duke@435 1178 }
duke@435 1179 thread_ticks = 0;
duke@435 1180 blocked_ticks = 0;
duke@435 1181 compiler_ticks = 0;
duke@435 1182 interpreter_ticks = 0;
duke@435 1183 for (int ut = 0; ut < ut_end; ut += 1) {
duke@435 1184 unknown_ticks_array[ut] = 0;
duke@435 1185 }
duke@435 1186 region_flag[ThreadProfilerMark::classLoaderRegion] = false;
duke@435 1187 class_loader_ticks = 0;
duke@435 1188 region_flag[ThreadProfilerMark::extraRegion] = false;
duke@435 1189 extra_ticks = 0;
duke@435 1190 timer.start();
duke@435 1191 interval_data_ref()->reset();
duke@435 1192 }
duke@435 1193
duke@435 1194 void ThreadProfiler::reset() {
duke@435 1195 timer.stop();
duke@435 1196 if (table != NULL) {
duke@435 1197 for (int index = 0; index < table_size; index++) {
duke@435 1198 ProfilerNode* n = table[index];
duke@435 1199 if (n != NULL) {
duke@435 1200 delete n;
duke@435 1201 }
duke@435 1202 }
duke@435 1203 }
duke@435 1204 initialize();
duke@435 1205 }
duke@435 1206
duke@435 1207 void FlatProfiler::allocate_table() {
duke@435 1208 { // Bytecode table
zgu@3900 1209 bytecode_ticks = NEW_C_HEAP_ARRAY(int, Bytecodes::number_of_codes, mtInternal);
zgu@3900 1210 bytecode_ticks_stub = NEW_C_HEAP_ARRAY(int, Bytecodes::number_of_codes, mtInternal);
duke@435 1211 for(int index = 0; index < Bytecodes::number_of_codes; index++) {
duke@435 1212 bytecode_ticks[index] = 0;
duke@435 1213 bytecode_ticks_stub[index] = 0;
duke@435 1214 }
duke@435 1215 }
duke@435 1216
duke@435 1217 if (ProfilerRecordPC) PCRecorder::init();
duke@435 1218
zgu@3900 1219 interval_data = NEW_C_HEAP_ARRAY(IntervalData, interval_print_size, mtInternal);
duke@435 1220 FlatProfiler::interval_reset();
duke@435 1221 }
duke@435 1222
duke@435 1223 void FlatProfiler::engage(JavaThread* mainThread, bool fullProfile) {
duke@435 1224 full_profile_flag = fullProfile;
duke@435 1225 if (bytecode_ticks == NULL) {
duke@435 1226 allocate_table();
duke@435 1227 }
duke@435 1228 if(ProfileVM && (vm_thread_profiler == NULL)){
duke@435 1229 vm_thread_profiler = new ThreadProfiler();
duke@435 1230 }
duke@435 1231 if (task == NULL) {
duke@435 1232 task = new FlatProfilerTask(WatcherThread::delay_interval);
duke@435 1233 task->enroll();
duke@435 1234 }
duke@435 1235 timer.start();
duke@435 1236 if (mainThread != NULL) {
duke@435 1237 // When mainThread was created, it might not have a ThreadProfiler
duke@435 1238 ThreadProfiler* pp = mainThread->get_thread_profiler();
duke@435 1239 if (pp == NULL) {
duke@435 1240 mainThread->set_thread_profiler(new ThreadProfiler());
duke@435 1241 } else {
duke@435 1242 pp->reset();
duke@435 1243 }
duke@435 1244 mainThread->get_thread_profiler()->engage();
duke@435 1245 }
duke@435 1246 // This is where we would assign thread_profiler
duke@435 1247 // if we wanted only one thread_profiler for all threads.
duke@435 1248 thread_profiler = NULL;
duke@435 1249 }
duke@435 1250
duke@435 1251 void FlatProfiler::disengage() {
duke@435 1252 if (!task) {
duke@435 1253 return;
duke@435 1254 }
duke@435 1255 timer.stop();
duke@435 1256 task->disenroll();
duke@435 1257 delete task;
duke@435 1258 task = NULL;
duke@435 1259 if (thread_profiler != NULL) {
duke@435 1260 thread_profiler->disengage();
duke@435 1261 } else {
duke@435 1262 MutexLocker tl(Threads_lock);
duke@435 1263 for (JavaThread* tp = Threads::first(); tp != NULL; tp = tp->next()) {
duke@435 1264 ThreadProfiler* pp = tp->get_thread_profiler();
duke@435 1265 if (pp != NULL) {
duke@435 1266 pp->disengage();
duke@435 1267 }
duke@435 1268 }
duke@435 1269 }
duke@435 1270 }
duke@435 1271
duke@435 1272 void FlatProfiler::reset() {
duke@435 1273 if (task) {
duke@435 1274 disengage();
duke@435 1275 }
duke@435 1276
duke@435 1277 class_loader_ticks = 0;
duke@435 1278 extra_ticks = 0;
duke@435 1279 received_gc_ticks = 0;
duke@435 1280 vm_operation_ticks = 0;
duke@435 1281 compiler_ticks = 0;
duke@435 1282 deopt_ticks = 0;
duke@435 1283 interpreter_ticks = 0;
duke@435 1284 blocked_ticks = 0;
duke@435 1285 unknown_ticks = 0;
duke@435 1286 received_ticks = 0;
duke@435 1287 delivered_ticks = 0;
duke@435 1288 timer.stop();
duke@435 1289 }
duke@435 1290
duke@435 1291 bool FlatProfiler::is_active() {
duke@435 1292 return task != NULL;
duke@435 1293 }
duke@435 1294
duke@435 1295 void FlatProfiler::print_byte_code_statistics() {
duke@435 1296 GrowableArray <ProfilerNode*>* array = new GrowableArray<ProfilerNode*>(200);
duke@435 1297
duke@435 1298 tty->print_cr(" Bytecode ticks:");
duke@435 1299 for (int index = 0; index < Bytecodes::number_of_codes; index++) {
duke@435 1300 if (FlatProfiler::bytecode_ticks[index] > 0 || FlatProfiler::bytecode_ticks_stub[index] > 0) {
duke@435 1301 tty->print_cr(" %4d %4d = %s",
duke@435 1302 FlatProfiler::bytecode_ticks[index],
duke@435 1303 FlatProfiler::bytecode_ticks_stub[index],
duke@435 1304 Bytecodes::name( (Bytecodes::Code) index));
duke@435 1305 }
duke@435 1306 }
duke@435 1307 tty->cr();
duke@435 1308 }
duke@435 1309
duke@435 1310 void print_ticks(const char* title, int ticks, int total) {
duke@435 1311 if (ticks > 0) {
duke@435 1312 tty->print("%5.1f%% %5d", ticks * 100.0 / total, ticks);
duke@435 1313 tty->fill_to(col3);
duke@435 1314 tty->print("%s", title);
duke@435 1315 tty->cr();
duke@435 1316 }
duke@435 1317 }
duke@435 1318
duke@435 1319 void ThreadProfiler::print(const char* thread_name) {
duke@435 1320 ResourceMark rm;
duke@435 1321 MutexLocker ppl(ProfilePrint_lock);
duke@435 1322 int index = 0; // Declared outside for loops for portability
duke@435 1323
duke@435 1324 if (table == NULL) {
duke@435 1325 return;
duke@435 1326 }
duke@435 1327
duke@435 1328 if (thread_ticks <= 0) {
duke@435 1329 return;
duke@435 1330 }
duke@435 1331
duke@435 1332 const char* title = "too soon to tell";
duke@435 1333 double secs = timer.seconds();
duke@435 1334
duke@435 1335 GrowableArray <ProfilerNode*>* array = new GrowableArray<ProfilerNode*>(200);
duke@435 1336 for(index = 0; index < table_size; index++) {
duke@435 1337 for(ProfilerNode* node = table[index]; node; node = node->next())
duke@435 1338 array->append(node);
duke@435 1339 }
duke@435 1340
duke@435 1341 array->sort(&ProfilerNode::compare);
duke@435 1342
duke@435 1343 // compute total (sanity check)
duke@435 1344 int active =
duke@435 1345 class_loader_ticks +
duke@435 1346 compiler_ticks +
duke@435 1347 interpreter_ticks +
duke@435 1348 unknown_ticks();
duke@435 1349 for (index = 0; index < array->length(); index++) {
duke@435 1350 active += array->at(index)->ticks.total();
duke@435 1351 }
duke@435 1352 int total = active + blocked_ticks;
duke@435 1353
duke@435 1354 tty->cr();
duke@435 1355 tty->print_cr("Flat profile of %3.2f secs (%d total ticks): %s", secs, total, thread_name);
duke@435 1356 if (total != thread_ticks) {
duke@435 1357 print_ticks("Lost ticks", thread_ticks-total, thread_ticks);
duke@435 1358 }
duke@435 1359 tty->cr();
duke@435 1360
duke@435 1361 // print interpreted methods
duke@435 1362 tick_counter interpreted_ticks;
duke@435 1363 bool has_interpreted_ticks = false;
duke@435 1364 int print_count = 0;
duke@435 1365 for (index = 0; index < array->length(); index++) {
duke@435 1366 ProfilerNode* n = array->at(index);
duke@435 1367 if (n->is_interpreted()) {
duke@435 1368 interpreted_ticks.add(&n->ticks);
duke@435 1369 if (!has_interpreted_ticks) {
duke@435 1370 interpretedNode::print_title(tty);
duke@435 1371 has_interpreted_ticks = true;
duke@435 1372 }
duke@435 1373 if (print_count++ < ProfilerNumberOfInterpretedMethods) {
duke@435 1374 n->print(tty, active);
duke@435 1375 }
duke@435 1376 }
duke@435 1377 }
duke@435 1378 if (has_interpreted_ticks) {
duke@435 1379 if (print_count <= ProfilerNumberOfInterpretedMethods) {
duke@435 1380 title = "Total interpreted";
duke@435 1381 } else {
duke@435 1382 title = "Total interpreted (including elided)";
duke@435 1383 }
duke@435 1384 interpretedNode::print_total(tty, &interpreted_ticks, active, title);
duke@435 1385 tty->cr();
duke@435 1386 }
duke@435 1387
duke@435 1388 // print compiled methods
duke@435 1389 tick_counter compiled_ticks;
duke@435 1390 bool has_compiled_ticks = false;
duke@435 1391 print_count = 0;
duke@435 1392 for (index = 0; index < array->length(); index++) {
duke@435 1393 ProfilerNode* n = array->at(index);
duke@435 1394 if (n->is_compiled()) {
duke@435 1395 compiled_ticks.add(&n->ticks);
duke@435 1396 if (!has_compiled_ticks) {
duke@435 1397 compiledNode::print_title(tty);
duke@435 1398 has_compiled_ticks = true;
duke@435 1399 }
duke@435 1400 if (print_count++ < ProfilerNumberOfCompiledMethods) {
duke@435 1401 n->print(tty, active);
duke@435 1402 }
duke@435 1403 }
duke@435 1404 }
duke@435 1405 if (has_compiled_ticks) {
duke@435 1406 if (print_count <= ProfilerNumberOfCompiledMethods) {
duke@435 1407 title = "Total compiled";
duke@435 1408 } else {
duke@435 1409 title = "Total compiled (including elided)";
duke@435 1410 }
duke@435 1411 compiledNode::print_total(tty, &compiled_ticks, active, title);
duke@435 1412 tty->cr();
duke@435 1413 }
duke@435 1414
duke@435 1415 // print stub methods
duke@435 1416 tick_counter stub_ticks;
duke@435 1417 bool has_stub_ticks = false;
duke@435 1418 print_count = 0;
duke@435 1419 for (index = 0; index < array->length(); index++) {
duke@435 1420 ProfilerNode* n = array->at(index);
duke@435 1421 if (n->is_stub()) {
duke@435 1422 stub_ticks.add(&n->ticks);
duke@435 1423 if (!has_stub_ticks) {
duke@435 1424 stubNode::print_title(tty);
duke@435 1425 has_stub_ticks = true;
duke@435 1426 }
duke@435 1427 if (print_count++ < ProfilerNumberOfStubMethods) {
duke@435 1428 n->print(tty, active);
duke@435 1429 }
duke@435 1430 }
duke@435 1431 }
duke@435 1432 if (has_stub_ticks) {
duke@435 1433 if (print_count <= ProfilerNumberOfStubMethods) {
duke@435 1434 title = "Total stub";
duke@435 1435 } else {
duke@435 1436 title = "Total stub (including elided)";
duke@435 1437 }
duke@435 1438 stubNode::print_total(tty, &stub_ticks, active, title);
duke@435 1439 tty->cr();
duke@435 1440 }
duke@435 1441
duke@435 1442 // print runtime stubs
duke@435 1443 tick_counter runtime_stub_ticks;
duke@435 1444 bool has_runtime_stub_ticks = false;
duke@435 1445 print_count = 0;
duke@435 1446 for (index = 0; index < array->length(); index++) {
duke@435 1447 ProfilerNode* n = array->at(index);
duke@435 1448 if (n->is_runtime_stub()) {
duke@435 1449 runtime_stub_ticks.add(&n->ticks);
duke@435 1450 if (!has_runtime_stub_ticks) {
duke@435 1451 runtimeStubNode::print_title(tty);
duke@435 1452 has_runtime_stub_ticks = true;
duke@435 1453 }
duke@435 1454 if (print_count++ < ProfilerNumberOfRuntimeStubNodes) {
duke@435 1455 n->print(tty, active);
duke@435 1456 }
duke@435 1457 }
duke@435 1458 }
duke@435 1459 if (has_runtime_stub_ticks) {
duke@435 1460 if (print_count <= ProfilerNumberOfRuntimeStubNodes) {
duke@435 1461 title = "Total runtime stubs";
duke@435 1462 } else {
duke@435 1463 title = "Total runtime stubs (including elided)";
duke@435 1464 }
duke@435 1465 runtimeStubNode::print_total(tty, &runtime_stub_ticks, active, title);
duke@435 1466 tty->cr();
duke@435 1467 }
duke@435 1468
duke@435 1469 if (blocked_ticks + class_loader_ticks + interpreter_ticks + compiler_ticks + unknown_ticks() != 0) {
duke@435 1470 tty->fill_to(col1);
duke@435 1471 tty->print_cr("Thread-local ticks:");
duke@435 1472 print_ticks("Blocked (of total)", blocked_ticks, total);
duke@435 1473 print_ticks("Class loader", class_loader_ticks, active);
duke@435 1474 print_ticks("Extra", extra_ticks, active);
duke@435 1475 print_ticks("Interpreter", interpreter_ticks, active);
duke@435 1476 print_ticks("Compilation", compiler_ticks, active);
duke@435 1477 print_ticks("Unknown: vtable stubs", unknown_ticks_array[ut_vtable_stubs], active);
duke@435 1478 print_ticks("Unknown: null method", unknown_ticks_array[ut_null_method], active);
duke@435 1479 print_ticks("Unknown: running frame", unknown_ticks_array[ut_running_frame], active);
duke@435 1480 print_ticks("Unknown: calling frame", unknown_ticks_array[ut_calling_frame], active);
duke@435 1481 print_ticks("Unknown: no pc", unknown_ticks_array[ut_no_pc], active);
duke@435 1482 print_ticks("Unknown: no last frame", unknown_ticks_array[ut_no_last_Java_frame], active);
duke@435 1483 print_ticks("Unknown: thread_state", unknown_ticks_array[ut_unknown_thread_state], active);
duke@435 1484 tty->cr();
duke@435 1485 }
duke@435 1486
duke@435 1487 if (WizardMode) {
duke@435 1488 tty->print_cr("Node area used: %dKb", (area_top - area_bottom) / 1024);
duke@435 1489 }
duke@435 1490 reset();
duke@435 1491 }
duke@435 1492
duke@435 1493 /*
duke@435 1494 ThreadProfiler::print_unknown(){
duke@435 1495 if (table == NULL) {
duke@435 1496 return;
duke@435 1497 }
duke@435 1498
duke@435 1499 if (thread_ticks <= 0) {
duke@435 1500 return;
duke@435 1501 }
duke@435 1502 } */
duke@435 1503
duke@435 1504 void FlatProfiler::print(int unused) {
duke@435 1505 ResourceMark rm;
duke@435 1506 if (thread_profiler != NULL) {
duke@435 1507 thread_profiler->print("All threads");
duke@435 1508 } else {
duke@435 1509 MutexLocker tl(Threads_lock);
duke@435 1510 for (JavaThread* tp = Threads::first(); tp != NULL; tp = tp->next()) {
duke@435 1511 ThreadProfiler* pp = tp->get_thread_profiler();
duke@435 1512 if (pp != NULL) {
duke@435 1513 pp->print(tp->get_thread_name());
duke@435 1514 }
duke@435 1515 }
duke@435 1516 }
duke@435 1517
duke@435 1518 if (ProfilerPrintByteCodeStatistics) {
duke@435 1519 print_byte_code_statistics();
duke@435 1520 }
duke@435 1521
duke@435 1522 if (non_method_ticks() > 0) {
duke@435 1523 tty->cr();
duke@435 1524 tty->print_cr("Global summary of %3.2f seconds:", timer.seconds());
duke@435 1525 print_ticks("Received ticks", received_ticks, received_ticks);
duke@435 1526 print_ticks("Received GC ticks", received_gc_ticks, received_ticks);
duke@435 1527 print_ticks("Compilation", compiler_ticks, received_ticks);
duke@435 1528 print_ticks("Deoptimization", deopt_ticks, received_ticks);
duke@435 1529 print_ticks("Other VM operations", vm_operation_ticks, received_ticks);
duke@435 1530 #ifndef PRODUCT
duke@435 1531 print_ticks("Blocked ticks", blocked_ticks, received_ticks);
duke@435 1532 print_ticks("Threads_lock blocks", threads_lock_ticks, received_ticks);
duke@435 1533 print_ticks("Delivered ticks", delivered_ticks, received_ticks);
duke@435 1534 print_ticks("All ticks", all_ticks, received_ticks);
duke@435 1535 #endif
duke@435 1536 print_ticks("Class loader", class_loader_ticks, received_ticks);
duke@435 1537 print_ticks("Extra ", extra_ticks, received_ticks);
duke@435 1538 print_ticks("Interpreter", interpreter_ticks, received_ticks);
duke@435 1539 print_ticks("Unknown code", unknown_ticks, received_ticks);
duke@435 1540 }
duke@435 1541
duke@435 1542 PCRecorder::print();
duke@435 1543
duke@435 1544 if(ProfileVM){
duke@435 1545 tty->cr();
duke@435 1546 vm_thread_profiler->print("VM Thread");
duke@435 1547 }
duke@435 1548 }
duke@435 1549
duke@435 1550 void IntervalData::print_header(outputStream* st) {
duke@435 1551 st->print("i/c/n/g");
duke@435 1552 }
duke@435 1553
duke@435 1554 void IntervalData::print_data(outputStream* st) {
duke@435 1555 st->print("%d/%d/%d/%d", interpreted(), compiled(), native(), compiling());
duke@435 1556 }
duke@435 1557
duke@435 1558 void FlatProfiler::interval_record_thread(ThreadProfiler* tp) {
duke@435 1559 IntervalData id = tp->interval_data();
duke@435 1560 int total = id.total();
duke@435 1561 tp->interval_data_ref()->reset();
duke@435 1562
duke@435 1563 // Insertion sort the data, if it's relevant.
duke@435 1564 for (int i = 0; i < interval_print_size; i += 1) {
duke@435 1565 if (total > interval_data[i].total()) {
duke@435 1566 for (int j = interval_print_size - 1; j > i; j -= 1) {
duke@435 1567 interval_data[j] = interval_data[j-1];
duke@435 1568 }
duke@435 1569 interval_data[i] = id;
duke@435 1570 break;
duke@435 1571 }
duke@435 1572 }
duke@435 1573 }
duke@435 1574
duke@435 1575 void FlatProfiler::interval_print() {
duke@435 1576 if ((interval_data[0].total() > 0)) {
duke@435 1577 tty->stamp();
duke@435 1578 tty->print("\t");
duke@435 1579 IntervalData::print_header(tty);
duke@435 1580 for (int i = 0; i < interval_print_size; i += 1) {
duke@435 1581 if (interval_data[i].total() > 0) {
duke@435 1582 tty->print("\t");
duke@435 1583 interval_data[i].print_data(tty);
duke@435 1584 }
duke@435 1585 }
duke@435 1586 tty->cr();
duke@435 1587 }
duke@435 1588 }
duke@435 1589
duke@435 1590 void FlatProfiler::interval_reset() {
duke@435 1591 for (int i = 0; i < interval_print_size; i += 1) {
duke@435 1592 interval_data[i].reset();
duke@435 1593 }
duke@435 1594 }
duke@435 1595
duke@435 1596 void ThreadProfiler::oops_do(OopClosure* f) {
duke@435 1597 if (table == NULL) return;
duke@435 1598
duke@435 1599 for(int index = 0; index < table_size; index++) {
duke@435 1600 for(ProfilerNode* node = table[index]; node; node = node->next())
duke@435 1601 node->oops_do(f);
duke@435 1602 }
duke@435 1603 }
duke@435 1604
duke@435 1605 void FlatProfiler::oops_do(OopClosure* f) {
duke@435 1606 if (thread_profiler != NULL) {
duke@435 1607 thread_profiler->oops_do(f);
duke@435 1608 } else {
duke@435 1609 for (JavaThread* tp = Threads::first(); tp != NULL; tp = tp->next()) {
duke@435 1610 ThreadProfiler* pp = tp->get_thread_profiler();
duke@435 1611 if (pp != NULL) {
duke@435 1612 pp->oops_do(f);
duke@435 1613 }
duke@435 1614 }
duke@435 1615 }
duke@435 1616 }

mercurial