/* src/vm/finalizer.c - finalizer linked list and thread
- Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ Copyright (C) 1996-2005, 2006, 2007 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
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- Contact: cacao@cacaojvm.org
-
- Authors: Christian Thalinger
-
- Changes:
-
- $Id: finalizer.c 5123 2006-07-12 21:45:34Z twisti $
-
*/
#include "vm/types.h"
#include "mm/memory.h"
-#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 "threads/lock-common.h"
+#include "threads/threads-common.h"
#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"
+#include "vmcore/options.h"
+
/* global variables ***********************************************************/
#if defined(ENABLE_THREADS)
-static java_lang_VMThread *finalizer_vmthread;
-static java_objectheader *lock_finalizer_thread;
+static java_object_t *lock_thread_finalizer;
#endif
bool finalizer_init(void)
{
#if defined(ENABLE_THREADS)
- lock_finalizer_thread = NEW(java_objectheader);
+ lock_thread_finalizer = NEW(java_object_t);
- lock_init_object_lock(lock_finalizer_thread);
+ LOCK_INIT_OBJECT_LOCK(lock_thread_finalizer);
#endif
/* everything's ok */
while (true) {
/* get the lock on the finalizer lock object, so we can call wait */
- lock_monitor_enter(lock_finalizer_thread);
+ lock_monitor_enter(lock_thread_finalizer);
/* wait forever (0, 0) on that object till we are signaled */
- lock_wait_for_object(lock_finalizer_thread, 0, 0);
+ lock_wait_for_object(lock_thread_finalizer, 0, 0);
/* leave the lock */
- lock_monitor_exit(lock_finalizer_thread);
+ lock_monitor_exit(lock_thread_finalizer);
/* and call the finalizers */
#if defined(ENABLE_THREADS)
bool finalizer_start_thread(void)
{
- java_lang_Thread *t;
-
- /* create the finalizer object */
+ utf *name;
- finalizer_vmthread =
- (java_lang_VMThread *) builtin_new(class_java_lang_VMThread);
+ name = utf_new_char("Finalizer");
- if (!finalizer_vmthread)
+ if (!threads_thread_start_internal(name, finalizer_thread))
return false;
- t = (java_lang_Thread *) builtin_new(class_java_lang_Thread);
-
- t->vmThread = finalizer_vmthread;
- t->name = javastring_new_from_ascii("Finalizer");
- t->daemon = true;
- t->priority = 5;
-
- finalizer_vmthread->thread = t;
-
- /* actually start the finalizer thread */
-
- threads_start_thread(t, finalizer_thread);
-
/* everything's ok */
return true;
#if defined(ENABLE_THREADS)
/* get the lock on the finalizer lock object, so we can call wait */
- lock_monitor_enter(lock_finalizer_thread);
+ lock_monitor_enter(lock_thread_finalizer);
/* signal the finalizer thread */
- lock_notify_object(lock_finalizer_thread);
+ lock_notify_object(lock_thread_finalizer);
/* leave the lock */
- lock_monitor_exit(lock_finalizer_thread);
+ lock_monitor_exit(lock_thread_finalizer);
#else
/* if we don't have threads, just run the finalizers */
void finalizer_run(void *o, void *p)
{
- java_objectheader *ob;
+ java_object_t *ob;
- ob = (java_objectheader *) o;
+ ob = (java_object_t *) o;
/* call the finalizer function */
/* if we had an exception in the finalizer, ignore it */
- *exceptionptr = NULL;
+ exceptions_clear_exception();
}