* src/vm/jit/code.h (codeinfo): Added field stackframesize.
[cacao.git] / src / vm / jit / replace.h
1 /* vm/jit/replace.h - on-stack replacement of methods
2
3    Copyright (C) 1996-2005, 2006 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    Contact: cacao@cacaojvm.org
26
27    Authors: Edwin Steiner
28
29    Changes:
30
31    $Id$
32
33 */
34
35
36 #ifndef _REPLACE_H
37 #define _REPLACE_H
38
39 /* forward typedefs ***********************************************************/
40
41 typedef struct rplpoint rplpoint;
42 typedef struct executionstate executionstate;
43 typedef struct sourcestate sourcestate;
44
45 #include "config.h"
46 #include "vm/types.h"
47
48 #include "arch.h"
49 #include "md-abi.h"
50
51 #include "vm/method.h"
52 #include "vm/jit/reg.h"
53
54
55 /*** structs *********************************************************/
56
57 typedef struct rplalloc rplalloc;
58
59 /* `rplalloc` is a compact struct for register allocation info        */
60
61 /* XXX optimize this for space efficiency */
62 struct rplalloc {
63         s4           index;     /* local index, -1 for stack slot         */
64         s4           regoff;    /* register index / stack slot offset     */
65         unsigned int flags:4;   /* OR of (INMEMORY,...)                   */
66         int          type:4;    /* TYPE_... constant                      */
67 };
68
69 #if INMEMORY > 0x08
70 #error value of INMEMORY is too big to fit in rplalloc.flags
71 #endif
72
73 /* An `rplpoint` represents a replacement point in a compiled method  */
74
75 struct rplpoint {
76         u1          *pc;           /* machine code PC of this point       */
77         u1          *outcode;      /* pointer to replacement-out code     */
78         codeinfo    *code;         /* codeinfo this point belongs to      */
79         rplpoint    *target;       /* target of the replacement           */
80         u8           mcode;        /* saved maching code for patching     */
81         rplalloc    *regalloc;     /* pointer to register index table     */
82         unsigned int regalloccount:24; /* number of local allocations     */
83         unsigned int type:4;           /* BBTYPE_... constant             */
84         unsigned int flags:8;          /* OR of RPLPOINT_... constants    */
85 };
86
87 /* An `executionsstate` represents the state of a thread as it reached */
88 /* an replacement point or is about to enter one.                      */
89
90 struct executionstate {
91         u1           *pc;                               /* program counter */
92         u1           *sp;                   /* stack pointer within method */
93         u1           *pv;                   /* procedure value. NULL means */
94                                             /* search the AVL tree         */
95
96         u8            intregs[INT_REG_CNT];             /* register values */
97         u8            fltregs[FLT_REG_CNT];             /* register values */
98
99         codeinfo     *code;
100 };
101
102 /* `sourcestate` will probably only be used for debugging              */
103
104 struct sourcestate {
105         u8           *javastack;
106         u1           *javastacktype;
107         s4            javastackdepth;
108
109         u8           *javalocals;
110         u1           *javalocaltype;
111         s4            javalocalcount;
112
113         u8            savedintregs[INT_SAV_CNT + 1]; /* XXX */
114         u8            savedfltregs[FLT_SAV_CNT + 1]; /* XXX */
115
116         u8           *syncslots;
117         s4            syncslotcount;
118
119         u1           *stackbase;
120 };
121
122 /*** prototypes ********************************************************/
123
124 bool replace_create_replacement_points(jitdata *jd);
125 void replace_free_replacement_points(codeinfo *code);
126
127 void replace_activate_replacement_point(rplpoint *rp,rplpoint *target);
128 void replace_deactivate_replacement_point(rplpoint *rp);
129 void replace_activate(codeinfo *code,codeinfo *target);
130
131 void replace_pop_activation_record(executionstate *es,
132                                                                    sourcestate *ss);
133
134 void replace_me(rplpoint *rp,executionstate *es);
135
136 #ifndef NDEBUG
137 void replace_show_replacement_points(codeinfo *code);
138 void replace_replacement_point_println(rplpoint *rp);
139 void replace_executionstate_println(executionstate *es);
140 void replace_sourcestate_println(sourcestate *ss);
141 #endif
142
143 /* machine dependent functions (code in ARCH_DIR/md.c) */
144
145 #if defined(ENABLE_JIT)
146 void md_patch_replacement_point(rplpoint *rp);
147 #endif
148
149 #endif
150
151 /*
152  * These are local overrides for various environment variables in Emacs.
153  * Please do not remove this and leave it at the end of the file, where
154  * Emacs will automagically detect them.
155  * ---------------------------------------------------------------------
156  * Local variables:
157  * mode: c
158  * indent-tabs-mode: t
159  * c-basic-offset: 4
160  * tab-width: 4
161  * End:
162  * vim:noexpandtab:sw=4:ts=4:
163  */