* src/vm/jit/intrp/Makefile.am (EXTRA_DIST): Added gray.fs and
[cacao.git] / src / vm / jit / patcher.h
1 /* src/vm/jit/patcher.h - code patching functions
2
3    Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    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., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Christian Thalinger
28
29    Changes:
30
31    $Id: patcher.h 4155 2006-01-12 21:17:46Z twisti $
32
33 */
34
35
36 #ifndef _PATCHER_H
37 #define _PATCHER_H
38
39 #include "config.h"
40 #include "vm/types.h"
41
42 #include "vm/global.h"
43
44
45 /* patcher macros *************************************************************/
46
47 #if defined(USE_THREADS)
48
49 #define PATCHER_MONITORENTER \
50         /* enter a monitor on the patching position */       \
51                                                              \
52         builtin_monitorenter(o);                             \
53                                                              \
54         /* check if the position has already been patched */ \
55                                                              \
56         if (o->vftbl) {                                      \
57                 builtin_monitorexit(o);                          \
58                                                              \
59                 return true;                                     \
60         }                                                    \
61
62
63 #define PATCHER_MONITOREXIT \
64         /* leave the monitor on the patching position */     \
65                                                              \
66         builtin_monitorexit(o);
67
68
69 #define PATCHER_MARK_PATCHED_MONITOREXIT \
70         /* mark position as patched */                       \
71                                                              \
72         o->vftbl = (vftbl_t *) 1;                            \
73                                                              \
74         PATCHER_MONITOREXIT
75
76 #else
77
78 #define PATCHER_MONITORENTER                 /* nop */
79 #define PATCHER_MONITOREXIT                  /* nop */
80 #define PATCHER_MARK_PATCHED_MONITOREXIT     /* nop */
81
82 #endif /* defined(USE_THREADS) */
83
84
85 /* function prototypes ********************************************************/
86
87 bool patcher_get_putstatic(u1 *sp);
88 #define PATCHER_get_putstatic (functionptr) patcher_get_putstatic
89
90 #if defined(__I386__)
91
92 bool patcher_getfield(u1 *sp);
93 #define PATCHER_getfield (functionptr) patcher_getfield
94
95 bool patcher_putfield(u1 *sp);
96 #define PATCHER_putfield (functionptr) patcher_putfield
97
98 #else
99
100 bool patcher_get_putfield(u1 *sp);
101 #define PATCHER_get_putfield (functionptr) patcher_get_putfield
102
103 #endif /* defined(__I386__) */
104
105 #if defined(__I386__) || defined(__X86_64__)
106
107 bool patcher_putfieldconst(u1 *sp);
108 #define PATCHER_putfieldconst (functionptr) patcher_putfieldconst
109
110 #endif /* defined(__I386__) || defined(__X86_64__) */
111
112 bool patcher_aconst(u1 *sp);
113 #define PATCHER_aconst (functionptr) patcher_aconst
114
115 bool patcher_builtin_multianewarray(u1 *sp);
116 #define PATCHER_builtin_multianewarray (functionptr) patcher_builtin_multianewarray
117
118 bool patcher_builtin_arraycheckcast(u1 *sp);
119 #define PATCHER_builtin_arraycheckcast (functionptr) patcher_builtin_arraycheckcast
120
121 bool patcher_invokestatic_special(u1 *sp);
122 #define PATCHER_invokestatic_special (functionptr) patcher_invokestatic_special
123
124 bool patcher_invokevirtual(u1 *sp);
125 #define PATCHER_invokevirtual (functionptr) patcher_invokevirtual
126
127 bool patcher_invokeinterface(u1 *sp);
128 #define PATCHER_invokeinterface (functionptr) patcher_invokeinterface
129
130
131 /* only for interpreter */
132 bool patcher_checkcast_instanceof(u1 *sp);
133 #define PATCHER_checkcast_instanceof (functionptr) patcher_checkcast_instanceof
134
135
136 bool patcher_checkcast_instanceof_flags(u1 *sp);
137 #define PATCHER_checkcast_instanceof_flags (functionptr) patcher_checkcast_instanceof_flags
138
139 bool patcher_checkcast_instanceof_interface(u1 *sp);
140 #define PATCHER_checkcast_instanceof_interface (functionptr) patcher_checkcast_instanceof_interface
141
142 #if defined(__I386__) || defined(__X86_64__) || defined(__POWERPC__)
143
144 bool patcher_checkcast_class(u1 *sp);
145 #define PATCHER_checkcast_class (functionptr) patcher_checkcast_class
146
147 bool patcher_instanceof_class(u1 *sp);
148 #define PATCHER_instanceof_class (functionptr) patcher_instanceof_class
149
150 #else /* defined(__I386__) || defined(__X86_64__) || defined(__POWERPC__) */
151
152 bool patcher_checkcast_instanceof_class(u1 *sp);
153 #define PATCHER_checkcast_instanceof_class (functionptr) patcher_checkcast_instanceof_class
154
155 #endif /* defined(__I386__) || defined(__X86_64__) || defined(__POWERPC__) */
156
157 bool patcher_clinit(u1 *sp);
158 #define PATCHER_clinit (functionptr) patcher_clinit
159
160 bool patcher_athrow_areturn(u1 *sp);
161 #define PATCHER_athrow_areturn (functionptr) patcher_athrow_areturn
162
163 #if !defined(ENABLE_STATICVM)
164 bool patcher_resolve_native(u1 *sp);
165 #define PATCHER_resolve_native (functionptr) patcher_resolve_native
166 #endif /* !defined(ENABLE_STATICVM) */
167
168
169 /* stuff for the interpreter **************************************************/
170
171 #if defined(ENABLE_INTRP)
172 bool intrp_patcher_get_putstatic(u1 *sp);
173 bool intrp_patcher_get_putfield(u1 *sp);
174 bool intrp_patcher_aconst(u1 *sp);
175 bool intrp_patcher_builtin_multianewarray(u1 *sp);
176 bool intrp_patcher_builtin_arraycheckcast(u1 *sp);
177 bool intrp_patcher_invokestatic_special(u1 *sp);
178 bool intrp_patcher_invokevirtual(u1 *sp);
179 bool intrp_patcher_invokeinterface(u1 *sp);
180 bool intrp_patcher_checkcast_instanceof(u1 *sp);
181 bool intrp_patcher_resolve_native(u1 *sp);
182 #endif /* defined(ENABLE_INTRP) */
183
184 #endif /* _PATCHER_H */
185
186
187 /*
188  * These are local overrides for various environment variables in Emacs.
189  * Please do not remove this and leave it at the end of the file, where
190  * Emacs will automagically detect them.
191  * ---------------------------------------------------------------------
192  * Local variables:
193  * mode: c
194  * indent-tabs-mode: t
195  * c-basic-offset: 4
196  * tab-width: 4
197  * End:
198  * vim:noexpandtab:sw=4:ts=4:
199  */
200