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