* src/vmcore/options.c (opt_verbosethreads): Added.
authortwisti <none@none>
Thu, 10 May 2007 14:04:05 +0000 (14:04 +0000)
committertwisti <none@none>
Thu, 10 May 2007 14:04:05 +0000 (14:04 +0000)
* src/vmcore/options.h (opt_verbosethreads): Likewise.

* src/vm/vm.c (XXusage): Added -verbose:threads.
(vm_create): Likewise.

* src/threads/threads-common.c (threads_create_thread): Renamed
variable thread to t.
(threads_thread_print_info): New function.
(threads_dump): Use threads_thread_print_info.

* src/threads/threads-common.h (threads_thread_print_info): Added.

* src/threads/native/threads.c (threads_init) [!NDEBUG]: Added
-verbose:threads debug-output.
(threads_startup_thread): Likewise.
(threads_attach_current_thread): Likewise.
(threads_detach_thread): Likewise.

src/threads/native/threads.c
src/threads/threads-common.c
src/threads/threads-common.h
src/vm/vm.c
src/vmcore/options.c
src/vmcore/options.h

index c8cbd190e39df7804a0d6f1c7e8f4cc47cb2d797..4cb0cba51b96644ec3ec3c5a3fab63fe878f2709 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: threads.c 7893 2007-05-10 13:27:29Z twisti $
+   $Id: threads.c 7894 2007-05-10 14:04:05Z twisti $
 
 */
 
@@ -848,6 +848,14 @@ bool threads_init(void)
 
        pthread_attr_setdetachstate(&threadattr, PTHREAD_CREATE_DETACHED);
 
+#if !defined(NDEBUG)
+       if (opt_verbosethreads) {
+               printf("[Starting thread ");
+               threads_thread_print_info(mainthread);
+               printf("]\n");
+       }
+#endif
+
        /* everything's ok */
 
        return true;
@@ -908,9 +916,10 @@ static void *threads_startup_thread(void *t)
        function = startup->function;
        psem     = startup->psem;
 
-       /* Seems like we've encountered a situation where thread->tid was not set by
-        * pthread_create. We alleviate this problem by waiting for pthread_create
-        * to return. */
+       /* Seems like we've encountered a situation where thread->tid was
+          not set by pthread_create. We alleviate this problem by waiting
+          for pthread_create to return. */
+
        threads_sem_wait(startup->psem_first);
 
 #if defined(__DARWIN__)
@@ -953,6 +962,14 @@ static void *threads_startup_thread(void *t)
                jvmti_ThreadStartEnd(JVMTI_EVENT_THREAD_START);
 #endif
 
+#if !defined(NDEBUG)
+       if (opt_verbosethreads) {
+               printf("[Starting thread ");
+               threads_thread_print_info(thread);
+               printf("]\n");
+       }
+#endif
+
        /* find and run the Thread.run()V method if no other function was passed */
 
        if (function == NULL) {
@@ -1011,6 +1028,14 @@ static void *threads_startup_thread(void *t)
                (function)();
        }
 
+#if !defined(NDEBUG)
+       if (opt_verbosethreads) {
+               printf("[Stopping thread ");
+               threads_thread_print_info(thread);
+               printf("]\n");
+       }
+#endif
+
 #if defined(ENABLE_JVMTI)
        /* fire thread end event */
 
@@ -1160,6 +1185,14 @@ bool threads_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon)
 
        threads_table_add(thread);
 
+#if !defined(NDEBUG)
+       if (opt_verbosethreads) {
+               printf("[Attaching thread ");
+               threads_thread_print_info(thread);
+               printf("]\n");
+       }
+#endif
+
 #if defined(ENABLE_INTRP)
        /* create interpreter stack */
 
@@ -1303,6 +1336,14 @@ bool threads_detach_thread(threadobject *thread)
 
        threads_table_remove(thread);
 
+#if !defined(NDEBUG)
+       if (opt_verbosethreads) {
+               printf("[Detaching thread ");
+               threads_thread_print_info(thread);
+               printf("]\n");
+       }
+#endif
+
        /* signal that this thread has finished */
 
        pthread_mutex_lock(&mutex_join);
index 8d8dc04592a89ee76d3c6fe6eba2746c5fc29aea..ef2b24362f090dd31431569293df4553a32e1eaa 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: threads-common.c 7893 2007-05-10 13:27:29Z twisti $
+   $Id: threads-common.c 7894 2007-05-10 14:04:05Z twisti $
 
 */
 
