1 /* src/vm/jit/asmhelper.c - code patching helper functions
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
8 This file is part of CACAO.
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.
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.
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
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Christian Thalinger
31 $Id: helper.c 2458 2005-05-12 23:02:07Z twisti $
37 #include "vm/exceptions.h"
38 #include "vm/initialize.h"
39 #include "vm/linker.h"
40 #include "vm/method.h"
41 #include "vm/references.h"
42 #include "vm/resolve.h"
43 #include "vm/stringlocal.h"
45 /* XXX class_resolveclassmethod */
46 #include "vm/loader.h"
49 /* helper_resolve_classinfo ****************************************************
51 This function returns the loaded and resolved class.
53 *******************************************************************************/
55 classinfo *helper_resolve_classinfo(constant_classref *cr)
59 /* resolve and load the class */
61 if (!resolve_classref(NULL, cr, resolveEager, true, &c)) {
62 java_objectheader *xptr;
63 java_objectheader *cause;
67 cause = *exceptionptr;
69 /* convert ClassNotFoundException's to NoClassDefFoundError's */
71 if (builtin_instanceof(cause, class_java_lang_ClassNotFoundException)) {
72 /* clear exception, because we are calling jit code again */
76 /* create new error */
79 new_exception_javastring(string_java_lang_NoClassDefFoundError,
80 ((java_lang_Throwable *) cause)->detailMessage);
82 /* we had an exception while creating the error */
87 /* set new exception */
95 /* return the classinfo pointer */
101 /* helper_resolve_methodinfo ***************************************************
103 This function returns the loaded and resolved methodinfo of the
106 *******************************************************************************/
108 methodinfo *helper_resolve_methodinfo(unresolved_method *um)
112 /* resolve the method */
114 if (!resolve_method(um, resolveEager, &m)) {
115 java_objectheader *xptr;
116 java_objectheader *cause;
120 cause = *exceptionptr;
122 /* convert ClassNotFoundException's to NoClassDefFoundError's */
124 if (builtin_instanceof(cause, class_java_lang_ClassNotFoundException)) {
125 /* clear exception, because we are calling jit code again */
127 *exceptionptr = NULL;
129 /* create new error */
132 new_exception_javastring(string_java_lang_NoClassDefFoundError,
133 ((java_lang_Throwable *) cause)->detailMessage);
135 /* we had an exception while creating the error */
140 /* set new exception */
142 *exceptionptr = xptr;
148 /* return the methodinfo pointer */
154 /* helper_resolve_fieldinfo ****************************************************
156 This function returns the fieldinfo pointer of the passed field.
158 *******************************************************************************/
160 void *helper_resolve_fieldinfo(unresolved_field *uf)
164 /* resolve the field */
166 if (!resolve_field(uf, resolveEager, &fi)) {
167 java_objectheader *xptr;
168 java_objectheader *cause;
172 cause = *exceptionptr;
174 /* convert ClassNotFoundException's to NoClassDefFoundError's */
176 if (builtin_instanceof(cause, class_java_lang_ClassNotFoundException)) {
177 /* clear exception, because we are calling jit code again */
179 *exceptionptr = NULL;
181 /* create new error */
184 new_exception_javastring(string_java_lang_NoClassDefFoundError,
185 ((java_lang_Throwable *) cause)->detailMessage);
187 /* we had an exception while creating the error */
192 /* set new exception */
194 *exceptionptr = xptr;
200 /* return the fieldinfo pointer */
206 /* helper_fillin_stacktrace ****************************************************
208 This function returns the exception given as parameter with a filled in stacktrace
210 *******************************************************************************/
212 java_objectheader *helper_fillin_stacktrace(java_objectheader* exc)
216 /*log_text("helper_fillin_stacktrace has beenentered");*/
217 /* these are panics, since this are sever problems, which must never happen*/
218 if (exc==0) panic("Exception must not be null in helper_fillin_stacktrace");
219 if ( ((java_lang_Throwable *) exc)->vmState!=0) return exc;
220 if (exc->vftbl==0) panic ("Exception vftbl must not be null in helper_fillin_stacktrace");
221 /*get classinfo from object instance*/
223 if (c==0) panic("Exception class must not be null in helper_fillin_stacktrace");
224 /*find the fillInStackTrace method*/
225 m=class_resolvemethod(c,utf_fillInStackTrace,utf_void__java_lang_Throwable);
226 if (m==0) panic ("Exception does not have a fillInStackTrace method");
228 /*log_text("helper_fillin_stacktrace doing it's work now");*/
229 asm_calljavafunction(m,exc,0,0,0);
231 /*return exception back to asmpart*/
235 java_objectheader *helper_fillin_stacktrace_always(java_objectheader* exc) {
236 if (exc==0) panic("Exception must not be null in helper_fillin_stacktrace");
237 ((java_lang_Throwable *) exc)->vmState=0;
238 return helper_fillin_stacktrace(exc);
244 * These are local overrides for various environment variables in Emacs.
245 * Please do not remove this and leave it at the end of the file, where
246 * Emacs will automagically detect them.
247 * ---------------------------------------------------------------------
250 * indent-tabs-mode: t
254 * vim:noexpandtab:sw=4:ts=4: