annotate src/share/vm/runtime/fprofiler.cpp @ 20197:ce8f6bb717c9

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