* src/vm/jit/powerpc/darwin/md-asm.h
[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 5077 2006-07-04 19:06:56Z 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 #include "vm/global.h"
46
47
48 /* patcher macros *************************************************************/
49
50 #define PATCHER_FLAG_PATCHED    (vftbl_t *) 0xdeadbeef
51
52
53 #if defined(ENABLE_THREADS)
54
55 #define PATCHER_MONITORENTER \
56         /* enter a monitor on the patching position */       \
57                                                              \
58         builtin_monitorenter(o);                             \
59                                                              \
60         /* check if the position has already been patched */ \
61                                                              \
62         if (o->vftbl != NULL) {                              \
63         assert(o->vftbl == PATCHER_FLAG_PATCHED);        \
64                                                          \
65                 builtin_monitorexit(o);                          \
66                                                              \
67                 return NULL;                                     \
68         }                                                    \
69
70
71 #define PATCHER_MONITOREXIT \
72         /* leave the monitor on the patching position */     \
73                                                              \
74         builtin_monitorexit(o);
75
76
77 #define PATCHER_MARK_PATCHED_MONITOREXIT \
78         /* mark position as patched */                       \
79                                                              \
80         o->vftbl = PATCHER_FLAG_PATCHED;                     \
81                                                              \
82         PATCHER_MONITOREXIT
83
84 #else
85
86 #define PATCHER_MONITORENTER                 /* nop */
87 #define PATCHER_MONITOREXIT                  /* nop */
88 #define PATCHER_MARK_PATCHED_MONITOREXIT     /* nop */
89
90 #endif /* defined(ENABLE_THREADS) */
91
92
93 /* function prototypes ********************************************************/
94
95 java_objectheader *patcher_wrapper(u1 *sp, u1 *pv, u1 *ra);
96 #define PATCHER_wrapper (functionptr) patcher_wrapper
97
98 bool patcher_get_putstatic(u1 *sp);
99 #define PATCHER_get_putstatic (functionptr) patcher_get_putstatic
100
101 #if defined(__I386__)
102
103 bool patcher_getfield(u1 *sp);
104 #define PATCHER_getfield (functionptr) patcher_getfield
105
106 bool patcher_putfield(u1 *sp);
107 #define PATCHER_putfield (functionptr) patcher_putfield
108
109 #else
110
111 bool patcher_get_putfield(u1 *sp);
112 #define PATCHER_get_putfield (functionptr) patcher_get_putfield
113
114 #endif /* defined(__I386__) */
115
116 #if defined(__I386__) || defined(__X86_64__)
117
118 bool patcher_putfieldconst(u1 *sp);
119 #define PATCHER_putfieldconst (functionptr) patcher_putfieldconst
120
121 #endif /* defined(__I386__) || defined(__X86_64__) */
122
123 bool patcher_aconst(u1 *sp);
124 #define PATCHER_aconst (functionptr) patcher_aconst
125
126 bool patcher_builtin_multianewarray(u1 *sp);
127 #define PATCHER_builtin_multianewarray (functionptr) patcher_builtin_multianewarray
128
129 bool patcher_builtin_arraycheckcast(u1 *sp);
130 #define PATCHER_builtin_arraycheckcast (functionptr) patcher_builtin_arraycheckcast
131
132 bool patcher_invokestatic_special(u1 *sp);
133 #define PATCHER_invokestatic_special (functionptr) patcher_invokestatic_special
134
135 bool patcher_invokevirtual(u1 *sp);
136 #define PATCHER_invokevirtual (functionptr) patcher_invokevirtual
137
138 bool patcher_invokeinterface(u1 *sp);
139 #define PATCHER_invokeinterface (functionptr) patcher_invokeinterface
140
141
142 /* only for interpreter */
143 bool patcher_checkcast_instanceof(u1 *sp);
144 #define PATCHER_checkcast_instanceof (functionptr) patcher_checkcast_instanceof
145
146
147 bool patcher_checkcast_instanceof_flags(u1 *sp);
148 #define PATCHER_checkcast_instanceof_flags (functionptr) patcher_checkcast_instanceof_flags
149
150 bool patcher_checkcast_instanceof_interface(u1 *sp);
151 #define PATCHER_checkcast_instanceof_interface (functionptr) patcher_checkcast_instanceof_interface
152
153 #if defined(__I386__) || defined(__X86_64__) || defined(__POWERPC__)
154
155 bool patcher_checkcast_class(u1 *sp);
156 #define PATCHER_checkcast_class (functionptr) patcher_checkcast_class
157
158 bool patcher_instanceof_class(u1 *sp);
159 #define PATCHER_instanceof_class (functionptr) patcher_instanceof_class
160
161 #else /* defined(__I386__) || defined(__X86_64__) || defined(__POWERPC__) */
162
163 bool patcher_checkcast_instanceof_class(u1 *sp);
164 #define PATCHER_checkcast_instanceof_class (functionptr) patcher_checkcast_instanceof_class
165
166 #endif /* defined(__I386__) || defined(__X86_64__) || defined(__POWERPC__) */
167
168 bool patcher_clinit(u1 *sp);
169 #define PATCHER_clinit (functionptr) patcher_clinit
170
171 bool patcher_athrow_areturn(u1 *sp);
172 #define PATCHER_athrow_areturn (functionptr) patcher_athrow_areturn
173
174 #if !defined(WITH_STATIC_CLASSPATH)
175 bool patcher_resolve_native(u1 *sp);
176 #define PATCHER_resolve_native (functionptr) patcher_resolve_native
177 #endif
178
179
180 /* stuff for the interpreter **************************************************/
181
182 #if defined(ENABLE_INTRP)
183 bool intrp_patcher_get_putstatic(u1 *sp);
184 bool intrp_patcher_get_putstatic_clinit(u1 *sp);
185 bool intrp_patcher_get_putfield(u1 *sp);
186 bool intrp_patcher_aconst(u1 *sp);
187 bool intrp_patcher_builtin_multianewarray(u1 *sp);
188 bool intrp_patcher_builtin_arraycheckcast(u1 *sp);
189 bool intrp_patcher_invokestatic_special(u1 *sp);
190 bool intrp_patcher_invokevirtual(u1 *sp);
191 bool intrp_patcher_invokeinterface(u1 *sp);
192 bool intrp_patcher_checkcast_instanceof(u1 *sp);
193 bool intrp_patcher_resolve_native(u1 *sp);
194 #endif /* defined(ENABLE_INTRP) */
195
196 #endif /* _PATCHER_H */
197
198
199 /*
200  * These are local overrides for various environment variables in Emacs.
201  * Please do not remove this and leave it at the end of the file, where
202  * Emacs will automagically detect them.
203  * ---------------------------------------------------------------------
204  * Local variables:
205  * mode: c
206  * indent-tabs-mode: t
207  * c-basic-offset: 4
208  * tab-width: 4
209  * End:
210  * vim:noexpandtab:sw=4:ts=4:
211  */
212