1 /* src/vm/jit/code.h - 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
38 #include "toolbox/list.h"
40 #include "vm/global.h"
42 #include "vm/jit/exceptiontable.h"
43 #include "vm/jit/linenumbertable.h"
44 #include "vm/jit/methodheader.h"
45 #include "vm/jit/replace.h"
47 #include "vmcore/method.h"
50 /* constants ******************************************************************/
52 #define CODE_FLAG_INVALID 0x0001
53 #define CODE_FLAG_LEAFMETHOD 0x0002
54 #define CODE_FLAG_SYNCHRONIZED 0x0004
57 /* codeinfo *******************************************************************
59 A codeinfo represents a particular realization of a method in
62 ATTENTION: The methodinfo entry in the code-structure MUST have the
63 offset 0, otherwise we have a problem in our compiler stub. This is
64 checked with an assert in code_init().
66 *******************************************************************************/
69 methodinfo *m; /* method this is a realization of */
70 codeinfo *prev; /* previous codeinfo of this method */
72 uint32_t flags; /* OR of CODE_FLAG_ constants */
74 u1 optlevel; /* optimization level of this code */
75 s4 basicblockcount; /* number of basic blocks */
77 int32_t synchronizedoffset; /* stack offset of synchronized obj. */
80 u1 *mcode; /* pointer to machine code */
81 u1 *entrypoint; /* machine code entry point */
82 s4 mcodelength; /* length of generated machine code */
84 exceptiontable_t *exceptiontable;
85 linenumbertable_t *linenumbertable;
91 #if defined(ENABLE_REPLACEMENT)
92 rplpoint *rplpoints; /* replacement points */
93 rplalloc *regalloc; /* register allocation info */
94 s4 rplpointcount; /* number of replacement points */
95 s4 globalcount; /* number of global allocations */
96 s4 regalloccount; /* number of total allocations */
97 s4 memuse; /* number of arg + local slots */
98 s4 stackframesize; /* size of the stackframe in slots */
99 u1 savedintcount; /* number of callee saved int regs */
100 u1 savedfltcount; /* number of callee saved flt regs */
101 # if defined(HAS_ADDRESS_REGISTER_FILE)
102 u1 savedadrcount; /* number of callee saved adr regs */
104 u1 *savedmcode; /* saved code under patches */
107 #if defined(ENABLE_PROFILING)
108 u4 frequency; /* number of method invocations */
110 s8 cycles; /* number of cpu cycles */
115 /* inline functions ***********************************************************/
117 /* code_xxx_invalid ************************************************************
119 Functions for CODE_FLAG_INVALID.
121 *******************************************************************************/
123 inline static int code_is_invalid(codeinfo *code)
125 return (code->flags & CODE_FLAG_INVALID);
128 inline static void code_flag_invalid(codeinfo *code)
130 code->flags |= CODE_FLAG_INVALID;
133 inline static void code_unflag_invalid(codeinfo *code)
135 code->flags &= ~CODE_FLAG_INVALID;
139 /* code_xxx_leafmethod *********************************************************
141 Functions for CODE_FLAG_LEAFMETHOD.
143 *******************************************************************************/
145 inline static int code_is_leafmethod(codeinfo *code)
147 return (code->flags & CODE_FLAG_LEAFMETHOD);
150 inline static void code_flag_leafmethod(codeinfo *code)
152 code->flags |= CODE_FLAG_LEAFMETHOD;
155 inline static void code_unflag_leafmethod(codeinfo *code)
157 code->flags &= ~CODE_FLAG_LEAFMETHOD;
161 /* code_xxx_synchronized *******************************************************
163 Functions for CODE_FLAG_SYNCHRONIZED.
165 *******************************************************************************/
167 inline static int code_is_synchronized(codeinfo *code)
169 return (code->flags & CODE_FLAG_SYNCHRONIZED);
172 inline static void code_flag_synchronized(codeinfo *code)
174 code->flags |= CODE_FLAG_SYNCHRONIZED;
177 inline static void code_unflag_synchronized(codeinfo *code)
179 code->flags &= ~CODE_FLAG_SYNCHRONIZED;
183 /* code_get_codeinfo_for_pv ****************************************************
185 Return the codeinfo for the given PV.
193 *******************************************************************************/
195 inline static codeinfo *code_get_codeinfo_for_pv(void *pv)
201 code = *((codeinfo **) (((uintptr_t) pv) + CodeinfoPointer));
207 /* function prototypes ********************************************************/
209 bool code_init(void);
211 codeinfo *code_codeinfo_new(methodinfo *m);
212 void code_codeinfo_free(codeinfo *code);
214 codeinfo *code_find_codeinfo_for_pc(u1 *pc);
215 codeinfo *code_find_codeinfo_for_pc_nocheck(u1 *pc);
217 methodinfo *code_get_methodinfo_for_pv(u1 *pv);
219 #if defined(ENABLE_REPLACEMENT)
220 int code_get_sync_slot_count(codeinfo *code);
221 #endif /* defined(ENABLE_REPLACEMENT) */
223 void code_free_code_of_method(methodinfo *m);
229 * These are local overrides for various environment variables in Emacs.
230 * Please do not remove this and leave it at the end of the file, where
231 * Emacs will automagically detect them.
232 * ---------------------------------------------------------------------
235 * indent-tabs-mode: t
239 * vim:noexpandtab:sw=4:ts=4: