* codegen_addpatchref: Passing displacement changes.
[cacao.git] / src / vm / jit / helper.c
1 /* src/vm/jit/asmhelper.c - code patching helper functions
2
3    Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    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., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Christian Thalinger
28
29    Changes:
30
31    $Id: helper.c 3007 2005-07-12 20:58:01Z twisti $
32
33 */
34
35
36 #include <assert.h>
37
38 #include "vm/class.h"
39 #include "vm/exceptions.h"
40 #include "vm/initialize.h"
41 #include "vm/linker.h"
42 #include "vm/method.h"
43 #include "vm/references.h"
44 #include "vm/resolve.h"
45 #include "vm/stringlocal.h"
46 #include "vm/jit/asmpart.h"
47
48 /* XXX class_resolveclassmethod */
49 #include "vm/loader.h"
50
51
52 /* helper_resolve_classinfo ****************************************************
53
54    This function returns the loaded and resolved class.
55
56 *******************************************************************************/
57
58 classinfo *helper_resolve_classinfo(constant_classref *cr)
59 {
60         classinfo *c;
61
62         /* resolve and load the class */
63
64         if (!resolve_classref(NULL, cr, resolveEager, true, true, &c))
65                 return NULL;
66
67         /* return the classinfo pointer */
68
69         return c;
70 }
71
72
73 /* helper_resolve_methodinfo ***************************************************
74
75    This function returns the loaded and resolved methodinfo of the
76    passed method.
77
78 *******************************************************************************/
79
80 methodinfo *helper_resolve_methodinfo(unresolved_method *um)
81 {
82         methodinfo *m;
83
84         /* resolve the method */
85
86         if (!resolve_method(um, resolveEager, &m)) {
87                 java_objectheader *xptr;
88                 java_objectheader *cause;
89
90                 /* get the cause */
91
92                 cause = *exceptionptr;
93
94                 /* convert ClassNotFoundException's to NoClassDefFoundError's */
95
96                 if (builtin_instanceof(cause, class_java_lang_ClassNotFoundException)) {
97                         /* clear exception, because we are calling jit code again */
98
99                         *exceptionptr = NULL;
100
101                         /* create new error */
102
103                         xptr =
104                                 new_exception_javastring(string_java_lang_NoClassDefFoundError,
105                                                                                  ((java_lang_Throwable *) cause)->detailMessage);
106
107                         /* we had an exception while creating the error */
108
109                         if (*exceptionptr)
110                                 return NULL;
111
112                         /* set new exception */
113
114                         *exceptionptr = xptr;
115                 }
116
117                 return NULL;
118         }
119
120         /* return the methodinfo pointer */
121
122         return m;
123 }
124
125
126 /* helper_resolve_fieldinfo ****************************************************
127
128    This function returns the fieldinfo pointer of the passed field.
129
130 *******************************************************************************/
131
132 void *helper_resolve_fieldinfo(unresolved_field *uf)
133 {
134         fieldinfo *fi;
135
136         /* resolve the field */
137
138         if (!resolve_field(uf, resolveEager, &fi)) {
139                 java_objectheader *xptr;
140                 java_objectheader *cause;
141
142                 /* get the cause */
143
144                 cause = *exceptionptr;
145
146                 /* convert ClassNotFoundException's to NoClassDefFoundError's */
147
148                 if (builtin_instanceof(cause, class_java_lang_ClassNotFoundException)) {
149                         /* clear exception, because we are calling jit code again */
150
151                         *exceptionptr = NULL;
152
153                         /* create new error */
154
155                         xptr =
156                                 new_exception_javastring(string_java_lang_NoClassDefFoundError,
157                                                                                  ((java_lang_Throwable *) cause)->detailMessage);
158
159                         /* we had an exception while creating the error */
160
161                         if (*exceptionptr)
162                                 return NULL;
163
164                         /* set new exception */
165
166                         *exceptionptr = xptr;
167                 }
168
169                 return NULL;
170         }
171
172         /* return the fieldinfo pointer */
173
174         return fi;
175 }
176
177
178 /*
179  * These are local overrides for various environment variables in Emacs.
180  * Please do not remove this and leave it at the end of the file, where
181  * Emacs will automagically detect them.
182  * ---------------------------------------------------------------------
183  * Local variables:
184  * mode: c
185  * indent-tabs-mode: t
186  * c-basic-offset: 4
187  * tab-width: 4
188  * End:
189  * vim:noexpandtab:sw=4:ts=4:
190  */