1 /* src/vm/jit/code.cpp - 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"
35 #include "vm/options.h"
38 #include "vm/jit/code.hpp"
39 #include "vm/jit/codegen-common.hpp"
40 #include "vm/jit/patcher-common.hpp"
41 #include "vm/jit/methodtree.h"
44 /* code_init *******************************************************************
46 Initialize the code-subsystem.
48 *******************************************************************************/
52 /* Check if offset of codeinfo.m == 0 (see comment in code.h). */
54 if (OFFSET(codeinfo, m) != 0)
55 vm_abort("code_init: offset of codeinfo.m != 0: %d != 0", OFFSET(codeinfo, m));
59 /* code_codeinfo_new ***********************************************************
61 Create a new codeinfo for the given method.
64 m................method to create a new codeinfo for
66 The following fields are set in codeinfo:
71 a new, initialized codeinfo, or
72 NULL if an exception occurred.
74 *******************************************************************************/
76 codeinfo *code_codeinfo_new(methodinfo *m)
84 patcher_list_create(code);
86 #if defined(ENABLE_STATISTICS)
88 size_codeinfo += sizeof(codeinfo);
95 /* code_find_codeinfo_for_pc ***************************************************
97 Return the codeinfo for the compilation unit that contains the
101 pc...............machine code position
104 the codeinfo * for the given PC
106 *******************************************************************************/
108 codeinfo *code_find_codeinfo_for_pc(void *pc)
112 pv = methodtree_find(pc);
114 return code_get_codeinfo_for_pv(pv);
118 /* code_find_codeinfo_for_pc ***************************************************
120 Return the codeinfo for the compilation unit that contains the
121 given PC. This method does not check the return value and is used
125 pc...............machine code position
128 the codeinfo * for the given PC, or NULL
130 *******************************************************************************/
132 codeinfo *code_find_codeinfo_for_pc_nocheck(void *pc)
136 pv = methodtree_find_nocheck(pc);
141 return code_get_codeinfo_for_pv(pv);
145 /* code_get_methodinfo_for_pv **************************************************
147 Return the methodinfo for the given PV.
155 *******************************************************************************/
157 methodinfo *code_get_methodinfo_for_pv(void *pv)
161 code = code_get_codeinfo_for_pv(pv);
163 /* This is the case for asm_vm_call_method. */
172 /* code_get_sync_slot_count ****************************************************
174 Return the number of stack slots used for storing the synchronized object
175 (and the return value around lock_monitor_exit calls) by the given code.
178 code.............the codeinfo of the code in question
182 the number of stack slots used for synchronization
184 *******************************************************************************/
186 #if defined(ENABLE_REPLACEMENT)
187 int code_get_sync_slot_count(codeinfo *code)
189 #ifdef ENABLE_THREADS
197 if (!code_is_synchronized(code))
202 #ifdef HAS_4BYTE_STACKSLOT
203 /* long and double need 2 4-byte slots */
204 if (IS_2_WORD_TYPE(code->m->parseddesc->returntype.type))
208 #if defined(__POWERPC__)
209 /* powerpc needs an extra slot */
215 #else /* !ENABLE_THREADS */
219 #endif /* ENABLE_THREADS */
221 #endif /* defined(ENABLE_REPLACEMENT) */
224 /* code_codeinfo_free **********************************************************
226 Free the memory used by a codeinfo.
229 code.............the codeinfo to free
231 *******************************************************************************/
233 void code_codeinfo_free(codeinfo *code)
238 if (code->mcode != NULL)
239 CFREE((void *) (ptrint) code->mcode, code->mcodelength);
241 patcher_list_free(code);
243 #if defined(ENABLE_REPLACEMENT)
244 replace_free_replacement_points(code);
247 FREE(code, codeinfo);
249 #if defined(ENABLE_STATISTICS)
251 size_codeinfo -= sizeof(codeinfo);
256 /* code_free_code_of_method ****************************************************
258 Free all codeinfos of the given method
261 m................the method of which the codeinfos are to be freed
263 *******************************************************************************/
265 void code_free_code_of_method(methodinfo *m)
276 nextcode = code->prev;
277 code_codeinfo_free(code);
284 * These are local overrides for various environment variables in Emacs.
285 * Please do not remove this and leave it at the end of the file, where
286 * Emacs will automagically detect them.
287 * ---------------------------------------------------------------------
290 * indent-tabs-mode: t
294 * vim:noexpandtab:sw=4:ts=4: