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