* src/vm/jit/i386/codegen.cn (codegen): Use the new functions for
[cacao.git] / src / vm / finalizer.c
index 7a8855f1b9a6fe7af5d5bc65c82ee00b1392b4a5..e0e69d02c0297e5ef6d67f51dc15a2c63ae81f83 100644 (file)
@@ -1,9 +1,9 @@
 /* src/vm/finalizer.c - finalizer linked list and thread
 
-   Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
-   R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
-   C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
-   Institut f. Computersprachen - TU Wien
+   Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+   C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+   E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+   J. Wenninger, Institut f. Computersprachen - TU Wien
 
    This file is part of CACAO.
 
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
 
-   Contact: cacao@complang.tuwien.ac.at
+   Contact: cacao@cacaojvm.org
 
    Authors: Christian Thalinger
 
    Changes:
 
-   $Id: finalizer.c 4145 2006-01-12 21:06:07Z twisti $
+   $Id: finalizer.c 5123 2006-07-12 21:45:34Z twisti $
 
 */
 
 #include "native/jni.h"
 #include "native/include/java_lang_Thread.h"
 #include "native/include/java_lang_VMThread.h"
+
+#if defined(ENABLE_THREADS)
+# include "threads/native/lock.h"
+#endif
+
 #include "vm/builtin.h"
 #include "vm/exceptions.h"
 #include "vm/global.h"
 #include "vm/options.h"
 #include "vm/stringlocal.h"
+#include "vm/vm.h"
 #include "vm/jit/asmpart.h"
 
 
 /* global variables ***********************************************************/
 
-#if defined(USE_THREADS)
+#if defined(ENABLE_THREADS)
 static java_lang_VMThread *finalizer_vmthread;
 static java_objectheader *lock_finalizer_thread;
 #endif
@@ -67,12 +73,10 @@ static java_objectheader *lock_finalizer_thread;
 
 bool finalizer_init(void)
 {
-#if defined(USE_THREADS)
+#if defined(ENABLE_THREADS)
        lock_finalizer_thread = NEW(java_objectheader);
 
-# if defined(NATIVE_THREADS)
-       initObjectLock(lock_finalizer_thread);
-# endif
+       lock_init_object_lock(lock_finalizer_thread);
 #endif
 
        /* everything's ok */
@@ -89,21 +93,21 @@ bool finalizer_init(void)
 
 *******************************************************************************/
 
-#if defined(USE_THREADS)
+#if defined(ENABLE_THREADS)
 static void finalizer_thread(void)
 {
        while (true) {
                /* get the lock on the finalizer lock object, so we can call wait */
 
-               builtin_monitorenter(lock_finalizer_thread);
+               lock_monitor_enter(lock_finalizer_thread);
 
                /* wait forever (0, 0) on that object till we are signaled */
        
-               wait_cond_for_object(lock_finalizer_thread, 0, 0);
+               lock_wait_for_object(lock_finalizer_thread, 0, 0);
 
                /* leave the lock */
 
-               builtin_monitorexit(lock_finalizer_thread);
+               lock_monitor_exit(lock_finalizer_thread);
 
                /* and call the finalizers */
 
@@ -119,7 +123,7 @@ static void finalizer_thread(void)
 
 *******************************************************************************/
 
-#if defined(USE_THREADS)
+#if defined(ENABLE_THREADS)
 bool finalizer_start_thread(void)
 {
        java_lang_Thread *t;
@@ -135,7 +139,7 @@ bool finalizer_start_thread(void)
        t = (java_lang_Thread *) builtin_new(class_java_lang_Thread);
 
        t->vmThread = finalizer_vmthread;
-       t->name     = javastring_new_char("Finalizer");
+       t->name     = javastring_new_from_ascii("Finalizer");
        t->daemon   = true;
        t->priority = 5;
 
@@ -161,18 +165,18 @@ bool finalizer_start_thread(void)
 
 void finalizer_notify(void)
 {
-#if defined(USE_THREADS)
+#if defined(ENABLE_THREADS)
        /* get the lock on the finalizer lock object, so we can call wait */
 
-       builtin_monitorenter(lock_finalizer_thread);
+       lock_monitor_enter(lock_finalizer_thread);
 
        /* signal the finalizer thread */
        
-       signal_cond_for_object(lock_finalizer_thread);
+       lock_notify_object(lock_finalizer_thread);
 
        /* leave the lock */
 
-       builtin_monitorexit(lock_finalizer_thread);
+       lock_monitor_exit(lock_finalizer_thread);
 #else
        /* if we don't have threads, just run the finalizers */
 
@@ -189,11 +193,13 @@ void finalizer_notify(void)
 
 void finalizer_run(void *o, void *p)
 {
-       java_objectheader *ob = (java_objectheader *) o;
+       java_objectheader *ob;
+
+       ob = (java_objectheader *) o;
 
        /* call the finalizer function */
 
-       ASM_CALLJAVAFUNCTION(ob->vftbl->class->finalizer, ob, NULL, NULL, NULL);
+       (void) vm_call_method(ob->vftbl->class->finalizer, ob);
 
        /* if we had an exception in the finalizer, ignore it */