< prev index next >

src/hotspot/share/jfr/recorder/checkpoint/types/jfrThreadState.cpp

Print this page

 67   },
 68   {
 69     (JVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_WAITING | JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT | JVMTI_THREAD_STATE_PARKED),
 70     "STATE_PARKED_TIMED"
 71   },
 72   {
 73     JVMTI_JAVA_LANG_THREAD_STATE_BLOCKED,
 74     "STATE_BLOCKED_ON_MONITOR_ENTER"
 75   }
 76 };
 77 
 78 void JfrThreadState::serialize(JfrCheckpointWriter& writer) {
 79   const u4 number_of_states = sizeof(states) / sizeof(jvmti_thread_state);
 80   writer.write_count(number_of_states);
 81   for (u4 i = 0; i < number_of_states; ++i) {
 82     writer.write_key(states[i].id);
 83     writer.write(states[i].description);
 84   }
 85 }
 86 
 87 traceid JfrThreadId::id(const Thread* t) {
 88   assert(t != NULL, "invariant");
 89   if (!t->is_Java_thread()) {
 90     return os_id(t);
 91   }



 92   const oop thread_obj = JavaThread::cast(t)->threadObj();
 93   return thread_obj != NULL ? java_lang_Thread::thread_id(thread_obj) : 0;
 94 }
 95 
 96 traceid JfrThreadId::os_id(const Thread* t) {
 97   assert(t != NULL, "invariant");
 98   const OSThread* const os_thread = t->osthread();
 99   return os_thread != NULL ? os_thread->thread_id() : 0;
100 }
101 
102 traceid JfrThreadId::jfr_id(const Thread* t) {
103   assert(t != NULL, "invariant");
104   return t->jfr_thread_local()->thread_id();
105 }
106 
107 // caller needs ResourceMark
108 const char* get_java_thread_name(const JavaThread* jt) {
109   assert(jt != NULL, "invariant");
110   const char* name_str = "<no-name - thread name unresolved>";
111   const oop thread_obj = jt->threadObj();
112   if (thread_obj != NULL) {




113     const oop name = java_lang_Thread::name(thread_obj);
114     if (name != NULL) {
115       name_str = java_lang_String::as_utf8_string(name);
116     }
117   } else if (jt->is_attaching_via_jni()) {
118     name_str = "<no-name - thread is attaching>";
119   }
120   assert(name_str != NULL, "unexpected NULL thread name");
121   return name_str;
122 }
123 
124 const char* JfrThreadName::name(const Thread* t) {
125   assert(t != NULL, "invariant");
126   return t->is_Java_thread() ? get_java_thread_name(JavaThread::cast(t)) : t->name();
127 }

 67   },
 68   {
 69     (JVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_WAITING | JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT | JVMTI_THREAD_STATE_PARKED),
 70     "STATE_PARKED_TIMED"
 71   },
 72   {
 73     JVMTI_JAVA_LANG_THREAD_STATE_BLOCKED,
 74     "STATE_BLOCKED_ON_MONITOR_ENTER"
 75   }
 76 };
 77 
 78 void JfrThreadState::serialize(JfrCheckpointWriter& writer) {
 79   const u4 number_of_states = sizeof(states) / sizeof(jvmti_thread_state);
 80   writer.write_count(number_of_states);
 81   for (u4 i = 0; i < number_of_states; ++i) {
 82     writer.write_key(states[i].id);
 83     writer.write(states[i].description);
 84   }
 85 }
 86 
 87 traceid JfrThreadId::id(const Thread* t, oop vthread) {
 88   assert(t != NULL, "invariant");
 89   if (!t->is_Java_thread()) {
 90     return os_id(t);
 91   }
 92   if (vthread != NULL) {
 93     return java_lang_Thread::thread_id(vthread);
 94   }
 95   const oop thread_obj = JavaThread::cast(t)->threadObj();
 96   return thread_obj != NULL ? java_lang_Thread::thread_id(thread_obj) : 0;
 97 }
 98 
 99 traceid JfrThreadId::os_id(const Thread* t) {
100   assert(t != NULL, "invariant");
101   const OSThread* const os_thread = t->osthread();
102   return os_thread != NULL ? os_thread->thread_id() : 0;
103 }
104 
105 traceid JfrThreadId::jfr_id(const Thread* t, traceid tid) {
106   assert(t != NULL, "invariant");
107   return tid != 0 ? tid : JfrThreadLocal::vm_thread_id(t);
108 }
109 
110 // caller needs ResourceMark
111 const char* get_java_thread_name(const JavaThread* jt, oop vthread) {
112   assert(jt != NULL, "invariant");
113   const char* name_str = "<no-name - thread name unresolved>";
114   oop thread_obj = vthread != NULL ? vthread : jt->threadObj();
115   if (thread_obj == NULL) {
116     if (jt->is_attaching_via_jni()) {
117       name_str = "<no-name - thread is attaching>";
118     }
119   } else {
120     const oop name = java_lang_Thread::name(thread_obj);
121     if (name != NULL) {
122       name_str = java_lang_String::as_utf8_string(name);
123     }


124   }
125   assert(name_str != NULL, "unexpected NULL thread name");
126   return name_str;
127 }
128 
129 const char* JfrThreadName::name(const Thread* t, oop vthread) {
130   assert(t != NULL, "invariant");
131   return t->is_Java_thread() ? get_java_thread_name(JavaThread::cast(t), vthread) : t->name();
132 }
< prev index next >