#include "vm/jit/builtin.hpp"
#include "vm/class.hpp"
#include "vm/exceptions.hpp"
+#include "vm/finalizer.hpp"
#include "vm/globals.hpp"
#include "vm/javaobjects.hpp"
#include "vm/method.hpp"
thread_set_object(t, NULL);
- /* Release the thread. */
-
- ThreadList::release_thread(t);
+ ThreadList::deactivate_thread(t);
}
*******************************************************************************/
+static void thread_cleanup_finalizer(java_handle_t *h, void *data)
+{
+ threadobject *t = reinterpret_cast<threadobject*>(data);
+ ThreadList::release_thread(t, false);
+}
+
bool threads_thread_start_internal(utf *name, functionptr f)
{
threadobject *t;
/* Create the Java thread object. */
- if (!thread_create_object(t, javastring_new(name), threadgroup_system))
+ if (!thread_create_object(t, javastring_new(name), threadgroup_system)) {
+ ThreadList::release_thread(t, true);
return false;
+ }
+
+ Finalizer::attach_custom_finalizer(thread_get_object(t), thread_cleanup_finalizer, t);
/* Start the thread. */
ThreadRuntime::setup_thread_vmdata(jlt, t);
+ Finalizer::attach_custom_finalizer(thread_get_object(t), thread_cleanup_finalizer, t);
+
/* Start the thread. Don't pass a function pointer (NULL) since
we want Thread.run()V here. */
/* Create the Java thread object. */
- if (!thread_create_object(t, name, group))
+ if (!thread_create_object(t, name, group)) {
+ ThreadList::release_thread(t, true);
return false;
+ }
/* The thread is completely initialized. */
{
/* Set the state inside a lock. */
- ThreadList::lock();
-
thread_set_state(t, THREAD_STATE_TERMINATED);
DEBUGTHREADS("is TERMINATED", t);
-
- ThreadList::unlock();
}
void thread_handle_set_priority(java_handle_t *th, int priority)
{
- ThreadListLocker l;
-
threadobject *t = thread_get_thread(th);
/* For GNU classpath, this should not happen, because both
setPriority() and start() are synchronized. */
bool thread_handle_is_interrupted(java_handle_t *th)
{
- ThreadListLocker l;
-
threadobject *t = thread_get_thread(th);
return t ? thread_is_interrupted(t) : false;
}
void thread_handle_interrupt(java_handle_t *th)
{
- ThreadListLocker l;
-
threadobject *t = thread_get_thread(th);
/* For GNU classpath, this should not happen, because both
interrupt() and start() are synchronized. */
int thread_handle_get_state(java_handle_t *th)
{
- ThreadListLocker l;
-
threadobject *t = thread_get_thread(th);
return t ? cacaothread_get_state(t) : THREAD_STATE_NEW;
}