< prev index next >

src/os/bsd/vm/os_bsd.cpp

Print this page
rev 10257 : 8149036: Add tracing for thread related events at os level
Reviewed-by:

@@ -30,10 +30,11 @@
 #include "code/vtableStubs.hpp"
 #include "compiler/compileBroker.hpp"
 #include "compiler/disassembler.hpp"
 #include "interpreter/interpreter.hpp"
 #include "jvm_bsd.h"
+#include "logging/log.hpp"
 #include "memory/allocation.inline.hpp"
 #include "memory/filemap.hpp"
 #include "mutex_bsd.inline.hpp"
 #include "oops/oop.inline.hpp"
 #include "os_bsd.inline.hpp"

@@ -679,10 +680,13 @@
   OSThread* osthread = thread->osthread();
   Monitor* sync = osthread->startThread_lock();
 
   osthread->set_thread_id(os::Bsd::gettid());
 
+  log_debug(os)("Thread is alive (tid: " UINTX_FORMAT ", pthread id: " UINTX_FORMAT ".",
+    os::current_thread_id(), (uintx) pthread_self());
+
 #ifdef __APPLE__
   uint64_t unique_thread_id = locate_unique_thread_id(osthread->thread_id());
   guarantee(unique_thread_id != 0, "unique thread id was not found");
   osthread->set_unique_thread_id(unique_thread_id);
 #endif

@@ -714,10 +718,13 @@
   }
 
   // call one more level start routine
   thread->run();
 
+  log_debug(os)("Thread finished (tid " UINTX_FORMAT ", pthread id " UINTX_FORMAT ").",
+    os::current_thread_id(), (uintx) pthread_self());
+
   return 0;
 }
 
 bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) {
   assert(thread->osthread() == NULL, "caller responsible");

@@ -774,16 +781,25 @@
 
   {
     pthread_t tid;
     int ret = pthread_create(&tid, &attr, (void* (*)(void*)) java_start, thread);
 
+    LogHandle(os) log;
+    if (log.is_debug()) {
+      char buf[64];
+      if (ret == 0) {
+        log.debug("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
+          (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
+      } else {
+        log.warning("Failed to start thread - pthread_create failed (%s) for attributes: %s.",
+          os::errno_name(errno), os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
+      }
+    }
+
     pthread_attr_destroy(&attr);
 
     if (ret != 0) {
-      if (PrintMiscellaneous && (Verbose || WizardMode)) {
-        perror("pthread_create()");
-      }
       // Need to clean up stuff we've allocated so far
       thread->set_osthread(NULL);
       delete osthread;
       return false;
     }

@@ -856,10 +872,13 @@
 
   // initialize signal mask for this thread
   // and save the caller's signal mask
   os::Bsd::hotspot_sigmask(thread);
 
+  log_debug(os)("Thread attached (tid: " UINTX_FORMAT ", pthread id: " UINTX_FORMAT ".",
+    os::current_thread_id(), (uintx) pthread_self());
+
   return true;
 }
 
 void os::pd_start_thread(Thread* thread) {
   OSThread * osthread = thread->osthread();
< prev index next >