* Updated to jitcache-arm-x86 branch d4f6023b26c5+d1b5b1c106ac
[cacao.git] / src / vm / jit / jitcache.hpp
1 /* src/vm/jit/jitcache.h - jit compiler output caching
2
3    Copyright (C) 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 #ifndef _JITCACHE_H
26 #define _JITCACHE_H
27
28 #include "vm/jit/patcher-common.hpp"
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 #if defined(ENABLE_JITCACHE)
35
36 #include "config.h"
37
38 #include <stdint.h>
39
40 #include "vm/class.h"
41 #include "vm/method.h"
42
43 typedef enum cachedreftype {
44         CRT_CODEINFO,
45         CRT_NUM,
46         CRT_ENTRYPOINT,
47         CRT_CODEGEN_FINISH_NATIVE_CALL,
48         CRT_ASM_HANDLE_EXCEPTION, /* 4 */
49         CRT_ASM_HANDLE_NAT_EXCEPTION,
50         CRT_OBJECT_HEADER,
51         CRT_BUILTIN, /* 7 */
52         CRT_BUILTIN_FP,
53         CRT_STRING,
54         CRT_CLASSINFO, /* 10 */
55         CRT_CLASSINFO_INDEX,
56         CRT_CLASSINFO_INTERFACETABLE,
57         CRT_CLASSINFO_VFTBL,
58         CRT_METHODINFO_STUBROUTINE, /* 14 */
59         CRT_METHODINFO_TABLE,
60         CRT_METHODINFO_INTERFACETABLE,
61         CRT_METHODINFO_METHODOFFSET,
62         CRT_FIELDINFO_VALUE, /* 18 */
63         CRT_FIELDINFO_OFFSET,
64         CRT_FIELDINFO_OFFSET_HIGH,
65         CRT_JUMPREFERENCE /* 21 */
66 } cachedreftype;
67
68 /* cachedref_t *****************************************************************
69
70    A cached reference contains information about a code or data position
71    which needs patching after restoring the it from disk.
72
73 *******************************************************************************/
74
75 struct cachedref_t {
76         cachedreftype type;                     /* type of the cached reference */
77         s4                        md_patch;             /* machine dependent back patching */
78         s4                disp;         /* displacement of ref in the data segment    */
79         void*       ref;          /* reference passed                           */
80 };
81
82 /*
83 typedef struct mru_entry_t {
84         classinfo *clazz;
85         mutex_t  lock;
86 }
87 */
88
89 /* typedefs *******************************************************************/
90
91 typedef void (*serializerfptr) (int, patchref_t *, methodinfo *);
92 typedef void (*deserializerfptr) (patchref_t *, int, methodinfo *);
93
94 /* jitcache_patcher_function_list_t typedef ***********************************/
95
96 struct jitcache_patcher_function_list_t {
97         functionptr patcher;
98         serializerfptr serializer;
99         deserializerfptr deserializer;
100 };
101
102 /* function prototypes ********************************************************/
103
104 void    jitcache_list_create(codeinfo *code);
105
106 void    jitcache_list_reset(codeinfo *code);
107
108 void    jitcache_list_free(codeinfo *code);
109
110 void    jitcache_add_cached_ref_jd(jitdata *jd, cachedreftype type, void* ref);
111
112 void    jitcache_add_cached_ref_md_jd(jitdata *jd, cachedreftype type, s4 md_patch, void* ref);
113
114 void    jitcache_add_cached_ref(codeinfo *code, cachedreftype type, void* ref, s4 disp);
115
116 void    jitcache_store(methodinfo *m);
117
118 u1      jitcache_load(methodinfo *m);
119
120 void    jitcache_handle_cached_ref(cachedref_t *cr, codeinfo *code);
121
122 void  jitcache_quit();
123
124 void    jitcache_freeclass(classinfo *);
125
126 #define JITCACHE_ADD_CACHED_REF_JD(jd, type, ref) \
127         (jitcache_add_cached_ref_jd(jd, type, (void*) ref))
128
129 #define JITCACHE_ADD_CACHED_REF_JD_COND(jd, type, ref, COND) \
130         if (COND) \
131         (jitcache_add_cached_ref_jd(jd, type, (void*) ref))
132
133 #define JITCACHE_ADD_CACHED_REF_MD_JD(jd, type, md_patch, ref) \
134         (jitcache_add_cached_ref_md_jd(jd, type, md_patch, (void*) ref))
135
136 #define JITCACHE_ADD_CACHED_REF(code, type, ref, disp) \
137         (jitcache_add_cached_ref(code, type, (void*) ref, disp))
138
139 #define JITCACHE_ADD_CACHED_REF_COND(code, type, ref, disp, COND) \
140         if (COND) \
141                 jitcache_add_cached_ref(code, type, (void*) ref, disp)
142
143 #else
144
145 #define JITCACHE_ADD_CACHED_REF_JD(jd, type, ref) \
146         while (0) { }
147
148 #define JITCACHE_ADD_CACHED_REF_JD_COND(jd, type, ref, COND) \
149         while (0) { }
150
151 #define JITCACHE_ADD_CACHED_REF_MD_JD(jd, type, md_patch, ref) \
152         while (0) { }
153
154 #define JITCACHE_ADD_CACHED_REF(code, type, ref, disp) \
155         while (0) { }
156
157 #define JITCACHE_ADD_CACHED_REF_COND(code, type, ref, disp, COND) \
158         while (0) { }
159
160 #endif /* ENABLE_JITCACHE */
161
162 #ifdef __cplusplus
163 }
164 #endif
165
166
167 #endif /* _JITCACHE_HPP */
168
169
170 /*
171  * These are local overrides for various environment variables in Emacs.
172  * Please do not remove this and leave it at the end of the file, where
173  * Emacs will automagically detect them.
174  * ---------------------------------------------------------------------
175  * Local variables:
176  * mode: c++
177  * indent-tabs-mode: t
178  * c-basic-offset: 4
179  * tab-width: 4
180  * End:
181  * vim:noexpandtab:sw=4:ts=4:
182  */