1 /* src/vm/jit/code.c - codeinfo struct for representing compiled code
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
27 Authors: Edwin Steiner
43 #include "vm/jit/code.h"
44 #include "vm/jit/codegen-common.h"
45 #include "vm/jit/methodheader.h"
46 #include "mm/memory.h"
47 #include "vm/options.h"
48 #include "vm/jit/code.h"
51 /* code_init *******************************************************************
53 Initialize the code-subsystem.
55 *******************************************************************************/
59 /* check for offset of code->m == 0 (see comment in code.h) */
61 assert(OFFSET(codeinfo, m) == 0);
69 /* code_codeinfo_new ***********************************************************
71 Create a new codeinfo for the given method.
74 m................method to create a new codeinfo for
76 The following fields are set in codeinfo:
79 all other fields are zeroed
82 a new, initialized codeinfo, or
83 NULL if an exception occurred.
85 *******************************************************************************/
87 codeinfo *code_codeinfo_new(methodinfo *m)
95 #if defined(ENABLE_STATISTICS)
97 size_codeinfo += sizeof(codeinfo);
104 /* code_find_codeinfo_for_pc ***************************************************
106 Return the codeinfo for the compilation unit that contains the
110 pc...............machine code position
113 the codeinfo * for the given PC
115 *******************************************************************************/
117 codeinfo *code_find_codeinfo_for_pc(u1 *pc)
121 pv = codegen_get_pv_from_pc(pc);
124 return *(codeinfo **)(pv + CodeinfoPointer);
128 /* code_get_sync_slot_count ****************************************************
130 Return the number of stack slots used for storing the synchronized object
131 (and the return value around lock_monitor_exit calls) by the given code.
134 code.............the codeinfo of the code in question
138 the number of stack slots used for synchronization
140 *******************************************************************************/
142 int code_get_sync_slot_count(codeinfo *code)
144 #ifdef ENABLE_THREADS
152 if (!(code->m->flags & ACC_SYNCHRONIZED))
157 #ifdef HAS_4BYTE_STACKSLOT
158 /* long and double need 2 4-byte slots */
159 if (IS_2_WORD_TYPE(code->m->parseddesc->returntype.type))
163 #if defined(__POWERPC__)
164 /* powerpc needs an extra slot */
170 #else /* !ENABLE_THREADS */
174 #endif /* ENABLE_THREADS */
178 /* code_get_stack_frame_size ***************************************************
180 Return the number of stack slots that the stack frame of the given code
183 IMPORTANT: The return value does *not* include the saved return address
184 slot, although it is part of non-leaf stack frames on RISC
185 architectures. The rationale behind this is that the saved
186 return address is never moved or changed by replacement, and
187 this way CISC and RISC architectures can be treated the same.
188 (See also doc/stack_frames.txt.)
191 code.............the codeinfo of the code in question
195 the number of stack slots
197 *******************************************************************************/
199 int code_get_stack_frame_size(codeinfo *code)
206 /* slots allocated by register allocator plus saved registers */
208 #ifdef HAS_4BYTE_STACKSLOT
209 count = code->memuse + code->savedintcount + 2*code->savedfltcount;
211 count = code->memuse + code->savedintcount + code->savedfltcount;
214 /* add slots needed in synchronized methods */
216 count += code_get_sync_slot_count(code);
218 /* keep stack aligned */
220 #if defined(__X86_64__)
221 /* the x86_64 codegen only aligns the stack in non-leaf methods */
222 if (!code->isleafmethod || opt_verbosecall)
223 count |= 1; /* even when return address is added */
226 /* XXX align stack on alpha */
227 #if defined(__MIPS__)
228 if (code->isleafmethod)
229 count = (count + 1) & ~1;
231 count |= 1; /* even when return address is added */
234 #if defined(__POWERPC__)
235 /* keep stack 16-byte aligned */
236 count = (count + 3) & ~3;
242 return code->stackframesize;
246 /* code_codeinfo_free **********************************************************
248 Free the memory used by a codeinfo.
251 code.............the codeinfo to free
253 *******************************************************************************/
255 void code_codeinfo_free(codeinfo *code)
260 if (code->mcode != NULL)
261 CFREE((void *) (ptrint) code->mcode, code->mcodelength);
263 replace_free_replacement_points(code);
265 FREE(code, codeinfo);
267 #if defined(ENABLE_STATISTICS)
269 size_codeinfo -= sizeof(codeinfo);
274 /* code_free_code_of_method ****************************************************
276 Free all codeinfos of the given method
279 m................the method of which the codeinfos are to be freed
281 *******************************************************************************/
283 void code_free_code_of_method(methodinfo *m)
294 nextcode = code->prev;
295 code_codeinfo_free(code);
302 * These are local overrides for various environment variables in Emacs.
303 * Please do not remove this and leave it at the end of the file, where
304 * Emacs will automagically detect them.
305 * ---------------------------------------------------------------------
308 * indent-tabs-mode: t
312 * vim:noexpandtab:sw=4:ts=4: