eb497607eb34eef04a52202ffd4b3c1859fd9a5b
[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 #include "config.h"
40 #include "vm/types.h"
41 #include "vm/method.h"
42 #include "arch.h"
43 #include "md-abi.h"
44
45 /*** structs *********************************************************/
46
47 typedef struct rplalloc rplalloc;
48
49 /* `rplalloc` is a compact struct for register allocation info        */
50
51 struct rplalloc {
52         unsigned int index:16;  /* register index / stack slot offset     */
53         unsigned int flags:4;   /* OR of (INMEMORY,...)                   */
54         int          type:4;    /* TYPE_... constant                      */
55         unsigned int next:1;    /* if true, switch to next local          */
56 };
57
58 #if INMEMORY > 0x08
59 #error value of INMEMORY is too big to fit in rplalloc.flags
60 #endif
61
62 /* An `rplpoint` represents a replacement point in a compiled method  */
63
64 struct rplpoint {
65         u1          *pc;           /* machine code PC of this point       */
66         u1          *outcode;      /* pointer to replacement-out code     */
67         codeinfo    *code;         /* codeinfo this point belongs to      */
68         rplpoint    *target;       /* target of the replacement           */
69         u8           mcode;        /* saved maching code for patching     */
70         rplalloc    *regalloc;     /* pointer to register index table     */
71         unsigned int regalloccount:24; /* number of local allocations     */
72         unsigned int type:4;           /* BBTYPE_... constant             */
73         unsigned int flags:8;          /* OR of RPLPOINT_... constants    */
74 };
75
76 /* An `executionsstate` represents the state of a thread as it reached */
77 /* an replacement point or is about to enter one.                      */
78
79 struct executionstate {
80         u1           *pc;                               /* program counter */
81         u1           *sp;                   /* stack pointer within method */
82
83         u8            intregs[INT_REG_CNT];             /* register values */
84         u8            fltregs[FLT_REG_CNT];             /* register values */
85 };
86
87 /* `sourcestate` will probably only be used for debugging              */
88
89 struct sourcestate {
90         u8           *javastack;
91         s4            javastackdepth;
92
93         u8           *javalocals;      /* indexed by (i*5 + type) */
94         s4            javalocalcount;
95
96         u8            savedintregs[INT_SAV_CNT + 1]; /* XXX */
97         u8            savedfltregs[FLT_SAV_CNT + 1]; /* XXX */
98
99         u8           *syncslots;
100         s4            syncslotcount;
101 };
102
103 /*** prototypes ********************************************************/
104
105 bool replace_create_replacement_points(codeinfo *code,registerdata *rd);
106 void replace_free_replacement_points(codeinfo *code);
107
108 void replace_activate_replacement_point(rplpoint *rp,rplpoint *target);
109 void replace_deactivate_replacement_point(rplpoint *rp);
110 void replace_activate(codeinfo *code,codeinfo *target);
111
112 void replace_me(rplpoint *rp,executionstate *es);
113
114 #ifndef NDEBUG
115 void replace_show_replacement_points(codeinfo *code);
116 void replace_replacement_point_println(rplpoint *rp);
117 void replace_executionstate_println(executionstate *es,codeinfo *code);
118 void replace_sourcestate_println(sourcestate *ss);
119 #endif
120
121 /* machine dependent functions (code in ARCH_DIR/md.c) */
122
123 #if defined(ENABLE_JIT)
124 void md_patch_replacement_point(rplpoint *rp);
125 #endif
126
127 #endif
128
129 /*
130  * These are local overrides for various environment variables in Emacs.
131  * Please do not remove this and leave it at the end of the file, where
132  * Emacs will automagically detect them.
133  * ---------------------------------------------------------------------
134  * Local variables:
135  * mode: c
136  * indent-tabs-mode: t
137  * c-basic-offset: 4
138  * tab-width: 4
139  * End:
140  * vim:noexpandtab:sw=4:ts=4:
141  */