* Updated to jitcache-arm-x86 branch d4f6023b26c5+d1b5b1c106ac
[cacao.git] / src / vm / jit / patcher-common.hpp
1 /* src/vm/jit/patcher-common.hpp - architecture independent code patching stuff
2
3    Copyright (C) 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _PATCHER_COMMON_HPP
27 #define _PATCHER_COMMON_HPP
28
29 /* forward typedefs ***********************************************************/
30
31 typedef struct cachedref_t cachedref_t;
32 typedef struct patchref_t patchref_t;
33
34 #include "config.h"
35 #include "vm/types.h"
36
37 #include "toolbox/list.hpp"
38
39 #include "vm/global.h"
40
41 #include "vm/jit/jit.hpp"
42
43 #if defined (ENABLE_JITCACHE)
44 struct cached_ref_t;
45 #endif
46
47 /* patchref_t ******************************************************************
48
49    A patcher reference contains information about a code position
50    which needs additional code patching during runtime.
51
52 *******************************************************************************/
53
54 struct patchref_t {
55         ptrint       mpc;           /* absolute position in code segment          */
56         ptrint       datap;         /* absolute position in data segment          */
57         s4           disp;          /* displacement of ref in the data segment    */
58         functionptr  patcher;       /* patcher function to call                   */
59         void*        ref;           /* reference passed                           */
60         uint32_t     mcode;         /* machine code to be patched back in         */
61         bool         done;          /* XXX preliminary: patch already applied?    */
62 #if defined (ENABLE_JITCACHE)
63         cachedref_t  *attached_ref;
64                                                                 /* cached reference which must be resolved    *
65                                                                  * patcher has been run.                      */
66 #endif
67 };
68
69
70 /* macros *********************************************************************/
71
72
73 /* function prototypes ********************************************************/
74
75 #ifdef __cplusplus
76 extern "C" {
77 #endif
78
79 void patcher_list_create(codeinfo *code);
80 void patcher_list_reset(codeinfo *code);
81 void patcher_list_free(codeinfo *code);
82
83 void patcher_add_patch_ref(jitdata *jd, functionptr patcher, void* ref, s4 disp);
84
85 void patcher_resolve(jitdata* jd);
86
87 bool patcher_is_patched(patchref_t* pr);
88 bool patcher_is_patched_at(void* pc);
89
90 // MD function.
91 bool patcher_is_valid_trap_instruction_at(void* pc);
92
93 java_handle_t *patcher_handler(u1 *pc);
94
95
96 /* empty patcher (just patches back original mcode) ***************************/
97
98 void patcher_patch_code(patchref_t *pr);
99
100
101 /* patcher prototypes and macros **********************************************/
102
103 /* new patcher functions */
104
105 bool patcher_resolve_class(patchref_t *pr);
106 #define PATCHER_resolve_class (functionptr) patcher_resolve_class
107
108 bool patcher_initialize_class(patchref_t *pr);
109 #define PATCHER_initialize_class (functionptr) patcher_initialize_class
110
111 bool patcher_resolve_classref_to_classinfo(patchref_t *pr);
112 #define PATCHER_resolve_classref_to_classinfo (functionptr) patcher_resolve_classref_to_classinfo
113
114 bool patcher_resolve_classref_to_vftbl(patchref_t *pr);
115 #define PATCHER_resolve_classref_to_vftbl (functionptr) patcher_resolve_classref_to_vftbl
116
117 bool patcher_resolve_classref_to_index(patchref_t *pr);
118 #define PATCHER_resolve_classref_to_index (functionptr) patcher_resolve_classref_to_index
119
120 bool patcher_resolve_classref_to_flags(patchref_t *pr);
121 #define PATCHER_resolve_classref_to_flags (functionptr) patcher_resolve_classref_to_flags
122
123 bool patcher_resolve_native_function(patchref_t *pr);
124 #define PATCHER_resolve_native_function (functionptr) patcher_resolve_native_function
125
126 /* old patcher functions */
127
128 bool patcher_get_putstatic(patchref_t *pr);
129 #define PATCHER_get_putstatic (functionptr) patcher_get_putstatic
130
131 #if defined(__I386__)
132
133 bool patcher_getfield(patchref_t *pr);
134 #define PATCHER_getfield (functionptr) patcher_getfield
135
136 bool patcher_putfield(patchref_t *pr);
137 #define PATCHER_putfield (functionptr) patcher_putfield
138
139 #else
140
141 bool patcher_get_putfield(patchref_t *pr);
142 #define PATCHER_get_putfield (functionptr) patcher_get_putfield
143
144 #endif /* defined(__I386__) */
145
146 #if defined(__I386__) || defined(__X86_64__)
147
148 bool patcher_putfieldconst(patchref_t *pr);
149 #define PATCHER_putfieldconst (functionptr) patcher_putfieldconst
150
151 #endif /* defined(__I386__) || defined(__X86_64__) */
152
153 bool patcher_invokestatic_special(patchref_t *pr);
154 #define PATCHER_invokestatic_special (functionptr) patcher_invokestatic_special
155
156 bool patcher_invokevirtual(patchref_t *pr);
157 #define PATCHER_invokevirtual (functionptr) patcher_invokevirtual
158
159 bool patcher_invokeinterface(patchref_t *pr);
160 #define PATCHER_invokeinterface (functionptr) patcher_invokeinterface
161
162 #if defined(__ALPHA__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__POWERPC64__) || defined(__S390__) || defined(__X86_64__) || defined(__M68K__)
163
164 bool patcher_checkcast_interface(patchref_t *pr);
165 #define PATCHER_checkcast_interface (functionptr) patcher_checkcast_interface
166
167 bool patcher_instanceof_interface(patchref_t *pr);
168 #define PATCHER_instanceof_interface (functionptr) patcher_instanceof_interface
169
170 #endif /* defined(__ALPHA__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__POWERPC64__) || defined(__S390__) || defined(__X86_64__) || defined(__M68K__) */
171
172 #if defined(__S390__)
173
174 bool patcher_checkcast_instanceof_interface(patchref_t *pr);
175 #define PATCHER_checkcast_instanceof_interface (functionptr) patcher_checkcast_instanceof_interface
176
177 #endif /* defined(__S390__) */
178
179 #if defined(__I386__)
180
181 bool patcher_aconst(patchref_t *pr);
182 #define PATCHER_aconst (functionptr) patcher_aconst
183
184 bool patcher_builtin_multianewarray(patchref_t *pr);
185 #define PATCHER_builtin_multianewarray (functionptr) patcher_builtin_multianewarray
186
187 bool patcher_builtin_arraycheckcast(patchref_t *pr);
188 #define PATCHER_builtin_arraycheckcast (functionptr) patcher_builtin_arraycheckcast
189
190 bool patcher_checkcast_instanceof_flags(patchref_t *pr);
191 #define PATCHER_checkcast_instanceof_flags (functionptr) patcher_checkcast_instanceof_flags
192
193 bool patcher_checkcast_class(patchref_t *pr);
194 #define PATCHER_checkcast_class (functionptr) patcher_checkcast_class
195
196 bool patcher_instanceof_class(patchref_t *pr);
197 #define PATCHER_instanceof_class (functionptr) patcher_instanceof_class
198
199 #endif /* defined(__I386__) */
200
201 #if defined (__ARM__)
202 void patch_md(s4 md_patch, ptrint dest, void* ref);
203 #endif /* defined(__ARM__) */
204
205 #ifdef __cplusplus
206 } // extern "C"
207 #endif
208
209 #endif // _PATCHER_COMMON_HPP
210
211
212 /*
213  * These are local overrides for various environment variables in Emacs.
214  * Please do not remove this and leave it at the end of the file, where
215  * Emacs will automagically detect them.
216  * ---------------------------------------------------------------------
217  * Local variables:
218  * mode: c++
219  * indent-tabs-mode: t
220  * c-basic-offset: 4
221  * tab-width: 4
222  * End:
223  * vim:noexpandtab:sw=4:ts=4:
224  */