1 /* mm/cacao-gc/final.c - GC module for finalization and weak references
3 Copyright (C) 2006, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
32 #include "mm/memory.hpp"
33 #include "vm/finalizer.hpp"
36 /* Global Variables ***********************************************************/
44 final_list = list_create(OFFSET(list_final_entry_t, linkage));
47 void final_register(java_object_t *o, methodinfo *finalizer)
49 list_final_entry_t *fe;
51 fe = NEW(list_final_entry_t);
52 fe->type = FINAL_REACHABLE;
54 fe->finalizer = finalizer;
56 list_add_first(final_list, fe);
58 GC_LOG2( printf("Finalizer registered for: %p\n", (void *) o); );
63 list_final_entry_t *fe;
64 list_final_entry_t *fe_next;
66 fe = list_first(final_list);
69 fe_next = list_next(final_list, fe);
71 if (fe->type == FINAL_RECLAIMABLE) {
73 GC_LOG( printf("Finalizer starting for: ");
74 heap_print_object(fe->o); printf("\n"); );
76 GC_ASSERT(fe->finalizer == fe->o->vftbl->class->finalizer);
78 fe->type = FINAL_FINALIZING;
80 finalizer_run(fe->o, NULL);
82 fe->type = FINAL_FINALIZED;
84 list_remove(final_list, fe);
85 FREE(fe, list_final_entry_t);
92 void final_set_all_reclaimable()
94 list_final_entry_t *fe;
96 fe = list_first(final_list);
99 if (fe->type == FINAL_REACHABLE)
100 fe->type = FINAL_RECLAIMABLE;
102 fe = list_next(final_list, fe);
108 * These are local overrides for various environment variables in Emacs.
109 * Please do not remove this and leave it at the end of the file, where
110 * Emacs will automagically detect them.
111 * ---------------------------------------------------------------------
114 * indent-tabs-mode: t
118 * vim:noexpandtab:sw=4:ts=4: