annotate src/share/vm/prims/jvmtiTrace.cpp @ 452:00b023ae2d78

6722113: CMS: Incorrect overflow handling during precleaning of Reference lists Summary: When we encounter marking stack overflow during precleaning of Reference lists, we were using the overflow list mechanism, which can cause problems on account of mutating the mark word of the header because of conflicts with mutator accesses and updates of that field. Instead we should use the usual mechanism for overflow handling in concurrent phases, namely dirtying of the card on which the overflowed object lies. Since precleaning effectively does a form of discovered list processing, albeit with discovery enabled, we needed to adjust some code to be correct in the face of interleaved processing and discovery. Reviewed-by: apetrusenko, jcoomes
author ysr
date Thu, 20 Nov 2008 12:27:41 -0800
parents 885fe0f95828
children ad8c8ca4ab0f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved.
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 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 # include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 # include "incls/_jvmtiTrace.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 //
a61af66fc99e Initial load
duke
parents:
diff changeset
29 // class JvmtiTrace
a61af66fc99e Initial load
duke
parents:
diff changeset
30 //
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // Support for JVMTI tracing code
a61af66fc99e Initial load
duke
parents:
diff changeset
32 //
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // ------------
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // Usage:
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // -XX:TraceJVMTI=DESC,DESC,DESC
a61af66fc99e Initial load
duke
parents:
diff changeset
36 //
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // DESC is DOMAIN ACTION KIND
a61af66fc99e Initial load
duke
parents:
diff changeset
38 //
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // DOMAIN is function name
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // event name
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // "all" (all functions and events)
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // "func" (all functions except boring)
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // "allfunc" (all functions)
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // "event" (all events)
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // "ec" (event controller)
a61af66fc99e Initial load
duke
parents:
diff changeset
46 //
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // ACTION is "+" (add)
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // "-" (remove)
a61af66fc99e Initial load
duke
parents:
diff changeset
49 //
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // KIND is
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // for func
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // "i" (input params)
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // "e" (error returns)
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // "o" (output)
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // for event
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // "t" (event triggered aka posted)
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // "s" (event sent)
a61af66fc99e Initial load
duke
parents:
diff changeset
58 //
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // Example:
a61af66fc99e Initial load
duke
parents:
diff changeset
60 // -XX:TraceJVMTI=ec+,GetCallerFrame+ie,Breakpoint+s
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 #ifdef JVMTI_TRACE
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 bool JvmtiTrace::_initialized = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 bool JvmtiTrace::_on = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 bool JvmtiTrace::_trace_event_controller = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 void JvmtiTrace::initialize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 if (_initialized) {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72 SafeResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 const char *very_end;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 const char *curr;
370
885fe0f95828 6744783: HotSpot segfaults if given -XX options with an empty string argument
never
parents: 0
diff changeset
76 if (TraceJVMTI != NULL) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
77 curr = TraceJVMTI;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
79 curr = ""; // hack in fixed tracing here
a61af66fc99e Initial load
duke
parents:
diff changeset
80 }
a61af66fc99e Initial load
duke
parents:
diff changeset
81 very_end = curr + strlen(curr);
a61af66fc99e Initial load
duke
parents:
diff changeset
82 while (curr < very_end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 const char *curr_end = strchr(curr, ',');
a61af66fc99e Initial load
duke
parents:
diff changeset
84 if (curr_end == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 curr_end = very_end;
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87 const char *op_pos = strchr(curr, '+');
a61af66fc99e Initial load
duke
parents:
diff changeset
88 const char *minus_pos = strchr(curr, '-');
a61af66fc99e Initial load
duke
parents:
diff changeset
89 if (minus_pos != NULL && (minus_pos < op_pos || op_pos == NULL)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 op_pos = minus_pos;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92 char op;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 const char *flags = op_pos + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
94 const char *flags_end = curr_end;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 if (op_pos == NULL || op_pos > curr_end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 flags = "ies";
a61af66fc99e Initial load
duke
parents:
diff changeset
97 flags_end = flags + strlen(flags);
a61af66fc99e Initial load
duke
parents:
diff changeset
98 op_pos = curr_end;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 op = '+';
a61af66fc99e Initial load
duke
parents:
diff changeset
100 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 op = *op_pos;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 }
a61af66fc99e Initial load
duke
parents:
diff changeset
103 jbyte bits = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 for (; flags < flags_end; ++flags) {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 switch (*flags) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 case 'i':
a61af66fc99e Initial load
duke
parents:
diff changeset
107 bits |= SHOW_IN;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 case 'I':
a61af66fc99e Initial load
duke
parents:
diff changeset
110 bits |= SHOW_IN_DETAIL;
a61af66fc99e Initial load
duke
parents:
diff changeset
111 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 case 'e':
a61af66fc99e Initial load
duke
parents:
diff changeset
113 bits |= SHOW_ERROR;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 case 'o':
a61af66fc99e Initial load
duke
parents:
diff changeset
116 bits |= SHOW_OUT;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 case 'O':
a61af66fc99e Initial load
duke
parents:
diff changeset
119 bits |= SHOW_OUT_DETAIL;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
121 case 't':
a61af66fc99e Initial load
duke
parents:
diff changeset
122 bits |= SHOW_EVENT_TRIGGER;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
124 case 's':
a61af66fc99e Initial load
duke
parents:
diff changeset
125 bits |= SHOW_EVENT_SENT;
a61af66fc99e Initial load
duke
parents:
diff changeset
126 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
127 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
128 tty->print_cr("Invalid trace flag '%c'", *flags);
a61af66fc99e Initial load
duke
parents:
diff changeset
129 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132 const int FUNC = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 const int EXCLUDE = 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
134 const int ALL_FUNC = 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
135 const int EVENT = 8;
a61af66fc99e Initial load
duke
parents:
diff changeset
136 const int ALL_EVENT = 16;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 int domain = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
138 size_t len = op_pos - curr;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 if (op_pos == curr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 domain = ALL_FUNC | FUNC | ALL_EVENT | EVENT | EXCLUDE;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 } else if (len==3 && strncmp(curr, "all", 3)==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 domain = ALL_FUNC | FUNC | ALL_EVENT | EVENT;
a61af66fc99e Initial load
duke
parents:
diff changeset
143 } else if (len==7 && strncmp(curr, "allfunc", 7)==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 domain = ALL_FUNC | FUNC;
a61af66fc99e Initial load
duke
parents:
diff changeset
145 } else if (len==4 && strncmp(curr, "func", 4)==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 domain = ALL_FUNC | FUNC | EXCLUDE;
a61af66fc99e Initial load
duke
parents:
diff changeset
147 } else if (len==8 && strncmp(curr, "allevent", 8)==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 domain = ALL_EVENT | EVENT;
a61af66fc99e Initial load
duke
parents:
diff changeset
149 } else if (len==5 && strncmp(curr, "event", 5)==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 domain = ALL_EVENT | EVENT;
a61af66fc99e Initial load
duke
parents:
diff changeset
151 } else if (len==2 && strncmp(curr, "ec", 2)==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 _trace_event_controller = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
153 tty->print_cr("JVMTI Tracing the event controller");
a61af66fc99e Initial load
duke
parents:
diff changeset
154 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 domain = FUNC | EVENT; // go searching
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 int exclude_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
159 if (domain & FUNC) {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 if (domain & ALL_FUNC) {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 if (domain & EXCLUDE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 tty->print("JVMTI Tracing all significant functions");
a61af66fc99e Initial load
duke
parents:
diff changeset
163 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 tty->print_cr("JVMTI Tracing all functions");
a61af66fc99e Initial load
duke
parents:
diff changeset
165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167 for (int i = 0; i <= _max_function_index; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
168 if (domain & EXCLUDE && i == _exclude_functions[exclude_index]) {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 ++exclude_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
170 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
171 bool do_op = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
172 if (domain & ALL_FUNC) {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 do_op = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
174 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 const char *fname = function_name(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
176 if (fname != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 size_t fnlen = strlen(fname);
a61af66fc99e Initial load
duke
parents:
diff changeset
178 if (len==fnlen && strncmp(curr, fname, fnlen)==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 tty->print_cr("JVMTI Tracing the function: %s", fname);
a61af66fc99e Initial load
duke
parents:
diff changeset
180 do_op = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
181 }
a61af66fc99e Initial load
duke
parents:
diff changeset
182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184 if (do_op) {
a61af66fc99e Initial load
duke
parents:
diff changeset
185 if (op == '+') {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 _trace_flags[i] |= bits;
a61af66fc99e Initial load
duke
parents:
diff changeset
187 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 _trace_flags[i] &= ~bits;
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190 _on = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192 }
a61af66fc99e Initial load
duke
parents:
diff changeset
193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195 if (domain & EVENT) {
a61af66fc99e Initial load
duke
parents:
diff changeset
196 if (domain & ALL_EVENT) {
a61af66fc99e Initial load
duke
parents:
diff changeset
197 tty->print_cr("JVMTI Tracing all events");
a61af66fc99e Initial load
duke
parents:
diff changeset
198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
199 for (int i = 0; i <= _max_event_index; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
200 bool do_op = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
201 if (domain & ALL_EVENT) {
a61af66fc99e Initial load
duke
parents:
diff changeset
202 do_op = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
203 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
204 const char *ename = event_name(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 if (ename != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 size_t evtlen = strlen(ename);
a61af66fc99e Initial load
duke
parents:
diff changeset
207 if (len==evtlen && strncmp(curr, ename, evtlen)==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
208 tty->print_cr("JVMTI Tracing the event: %s", ename);
a61af66fc99e Initial load
duke
parents:
diff changeset
209 do_op = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
210 }
a61af66fc99e Initial load
duke
parents:
diff changeset
211 }
a61af66fc99e Initial load
duke
parents:
diff changeset
212 }
a61af66fc99e Initial load
duke
parents:
diff changeset
213 if (do_op) {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 if (op == '+') {
a61af66fc99e Initial load
duke
parents:
diff changeset
215 _event_trace_flags[i] |= bits;
a61af66fc99e Initial load
duke
parents:
diff changeset
216 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
217 _event_trace_flags[i] &= ~bits;
a61af66fc99e Initial load
duke
parents:
diff changeset
218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
219 _on = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
222 }
a61af66fc99e Initial load
duke
parents:
diff changeset
223 if (!_on && (domain & (FUNC|EVENT))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
224 tty->print_cr("JVMTI Trace domain not found");
a61af66fc99e Initial load
duke
parents:
diff changeset
225 }
a61af66fc99e Initial load
duke
parents:
diff changeset
226 curr = curr_end + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
227 }
a61af66fc99e Initial load
duke
parents:
diff changeset
228 _initialized = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
230
a61af66fc99e Initial load
duke
parents:
diff changeset
231
a61af66fc99e Initial load
duke
parents:
diff changeset
232 void JvmtiTrace::shutdown() {
a61af66fc99e Initial load
duke
parents:
diff changeset
233 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
234 _on = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
235 _trace_event_controller = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
236 for (i = 0; i <= _max_function_index; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
237 _trace_flags[i] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
238 }
a61af66fc99e Initial load
duke
parents:
diff changeset
239 for (i = 0; i <= _max_event_index; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
240 _event_trace_flags[i] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
241 }
a61af66fc99e Initial load
duke
parents:
diff changeset
242 }
a61af66fc99e Initial load
duke
parents:
diff changeset
243
a61af66fc99e Initial load
duke
parents:
diff changeset
244
a61af66fc99e Initial load
duke
parents:
diff changeset
245 const char* JvmtiTrace::enum_name(const char** names, const jint* values, jint value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
246 for (int index = 0; names[index] != 0; ++index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
247 if (values[index] == value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
248 return names[index];
a61af66fc99e Initial load
duke
parents:
diff changeset
249 }
a61af66fc99e Initial load
duke
parents:
diff changeset
250 }
a61af66fc99e Initial load
duke
parents:
diff changeset
251 return "*INVALID-ENUM-VALUE*";
a61af66fc99e Initial load
duke
parents:
diff changeset
252 }
a61af66fc99e Initial load
duke
parents:
diff changeset
253
a61af66fc99e Initial load
duke
parents:
diff changeset
254
a61af66fc99e Initial load
duke
parents:
diff changeset
255 // return a valid string no matter what state the thread is in
a61af66fc99e Initial load
duke
parents:
diff changeset
256 const char *JvmtiTrace::safe_get_thread_name(Thread *thread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
257 if (thread == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 return "NULL";
a61af66fc99e Initial load
duke
parents:
diff changeset
259 }
a61af66fc99e Initial load
duke
parents:
diff changeset
260 if (!thread->is_Java_thread()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
261 return thread->name();
a61af66fc99e Initial load
duke
parents:
diff changeset
262 }
a61af66fc99e Initial load
duke
parents:
diff changeset
263 JavaThread *java_thread = (JavaThread *)thread;
a61af66fc99e Initial load
duke
parents:
diff changeset
264 oop threadObj = java_thread->threadObj();
a61af66fc99e Initial load
duke
parents:
diff changeset
265 if (threadObj == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
266 return "NULL";
a61af66fc99e Initial load
duke
parents:
diff changeset
267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
268 typeArrayOop name = java_lang_Thread::name(threadObj);
a61af66fc99e Initial load
duke
parents:
diff changeset
269 if (name == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
270 return "<NOT FILLED IN>";
a61af66fc99e Initial load
duke
parents:
diff changeset
271 }
a61af66fc99e Initial load
duke
parents:
diff changeset
272 return UNICODE::as_utf8((jchar*) name->base(T_CHAR), name->length());
a61af66fc99e Initial load
duke
parents:
diff changeset
273 }
a61af66fc99e Initial load
duke
parents:
diff changeset
274
a61af66fc99e Initial load
duke
parents:
diff changeset
275
a61af66fc99e Initial load
duke
parents:
diff changeset
276 // return the name of the current thread
a61af66fc99e Initial load
duke
parents:
diff changeset
277 const char *JvmtiTrace::safe_get_current_thread_name() {
a61af66fc99e Initial load
duke
parents:
diff changeset
278 if (JvmtiEnv::is_vm_live()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
279 return JvmtiTrace::safe_get_thread_name(Thread::current());
a61af66fc99e Initial load
duke
parents:
diff changeset
280 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
281 return "VM not live";
a61af66fc99e Initial load
duke
parents:
diff changeset
282 }
a61af66fc99e Initial load
duke
parents:
diff changeset
283 }
a61af66fc99e Initial load
duke
parents:
diff changeset
284
a61af66fc99e Initial load
duke
parents:
diff changeset
285 // return a valid string no matter what the state of k_mirror
a61af66fc99e Initial load
duke
parents:
diff changeset
286 const char * JvmtiTrace::get_class_name(oop k_mirror) {
a61af66fc99e Initial load
duke
parents:
diff changeset
287 if (java_lang_Class::is_primitive(k_mirror)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
288 return "primitive";
a61af66fc99e Initial load
duke
parents:
diff changeset
289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
290 klassOop k_oop = java_lang_Class::as_klassOop(k_mirror);
a61af66fc99e Initial load
duke
parents:
diff changeset
291 if (k_oop == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
292 return "INVALID";
a61af66fc99e Initial load
duke
parents:
diff changeset
293 }
a61af66fc99e Initial load
duke
parents:
diff changeset
294 return Klass::cast(k_oop)->external_name();
a61af66fc99e Initial load
duke
parents:
diff changeset
295 }
a61af66fc99e Initial load
duke
parents:
diff changeset
296
a61af66fc99e Initial load
duke
parents:
diff changeset
297 #endif /*JVMTI_TRACE */