// Set the Java object in the thread data-structure. This
// indicates that the thread is attached to the VM.
- thread_set_object(t, jlt.get_handle());
+ t->object = LLNI_DIRECT(jlt.get_handle());
return ThreadRuntime::invoke_thread_initializer(jlt, t, thread_method_init, name, group);
}
void thread_free(threadobject *t)
{
+ java_handle_t *h = LLNI_WRAP(t->object);
+ java_lang_Thread jlt(h);
+ ThreadRuntime::clear_heap_reference(jlt);
+
/* Set the reference to the Java object to NULL. */
- thread_set_object(t, NULL);
+ t->object = 0;
ThreadList::deactivate_thread(t);
}
{
threadobject *t;
- /* Enter the join-mutex, so if the main-thread is currently
- waiting to join all threads, the number of non-daemon threads
- is correct. */
-
- threads_mutex_join_lock();
-
/* Create internal thread data-structure. */
t = thread_new(THREAD_FLAG_INTERNAL | THREAD_FLAG_DAEMON);
ThreadList::add_to_active_thread_list(t);
- /* The thread is flagged as (non-)daemon thread, we can leave the
- mutex. */
-
- threads_mutex_join_unlock();
-
/* Create the Java thread object. */
if (!thread_create_object(t, javastring_new(name), threadgroup_system)) {
return false;
}
- Finalizer::attach_custom_finalizer(thread_get_object(t), thread_cleanup_finalizer, t);
+ Finalizer::attach_custom_finalizer(LLNI_WRAP(t->object), thread_cleanup_finalizer, t);
/* Start the thread. */
{
java_lang_Thread jlt(object);
- /* Enter the join-mutex, so if the main-thread is currently
- waiting to join all threads, the number of non-daemon threads
- is correct. */
-
- threads_mutex_join_lock();
-
/* Create internal thread data-structure. */
- threadobject* t = thread_new(THREAD_FLAG_JAVA);
-
+ u4 flags = THREAD_FLAG_JAVA;
#if defined(ENABLE_JAVASE)
/* Is this a daemon thread? */
- if (jlt.get_daemon() == true)
- t->flags |= THREAD_FLAG_DAEMON;
+ if (jlt.get_daemon())
+ flags |= THREAD_FLAG_DAEMON;
#endif
+ threadobject* t = thread_new(flags);
+
/* Link the two objects together. */
- thread_set_object(t, object);
+ t->object = LLNI_DIRECT(object);
/* Add the thread to the thread list. */
ThreadList::add_to_active_thread_list(t);
- threads_mutex_join_unlock();
+ Atomic::write_memory_barrier();
ThreadRuntime::setup_thread_vmdata(jlt, t);
- Finalizer::attach_custom_finalizer(thread_get_object(t), thread_cleanup_finalizer, t);
+ Finalizer::attach_custom_finalizer(LLNI_WRAP(t->object), thread_cleanup_finalizer, t);
/* Start the thread. Don't pass a function pointer (NULL) since
we want Thread.run()V here. */
if (result == true)
return true;
- /* Enter the join-mutex, so if the main-thread is currently
- waiting to join all threads, the number of non-daemon threads
- is correct. */
-
- threads_mutex_join_lock();
-
/* Create internal thread data structure. */
- t = thread_new(THREAD_FLAG_JAVA);
-
+ u4 flags = THREAD_FLAG_JAVA;
if (isdaemon)
- t->flags |= THREAD_FLAG_DAEMON;
+ flags |= THREAD_FLAG_DAEMON;
+
+ t = thread_new(flags);
/* Store the internal thread data-structure in the TSD. */
ThreadList::add_to_active_thread_list(t);
- threads_mutex_join_unlock();
-
DEBUGTHREADS("attaching", t);
/* Get the thread name. */
void thread_fprint_name(threadobject *t, FILE *stream)
{
- if (thread_get_object(t) == NULL)
+ if (LLNI_WRAP(t->object) == NULL)
vm_abort("");
- java_lang_Thread jlt(thread_get_object(t));
+ java_lang_Thread jlt(LLNI_WRAP(t->object));
ThreadRuntime::print_thread_name(jlt, stream);
}
void thread_print_info(threadobject *t)
{
- java_lang_Thread jlt(thread_get_object(t));
+ java_lang_Thread jlt(LLNI_WRAP(t->object));
/* Print as much as we can when we are in state NEW. */