From: Michael Starzinger Date: Sat, 6 Oct 2007 21:33:39 +0000 (+0200) Subject: * src/threads/threads-common.h (threads_thread_get_object): Added. X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=52256a78ebe6343d81a8887f9232d74252caf162;p=cacao.git * src/threads/threads-common.h (threads_thread_get_object): Added. (threads_thread_set_object): Added. * src/threads/threads-common.c: Use above functions throughout the code. * src/threads/native/threads.c: Likewise. * src/native/vm/java_lang_Thread.c: Likewise. (_Jv_java_lang_Thread_start): Fixed compiler warning. (_Jv_java_lang_Thread_currentThread) [ENABLE_JAVASE]: Fixed for handles. --- diff --git a/src/native/vm/java_lang_Thread.c b/src/native/vm/java_lang_Thread.c index 9e9dbac23..fb7724944 100644 --- a/src/native/vm/java_lang_Thread.c +++ b/src/native/vm/java_lang_Thread.c @@ -91,7 +91,7 @@ void _Jv_java_lang_Thread_sleep(s8 millis) void _Jv_java_lang_Thread_start(java_lang_Thread *this, s8 stacksize) { #if defined(ENABLE_THREADS) - threads_thread_start(this); + threads_thread_start((java_handle_t *) this); #endif } @@ -235,32 +235,39 @@ void _Jv_java_lang_Thread_stop(java_lang_Thread *this, java_lang_Throwable *t) java_lang_Thread *_Jv_java_lang_Thread_currentThread(void) { #if defined(ENABLE_THREADS) - threadobject *thread; + threadobject *thread; +#endif + java_lang_Thread *t; +#if defined(ENABLE_JAVASE) + java_lang_ThreadGroup *group; #endif - java_lang_Thread *t; #if defined(ENABLE_THREADS) thread = THREADOBJECT; - t = LLNI_WRAP(thread->object); + t = (java_lang_Thread *) threads_thread_get_object(thread); if (t == NULL) log_text("t ptr is NULL\n"); # if defined(ENABLE_JAVASE) - if (LLNI_field_direct(t, group) == NULL) { + LLNI_field_get_ref(t, group, group); + + if (group == NULL) { /* ThreadGroup of currentThread is not initialized */ - LLNI_field_direct(t, group) = (java_lang_ThreadGroup *) + group = (java_lang_ThreadGroup *) native_new_and_init(class_java_lang_ThreadGroup); - if (LLNI_field_direct(t, group) == NULL) + if (group == NULL) log_text("unable to create ThreadGroup"); + + LLNI_field_set_ref(t, group, group); } # endif #else /* we just return a fake java.lang.Thread object, otherwise we get - NullPointerException's in GNU classpath */ + NullPointerException's in GNU classpath */ t = (java_lang_Thread *) builtin_new(class_java_lang_Thread); #endif diff --git a/src/threads/native/threads.c b/src/threads/native/threads.c index fbb193e0e..8e5d7ba71 100644 --- a/src/threads/native/threads.c +++ b/src/threads/native/threads.c @@ -927,7 +927,7 @@ bool threads_init(void) /* set the object in the internal data structure */ - mainthread->object = LLNI_DIRECT(t); + threads_thread_set_object(mainthread, t); #if defined(ENABLE_INTRP) /* create interpreter stack */ @@ -1112,7 +1112,7 @@ static void *threads_startup_thread(void *arg) /* get the java.lang.Thread object for this thread */ - object = (java_lang_Thread *) LLNI_WRAP(thread->object); + object = (java_lang_Thread *) threads_thread_get_object(thread); /* set our priority */ @@ -1388,7 +1388,7 @@ bool threads_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon) if (t == NULL) return false; - thread->object = LLNI_DIRECT(t); + threads_thread_set_object(thread, t); /* thread is completely initialized */ @@ -1444,7 +1444,7 @@ bool threads_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon) /* get the main thread */ mainthread = threads_list_first(); - mainthreado = (java_lang_Thread *) LLNI_WRAP(mainthread->object); + mainthreado = (java_lang_Thread *) threads_thread_get_object(mainthread); group = LLNI_field_direct(mainthreado, group); #endif } @@ -1513,7 +1513,7 @@ bool threads_detach_thread(threadobject *t) #endif #if defined(ENABLE_JAVASE) - object = (java_lang_Thread *) LLNI_WRAP(t->object); + object = (java_lang_Thread *) threads_thread_get_object(t); LLNI_field_get_ref(object, group, group); diff --git a/src/threads/threads-common.c b/src/threads/threads-common.c index dbede9349..e53c0f566 100644 --- a/src/threads/threads-common.c +++ b/src/threads/threads-common.c @@ -454,7 +454,7 @@ bool threads_thread_start_internal(utf *name, functionptr f) LLNI_field_set_val(object, vm_thread, (java_lang_Object *) t); #endif - t->object = LLNI_DIRECT(object); + threads_thread_set_object(t, object); /* set java.lang.Thread fields */ @@ -530,7 +530,7 @@ void threads_thread_start(java_handle_t *object) /* link the two objects together */ - thread->object = LLNI_DIRECT(object); + threads_thread_set_object(thread, object); #if defined(WITH_CLASSPATH_GNU) LLNI_field_get_ref(o, vmThread, vmt); @@ -568,7 +568,7 @@ void threads_thread_print_info(threadobject *t) /* the thread may be currently in initalization, don't print it */ - object = (java_lang_Thread *) LLNI_WRAP(t->object); + object = (java_lang_Thread *) threads_thread_get_object(t); if (object != NULL) { /* get thread name */ diff --git a/src/threads/threads-common.h b/src/threads/threads-common.h index d1412c786..3cea52547 100644 --- a/src/threads/threads-common.h +++ b/src/threads/threads-common.h @@ -33,7 +33,7 @@ #include "vm/global.h" -#include "native/jni.h" +#include "native/llni.h" #if defined(ENABLE_THREADS) # include "threads/native/threads.h" @@ -87,6 +87,32 @@ extern bool threads_pthreads_implementation_nptl; #endif +/* inline functions ***********************************************************/ + +/* threads_thread_get_object *************************************************** + + Return the java.lang.Thread object for the given thread. + +*******************************************************************************/ + +static inline java_handle_t *threads_thread_get_object(threadobject *t) +{ + return LLNI_WRAP(t->object); +} + + +/* threads_thread_set_object *************************************************** + + Set the java.lang.Thread object for the given thread. + +*******************************************************************************/ + +static inline void threads_thread_set_object(threadobject *t, java_handle_t *object) +{ + t->object = LLNI_DIRECT(object); +} + + /* function prototypes ********************************************************/ void threads_preinit(void);