* src/vm/jit/replace.h (rplpoint): Removed members outcode, code,
[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_t executionstate_t;
43 typedef struct sourcestate_t sourcestate_t;
44 typedef struct sourceframe_t sourceframe_t;
45
46 #include "config.h"
47 #include "vm/types.h"
48
49 #include "arch.h"
50 #include "md-abi.h"
51
52 #include "vm/method.h"
53 #include "vm/jit/reg.h"
54
55
56 /*** structs *********************************************************/
57
58 typedef struct rplalloc rplalloc;
59
60 #define RPLALLOC_STACK  -1
61 #define RPLALLOC_PARAM  -2
62 #define RPLALLOC_SYNC   -3
63
64 /* `rplalloc` is a compact struct for register allocation info        */
65
66 /* XXX optimize this for space efficiency */
67 struct rplalloc {
68         s4           index;     /* local index, -1 for stack slot         */
69         s4           regoff;    /* register index / stack slot offset     */
70         unsigned int flags:4;   /* OR of (INMEMORY,...)                   */
71         unsigned int type:4;    /* TYPE_... constant                      */
72 };
73
74 #if INMEMORY > 0x08
75 #error value of INMEMORY is too big to fit in rplalloc.flags
76 #endif
77
78
79 /* XXX what to do about overlapping rplpoints? */
80 /* CAUTION: Do not change the numerical values. These are used as     */
81 /*          indices into replace_normalize_type_map.                  */
82 #define RPLPOINT_TYPE_STD     BBTYPE_STD
83 #define RPLPOINT_TYPE_EXH     BBTYPE_EXH
84 #define RPLPOINT_TYPE_SBR     BBTYPE_SBR
85 #define RPLPOINT_TYPE_CALL    3
86 #define RPLPOINT_TYPE_INLINE  4
87 #define RPLPOINT_TYPE_RETURN  5
88 #define RPLPOINT_TYPE_BODY    6
89
90 #define RPLPOINT_FLAG_NOTRAP  0x01  /* rplpoint cannot be trapped */
91 #define RPLPOINT_FLAG_ACTIVE  0x08  /* trap is active             */
92
93
94 #if !defined(NDEBUG)
95 #define RPLPOINT_CHECK(type)     , RPLPOINT_TYPE_##type
96 #define RPLPOINT_CHECK_BB(bptr)  , (bptr)->type
97 #else
98 #define RPLPOINT_CHECK(type)
99 #define RPLPOINT_CHECK_BB(bptr)
100 #endif
101
102
103 /* An `rplpoint` represents a replacement point in a compiled method  */
104
105 struct rplpoint {
106         u1          *pc;           /* machine code PC of this point       */
107         methodinfo  *method;       /* source method this point is in      */
108         rplpoint    *parent;       /* rplpoint of the inlined body        */ /* XXX unify with code */
109         rplalloc    *regalloc;     /* pointer to register index table     */
110         s4           id;           /* id of the rplpoint within method    */
111         s4           callsize;     /* size of call code in bytes          */
112         unsigned int regalloccount:20; /* number of local allocations     */
113         unsigned int type:4;           /* RPLPOINT_TYPE_... constant      */
114         unsigned int flags:8;          /* OR of RPLPOINT_... constants    */
115 };
116
117
118 /* An `executionsstate` represents the state of a thread as it reached */
119 /* an replacement point or is about to enter one.                      */
120
121 struct executionstate_t {
122         u1           *pc;                               /* program counter */
123         u1           *sp;                   /* stack pointer within method */
124         u1           *pv;                   /* procedure value. NULL means */
125                                             /* search the AVL tree         */
126
127         u8            intregs[INT_REG_CNT];             /* register values */
128         u8            fltregs[FLT_REG_CNT];             /* register values */
129
130         codeinfo     *code;            /* codeinfo corresponding to the pv */
131 };
132
133
134 struct sourceframe_t {
135         sourceframe_t *down;           /* source frame down the call chain */
136
137         methodinfo    *method;                  /* method this frame is in */
138         s4             id;
139         s4             type;
140
141         u8             instance;
142
143         u8            *javastack;                  /* values of stack vars */
144         u1            *javastacktype;              /*  types of stack vars */
145         s4             javastackdepth;             /* number of stack vars */
146
147         u8            *javalocals;                 /* values of javalocals */
148         u1            *javalocaltype;              /*  types of javalocals */
149         s4             javalocalcount;             /* number of javalocals */
150
151         u8            *syncslots;
152         s4             syncslotcount; /* XXX do we need more than one? */
153
154         rplpoint      *readrp;         /* rplpoint used to read this frame */
155 };
156
157
158 struct sourcestate_t {
159         sourceframe_t *frames;    /* list of source frames, from bottom up */
160 };
161
162
163 /*** prototypes ********************************************************/
164
165 bool replace_create_replacement_points(jitdata *jd);
166 void replace_free_replacement_points(codeinfo *code);
167
168 void replace_activate_replacement_points(codeinfo *code, bool mappable);
169 void replace_deactivate_replacement_points(codeinfo *code);
170
171 void replace_me(rplpoint *rp,executionstate_t *es);
172
173 #if !defined(NDEBUG)
174 void replace_show_replacement_points(codeinfo *code);
175 void replace_replacement_point_println(rplpoint *rp, int depth);
176 void replace_executionstate_println(executionstate_t *es);
177 void replace_sourcestate_println(sourcestate_t *ss);
178 void replace_source_frame_println(sourceframe_t *frame);
179 #endif
180
181 /* machine dependent functions (code in ARCH_DIR/md.c) */
182
183 #if defined(ENABLE_JIT)
184 void md_patch_replacement_point(codeinfo *code, s4 index, rplpoint *rp,
185                                                                 u1 *savedmcode);
186 #endif
187
188 #endif
189
190 /*
191  * These are local overrides for various environment variables in Emacs.
192  * Please do not remove this and leave it at the end of the file, where
193  * Emacs will automagically detect them.
194  * ---------------------------------------------------------------------
195  * Local variables:
196  * mode: c
197  * indent-tabs-mode: t
198  * c-basic-offset: 4
199  * tab-width: 4
200  * End:
201  * vim:noexpandtab:sw=4:ts=4:
202  */