src/hotspot/share/jfr/recorder/checkpoint/types/jfrThreadState.cpp
changeset 58863 c16ac7a2eba4
parent 50113 caf115bb98ad
equal deleted inserted replaced
58861:2c3cc4b01880 58863:c16ac7a2eba4
     1 /*
     1 /*
     2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
     2 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
     3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4 *
     4 *
     5 * This code is free software; you can redistribute it and/or modify it
     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
     6 * under the terms of the GNU General Public License version 2 only, as
     7 * published by the Free Software Foundation.
     7 * published by the Free Software Foundation.
    21 * questions.
    21 * questions.
    22 *
    22 *
    23 */
    23 */
    24 
    24 
    25 #include "precompiled.hpp"
    25 #include "precompiled.hpp"
       
    26 #include "classfile/javaClasses.inline.hpp"
    26 #include "jfr/recorder/checkpoint/types/jfrThreadState.hpp"
    27 #include "jfr/recorder/checkpoint/types/jfrThreadState.hpp"
    27 #include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp"
    28 #include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp"
       
    29 #include "jfr/support/jfrThreadLocal.hpp"
    28 #include "jvmtifiles/jvmti.h"
    30 #include "jvmtifiles/jvmti.h"
       
    31 #include "runtime/osThread.hpp"
       
    32 #include "runtime/thread.hpp"
    29 
    33 
    30 struct jvmti_thread_state {
    34 struct jvmti_thread_state {
    31   u8 id;
    35   u8 id;
    32   const char* description;
    36   const char* description;
    33 };
    37 };
    78     writer.write_key(states[i].id);
    82     writer.write_key(states[i].id);
    79     writer.write(states[i].description);
    83     writer.write(states[i].description);
    80   }
    84   }
    81 }
    85 }
    82 
    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 JavaThread* const jt = (JavaThread*)t;
       
    93   const oop thread_obj = jt->threadObj();
       
    94   return thread_obj != NULL ? java_lang_Thread::thread_id(thread_obj) : 0;
       
    95 }
       
    96 
       
    97 traceid JfrThreadId::os_id(const Thread* t) {
       
    98   assert(t != NULL, "invariant");
       
    99   const OSThread* const os_thread = t->osthread();
       
   100   return os_thread != NULL ? os_thread->thread_id() : 0;
       
   101 }
       
   102 
       
   103 traceid JfrThreadId::jfr_id(const Thread* t) {
       
   104   assert(t != NULL, "invariant");
       
   105   return t->jfr_thread_local()->thread_id();
       
   106 }
       
   107 
       
   108 // caller needs ResourceMark
       
   109 const char* get_java_thread_name(const Thread* t) {
       
   110   assert(t != NULL, "invariant");
       
   111   assert(t->is_Java_thread(), "invariant");
       
   112   const JavaThread* const jt = ((JavaThread*)t);
       
   113   const char* name_str = "<no-name - thread name unresolved>";
       
   114   const oop thread_obj = jt->threadObj();
       
   115   if (thread_obj != NULL) {
       
   116     const oop name = java_lang_Thread::name(thread_obj);
       
   117     if (name != NULL) {
       
   118       name_str = java_lang_String::as_utf8_string(name);
       
   119     }
       
   120   } else if (jt->is_attaching_via_jni()) {
       
   121     name_str = "<no-name - thread is attaching>";
       
   122   }
       
   123   assert(name_str != NULL, "unexpected NULL thread name");
       
   124   return name_str;
       
   125 }
       
   126 
       
   127 const char* JfrThreadName::name(const Thread* t) {
       
   128   assert(t != NULL, "invariant");
       
   129   return t->is_Java_thread() ? get_java_thread_name(t) : t->name();
       
   130 }