1 /* src/vm/jit/code.c - codeinfo struct for representing compiled code
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine 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
33 #include "mm/memory.h"
37 #include "vm/jit/code.h"
38 #include "vm/jit/codegen-common.h"
39 #include "vm/jit/jitcache.h"
40 #include "vm/jit/methodtree.h"
41 #include "vm/jit/patcher-common.h"
43 #include "vmcore/options.h"
46 /* code_init *******************************************************************
48 Initialize the code-subsystem.
50 *******************************************************************************/
54 /* Check if offset of codeinfo.m == 0 (see comment in code.h). */
56 if (OFFSET(codeinfo, m) != 0)
57 vm_abort("code_init: offset of codeinfo.m != 0: %d != 0", OFFSET(codeinfo, m));
61 /* code_codeinfo_new ***********************************************************
63 Create a new codeinfo for the given method.
66 m................method to create a new codeinfo for
68 The following fields are set in codeinfo:
74 a new, initialized codeinfo, or
75 NULL if an exception occurred.
77 *******************************************************************************/
79 codeinfo *code_codeinfo_new(methodinfo *m)
87 patcher_list_create(code);
89 #if defined (ENABLE_JITCACHE)
90 jitcache_list_create(code);
93 #if defined (ENABLE_STATISTICS)
95 size_codeinfo += sizeof(codeinfo);
102 /* code_find_codeinfo_for_pc ***************************************************
104 Return the codeinfo for the compilation unit that contains the
108 pc...............machine code position
111 the codeinfo * for the given PC
113 *******************************************************************************/
115 codeinfo *code_find_codeinfo_for_pc(void *pc)
119 pv = methodtree_find(pc);
121 return code_get_codeinfo_for_pv(pv);
125 /* code_find_codeinfo_for_pc ***************************************************
127 Return the codeinfo for the compilation unit that contains the
128 given PC. This method does not check the return value and is used
132 pc...............machine code position
135 the codeinfo * for the given PC, or NULL
137 *******************************************************************************/
139 codeinfo *code_find_codeinfo_for_pc_nocheck(void *pc)
143 pv = methodtree_find_nocheck(pc);
148 return code_get_codeinfo_for_pv(pv);
152 /* code_get_methodinfo_for_pv **************************************************
154 Return the methodinfo for the given PV.
162 *******************************************************************************/
164 methodinfo *code_get_methodinfo_for_pv(void *pv)
168 code = code_get_codeinfo_for_pv(pv);
170 /* This is the case for asm_vm_call_method. */
179 /* code_get_sync_slot_count ****************************************************
181 Return the number of stack slots used for storing the synchronized object
182 (and the return value around lock_monitor_exit calls) by the given code.
185 code.............the codeinfo of the code in question
189 the number of stack slots used for synchronization
191 *******************************************************************************/
193 #if defined(ENABLE_REPLACEMENT)
194 int code_get_sync_slot_count(codeinfo *code)
196 #ifdef ENABLE_THREADS
204 if (!code_is_synchronized(code))
209 #ifdef HAS_4BYTE_STACKSLOT
210 /* long and double need 2 4-byte slots */
211 if (IS_2_WORD_TYPE(code->m->parseddesc->returntype.type))
215 #if defined(__POWERPC__)
216 /* powerpc needs an extra slot */
222 #else /* !ENABLE_THREADS */
226 #endif /* ENABLE_THREADS */
228 #endif /* defined(ENABLE_REPLACEMENT) */
231 /* code_codeinfo_free **********************************************************
233 Free the memory used by a codeinfo.
236 code.............the codeinfo to free
238 *******************************************************************************/
240 void code_codeinfo_free(codeinfo *code)
245 if (code->mcode != NULL)
246 CFREE((void *) (ptrint) code->mcode, code->mcodelength);
248 patcher_list_free(code);
250 #if defined(ENABLE_JITCACHE)
251 jitcache_list_free(code);
254 #if defined(ENABLE_REPLACEMENT)
255 replace_free_replacement_points(code);
258 FREE(code, codeinfo);
260 #if defined(ENABLE_STATISTICS)
262 size_codeinfo -= sizeof(codeinfo);
267 /* code_free_code_of_method ****************************************************
269 Free all codeinfos of the given method
272 m................the method of which the codeinfos are to be freed
274 *******************************************************************************/
276 void code_free_code_of_method(methodinfo *m)
287 nextcode = code->prev;
288 code_codeinfo_free(code);
295 * These are local overrides for various environment variables in Emacs.
296 * Please do not remove this and leave it at the end of the file, where
297 * Emacs will automagically detect them.
298 * ---------------------------------------------------------------------
301 * indent-tabs-mode: t
305 * vim:noexpandtab:sw=4:ts=4: