* Merged with default branch at rev 16f3633aaa5a.
[cacao.git] / src / threads / threads-common.c
index 89515056c98594f327eee75f526386e795cb11c2..33691910e3b2aeccf89e96aae7fd64b2dc8dff86 100644 (file)
@@ -280,6 +280,12 @@ threadobject *threads_thread_new(void)
                /* set the threads-index */
 
                t->index = list_threads->size + 1;
+
+#if defined(ENABLE_GC_CACAO)
+               /* register reference to java.lang.Thread with the GC */
+
+               gc_reference_register((java_object_t **) &(t->object), GC_REFTYPE_THREADOBJECT);
+#endif
        }
 
        /* pre-compute the thinlock-word */
@@ -287,8 +293,13 @@ threadobject *threads_thread_new(void)
        assert(t->index != 0);
 
        t->thinlock = lock_pre_compute_thinlock(t->index);
+       t->flags    = 0;
        t->state    = THREAD_STATE_NEW;
 
+#if defined(ENABLE_GC_CACAO)
+       t->flags |= THREAD_FLAG_IN_NATIVE; 
+#endif
+
        /* initialize the implementation-specific bits */
 
        threads_impl_thread_new(t);
@@ -384,7 +395,7 @@ bool threads_thread_start_internal(utf *name, functionptr f)
 
        t = threads_thread_new();
 
-       t->flags = THREAD_FLAG_INTERNAL | THREAD_FLAG_DAEMON;
+       t->flags |= THREAD_FLAG_INTERNAL | THREAD_FLAG_DAEMON;
 
        /* The thread is flagged as (non-)daemon thread, we can leave the
           mutex. */
@@ -471,7 +482,7 @@ void threads_thread_start(java_lang_Thread *object)
 
        /* this is a normal Java thread */
 
-       thread->flags = THREAD_FLAG_JAVA;
+       thread->flags |= THREAD_FLAG_JAVA;
 
 #if defined(ENABLE_JAVASE)
        /* is this a daemon thread? */
@@ -516,6 +527,9 @@ void threads_thread_start(java_lang_Thread *object)
 void threads_thread_print_info(threadobject *t)
 {
        java_lang_Thread *object;
+#if defined(WITH_CLASSPATH_GNU)
+       java_lang_String *namestring;
+#endif
        utf              *name;
 
        assert(t->state != THREAD_STATE_NEW);
@@ -528,7 +542,8 @@ void threads_thread_print_info(threadobject *t)
                /* get thread name */
 
 #if defined(WITH_CLASSPATH_GNU)
-               name = javastring_toutf((java_handle_t *) LLNI_field_direct(object, name), false);
+               LLNI_field_get_ref(object, name, namestring);
+               name = javastring_toutf((java_handle_t *) namestring, false);
 #elif defined(WITH_CLASSPATH_SUN) || defined(WITH_CLASSPATH_CLDC1_1)
                /* FIXME: In cldc the name is a char[] */
 /*             name = object->name; */