1 /* 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
41 #include "vm/jit/code.h"
42 #include "mm/memory.h"
43 #include "vm/options.h"
46 /* code_codeinfo_new ***********************************************************
48 Create a new codeinfo for the given method.
51 m................method to create a new codeinfo for
53 The following fields are set in codeinfo:
56 all other fields are zeroed
59 a new, initialized codeinfo, or
60 NULL if an exception occurred.
62 *******************************************************************************/
64 codeinfo *code_codeinfo_new(methodinfo *m)
70 memset(code,0,sizeof(codeinfo));
73 code->isleafmethod = m->isleafmethod; /* XXX will be moved to codeinfo */
78 /* code_get_sync_slot_count ****************************************************
80 Return the number of stack slots used for storing the synchronized object
81 (and the return value around monitorExit calls) by the given code.
84 code.............the codeinfo of the code in question
88 the number of stack slots used for synchronization
90 *******************************************************************************/
92 int code_get_sync_slot_count(codeinfo *code)
102 if (!(code->m->flags & ACC_SYNCHRONIZED))
107 #ifdef HAS_4BYTE_STACKSLOT
108 /* long and double need 2 4-byte slots */
109 if (IS_2_WORD_TYPE(code->m->parseddesc->returntype.type))
113 #if defined(__POWERPC__)
114 /* powerpc needs an extra slot */
120 #else /* !USE_THREADS */
124 #endif /* USE_THREADS */
127 /* code_get_stack_frame_size ***************************************************
129 Return the number of stack slots that the stack frame of the given code
132 IMPORTANT: The return value does *not* include the saved return address
133 slot, although it is part of non-leaf stack frames on RISC
134 architectures. The rationale behind this is that the saved
135 return address is never moved or changed by replacement, and
136 this way CISC and RISC architectures can be treated the same.
137 (See also doc/stack_frames.txt.)
140 code.............the codeinfo of the code in question
144 the number of stack slots
146 *******************************************************************************/
148 int code_get_stack_frame_size(codeinfo *code)
154 #ifdef HAS_4BYTE_STACKSLOT
155 count = code->memuse + code->savedintcount + 2*code->savedfltcount;
157 count = code->memuse + code->savedintcount + code->savedfltcount;
160 /* add slots needed in synchronized methods */
161 count += code_get_sync_slot_count(code);
163 #if defined(__X86_64__)
164 /* keep stack 16-byte aligned */
165 if (!code->isleafmethod || opt_verbosecall)
166 count |= 1; /* even when return address is added */
169 #if defined(__POWERPC__)
170 /* keep stack 16-byte aligned */
171 count = (count + 3) & ~3;
177 /* code_codeinfo_free **********************************************************
179 Free the memory used by a codeinfo.
182 code.............the codeinfo to free
184 *******************************************************************************/
186 void code_codeinfo_free(codeinfo *code)
192 CFREE((void *) (ptrint) code->mcode, code->mcodelength);
194 replace_free_replacement_points(code);
199 /* code_free_code_of_method ****************************************************
201 Free all codeinfos of the given method
204 m................the method of which the codeinfos are to be freed
206 *******************************************************************************/
208 void code_free_code_of_method(methodinfo *m)
219 nextcode = code->prev;
220 code_codeinfo_free(code);
227 * These are local overrides for various environment variables in Emacs.
228 * Please do not remove this and leave it at the end of the file, where
229 * Emacs will automagically detect them.
230 * ---------------------------------------------------------------------
233 * indent-tabs-mode: t
237 * vim:noexpandtab:sw=4:ts=4: