X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=src%2Fthreads%2Fthreadlist.cpp;h=ce055a083e15ff9f2dddd9b19a89472cdd1aff60;hb=c7982045b8e1a27aca0c14398bd17a90f88ae8cc;hp=18720899ccb23d577cade9c0b2f17b7a60efc149;hpb=8d97ffb4a74ea3e36d7838ee36fc3c55c02c70a3;p=cacao.git diff --git a/src/threads/threadlist.cpp b/src/threads/threadlist.cpp index 18720899c..ce055a083 100644 --- a/src/threads/threadlist.cpp +++ b/src/threads/threadlist.cpp @@ -1,6 +1,6 @@ /* src/threads/threadlist.cpp - thread list - Copyright (C) 2008 + Copyright (C) 2008, 2009 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO This file is part of CACAO. @@ -43,10 +43,13 @@ Mutex ThreadList::_mutex; // a mutex for all thread lists -list ThreadList::_active_thread_list; // list of active threads -list ThreadList::_free_thread_list; // list of free threads -list ThreadList::_free_index_list; // list of free thread indexes +List ThreadList::_active_thread_list; // list of active threads +List ThreadList::_free_thread_list; // list of free threads +List ThreadList::_free_index_list; // list of free thread indexes +int32_t ThreadList::_number_of_started_java_threads; +int32_t ThreadList::_number_of_active_java_threads; +int32_t ThreadList::_peak_of_active_java_threads; int32_t ThreadList::_number_of_non_daemon_threads; @@ -56,13 +59,15 @@ int32_t ThreadList::_number_of_non_daemon_threads; */ void ThreadList::dump_threads() { - // XXX we should stop the world here + // XXX we should stop the world here and remove explicit + // thread suspension from the loop below. // Lock the thread lists. lock(); - printf("Full thread dump CACAO "VERSION":\n"); + printf("Full thread dump CACAO "VERSION_FULL":\n"); // Iterate over all started threads. + threadobject* self = THREADOBJECT; for (List::iterator it = _active_thread_list.begin(); it != _active_thread_list.end(); it++) { threadobject* t = *it; @@ -70,13 +75,10 @@ void ThreadList::dump_threads() if (t->state == THREAD_STATE_NEW) continue; -#if defined(ENABLE_GC_CACAO) - /* Suspend the thread. */ - /* XXX Is the suspend reason correct? */ + /* Suspend the thread (and ignore return value). */ - if (threads_suspend_thread(t, SUSPEND_REASON_JNI) == false) - vm_abort("threads_dump: threads_suspend_thread failed"); -#endif + if (t != self) + (void) threads_suspend_thread(t, SUSPEND_REASON_DUMP); /* Print thread info. */ @@ -88,12 +90,58 @@ void ThreadList::dump_threads() stacktrace_print_of_thread(t); -#if defined(ENABLE_GC_CACAO) - /* Resume the thread. */ + /* Resume the thread (and ignore return value). */ - if (threads_resume_thread(t) == false) - vm_abort("threads_dump: threads_resume_thread failed"); -#endif + if (t != self) + (void) threads_resume_thread(t, SUSPEND_REASON_DUMP); + } + + // Unlock the thread lists. + unlock(); +} + + +/** + * Fills the passed list with all currently active threads. Creating a copy + * of the thread list here, is the only way to ensure we do not end up in a + * dead-lock when iterating over the list. + * + * @param list list class to be filled + */ +void ThreadList::get_active_threads(List &list) +{ + // Lock the thread lists. + lock(); + + // Use the assignment operator to create a copy of the thread list. + list = _active_thread_list; + + // Unlock the thread lists. + unlock(); +} + + +/** + * Fills the passed list with all currently active threads which should be + * visible to Java. Creating a copy of the thread list here, is the only way + * to ensure we do not end up in a dead-lock when iterating over the list. + * + * @param list list class to be filled + */ +void ThreadList::get_active_java_threads(List &list) +{ + // Lock the thread lists. + lock(); + + // Iterate over all active threads. + for (List::iterator it = _active_thread_list.begin(); it != _active_thread_list.end(); it++) { + threadobject* t = *it; + + // We skip internal threads. + if (t->flags & THREAD_FLAG_INTERNAL) + continue; + + list.push_back(t); } // Unlock the thread lists. @@ -145,6 +193,40 @@ int32_t ThreadList::get_free_thread_index() } +/** + * Return the number of daemon threads visible to Java. + * + * NOTE: This function does a linear-search over the threads list, + * because it is only used by the management interface. + * + * @return number of daemon threads + */ +int32_t ThreadList::get_number_of_daemon_java_threads(void) +{ + int number = 0; + + // Lock the thread lists. + lock(); + + // Iterate over all active threads. + for (List::iterator it = _active_thread_list.begin(); it != _active_thread_list.end(); it++) { + threadobject* t = *it; + + // We skip internal threads. + if (t->flags & THREAD_FLAG_INTERNAL) + continue; + + if (thread_is_daemon(t)) + number++; + } + + // Unlock the thread lists. + unlock(); + + return number; +} + + /** * Return the number of non-daemon threads. *