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
29 Changes: Christian Thalinger
41 #include "vm/jit/code.h"
42 #include "mm/memory.h"
43 #include "vm/options.h"
47 /* code_codeinfo_new ***********************************************************
49 Create a new codeinfo for the given method.
52 m................method to create a new codeinfo for
54 The following fields are set in codeinfo:
57 all other fields are zeroed
60 a new, initialized codeinfo, or
61 NULL if an exception occurred.
63 *******************************************************************************/
65 codeinfo *code_codeinfo_new(methodinfo *m)
73 #if defined(ENABLE_STATISTICS)
75 size_codeinfo += sizeof(codeinfo);
82 /* code_get_sync_slot_count ****************************************************
84 Return the number of stack slots used for storing the synchronized object
85 (and the return value around lock_monitor_exit calls) by the given code.
88 code.............the codeinfo of the code in question
92 the number of stack slots used for synchronization
94 *******************************************************************************/
96 int code_get_sync_slot_count(codeinfo *code)
106 if (!(code->m->flags & ACC_SYNCHRONIZED))
111 #ifdef HAS_4BYTE_STACKSLOT
112 /* long and double need 2 4-byte slots */
113 if (IS_2_WORD_TYPE(code->m->parseddesc->returntype.type))
117 #if defined(__POWERPC__)
118 /* powerpc needs an extra slot */
124 #else /* !ENABLE_THREADS */
128 #endif /* ENABLE_THREADS */
132 /* code_get_stack_frame_size ***************************************************
134 Return the number of stack slots that the stack frame of the given code
137 IMPORTANT: The return value does *not* include the saved return address
138 slot, although it is part of non-leaf stack frames on RISC
139 architectures. The rationale behind this is that the saved
140 return address is never moved or changed by replacement, and
141 this way CISC and RISC architectures can be treated the same.
142 (See also doc/stack_frames.txt.)
145 code.............the codeinfo of the code in question
149 the number of stack slots
151 *******************************************************************************/
153 int code_get_stack_frame_size(codeinfo *code)
160 /* slots allocated by register allocator plus saved registers */
162 #ifdef HAS_4BYTE_STACKSLOT
163 count = code->memuse + code->savedintcount + 2*code->savedfltcount;
165 count = code->memuse + code->savedintcount + code->savedfltcount;
168 /* add slots needed in synchronized methods */
170 count += code_get_sync_slot_count(code);
172 /* keep stack aligned */
174 #if defined(__X86_64__)
175 /* the x86_64 codegen only aligns the stack in non-leaf methods */
176 if (!code->isleafmethod || opt_verbosecall)
177 count |= 1; /* even when return address is added */
180 /* XXX align stack on alpha */
181 #if defined(__MIPS__)
182 if (code->isleafmethod)
183 count = (count + 1) & ~1;
185 count |= 1; /* even when return address is added */
188 #if defined(__POWERPC__)
189 /* keep stack 16-byte aligned */
190 count = (count + 3) & ~3;
200 /* code_codeinfo_free **********************************************************
202 Free the memory used by a codeinfo.
205 code.............the codeinfo to free
207 *******************************************************************************/
209 void code_codeinfo_free(codeinfo *code)
214 if (code->mcode != NULL)
215 CFREE((void *) (ptrint) code->mcode, code->mcodelength);
217 replace_free_replacement_points(code);
219 FREE(code, codeinfo);
221 #if defined(ENABLE_STATISTICS)
223 size_codeinfo -= sizeof(codeinfo);
228 /* code_free_code_of_method ****************************************************
230 Free all codeinfos of the given method
233 m................the method of which the codeinfos are to be freed
235 *******************************************************************************/
237 void code_free_code_of_method(methodinfo *m)
248 nextcode = code->prev;
249 code_codeinfo_free(code);
256 * These are local overrides for various environment variables in Emacs.
257 * Please do not remove this and leave it at the end of the file, where
258 * Emacs will automagically detect them.
259 * ---------------------------------------------------------------------
262 * indent-tabs-mode: t
266 * vim:noexpandtab:sw=4:ts=4: