9b2c5916c99c9267ceed107dd48fb65e357bda82
[cacao.git] / src / vm / jit / patcher.h
1 /* src/vm/jit/patcher.h - code patching functions
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: Christian Thalinger
28
29    Changes: Edwin Steiner
30
31    $Id: patcher.h 5929 2006-11-06 17:13:40Z twisti $
32
33 */
34
35
36 #ifndef _PATCHER_H
37 #define _PATCHER_H
38
39 #include "config.h"
40
41 #include <assert.h>
42
43 #include "vm/types.h"
44
45 #if defined(ENABLE_THREADS)
46 # include "threads/native/lock.h"
47 #endif
48
49 #include "vm/global.h"
50
51
52 /* patcher macros *************************************************************/
53
54 #define PATCHER_FLAG_PATCHED    (vftbl_t *) 0xdeadbeef
55
56
57 #if defined(ENABLE_THREADS)
58
59 #define PATCHER_MONITORENTER \
60         /* enter a monitor on the patching position */       \
61                                                              \
62         lock_monitor_enter(o);                               \
63                                                              \
64         /* check if the position has already been patched */ \
65                                                              \
66         if (o->vftbl != NULL) {                              \
67         assert(o->vftbl == PATCHER_FLAG_PATCHED);        \
68                                                          \
69                 lock_monitor_exit(o);                            \
70                                                              \
71                 return NULL;                                     \
72         }                                                    \
73
74
75 #define PATCHER_MONITOREXIT \
76         /* leave the monitor on the patching position */     \
77                                                              \
78         lock_monitor_exit(o);
79
80
81 #define PATCHER_MARK_PATCHED_MONITOREXIT \
82         /* mark position as patched */                       \
83                                                              \
84         o->vftbl = PATCHER_FLAG_PATCHED;                     \
85                                                              \
86         PATCHER_MONITOREXIT
87
88 #else
89
90 #define PATCHER_MONITORENTER                 /* nop */
91 #define PATCHER_MONITOREXIT                  /* nop */
92 #define PATCHER_MARK_PATCHED_MONITOREXIT     /* nop */
93
94 #endif /* defined(ENABLE_THREADS) */
95
96
97 /* function prototypes ********************************************************/
98
99 java_objectheader *patcher_wrapper(u1 *sp, u1 *pv, u1 *ra);
100 #define PATCHER_wrapper (functionptr) patcher_wrapper
101
102 bool patcher_resolve_class(u1 *sp);
103 #define PATCHER_resolve_class (functionptr) patcher_resolve_class
104
105 bool patcher_initialize_class(u1 *sp);
106 #define PATCHER_initialize_class (functionptr) patcher_initialize_class
107
108 bool patcher_resolve_classref_to_classinfo(u1 *sp);
109 #define PATCHER_resolve_classref_to_classinfo (functionptr) patcher_resolve_classref_to_classinfo
110
111 bool patcher_resolve_classref_to_vftbl(u1 *sp);
112 #define PATCHER_resolve_classref_to_vftbl (functionptr) patcher_resolve_classref_to_vftbl
113
114 bool patcher_resolve_classref_to_flags(u1 *sp);
115 #define PATCHER_resolve_classref_to_flags (functionptr) patcher_resolve_classref_to_flags
116
117 #if !defined(WITH_STATIC_CLASSPATH)
118 bool patcher_resolve_native_function(u1 *sp);
119 #define PATCHER_resolve_native_function (functionptr) patcher_resolve_native_function
120 #endif
121
122
123 bool patcher_get_putstatic(u1 *sp);
124 #define PATCHER_get_putstatic (functionptr) patcher_get_putstatic
125
126 #if defined(__I386__)
127
128 bool patcher_getfield(u1 *sp);
129 #define PATCHER_getfield (functionptr) patcher_getfield
130
131 bool patcher_putfield(u1 *sp);
132 #define PATCHER_putfield (functionptr) patcher_putfield
133
134 #else
135
136 bool patcher_get_putfield(u1 *sp);
137 #define PATCHER_get_putfield (functionptr) patcher_get_putfield
138
139 #endif /* defined(__I386__) */
140
141 #if defined(__I386__) || defined(__X86_64__)
142
143 bool patcher_putfieldconst(u1 *sp);
144 #define PATCHER_putfieldconst (functionptr) patcher_putfieldconst
145
146 #endif /* defined(__I386__) || defined(__X86_64__) */
147
148 bool patcher_aconst(u1 *sp);
149 #define PATCHER_aconst (functionptr) patcher_aconst
150
151 bool patcher_builtin_multianewarray(u1 *sp);
152 #define PATCHER_builtin_multianewarray (functionptr) patcher_builtin_multianewarray
153
154 bool patcher_builtin_arraycheckcast(u1 *sp);
155 #define PATCHER_builtin_arraycheckcast (functionptr) patcher_builtin_arraycheckcast
156
157 bool patcher_invokestatic_special(u1 *sp);
158 #define PATCHER_invokestatic_special (functionptr) patcher_invokestatic_special
159
160 bool patcher_invokevirtual(u1 *sp);
161 #define PATCHER_invokevirtual (functionptr) patcher_invokevirtual
162
163 bool patcher_invokeinterface(u1 *sp);
164 #define PATCHER_invokeinterface (functionptr) patcher_invokeinterface
165
166
167 /* only for interpreter */
168 bool patcher_checkcast_instanceof(u1 *sp);
169 #define PATCHER_checkcast_instanceof (functionptr) patcher_checkcast_instanceof
170
171
172 bool patcher_checkcast_instanceof_flags(u1 *sp);
173 #define PATCHER_checkcast_instanceof_flags (functionptr) patcher_checkcast_instanceof_flags
174
175 bool patcher_checkcast_instanceof_interface(u1 *sp);
176 #define PATCHER_checkcast_instanceof_interface (functionptr) patcher_checkcast_instanceof_interface
177
178 bool patcher_checkcast_interface(u1 *sp);
179 #define PATCHER_checkcast_interface (functionptr) patcher_checkcast_interface
180
181 bool patcher_instanceof_interface(u1 *sp);
182 #define PATCHER_instanceof_interface (functionptr) patcher_instanceof_interface
183
184 #if defined(__I386__) || defined(__X86_64__) || defined(__POWERPC__) || defined(__POWERPC64__)
185
186 bool patcher_checkcast_class(u1 *sp);
187 #define PATCHER_checkcast_class (functionptr) patcher_checkcast_class
188
189 bool patcher_instanceof_class(u1 *sp);
190 #define PATCHER_instanceof_class (functionptr) patcher_instanceof_class
191
192 #else /* defined(__I386__) || defined(__X86_64__) || defined(__POWERPC__) || defined(__POWERPC64__)*/
193
194 bool patcher_checkcast_instanceof_class(u1 *sp);
195 #define PATCHER_checkcast_instanceof_class (functionptr) patcher_checkcast_instanceof_class
196
197 #endif /* defined(__I386__) || defined(__X86_64__) || defined(__POWERPC__) || defined(__POWERPC64__)*/
198
199 bool patcher_clinit(u1 *sp);
200 #define PATCHER_clinit (functionptr) patcher_clinit
201
202 bool patcher_athrow_areturn(u1 *sp);
203 #define PATCHER_athrow_areturn (functionptr) patcher_athrow_areturn
204
205 #if !defined(WITH_STATIC_CLASSPATH)
206 bool patcher_resolve_native(u1 *sp);
207 #define PATCHER_resolve_native (functionptr) patcher_resolve_native
208 #endif
209
210
211 /* stuff for the interpreter **************************************************/
212
213 #if defined(ENABLE_INTRP)
214 bool intrp_patcher_get_putstatic(u1 *sp);
215 bool intrp_patcher_get_putstatic_clinit(u1 *sp);
216 bool intrp_patcher_get_putfield(u1 *sp);
217 bool intrp_patcher_aconst(u1 *sp);
218 bool intrp_patcher_builtin_multianewarray(u1 *sp);
219 bool intrp_patcher_builtin_arraycheckcast(u1 *sp);
220 bool intrp_patcher_invokestatic_special(u1 *sp);
221 bool intrp_patcher_invokevirtual(u1 *sp);
222 bool intrp_patcher_invokeinterface(u1 *sp);
223 bool intrp_patcher_checkcast_instanceof(u1 *sp);
224 bool intrp_patcher_resolve_native(u1 *sp);
225 #endif /* defined(ENABLE_INTRP) */
226
227 #endif /* _PATCHER_H */
228
229
230 /*
231  * These are local overrides for various environment variables in Emacs.
232  * Please do not remove this and leave it at the end of the file, where
233  * Emacs will automagically detect them.
234  * ---------------------------------------------------------------------
235  * Local variables:
236  * mode: c
237  * indent-tabs-mode: t
238  * c-basic-offset: 4
239  * tab-width: 4
240  * End:
241  * vim:noexpandtab:sw=4:ts=4:
242  */
243