1 /* src/vm/jit/code.hpp - 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
36 #include "toolbox/list.hpp"
38 #include "vm/global.h"
39 #include "vm/method.hpp"
41 #include "vm/jit/exceptiontable.h"
42 #include "vm/jit/linenumbertable.hpp"
43 #include "vm/jit/methodheader.h"
44 #include "vm/jit/patcher-common.hpp"
45 #include "vm/jit/replace.hpp"
48 /* constants ******************************************************************/
50 #define CODE_FLAG_INVALID 0x0001
51 #define CODE_FLAG_LEAFMETHOD 0x0002
52 #define CODE_FLAG_SYNCHRONIZED 0x0004
53 #define CODE_FLAG_TLH 0x0008
56 /* codeinfo *******************************************************************
58 A codeinfo represents a particular realization of a method in
61 ATTENTION: The methodinfo entry in the code-structure MUST have the
62 offset 0, otherwise we have a problem in our compiler stub. This is
63 checked with an assert in code_init().
65 *******************************************************************************/
68 methodinfo *m; /* method this is a realization of */
69 codeinfo *prev; /* previous codeinfo of this method */
71 uint32_t flags; /* OR of CODE_FLAG_ constants */
73 u1 optlevel; /* optimization level of this code */
74 s4 basicblockcount; /* number of basic blocks */
76 int32_t synchronizedoffset; /* stack offset of synchronized obj. */
79 u1 *mcode; /* pointer to machine code */
80 u1 *entrypoint; /* machine code entry point */
81 s4 mcodelength; /* length of generated machine code */
83 exceptiontable_t *exceptiontable;
84 LinenumberTable* linenumbertable;
88 List<patchref_t>* patchers;
94 s4 stackframesize; /* size of the stackframe in slots */
96 #if defined(ENABLE_REPLACEMENT)
97 rplpoint *rplpoints; /* replacement points */
98 rplalloc *regalloc; /* register allocation info */
99 s4 rplpointcount; /* number of replacement points */
100 s4 globalcount; /* number of global allocations */
101 s4 regalloccount; /* number of total allocations */
102 s4 memuse; /* number of arg + local slots */
103 u1 savedintcount; /* number of callee saved int regs */
104 u1 savedfltcount; /* number of callee saved flt regs */
105 # if defined(HAS_ADDRESS_REGISTER_FILE)
106 u1 savedadrcount; /* number of callee saved adr regs */
108 u1 *savedmcode; /* saved code under patches */
111 #if defined(ENABLE_PROFILING)
112 u4 frequency; /* number of method invocations */
114 s8 cycles; /* number of cpu cycles */
123 /* inline functions ***********************************************************/
125 /* code_xxx_invalid ************************************************************
127 Functions for CODE_FLAG_INVALID.
129 *******************************************************************************/
131 inline static int code_is_invalid(codeinfo *code)
133 return (code->flags & CODE_FLAG_INVALID);
136 inline static void code_flag_invalid(codeinfo *code)
138 code->flags |= CODE_FLAG_INVALID;
141 inline static void code_unflag_invalid(codeinfo *code)
143 code->flags &= ~CODE_FLAG_INVALID;
147 /* code_xxx_leafmethod *********************************************************
149 Functions for CODE_FLAG_LEAFMETHOD.
151 *******************************************************************************/
153 inline static int code_is_leafmethod(codeinfo *code)
155 return (code->flags & CODE_FLAG_LEAFMETHOD);
158 inline static void code_flag_leafmethod(codeinfo *code)
160 code->flags |= CODE_FLAG_LEAFMETHOD;
163 inline static void code_unflag_leafmethod(codeinfo *code)
165 code->flags &= ~CODE_FLAG_LEAFMETHOD;
169 /* code_xxx_synchronized *******************************************************
171 Functions for CODE_FLAG_SYNCHRONIZED.
173 *******************************************************************************/
175 inline static int code_is_synchronized(codeinfo *code)
177 return (code->flags & CODE_FLAG_SYNCHRONIZED);
180 inline static void code_flag_synchronized(codeinfo *code)
182 code->flags |= CODE_FLAG_SYNCHRONIZED;
185 inline static void code_unflag_synchronized(codeinfo *code)
187 code->flags &= ~CODE_FLAG_SYNCHRONIZED;
191 /* code_get_codeinfo_for_pv ****************************************************
193 Return the codeinfo for the given PV.
201 *******************************************************************************/
203 inline static codeinfo *code_get_codeinfo_for_pv(void *pv)
209 code = *((codeinfo **) (((uintptr_t) pv) + CodeinfoPointer));
215 /* function prototypes ********************************************************/
217 void code_init(void);
219 codeinfo *code_codeinfo_new(methodinfo *m);
220 void code_codeinfo_free(codeinfo *code);
222 codeinfo *code_find_codeinfo_for_pc(void *pc);
223 codeinfo *code_find_codeinfo_for_pc_nocheck(void *pc);
225 methodinfo *code_get_methodinfo_for_pv(void *pv);
227 #if defined(ENABLE_REPLACEMENT)
228 int code_get_sync_slot_count(codeinfo *code);
229 #endif /* defined(ENABLE_REPLACEMENT) */
231 void code_free_code_of_method(methodinfo *m);
241 * These are local overrides for various environment variables in Emacs.
242 * Please do not remove this and leave it at the end of the file, where
243 * Emacs will automagically detect them.
244 * ---------------------------------------------------------------------
247 * indent-tabs-mode: t
251 * vim:noexpandtab:sw=4:ts=4: