1 /* src/vm/jit/exceptiontable.c - method exception table
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
31 #include "mm/memory.h"
33 #include "vm/jit/code.hpp"
34 #include "vm/jit/exceptiontable.h"
35 #include "vm/jit/jit.hpp"
38 /* exceptiontable_create *******************************************************
40 Builds the exception table for the currently compiled method.
43 jd ... JIT data of the currently compiled method
45 *******************************************************************************/
47 void exceptiontable_create(jitdata *jd)
51 exceptiontable_entry_t *ete;
55 /* Get required compiler data. */
59 /* Don't allocate an exception table if we don't need one. */
61 if (jd->exceptiontablelength == 0)
64 /* Allocate the exception table and the entries array. */
66 et = NEW(exceptiontable_t);
67 ete = MNEW(exceptiontable_entry_t, jd->exceptiontablelength);
69 /* Fill the exception table. */
71 et->length = jd->exceptiontablelength;
74 /* Fill the exception table entries. */
76 pv = code->entrypoint;
78 for (ex = jd->exceptiontable; ex != NULL; ex = ex->down, ete++) {
79 /* Resolve basicblock relative start PCs to absolute
82 ete->startpc = pv + ex->start->mpc;
83 ete->endpc = pv + ex->end->mpc;
84 ete->handlerpc = pv + ex->handler->mpc;
86 /* Store the catch type. */
88 ete->catchtype.any = ex->catchtype.any;
91 /* Store the exception table in the codeinfo. */
93 code->exceptiontable = et;
96 exceptiontable_print(code);
101 /* exceptiontable_free *********************************************************
103 Frees the memory allocated by the exception table stored in the
107 code ... codeinfo of a method realization
109 *******************************************************************************/
111 void exceptiontable_free(codeinfo *code)
113 exceptiontable_t *et;
114 exceptiontable_entry_t *ete;
118 assert(code != NULL);
120 /* Free the exception table memory. */
122 et = code->exceptiontable;
128 MFREE(ete, exceptiontable_entry_t, et->length);
130 /* Clear the pointer. */
135 FREE(et, exceptiontable_t);
137 /* Clear the pointer. */
139 code->exceptiontable = NULL;
144 /* exceptiontable_print ********************************************************
146 Print the exception table.
149 code ... codeinfo of a method realization
151 *******************************************************************************/
154 void exceptiontable_print(codeinfo *code)
156 exceptiontable_t *et;
157 exceptiontable_entry_t *ete;
160 et = code->exceptiontable;
162 /* Print the exception table. */
165 log_print("[exceptiontable: m=%p, code=%p, exceptiontable=%p, length=%d, method=",
166 code->m, code, et, (et != NULL) ? et->length : 0);
167 method_print(code->m);
174 /* Iterate over all entries. */
176 for (i = 0, ete = et->entries; i < et->length; i++, ete++) {
178 log_print("[exceptiontable entry %3d: startpc=%p, endpc=%p, handlerpc=%p, catchtype=%p (",
179 i, ete->startpc, ete->endpc, ete->handlerpc, ete->catchtype.any);
181 if (ete->catchtype.any != NULL)
182 if (IS_CLASSREF(ete->catchtype))
183 class_classref_print(ete->catchtype.ref);
185 class_print(ete->catchtype.cls);
197 * These are local overrides for various environment variables in Emacs.
198 * Please do not remove this and leave it at the end of the file, where
199 * Emacs will automagically detect them.
200 * ---------------------------------------------------------------------
203 * indent-tabs-mode: t
207 * vim:noexpandtab:sw=4:ts=4: