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