1 /* src/vm/jit/linenumbertable.c - linenumber handling stuff
4 CACAOVM - Verein zu Foerderung der freien virtuellen Machine 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.h"
34 #include "vm/jit/codegen-common.h"
35 #include "vm/jit/linenumbertable.h"
38 /* linenumbertable_create ******************************************************
40 Creates the linenumber table. We allocate an array and store the
41 linenumber entry in reverse-order, so we can search the correct
42 linenumber more easily.
44 *******************************************************************************/
46 void linenumbertable_create(jitdata *jd)
50 linenumbertable_t *lnt;
51 linenumbertable_entry_t *lnte;
53 linenumbertable_list_entry_t *le;
57 /* Get required compiler data. */
62 /* Don't allocate a linenumber table if we don't need one. */
69 /* Allocate the linenumber table and the entries array. */
71 lnt = NEW(linenumbertable_t);
72 lnte = MNEW(linenumbertable_entry_t, l->size);
74 /* Fill the linenumber table. */
76 lnt->length = l->size;
79 /* Fill the linenumber table entries in reverse order, so the
80 search can be forward. */
82 pv = code->entrypoint;
84 for (le = list_last_unsynced(l); le != NULL;
85 le = list_prev_unsynced(l, le), lnte++) {
86 /* If the entry contains an mcode pointer (normal case),
87 resolve it (see doc/inlining_stacktrace.txt for
90 if (le->linenumber >= -2)
93 pc = (void *) le->mpc;
95 /* Fill the linenumber table entry. */
97 lnte->linenumber = le->linenumber;
101 /* Store the linenumber table in the codeinfo. */
103 code->linenumbertable = lnt;
107 /* linenumbertable_list_entry_add **********************************************
109 Add a line number reference.
112 cd.............current codegen data
113 linenumber.....number of line that starts with the given mcodeptr
115 *******************************************************************************/
117 void linenumbertable_list_entry_add(codegendata *cd, int32_t linenumber)
119 linenumbertable_list_entry_t *le;
121 le = DNEW(linenumbertable_list_entry_t);
123 le->linenumber = linenumber;
124 le->mpc = cd->mcodeptr - cd->mcodebase;
126 list_add_last_unsynced(cd->linenumbers, le);
130 /* linenumbertable_list_entry_add_inline_start *********************************
132 Add a marker to the line number table indicating the start of an
133 inlined method body. (see doc/inlining_stacktrace.txt)
136 cd ..... current codegen data
137 iptr ... the ICMD_INLINE_BODY instruction
139 *******************************************************************************/
141 void linenumbertable_list_entry_add_inline_start(codegendata *cd, instruction *iptr)
143 linenumbertable_list_entry_t *le;
144 insinfo_inline *insinfo;
147 le = DNEW(linenumbertable_list_entry_t);
149 le->linenumber = (-2); /* marks start of inlined method */
150 le->mpc = (mpc = cd->mcodeptr - cd->mcodebase);
152 list_add_last_unsynced(cd->linenumbers, le);
154 insinfo = iptr->sx.s23.s3.inlineinfo;
156 insinfo->startmpc = mpc; /* store for corresponding INLINE_END */
160 /* linenumbertable_list_entry_add_inline_end ***********************************
162 Add a marker to the line number table indicating the end of an
163 inlined method body. (see doc/inlining_stacktrace.txt)
166 cd ..... current codegen data
167 iptr ... the ICMD_INLINE_END instruction
170 iptr->method must point to the inlined callee.
172 *******************************************************************************/
174 void linenumbertable_list_entry_add_inline_end(codegendata *cd, instruction *iptr)
176 linenumbertable_list_entry_t *le;
177 insinfo_inline *insinfo;
179 insinfo = iptr->sx.s23.s3.inlineinfo;
183 le = DNEW(linenumbertable_list_entry_t);
185 /* special entry containing the methodinfo * */
186 le->linenumber = (-3) - iptr->line;
187 le->mpc = (uintptr_t) insinfo->method;
189 list_add_last_unsynced(cd->linenumbers, le);
191 le = DNEW(linenumbertable_list_entry_t);
193 /* end marker with PC of start of body */
194 le->linenumber = (-1);
195 le->mpc = insinfo->startmpc;
197 list_add_last_unsynced(cd->linenumbers, le);
201 /* linenumbertable_linenumber_for_pc_intern ************************************
203 This function search the line number table for the line
204 corresponding to a given pc. The function recurses for inlined
207 *******************************************************************************/
209 static s4 linenumbertable_linenumber_for_pc_intern(methodinfo **pm, linenumbertable_entry_t *lnte, int32_t lntsize, void *pc)
211 linenumbertable_entry_t *lntinline; /* special entry for inlined method */
213 for (; lntsize > 0; lntsize--, lnte++) {
214 /* Note: In case of inlining this may actually compare the pc
215 against a methodinfo *, yielding a non-sensical
216 result. This is no problem, however, as we ignore such
217 entries in the switch below. This way we optimize for the
218 common case (ie. a real pc in lntentry->pc). */
220 if (pc >= lnte->pc) {
221 /* did we reach the current line? */
223 if (lnte->linenumber >= 0)
224 return lnte->linenumber;
226 /* we found a special inline entry (see
227 doc/inlining_stacktrace.txt for details */
229 switch (lnte->linenumber) {
231 /* begin of inlined method (ie. INLINE_END
234 lntinline = --lnte; /* get entry with methodinfo * */
235 lnte--; /* skip the special entry */
238 /* search inside the inlined method */
240 if (linenumbertable_linenumber_for_pc_intern(pm, lnte, lntsize, pc)) {
241 /* the inlined method contained the pc */
243 *pm = (methodinfo *) lntinline->pc;
245 assert(lntinline->linenumber <= -3);
247 return (-3) - lntinline->linenumber;
250 /* pc was not in inlined method, continue search.
251 Entries inside the inlined method will be skipped
252 because their lntentry->pc is higher than pc. */
256 /* end of inlined method */
260 /* default: is only reached for an -3-line entry after
261 a skipped -2 entry. We can safely ignore it and
262 continue searching. */
273 /* linenumbertable_linenumber_for_pc *******************************************
275 A wrapper for linenumbertable_linenumber_for_pc_intern.
277 NOTE: We have a intern version because the function is called
278 recursively for inlined methods.
280 *******************************************************************************/
282 int32_t linenumbertable_linenumber_for_pc(methodinfo **pm, codeinfo *code, void *pc)
284 linenumbertable_t *lnt;
287 /* Get line number table. */
289 lnt = code->linenumbertable;
294 /* Get the line number. */
296 linenumber = linenumbertable_linenumber_for_pc_intern(pm, lnt->entries, lnt->length, pc);
303 * These are local overrides for various environment variables in Emacs.
304 * Please do not remove this and leave it at the end of the file, where
305 * Emacs will automagically detect them.
306 * ---------------------------------------------------------------------
309 * indent-tabs-mode: t
313 * vim:noexpandtab:sw=4:ts=4: