1 /* src/vm/jit/patcher.h - code patching functions
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
8 This file is part of CACAO.
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.
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.
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
37 #include "threads/lock-common.h"
39 #include "vm/global.h"
42 #if defined(__ALPHA__) || defined(__ARM__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__S390__)
43 # error "you should no longer include this file"
47 /* patcher macros *************************************************************/
49 #define PATCHER_FLAG_PATCHED (vftbl_t *) 0xdeadbeef
52 #if defined(ENABLE_THREADS)
54 #define PATCHER_MONITORENTER \
55 /* enter a monitor on the patching position */ \
57 lock_monitor_enter(o); \
59 /* check if the position has already been patched */ \
61 if (o->vftbl != NULL) { \
62 assert(o->vftbl == PATCHER_FLAG_PATCHED); \
64 lock_monitor_exit(o); \
70 #define PATCHER_MONITOREXIT \
71 /* leave the monitor on the patching position */ \
76 #define PATCHER_MARK_PATCHED_MONITOREXIT \
77 /* mark position as patched */ \
79 o->vftbl = PATCHER_FLAG_PATCHED; \
85 #define PATCHER_MONITORENTER /* nop */
86 #define PATCHER_MONITOREXIT /* nop */
87 #define PATCHER_MARK_PATCHED_MONITOREXIT /* nop */
89 #endif /* defined(ENABLE_THREADS) */
92 /* function prototypes ********************************************************/
94 java_object_t *patcher_wrapper(u1 *sp, u1 *pv, u1 *ra);
95 #define PATCHER_wrapper (functionptr) patcher_wrapper
97 bool patcher_resolve_class(u1 *sp);
98 #define PATCHER_resolve_class (functionptr) patcher_resolve_class
100 bool patcher_initialize_class(u1 *sp);
101 #define PATCHER_initialize_class (functionptr) patcher_initialize_class
103 bool patcher_resolve_classref_to_classinfo(u1 *sp);
104 #define PATCHER_resolve_classref_to_classinfo (functionptr) patcher_resolve_classref_to_classinfo
106 bool patcher_resolve_classref_to_vftbl(u1 *sp);
107 #define PATCHER_resolve_classref_to_vftbl (functionptr) patcher_resolve_classref_to_vftbl
109 bool patcher_resolve_classref_to_flags(u1 *sp);
110 #define PATCHER_resolve_classref_to_flags (functionptr) patcher_resolve_classref_to_flags
112 bool patcher_resolve_native_function(u1 *sp);
113 #define PATCHER_resolve_native_function (functionptr) patcher_resolve_native_function
116 bool patcher_get_putstatic(u1 *sp);
117 #define PATCHER_get_putstatic (functionptr) patcher_get_putstatic
119 #if defined(__I386__)
121 bool patcher_getfield(u1 *sp);
122 #define PATCHER_getfield (functionptr) patcher_getfield
124 bool patcher_putfield(u1 *sp);
125 #define PATCHER_putfield (functionptr) patcher_putfield
129 bool patcher_get_putfield(u1 *sp);
130 #define PATCHER_get_putfield (functionptr) patcher_get_putfield
132 #endif /* defined(__I386__) */
134 #if defined(__I386__) || defined(__X86_64__)
136 bool patcher_putfieldconst(u1 *sp);
137 #define PATCHER_putfieldconst (functionptr) patcher_putfieldconst
139 #endif /* defined(__I386__) || defined(__X86_64__) */
141 bool patcher_aconst(u1 *sp);
142 #define PATCHER_aconst (functionptr) patcher_aconst
144 bool patcher_builtin_multianewarray(u1 *sp);
145 #define PATCHER_builtin_multianewarray (functionptr) patcher_builtin_multianewarray
147 bool patcher_builtin_arraycheckcast(u1 *sp);
148 #define PATCHER_builtin_arraycheckcast (functionptr) patcher_builtin_arraycheckcast
150 bool patcher_invokestatic_special(u1 *sp);
151 #define PATCHER_invokestatic_special (functionptr) patcher_invokestatic_special
153 bool patcher_invokevirtual(u1 *sp);
154 #define PATCHER_invokevirtual (functionptr) patcher_invokevirtual
156 bool patcher_invokeinterface(u1 *sp);
157 #define PATCHER_invokeinterface (functionptr) patcher_invokeinterface
160 /* only for interpreter */
161 bool patcher_checkcast_instanceof(u1 *sp);
162 #define PATCHER_checkcast_instanceof (functionptr) patcher_checkcast_instanceof
165 bool patcher_checkcast_instanceof_flags(u1 *sp);
166 #define PATCHER_checkcast_instanceof_flags (functionptr) patcher_checkcast_instanceof_flags
168 bool patcher_checkcast_instanceof_interface(u1 *sp);
169 #define PATCHER_checkcast_instanceof_interface (functionptr) patcher_checkcast_instanceof_interface
171 bool patcher_checkcast_interface(u1 *sp);
172 #define PATCHER_checkcast_interface (functionptr) patcher_checkcast_interface
174 bool patcher_instanceof_interface(u1 *sp);
175 #define PATCHER_instanceof_interface (functionptr) patcher_instanceof_interface
177 #if defined(__I386__) || defined(__X86_64__) || defined(__POWERPC__) || defined(__POWERPC64__)
179 bool patcher_checkcast_class(u1 *sp);
180 #define PATCHER_checkcast_class (functionptr) patcher_checkcast_class
182 bool patcher_instanceof_class(u1 *sp);
183 #define PATCHER_instanceof_class (functionptr) patcher_instanceof_class
185 #else /* defined(__I386__) || defined(__X86_64__) || defined(__POWERPC__) || defined(__POWERPC64__)*/
187 bool patcher_checkcast_instanceof_class(u1 *sp);
188 #define PATCHER_checkcast_instanceof_class (functionptr) patcher_checkcast_instanceof_class
190 #endif /* defined(__I386__) || defined(__X86_64__) || defined(__POWERPC__) || defined(__POWERPC64__)*/
192 bool patcher_clinit(u1 *sp);
193 #define PATCHER_clinit (functionptr) patcher_clinit
195 bool patcher_athrow_areturn(u1 *sp);
196 #define PATCHER_athrow_areturn (functionptr) patcher_athrow_areturn
198 bool patcher_resolve_native(u1 *sp);
199 #define PATCHER_resolve_native (functionptr) patcher_resolve_native
202 /* stuff for the interpreter **************************************************/
204 #if defined(ENABLE_INTRP)
205 bool intrp_patcher_get_putstatic(u1 *sp);
206 bool intrp_patcher_get_putstatic_clinit(u1 *sp);
207 bool intrp_patcher_get_putfield(u1 *sp);
208 bool intrp_patcher_aconst(u1 *sp);
209 bool intrp_patcher_builtin_multianewarray(u1 *sp);
210 bool intrp_patcher_builtin_arraycheckcast(u1 *sp);
211 bool intrp_patcher_invokestatic_special(u1 *sp);
212 bool intrp_patcher_invokevirtual(u1 *sp);
213 bool intrp_patcher_invokeinterface(u1 *sp);
214 bool intrp_patcher_checkcast_instanceof(u1 *sp);
215 bool intrp_patcher_resolve_native(u1 *sp);
216 #endif /* defined(ENABLE_INTRP) */
218 #endif /* architecture list */
220 #endif /* _PATCHER_H */
224 * These are local overrides for various environment variables in Emacs.
225 * Please do not remove this and leave it at the end of the file, where
226 * Emacs will automagically detect them.
227 * ---------------------------------------------------------------------
230 * indent-tabs-mode: t
234 * vim:noexpandtab:sw=4:ts=4: