/* 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, 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
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
-
- Authors: Christian Thalinger
-
- Changes:
-
- $Id: finalizer.c 4145 2006-01-12 21:06:07Z twisti $
+ $Id: finalizer.c 7831 2007-04-26 12:48:16Z 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"
+
+#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(USE_THREADS)
-static java_lang_VMThread *finalizer_vmthread;
-static java_objectheader *lock_finalizer_thread;
+#if defined(ENABLE_THREADS)
+static java_objectheader *lock_thread_finalizer;
#endif
bool finalizer_init(void)
{
-#if defined(USE_THREADS)
- lock_finalizer_thread = NEW(java_objectheader);
+#if defined(ENABLE_THREADS)
+ lock_thread_finalizer = NEW(java_objectheader);
-# if defined(NATIVE_THREADS)
- initObjectLock(lock_finalizer_thread);
-# endif
+ LOCK_INIT_OBJECT_LOCK(lock_thread_finalizer);
#endif
/* everything's ok */
*******************************************************************************/
-#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_thread_finalizer);
/* 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_thread_finalizer, 0, 0);
/* leave the lock */
- builtin_monitorexit(lock_finalizer_thread);
+ lock_monitor_exit(lock_thread_finalizer);
/* and call the finalizers */
*******************************************************************************/
-#if defined(USE_THREADS)
+#if defined(ENABLE_THREADS)
bool finalizer_start_thread(void)
{
- java_lang_Thread *t;
+ utf *name;
- /* create the finalizer object */
+ name = utf_new_char("Finalizer");
- finalizer_vmthread =
- (java_lang_VMThread *) builtin_new(class_java_lang_VMThread);
-
- 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_char("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;
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_thread_finalizer);
/* signal the finalizer thread */
- signal_cond_for_object(lock_finalizer_thread);
+ lock_notify_object(lock_thread_finalizer);
/* leave the lock */
- builtin_monitorexit(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_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 */
- *exceptionptr = NULL;
+ exceptions_clear_exception();
}