61c83bdabff414b37579877beafb6fb8f76188f5
[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 2955 2005-07-09 13:55:06Z 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                 java_objectheader *xptr;
66                 java_objectheader *cause;
67
68                 /* get the cause */
69
70                 cause = *exceptionptr;
71
72                 /* convert ClassNotFoundException's to NoClassDefFoundError's */
73
74                 if (builtin_instanceof(cause, class_java_lang_ClassNotFoundException)) {
75                         /* clear exception, because we are calling jit code again */
76
77                         *exceptionptr = NULL;
78
79                         /* create new error */
80
81                         xptr =
82                                 new_exception_javastring(string_java_lang_NoClassDefFoundError,
83                                                                                  ((java_lang_Throwable *) cause)->detailMessage);
84
85                         /* we had an exception while creating the error */
86
87                         if (*exceptionptr)
88                                 return NULL;
89
90                         /* set new exception */
91
92                         *exceptionptr = xptr;
93                 }
94
95                 return NULL;
96         }
97
98         /* return the classinfo pointer */
99
100         return c;
101 }
102
103
104 /* helper_resolve_methodinfo ***************************************************
105
106    This function returns the loaded and resolved methodinfo of the
107    passed method.
108
109 *******************************************************************************/
110
111 methodinfo *helper_resolve_methodinfo(unresolved_method *um)
112 {
113         methodinfo *m;
114
115         /* resolve the method */
116
117         if (!resolve_method(um, resolveEager, &m)) {
118                 java_objectheader *xptr;
119                 java_objectheader *cause;
120
121                 /* get the cause */
122
123                 cause = *exceptionptr;
124
125                 /* convert ClassNotFoundException's to NoClassDefFoundError's */
126
127                 if (builtin_instanceof(cause, class_java_lang_ClassNotFoundException)) {
128                         /* clear exception, because we are calling jit code again */
129
130                         *exceptionptr = NULL;
131
132                         /* create new error */
133
134                         xptr =
135                                 new_exception_javastring(string_java_lang_NoClassDefFoundError,
136                                                                                  ((java_lang_Throwable *) cause)->detailMessage);
137
138                         /* we had an exception while creating the error */
139
140                         if (*exceptionptr)
141                                 return NULL;
142
143                         /* set new exception */
144
145                         *exceptionptr = xptr;
146                 }
147
148                 return NULL;
149         }
150
151         /* return the methodinfo pointer */
152
153         return m;
154 }
155
156
157 /* helper_resolve_fieldinfo ****************************************************
158
159    This function returns the fieldinfo pointer of the passed field.
160
161 *******************************************************************************/
162
163 void *helper_resolve_fieldinfo(unresolved_field *uf)
164 {
165         fieldinfo *fi;
166
167         /* resolve the field */
168
169         if (!resolve_field(uf, resolveEager, &fi)) {
170                 java_objectheader *xptr;
171                 java_objectheader *cause;
172
173                 /* get the cause */
174
175                 cause = *exceptionptr;
176
177                 /* convert ClassNotFoundException's to NoClassDefFoundError's */
178
179                 if (builtin_instanceof(cause, class_java_lang_ClassNotFoundException)) {
180                         /* clear exception, because we are calling jit code again */
181
182                         *exceptionptr = NULL;
183
184                         /* create new error */
185
186                         xptr =
187                                 new_exception_javastring(string_java_lang_NoClassDefFoundError,
188                                                                                  ((java_lang_Throwable *) cause)->detailMessage);
189
190                         /* we had an exception while creating the error */
191
192                         if (*exceptionptr)
193                                 return NULL;
194
195                         /* set new exception */
196
197                         *exceptionptr = xptr;
198                 }
199
200                 return NULL;
201         }
202
203         /* return the fieldinfo pointer */
204
205         return fi;
206 }
207
208
209 /*
210  * These are local overrides for various environment variables in Emacs.
211  * Please do not remove this and leave it at the end of the file, where
212  * Emacs will automagically detect them.
213  * ---------------------------------------------------------------------
214  * Local variables:
215  * mode: c
216  * indent-tabs-mode: t
217  * c-basic-offset: 4
218  * tab-width: 4
219  * End:
220  * vim:noexpandtab:sw=4:ts=4:
221  */