CACAO
exceptiontable.cpp
Go to the documentation of this file.
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 
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 
46 {
47  codeinfo *code;
48  exceptiontable_t *et;
50  exception_entry *ex;
51  uint8_t *pv;
52 
53  /* Get required compiler data. */
54 
55  code = jd->code;
56 
57  /* Don't allocate an exception table if we don't need one. */
58 
59  if (jd->exceptiontablelength == 0)
60  return;
61 
62  /* Allocate the exception table and the entries array. */
63 
64  et = NEW(exceptiontable_t);
66 
67  /* Fill the exception table. */
68 
69  et->length = jd->exceptiontablelength;
70  et->entries = ete;
71 
72  /* Fill the exception table entries. */
73 
74  pv = code->entrypoint;
75 
76  for (ex = jd->exceptiontable; ex != NULL; ex = ex->down, ete++) {
77  /* Resolve basicblock relative start PCs to absolute
78  addresses. */
79 
80  ete->startpc = pv + ex->start->mpc;
81  ete->endpc = pv + ex->end->mpc;
82  ete->handlerpc = pv + ex->handler->mpc;
83 
84  /* Store the catch type. */
85 
86  ete->catchtype.any = ex->catchtype.any;
87  }
88 
89  /* Store the exception table in the codeinfo. */
90 
91  code->exceptiontable = et;
92 
93 #if 0
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 
110 {
111  exceptiontable_t *et;
113 
114  /* Sanity check. */
115 
116  assert(code != NULL);
117 
118  /* Free the exception table memory. */
119 
120  et = code->exceptiontable;
121 
122  if (et != NULL) {
123  ete = et->entries;
124 
125  if (ete != NULL) {
127 
128  /* Clear the pointer. */
129 
130  et->entries = NULL;
131  }
132 
133  FREE(et, exceptiontable_t);
134 
135  /* Clear the pointer. */
136 
137  code->exceptiontable = NULL;
138  }
139 }
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)
153 {
154  exceptiontable_t *et;
156  int i;
157 
158  et = code->exceptiontable;
159 
160  /* Print the exception table. */
161 
162  log_start();
163  log_print("[exceptiontable: m=%p, code=%p, exceptiontable=%p, length=%d, method=",
164  code->m, code, et, (et != NULL) ? et->length : 0);
165  method_print(code->m);
166  log_print("]");
167  log_finish();
168 
169  if (et == NULL)
170  return;
171 
172  /* Iterate over all entries. */
173 
174  for (i = 0, ete = et->entries; i < et->length; i++, ete++) {
175  log_start();
176  log_print("[exceptiontable entry %3d: startpc=%p, endpc=%p, handlerpc=%p, catchtype=%p (",
177  i, ete->startpc, ete->endpc, ete->handlerpc, ete->catchtype.any);
178 
179  if (ete->catchtype.any != NULL)
180  if (ete->catchtype.is_classref())
182  else
183  class_print(ete->catchtype.cls);
184  else
185  log_print("ANY");
186 
187  log_print(")]");
188  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  */
#define pv
Definition: md-asm.hpp:65
s4 exceptiontablelength
Definition: jit.hpp:167
Definition: jit.hpp:126
void method_print(methodinfo *m)
Definition: method.cpp:1189
exception_entry * exceptiontable
Definition: jit.hpp:168
#define NEW(type)
Definition: memory.hpp:93
bool is_classref() const
Definition: references.hpp:66
#define FREE(ptr, type)
Definition: memory.hpp:94
void class_print(classinfo *c)
Definition: class.cpp:2231
codeinfo * code
Definition: jit.hpp:128
void * handlerpc
s4 mpc
Definition: jit.hpp:345
void * startpc
constant_classref * ref
Definition: references.hpp:62
void log_finish(void)
Definition: logging.cpp:117
methodinfo * m
Definition: code.hpp:75
void log_print(const char *text,...)
Definition: logging.cpp:149
exceptiontable_t * exceptiontable
Definition: code.hpp:93
basicblock * start
Definition: jit.hpp:234
basicblock * handler
Definition: jit.hpp:236
void class_classref_print(constant_classref *cr)
Definition: class.cpp:2251
classref_or_classinfo catchtype
Definition: jit.hpp:237
void log_start(void)
Definition: logging.cpp:106
void exceptiontable_free(codeinfo *code)
MIIterator i
void * endpc
void exceptiontable_print(codeinfo *code)
exception_entry * down
Definition: jit.hpp:240
void exceptiontable_create(jitdata *jd)
#define MNEW(type, num)
Definition: memory.hpp:96
basicblock * end
Definition: jit.hpp:235
classref_or_classinfo catchtype
Definition: jit.hpp:233
#define MFREE(ptr, type, num)
Definition: memory.hpp:97
const char const void jint length
Definition: jvmti.h:352
exceptiontable_entry_t * entries
u1 * entrypoint
Definition: code.hpp:84