57682f463921702b7410b8bf1b2ee132b4242627
[cacao.git] / src / vm / jit / code.h
1 /* src/vm/jit/code.h - codeinfo struct for representing compiled code
2
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
7
8    This file is part of CACAO.
9
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.
14
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.
19
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
23    02110-1301, USA.
24
25    $Id$
26
27 */
28
29
30 #ifndef _CODE_H
31 #define _CODE_H
32
33 /* forward typedefs ***********************************************************/
34
35 #include "config.h"
36 #include "vm/types.h"
37
38 #include "toolbox/list.h"
39
40 #include "vm/global.h"
41
42 #include "vm/jit/replace.h"
43
44 #include "vmcore/method.h"
45
46
47 /* constants ******************************************************************/
48
49 #define CODE_FLAG_INVALID     0x0001
50 #define CODE_FLAG_LEAFMETHOD  0x0002
51
52
53 /* codeinfo *******************************************************************
54
55    A codeinfo represents a particular realization of a method in
56    machine code.
57
58    ATTENTION: The methodinfo entry in the code-structure MUST have the
59    offset 0, otherwise we have a problem in our compiler stub. This is
60    checked with an assert in code_init().
61
62 *******************************************************************************/
63
64 struct codeinfo {
65         methodinfo   *m;                    /* method this is a realization of    */
66         codeinfo     *prev;                 /* previous codeinfo of this method   */
67
68         u4            codeflags;            /* or of CODE_FLAG_ constants         */
69
70         u1            optlevel;             /* optimization level of this code    */
71         s4            basicblockcount;      /* number of basic blocks             */
72
73         /* machine code */
74         u1           *mcode;                /* pointer to machine code            */
75         u1           *entrypoint;           /* machine code entry point           */
76         s4            mcodelength;          /* length of generated machine code   */
77
78         /* patcher list */
79         list_t       *patchers;
80
81         /* replacement */                                   
82 #if defined(ENABLE_REPLACEMENT)
83         rplpoint     *rplpoints;            /* replacement points                 */
84         rplalloc     *regalloc;             /* register allocation info           */
85         s4            rplpointcount;        /* number of replacement points       */
86         s4            globalcount;          /* number of global allocations       */
87         s4            regalloccount;        /* number of total allocations        */
88         s4            memuse;               /* number of arg + local slots        */
89         s4            stackframesize;       /* size of the stackframe in slots    */
90         u1            savedintcount;        /* number of callee saved int regs    */
91         u1            savedfltcount;        /* number of callee saved flt regs    */
92 # if defined(HAS_ADDRESS_REGISTER_FILE)
93         u1            savedadrcount;        /* number of callee saved adr regs    */
94 # endif
95         u1           *savedmcode;           /* saved code under patches           */
96 #endif
97
98 #if defined(ENABLE_PROFILING)
99         u4            frequency;            /* number of method invocations       */
100         u4           *bbfrequency;                  
101         s8            cycles;               /* number of cpu cycles               */
102 #endif
103 };
104
105
106 /* macros *********************************************************************/
107
108 #define CODE_IS_VALID(code)       (!((code)->codeflags & CODE_FLAG_INVALID))
109 #define CODE_IS_INVALID(code)     ((code)->codeflags & CODE_FLAG_INVALID)
110 #define CODE_IS_LEAFMETHOD(code)  ((code)->codeflags & CODE_FLAG_LEAFMETHOD)
111
112 #define CODE_SETFLAG_INVALID(code)                                   \
113             ((code)->codeflags |= CODE_FLAG_INVALID)
114 #define CODE_SETFLAG_LEAFMETHOD(code)                                \
115             ((code)->codeflags |= CODE_FLAG_LEAFMETHOD)
116
117
118 /* function prototypes ********************************************************/
119
120 bool code_init(void);
121
122 codeinfo *code_codeinfo_new(methodinfo *m);
123 void code_codeinfo_free(codeinfo *code);
124
125 codeinfo *code_find_codeinfo_for_pc(u1 *pc);
126
127 methodinfo *code_get_methodinfo_for_pv(u1 *pv);
128
129 #if defined(ENABLE_REPLACEMENT)
130 int code_get_sync_slot_count(codeinfo *code);
131 #endif /* defined(ENABLE_REPLACEMENT) */
132
133 void code_free_code_of_method(methodinfo *m);
134
135 #endif /* _CODE_H */
136
137
138 /*
139  * These are local overrides for various environment variables in Emacs.
140  * Please do not remove this and leave it at the end of the file, where
141  * Emacs will automagically detect them.
142  * ---------------------------------------------------------------------
143  * Local variables:
144  * mode: c
145  * indent-tabs-mode: t
146  * c-basic-offset: 4
147  * tab-width: 4
148  * End:
149  * vim:noexpandtab:sw=4:ts=4:
150  */