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