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