1 /* mm/cacao-gc/final.c - GC module for finalization and weak references
3 Copyright (C) 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
34 #include "mm/memory.h"
35 #include "vm/finalizer.h"
38 /* Global Variables ***********************************************************/
46 final_list = list_create(OFFSET(list_final_entry_t, linkage));
49 void final_register(java_object_t *o, methodinfo *finalizer)
51 list_final_entry_t *fe;
53 fe = NEW(list_final_entry_t);
54 fe->type = FINAL_REACHABLE;
56 fe->finalizer = finalizer;
58 list_add_first(final_list, fe);
60 GC_LOG2( printf("Finalizer registered for: %p\n", (void *) o); );
65 list_final_entry_t *fe;
66 list_final_entry_t *fe_next;
68 fe = list_first(final_list);
71 fe_next = list_next(final_list, fe);
73 if (fe->type == FINAL_RECLAIMABLE) {
75 GC_LOG( printf("Finalizer starting for: ");
76 heap_print_object(fe->o); printf("\n"); );
78 GC_ASSERT(fe->finalizer == fe->o->vftbl->class->finalizer);
80 fe->type = FINAL_FINALIZING;
82 finalizer_run(fe->o, NULL);
84 fe->type = FINAL_FINALIZED;
86 list_remove(final_list, fe);
87 FREE(fe, list_final_entry_t);
94 void final_set_all_reclaimable()
96 list_final_entry_t *fe;
98 fe = list_first(final_list);
101 if (fe->type == FINAL_REACHABLE)
102 fe->type = FINAL_RECLAIMABLE;
104 fe = list_next(final_list, fe);
110 * These are local overrides for various environment variables in Emacs.
111 * Please do not remove this and leave it at the end of the file, where
112 * Emacs will automagically detect them.
113 * ---------------------------------------------------------------------
116 * indent-tabs-mode: t
120 * vim:noexpandtab:sw=4:ts=4: