1 /* src/vm/jit/code.c - codeinfo struct for representing compiled code
3 Copyright (C) 1996-2005, 2006, 2007 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
36 #include "mm/memory.h"
38 #if defined(ENABLE_THREADS)
39 # include "threads/native/lock.h"
42 #include "vm/jit/code.h"
43 #include "vm/jit/codegen-common.h"
44 #include "vm/jit/methodheader.h"
45 #include "vm/jit/patcher-common.h"
47 #include "vmcore/options.h"
50 /* code_init *******************************************************************
52 Initialize the code-subsystem.
54 *******************************************************************************/
58 /* check for offset of code->m == 0 (see comment in code.h) */
60 assert(OFFSET(codeinfo, m) == 0);
68 /* code_codeinfo_new ***********************************************************
70 Create a new codeinfo for the given method.
73 m................method to create a new codeinfo for
75 The following fields are set in codeinfo:
80 a new, initialized codeinfo, or
81 NULL if an exception occurred.
83 *******************************************************************************/
85 codeinfo *code_codeinfo_new(methodinfo *m)
93 patcher_list_create(code);
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_methodinfo_for_pv **************************************************
130 Return the methodinfo for the given PV.
138 *******************************************************************************/
140 methodinfo *code_get_methodinfo_for_pv(u1 *pv)
144 code = *((codeinfo **) (pv + CodeinfoPointer));
150 /* code_get_sync_slot_count ****************************************************
152 Return the number of stack slots used for storing the synchronized object
153 (and the return value around lock_monitor_exit calls) by the given code.
156 code.............the codeinfo of the code in question
160 the number of stack slots used for synchronization
162 *******************************************************************************/
164 #if defined(ENABLE_REPLACEMENT)
165 int code_get_sync_slot_count(codeinfo *code)
167 #ifdef ENABLE_THREADS
175 if (!(code->m->flags & ACC_SYNCHRONIZED))
180 #ifdef HAS_4BYTE_STACKSLOT
181 /* long and double need 2 4-byte slots */
182 if (IS_2_WORD_TYPE(code->m->parseddesc->returntype.type))
186 #if defined(__POWERPC__)
187 /* powerpc needs an extra slot */
193 #else /* !ENABLE_THREADS */
197 #endif /* ENABLE_THREADS */
199 #endif /* defined(ENABLE_REPLACEMENT) */
202 /* code_codeinfo_free **********************************************************
204 Free the memory used by a codeinfo.
207 code.............the codeinfo to free
209 *******************************************************************************/
211 void code_codeinfo_free(codeinfo *code)
216 if (code->mcode != NULL)
217 CFREE((void *) (ptrint) code->mcode, code->mcodelength);
219 patcher_list_free(code);
221 #if defined(ENABLE_REPLACEMENT)
222 replace_free_replacement_points(code);
225 FREE(code, codeinfo);
227 #if defined(ENABLE_STATISTICS)
229 size_codeinfo -= sizeof(codeinfo);
234 /* code_free_code_of_method ****************************************************
236 Free all codeinfos of the given method
239 m................the method of which the codeinfos are to be freed
241 *******************************************************************************/
243 void code_free_code_of_method(methodinfo *m)
254 nextcode = code->prev;
255 code_codeinfo_free(code);
262 * These are local overrides for various environment variables in Emacs.
263 * Please do not remove this and leave it at the end of the file, where
264 * Emacs will automagically detect them.
265 * ---------------------------------------------------------------------
268 * indent-tabs-mode: t
272 * vim:noexpandtab:sw=4:ts=4: