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