@@ -526,14 +526,14 @@ void threads_table_dump(void)
 
 threadobject *threads_create_thread(void)
 {
-       threadobject *thread;
+       threadobject *t;
 
        /* allocate internal thread data-structure */
 
 #if defined(ENABLE_GC_BOEHM)
-       thread = GCNEW_UNCOLLECTABLE(threadobject, 1);
+       t = GCNEW_UNCOLLECTABLE(threadobject, 1);
 #else
-       thread = NEW(threadobject);
+       t = NEW(threadobject);
 #endif
 
 #if defined(ENABLE_STATISTICS)
@@ -543,10 +543,10 @@ threadobject *threads_create_thread(void)
 
        /* initialize thread data structure */
 
-       threads_init_threadobject(thread);
-       lock_init_execution_env(thread);
+       threads_init_threadobject(t);
+       lock_init_execution_env(t);
 
-       return thread;
+       return t;
 }
 
 
@@ -665,6 +665,76 @@ void threads_thread_start(java_lang_Thread *object)
 }
 
 
+/* threads_thread_print_info ***************************************************
+
+   Print information of the passed thread.
+   
+*******************************************************************************/
+
+void threads_thread_print_info(threadobject *t)
+{
+       java_lang_Thread *object;
+       utf              *name;
+
+       /* the thread may be currently in initalization, don't print it */
+
+       object = t->object;
+
+       if (object != NULL) {
+               /* get thread name */
+
+#if defined(ENABLE_JAVASE)
+               name = javastring_toutf((java_objectheader *) object->name, false);
+#elif defined(ENABLE_JAVAME_CLDC1_1)
+               name = object->name;
+#endif
+
+               printf("\"");
+               utf_display_printable_ascii(name);
+               printf("\"");
+
+               if (t->flags & THREAD_FLAG_DAEMON)
+                       printf(" daemon");
+
+               printf(" prio=%d", object->priority);
+
+#if SIZEOF_VOID_P == 8
+               printf(" t=0x%016lx tid=0x%016lx (%ld)",
+                          (ptrint) t, (ptrint) t->tid, (ptrint) t->tid);
+#else
+               printf(" t=0x%08x tid=0x%08x (%d)",
+                          (ptrint) t, (ptrint) t->tid, (ptrint) t->tid);
+#endif
+
+               /* print thread state */
+
+               switch (t->state) {
+               case THREAD_STATE_NEW:
+                       printf(" new");
+                       break;
+               case THREAD_STATE_RUNNABLE:
+                       printf(" runnable");
+                       break;
+               case THREAD_STATE_BLOCKED:
+                       printf(" blocked");
+                       break;
+               case THREAD_STATE_WAITING:
+                       printf(" waiting");
+                       break;
+               case THREAD_STATE_TIMED_WAITING:
+                       printf(" waiting on condition");
+                       break;
+               case THREAD_STATE_TERMINATED:
+                       printf(" terminated");
+                       break;
+               default:
+                       vm_abort("threads_thread_print_info: unknown thread state %d",
+                                        t->state);
+               }
+       }
+}
+
+
 /* threads_get_current_tid *****************************************************
 
    Return the tid of the current thread.
@@ -766,9 +836,7 @@ bool threads_thread_is_alive(threadobject *thread)
 
 void threads_dump(void)
 {
-       threadobject     *t;
-       java_lang_Thread *object;
-       utf              *name;
+       threadobject *t;
 
        /* XXX we should stop the world here */
 
