Line data Source code
1 : /* src/vm/jit/exceptiontable.c - method exception table
2 :
3 : Copyright (C) 1996-2013
4 : CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 :
6 : This file is part of CACAO.
7 :
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.
12 :
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.
17 :
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
21 : 02110-1301, USA.
22 :
23 : */
24 :
25 : #include "vm/jit/exceptiontable.hpp"
26 : #include "config.h"
27 : #include <assert.h> // for assert
28 : #include <stdint.h> // for uint8_t
29 : #include "mm/memory.hpp" // for NEW
30 : #include "toolbox/logging.hpp" // for log_print, log_finish, etc
31 : #include "vm/class.hpp" // for class_classref_print, etc
32 : #include "vm/jit/code.hpp" // for codeinfo
33 : #include "vm/jit/jit.hpp" // for exception_entry, jitdata, etc
34 : #include "vm/method.hpp" // for method_print
35 :
36 : /* exceptiontable_create *******************************************************
37 :
38 : Builds the exception table for the currently compiled method.
39 :
40 : IN:
41 : jd ... JIT data of the currently compiled method
42 :
43 : *******************************************************************************/
44 :
45 99456 : void exceptiontable_create(jitdata *jd)
46 : {
47 : codeinfo *code;
48 : exceptiontable_t *et;
49 : exceptiontable_entry_t *ete;
50 : exception_entry *ex;
51 : uint8_t *pv;
52 :
53 : /* Get required compiler data. */
54 :
55 99456 : code = jd->code;
56 :
57 : /* Don't allocate an exception table if we don't need one. */
58 :
59 99456 : if (jd->exceptiontablelength == 0)
60 93904 : return;
61 :
62 : /* Allocate the exception table and the entries array. */
63 :
64 5552 : et = NEW(exceptiontable_t);
65 5552 : ete = MNEW(exceptiontable_entry_t, jd->exceptiontablelength);
66 :
67 : /* Fill the exception table. */
68 :
69 5552 : et->length = jd->exceptiontablelength;
70 5552 : et->entries = ete;
71 :
72 : /* Fill the exception table entries. */
73 :
74 5552 : pv = code->entrypoint;
75 :
76 19243 : for (ex = jd->exceptiontable; ex != NULL; ex = ex->down, ete++) {
77 : /* Resolve basicblock relative start PCs to absolute
78 : addresses. */
79 :
80 13691 : ete->startpc = pv + ex->start->mpc;
81 13691 : ete->endpc = pv + ex->end->mpc;
82 13691 : ete->handlerpc = pv + ex->handler->mpc;
83 :
84 : /* Store the catch type. */
85 :
86 13691 : ete->catchtype.any = ex->catchtype.any;
87 : }
88 :
89 : /* Store the exception table in the codeinfo. */
90 :
91 5552 : code->exceptiontable = et;
92 :
93 : #if 0
94 : exceptiontable_print(code);
95 : #endif
96 : }
97 :
98 :
99 : /* exceptiontable_free *********************************************************
100 :
101 : Frees the memory allocated by the exception table stored in the
102 : codeinfo.
103 :
104 : IN:
105 : code ... codeinfo of a method realization
106 :
107 : *******************************************************************************/
108 :
109 0 : void exceptiontable_free(codeinfo *code)
110 : {
111 : exceptiontable_t *et;
112 : exceptiontable_entry_t *ete;
113 :
114 : /* Sanity check. */
115 :
116 0 : assert(code != NULL);
117 :
118 : /* Free the exception table memory. */
119 :
120 0 : et = code->exceptiontable;
121 :
122 0 : if (et != NULL) {
123 0 : ete = et->entries;
124 :
125 0 : if (ete != NULL) {
126 0 : MFREE(ete, exceptiontable_entry_t, et->length);
127 :
128 : /* Clear the pointer. */
129 :
130 0 : et->entries = NULL;
131 : }
132 :
133 0 : FREE(et, exceptiontable_t);
134 :
135 : /* Clear the pointer. */
136 :
137 0 : code->exceptiontable = NULL;
138 : }
139 0 : }
140 :
141 :
142 : /* exceptiontable_print ********************************************************
143 :
144 : Print the exception table.
145 :
146 : IN:
147 : code ... codeinfo of a method realization
148 :
149 : *******************************************************************************/
150 :
151 : #if !defined(NDEBUG)
152 0 : void exceptiontable_print(codeinfo *code)
153 : {
154 : exceptiontable_t *et;
155 : exceptiontable_entry_t *ete;
156 : int i;
157 :
158 0 : et = code->exceptiontable;
159 :
160 : /* Print the exception table. */
161 :
162 0 : log_start();
163 : log_print("[exceptiontable: m=%p, code=%p, exceptiontable=%p, length=%d, method=",
164 0 : code->m, code, et, (et != NULL) ? et->length : 0);
165 0 : method_print(code->m);
166 0 : log_print("]");
167 0 : log_finish();
168 :
169 0 : if (et == NULL)
170 0 : return;
171 :
172 : /* Iterate over all entries. */
173 :
174 0 : for (i = 0, ete = et->entries; i < et->length; i++, ete++) {
175 0 : log_start();
176 : log_print("[exceptiontable entry %3d: startpc=%p, endpc=%p, handlerpc=%p, catchtype=%p (",
177 0 : i, ete->startpc, ete->endpc, ete->handlerpc, ete->catchtype.any);
178 :
179 0 : if (ete->catchtype.any != NULL)
180 0 : if (ete->catchtype.is_classref())
181 0 : class_classref_print(ete->catchtype.ref);
182 : else
183 0 : class_print(ete->catchtype.cls);
184 : else
185 0 : log_print("ANY");
186 :
187 0 : log_print(")]");
188 0 : log_finish();
189 : }
190 : }
191 : #endif
192 :
193 :
194 : /*
195 : * These are local overrides for various environment variables in Emacs.
196 : * Please do not remove this and leave it at the end of the file, where
197 : * Emacs will automagically detect them.
198 : * ---------------------------------------------------------------------
199 : * Local variables:
200 : * mode: c++
201 : * indent-tabs-mode: t
202 : * c-basic-offset: 4
203 : * tab-width: 4
204 : * End:
205 : * vim:noexpandtab:sw=4:ts=4:
206 : */
|