CACAO
Main Page
Related Pages
Modules
Namespaces
Data Structures
Files
File List
Globals
source
cacao
src
vm
jit
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
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
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
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
);
65
ete =
MNEW
(
exceptiontable_entry_t
, jd->
exceptiontablelength
);
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
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
void
exceptiontable_free
(
codeinfo
*code)
110
{
111
exceptiontable_t
*et;
112
exceptiontable_entry_t
*ete;
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) {
126
MFREE
(ete,
exceptiontable_entry_t
, et->
length
);
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)
152
void
exceptiontable_print
(
codeinfo
*code)
153
{
154
exceptiontable_t
*et;
155
exceptiontable_entry_t
*ete;
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
())
181
class_classref_print
(ete->
catchtype
.
ref
);
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
*/
pv
#define pv
Definition:
md-asm.hpp:65
jitdata::exceptiontablelength
s4 exceptiontablelength
Definition:
jit.hpp:167
jitdata
Definition:
jit.hpp:126
method_print
void method_print(methodinfo *m)
Definition:
method.cpp:1189
jitdata::exceptiontable
exception_entry * exceptiontable
Definition:
jit.hpp:168
NEW
#define NEW(type)
Definition:
memory.hpp:93
classref_or_classinfo::is_classref
bool is_classref() const
Definition:
references.hpp:66
exceptiontable_t
Definition:
exceptiontable.hpp:46
FREE
#define FREE(ptr, type)
Definition:
memory.hpp:94
class_print
void class_print(classinfo *c)
Definition:
class.cpp:2231
jitdata::code
codeinfo * code
Definition:
jit.hpp:128
exceptiontable_entry_t::handlerpc
void * handlerpc
Definition:
exceptiontable.hpp:57
basicblock::mpc
s4 mpc
Definition:
jit.hpp:345
classref_or_classinfo::cls
classinfo * cls
Definition:
references.hpp:63
exceptiontable_entry_t::startpc
void * startpc
Definition:
exceptiontable.hpp:56
classref_or_classinfo::ref
constant_classref * ref
Definition:
references.hpp:62
log_finish
void log_finish(void)
Definition:
logging.cpp:117
codeinfo
Definition:
code.hpp:74
codeinfo::m
methodinfo * m
Definition:
code.hpp:75
log_print
void log_print(const char *text,...)
Definition:
logging.cpp:149
codeinfo::exceptiontable
exceptiontable_t * exceptiontable
Definition:
code.hpp:93
class.hpp
exception_entry::start
basicblock * start
Definition:
jit.hpp:234
exception_entry::handler
basicblock * handler
Definition:
jit.hpp:236
class_classref_print
void class_classref_print(constant_classref *cr)
Definition:
class.cpp:2251
exception_entry::catchtype
classref_or_classinfo catchtype
Definition:
jit.hpp:237
log_start
void log_start(void)
Definition:
logging.cpp:106
exceptiontable_free
void exceptiontable_free(codeinfo *code)
Definition:
exceptiontable.cpp:109
i
MIIterator i
Definition:
LivetimeAnalysisPass.cpp:149
exceptiontable_entry_t::endpc
void * endpc
Definition:
exceptiontable.hpp:55
method.hpp
exceptiontable_print
void exceptiontable_print(codeinfo *code)
Definition:
exceptiontable.cpp:152
exception_entry::down
exception_entry * down
Definition:
jit.hpp:240
exceptiontable_entry_t
Definition:
exceptiontable.hpp:54
logging.hpp
jit.hpp
exceptiontable_create
void exceptiontable_create(jitdata *jd)
Definition:
exceptiontable.cpp:45
code.hpp
MNEW
#define MNEW(type, num)
Definition:
memory.hpp:96
exception_entry::end
basicblock * end
Definition:
jit.hpp:235
exceptiontable_entry_t::catchtype
classref_or_classinfo catchtype
Definition:
exceptiontable.hpp:58
exceptiontable.hpp
exceptiontable_t::length
int32_t length
Definition:
exceptiontable.hpp:47
exception_entry
Definition:
jit.hpp:233
MFREE
#define MFREE(ptr, type, num)
Definition:
memory.hpp:97
length
const char const void jint length
Definition:
jvmti.h:352
exceptiontable_t::entries
exceptiontable_entry_t * entries
Definition:
exceptiontable.hpp:48
codeinfo::entrypoint
u1 * entrypoint
Definition:
code.hpp:84
memory.hpp
classref_or_classinfo::any
void * any
Definition:
references.hpp:64
Generated on Fri Aug 4 2017 03:01:53 for CACAO by
1.8.5