@@ -781,67 +849,15 @@ void threads_dump(void)
        /* iterate over all started threads */
 
        for (t = threads_table_first(); t != NULL; t = threads_table_next(t)) {
-               /* get thread object */
-
-               object = t->object;
+               /* print thread info */
 
-               /* the thread may be currently in initalization, don't print it */
+               printf("\n");
+               threads_thread_print_info(t);
+               printf("\n");
 
-               if (object != NULL) {
-                       /* get thread name */
+               /* print trace of thread */
 
-#if defined(ENABLE_JAVASE)
-                       name = javastring_toutf((java_objectheader *) object->name, false);
-#elif defined(ENABLE_JAVAME_CLDC1_1)
-                       name = object->name;
-#endif
-
-                       printf("\n\"");
-                       utf_display_printable_ascii(name);
-                       printf("\"");
-
-                       if (t->flags & THREAD_FLAG_DAEMON)
-                               printf(" daemon");
-
-                       printf(" prio=%d", object->priority);
-
-#if SIZEOF_VOID_P == 8
-                       printf(" tid=0x%016lx (%ld)", (ptrint) t->tid, (ptrint) t->tid);
-#else
-                       printf(" tid=0x%08x (%d)", (ptrint) t->tid, (ptrint) t->tid);
-#endif
-
-                       /* print thread state */
-
-                       switch (t->state) {
-                       case THREAD_STATE_NEW:
-                               printf(" new");
-                               break;
-                       case THREAD_STATE_RUNNABLE:
-                               printf(" runnable");
-                               break;
-                       case THREAD_STATE_BLOCKED:
-                               printf(" blocked");
-                               break;
-                       case THREAD_STATE_WAITING:
-                               printf(" waiting");
-                               break;
-                       case THREAD_STATE_TIMED_WAITING:
-                               printf(" waiting on condition");
-                               break;
-                       case THREAD_STATE_TERMINATED:
-                               printf(" terminated");
-                               break;
-                       default:
-                               vm_abort("threads_dump: unknown thread state %d", t->state);
-                       }
-
-                       printf("\n");
-
-                       /* print trace of thread */
-
-                       threads_thread_print_stacktrace(t);
-               }
+               threads_thread_print_stacktrace(t);
        }
 
        /* unlock the threads table */
index 4e515f22ea2bcc98762d16a2c861650171e24a99..e07c3d416c632a9a16335a5d7519300ec4c28d6d 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: threads-common.h 7875 2007-05-07 11:35:30Z twisti $
+   $Id: threads-common.h 7894 2007-05-10 14:04:05Z twisti $
 
 */
 
@@ -120,6 +120,8 @@ threadobject *threads_create_thread(void);
 bool          threads_thread_start_internal(utf *name, functionptr f);
 void          threads_thread_start(java_lang_Thread *object);
 
+void          threads_thread_print_info(threadobject *t);
+
 ptrint        threads_get_current_tid(void);
 utf          *threads_thread_get_state(threadobject *thread);
 bool          threads_thread_is_alive(threadobject *thread);
index 6e508905ff8bde5f81d55361293bcc8342db9d5b..44d0cec5469fd58c4ddf7c3286c40eda73f1a743 100644 (file)
@@ -487,7 +487,7 @@ static void XXusage(void)
 {
        puts("    -v                       write state-information");
 #if !defined(NDEBUG)
-       puts("    -verbose[:call|exception|jit|memory]");
+       puts("    -verbose[:call|exception|jit|memory|threads]");
        puts("                             enable specific verbose output");
        puts("    -debug-color             colored output for ANSI terms");
 #endif
@@ -1120,12 +1120,16 @@ bool vm_create(JavaVMInitArgs *vm_args)
                                opt_stat = true;
 # endif
                        }
+                       else if (strcmp("threads", opt_arg) == 0) {
+                               opt_verbosethreads = true;
+                       }
+#endif
                        else {
                                printf("Unknown -verbose option: %s\n", opt_arg);
                                usage();
                        }
-#endif
                        break;
+
                case OPT_DEBUGCOLOR:
                        opt_debugcolor = true;
                        break;
index f24d7d11fb8961586ac9118ebc5968242aea85b2..4f31ef465bcf360293f20c1b99243b9bbe4dd920 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: options.c 7887 2007-05-08 13:03:07Z twisti $
+   $Id: options.c 7894 2007-05-10 14:04:05Z twisti $
 
 */
 
@@ -79,6 +79,7 @@ bool opt_verbosejni       = false;
 bool opt_verbosecall      = false;      /* trace all method invocation        */
 bool opt_verboseexception = false;
 bool opt_verbosememory    = false;
+bool opt_verbosethreads   = false;
 
 bool showmethods = false;
 bool showconstantpool = false;
index 2409cabc480bc93f0b0da373c9e0e884734b8042..92ecd07bb5f8fc6bd15710667cf565c8fb67d42c 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: options.h 7596 2007-03-28 21:05:53Z twisti $
+   $Id: options.h 7894 2007-05-10 14:04:05Z twisti $
 
 */
 
@@ -88,6 +88,7 @@ extern bool opt_verbosejni;
 extern bool opt_verbosecall;
 extern bool opt_verboseexception;
 extern bool opt_verbosememory;
+extern bool opt_verbosethreads;
 
 extern bool showmethods;
 extern bool showconstantpool;