1 /*
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
249 return names[index];
250 }
251 }
252 return "*INVALID-ENUM-VALUE*";
253 }
254
255
256 // return a valid string no matter what state the thread is in
257 const char *JvmtiTrace::safe_get_thread_name(Thread *thread) {
258 if (thread == NULL) {
259 return "NULL";
260 }
261 if (!thread->is_Java_thread()) {
262 return thread->name();
263 }
264 JavaThread *java_thread = (JavaThread *)thread;
265 oop threadObj = java_thread->threadObj();
266 if (threadObj == NULL) {
267 return "NULL";
268 }
269 typeArrayOop name = java_lang_Thread::name(threadObj);
270 if (name == NULL) {
271 return "<NOT FILLED IN>";
272 }
273 return UNICODE::as_utf8((jchar*) name->base(T_CHAR), name->length());
274 }
275
276
277 // return the name of the current thread
278 const char *JvmtiTrace::safe_get_current_thread_name() {
279 if (JvmtiEnv::is_vm_live()) {
280 return JvmtiTrace::safe_get_thread_name(Thread::current());
281 } else {
282 return "VM not live";
283 }
284 }
285
286 // return a valid string no matter what the state of k_mirror
287 const char * JvmtiTrace::get_class_name(oop k_mirror) {
288 if (java_lang_Class::is_primitive(k_mirror)) {
289 return "primitive";
290 }
291 Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
292 if (k_oop == NULL) {
293 return "INVALID";
|
1 /*
2 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
249 return names[index];
250 }
251 }
252 return "*INVALID-ENUM-VALUE*";
253 }
254
255
256 // return a valid string no matter what state the thread is in
257 const char *JvmtiTrace::safe_get_thread_name(Thread *thread) {
258 if (thread == NULL) {
259 return "NULL";
260 }
261 if (!thread->is_Java_thread()) {
262 return thread->name();
263 }
264 JavaThread *java_thread = (JavaThread *)thread;
265 oop threadObj = java_thread->threadObj();
266 if (threadObj == NULL) {
267 return "NULL";
268 }
269 oop name = java_lang_Thread::name(threadObj);
270 if (name == NULL) {
271 return "<NOT FILLED IN>";
272 }
273 return java_lang_String::as_utf8_string(name);
274 }
275
276
277 // return the name of the current thread
278 const char *JvmtiTrace::safe_get_current_thread_name() {
279 if (JvmtiEnv::is_vm_live()) {
280 return JvmtiTrace::safe_get_thread_name(Thread::current());
281 } else {
282 return "VM not live";
283 }
284 }
285
286 // return a valid string no matter what the state of k_mirror
287 const char * JvmtiTrace::get_class_name(oop k_mirror) {
288 if (java_lang_Class::is_primitive(k_mirror)) {
289 return "primitive";
290 }
291 Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
292 if (k_oop == NULL) {
293 return "INVALID";
|