src/share/vm/prims/jvmtiEnv.cpp

Print this page




 925 // thread - NOT pre-checked
 926 // info_ptr - pre-checked for NULL
 927 jvmtiError
 928 JvmtiEnv::GetThreadInfo(jthread thread, jvmtiThreadInfo* info_ptr) {
 929   ResourceMark rm;
 930   HandleMark hm;
 931 
 932   JavaThread* current_thread = JavaThread::current();
 933 
 934   // if thread is NULL the current thread is used
 935   oop thread_oop;
 936   if (thread == NULL) {
 937     thread_oop = current_thread->threadObj();
 938   } else {
 939     thread_oop = JNIHandles::resolve_external_guard(thread);
 940   }
 941   if (thread_oop == NULL || !thread_oop->is_a(SystemDictionary::Thread_klass()))
 942     return JVMTI_ERROR_INVALID_THREAD;
 943 
 944   Handle thread_obj(current_thread, thread_oop);
 945   typeArrayHandle    name;
 946   ThreadPriority priority;
 947   Handle     thread_group;
 948   Handle context_class_loader;
 949   bool          is_daemon;
 950 
 951   { MutexLocker mu(Threads_lock);
 952 
 953     name = typeArrayHandle(current_thread, java_lang_Thread::name(thread_obj()));
 954     priority = java_lang_Thread::priority(thread_obj());
 955     thread_group = Handle(current_thread, java_lang_Thread::threadGroup(thread_obj()));
 956     is_daemon = java_lang_Thread::is_daemon(thread_obj());
 957 
 958     oop loader = java_lang_Thread::context_class_loader(thread_obj());
 959     context_class_loader = Handle(current_thread, loader);
 960   }
 961   { const char *n;
 962 
 963     if (name() != NULL) {
 964       n = UNICODE::as_utf8((jchar*) name->base(T_CHAR), name->length());
 965     } else {
 966       n = UNICODE::as_utf8(NULL, 0);
 967     }
 968 
 969     info_ptr->name = (char *) jvmtiMalloc(strlen(n)+1);
 970     if (info_ptr->name == NULL)
 971       return JVMTI_ERROR_OUT_OF_MEMORY;
 972 
 973     strcpy(info_ptr->name, n);
 974   }
 975   info_ptr->is_daemon = is_daemon;
 976   info_ptr->priority  = priority;
 977 
 978   info_ptr->context_class_loader = (context_class_loader.is_null()) ? NULL :
 979                                      jni_reference(context_class_loader);
 980   info_ptr->thread_group = jni_reference(thread_group);
 981 
 982   return JVMTI_ERROR_NONE;
 983 } /* end GetThreadInfo */
 984 




 925 // thread - NOT pre-checked
 926 // info_ptr - pre-checked for NULL
 927 jvmtiError
 928 JvmtiEnv::GetThreadInfo(jthread thread, jvmtiThreadInfo* info_ptr) {
 929   ResourceMark rm;
 930   HandleMark hm;
 931 
 932   JavaThread* current_thread = JavaThread::current();
 933 
 934   // if thread is NULL the current thread is used
 935   oop thread_oop;
 936   if (thread == NULL) {
 937     thread_oop = current_thread->threadObj();
 938   } else {
 939     thread_oop = JNIHandles::resolve_external_guard(thread);
 940   }
 941   if (thread_oop == NULL || !thread_oop->is_a(SystemDictionary::Thread_klass()))
 942     return JVMTI_ERROR_INVALID_THREAD;
 943 
 944   Handle thread_obj(current_thread, thread_oop);
 945   Handle name;
 946   ThreadPriority priority;
 947   Handle     thread_group;
 948   Handle context_class_loader;
 949   bool          is_daemon;
 950 
 951   { MutexLocker mu(Threads_lock);
 952 
 953     name = Handle(current_thread, java_lang_Thread::name(thread_obj()));
 954     priority = java_lang_Thread::priority(thread_obj());
 955     thread_group = Handle(current_thread, java_lang_Thread::threadGroup(thread_obj()));
 956     is_daemon = java_lang_Thread::is_daemon(thread_obj());
 957 
 958     oop loader = java_lang_Thread::context_class_loader(thread_obj());
 959     context_class_loader = Handle(current_thread, loader);
 960   }
 961   { const char *n;
 962 
 963     if (name() != NULL) {
 964       n = java_lang_String::as_utf8_string(name());
 965     } else {
 966       n = UNICODE::as_utf8(NULL, 0);
 967     }
 968 
 969     info_ptr->name = (char *) jvmtiMalloc(strlen(n)+1);
 970     if (info_ptr->name == NULL)
 971       return JVMTI_ERROR_OUT_OF_MEMORY;
 972 
 973     strcpy(info_ptr->name, n);
 974   }
 975   info_ptr->is_daemon = is_daemon;
 976   info_ptr->priority  = priority;
 977 
 978   info_ptr->context_class_loader = (context_class_loader.is_null()) ? NULL :
 979                                      jni_reference(context_class_loader);
 980   info_ptr->thread_group = jni_reference(thread_group);
 981 
 982   return JVMTI_ERROR_NONE;
 983 } /* end GetThreadInfo */
 984