1 /* src/native/vm/gnu/java_lang_VMThrowable.c
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
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.
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.
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
32 #include "native/jni.h"
33 #include "native/llni.h"
34 #include "native/native.h"
36 #include "native/include/java_lang_Object.h"
37 #include "native/include/java_lang_Class.h"
38 #include "native/include/java_lang_String.h"
39 #include "native/include/java_lang_StackTraceElement.h"
40 #include "native/include/java_lang_Throwable.h"
42 #include "native/include/java_lang_VMThrowable.h"
45 #include "vm/builtin.h"
46 #include "vm/exceptions.h"
47 #include "vm/stringlocal.h"
49 #include "vm/jit/code.h"
50 #include "vm/jit/linenumbertable.h"
51 #include "vm/jit/stacktrace.h"
53 #include "vmcore/class.h"
54 #include "vmcore/loader.h"
57 /* native methods implemented by this file ************************************/
59 static JNINativeMethod methods[] = {
60 { "fillInStackTrace", "(Ljava/lang/Throwable;)Ljava/lang/VMThrowable;", (void *) (ptrint) &Java_java_lang_VMThrowable_fillInStackTrace },
61 { "getStackTrace", "(Ljava/lang/Throwable;)[Ljava/lang/StackTraceElement;", (void *) (ptrint) &Java_java_lang_VMThrowable_getStackTrace },
65 /* _Jv_java_lang_VMThrowable_init **********************************************
67 Register native functions.
69 *******************************************************************************/
71 void _Jv_java_lang_VMThrowable_init(void)
75 u = utf_new_char("java/lang/VMThrowable");
77 native_method_register(u, methods, NATIVE_METHODS_COUNT);
82 * Class: java/lang/VMThrowable
83 * Method: fillInStackTrace
84 * Signature: (Ljava/lang/Throwable;)Ljava/lang/VMThrowable;
86 JNIEXPORT java_lang_VMThrowable* JNICALL Java_java_lang_VMThrowable_fillInStackTrace(JNIEnv *env, jclass clazz, java_lang_Throwable *t)
88 java_lang_VMThrowable *vmto;
89 java_handle_bytearray_t *ba;
92 vmto = (java_lang_VMThrowable *)
93 native_new_and_init(class_java_lang_VMThrowable);
98 ba = stacktrace_get_current();
103 o = (java_lang_Object *) ba;
105 LLNI_field_set_ref(vmto, vmdata, o);
112 * Class: java/lang/VMThrowable
113 * Method: getStackTrace
114 * Signature: (Ljava/lang/Throwable;)[Ljava/lang/StackTraceElement;
116 JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_VMThrowable_getStackTrace(JNIEnv *env, java_lang_VMThrowable *this, java_lang_Throwable *t)
119 java_handle_bytearray_t *ba;
121 stacktrace_entry_t *ste;
122 java_handle_objectarray_t *oa;
123 java_lang_StackTraceElement *steo;
126 java_lang_String *filename;
128 java_handle_t *declaringclass;
131 /* Get the stacktrace from the VMThrowable object. */
133 LLNI_field_get_ref(this, vmdata, o);
135 ba = (java_handle_bytearray_t *) o;
137 st = (stacktrace_t *) LLNI_array_data(ba);
143 /* Create the stacktrace element array. */
145 oa = builtin_anewarray(st->length, class_java_lang_StackTraceElement);
150 for (i = 0; i < st->length; i++, ste++) {
151 /* allocate a new stacktrace element */
153 steo = (java_lang_StackTraceElement *)
154 builtin_new(class_java_lang_StackTraceElement);
159 /* Get the codeinfo and methodinfo. */
166 if (!(m->flags & ACC_NATIVE)) {
167 if (m->clazz->sourcefile)
168 filename = (java_lang_String *) javastring_new(m->clazz->sourcefile);
175 /* get line number */
177 if (m->flags & ACC_NATIVE) {
181 /* FIXME The linenumbertable_linenumber_for_pc could
182 change the methodinfo pointer when hitting an inlined
185 linenumber = linenumbertable_linenumber_for_pc(&m, code, ste->pc);
186 linenumber = (linenumber == 0) ? -1 : linenumber;
189 /* get declaring class name */
191 declaringclass = class_get_classname(m->clazz);
193 /* Fill the java.lang.StackTraceElement object. */
195 LLNI_field_set_ref(steo, fileName , filename);
196 LLNI_field_set_val(steo, lineNumber , linenumber);
197 LLNI_field_set_ref(steo, declaringClass, (java_lang_String*) declaringclass);
198 LLNI_field_set_ref(steo, methodName , (java_lang_String *) javastring_new(m->name));
199 LLNI_field_set_val(steo, isNative , (m->flags & ACC_NATIVE) ? 1 : 0);
201 array_objectarray_element_set(oa, i, (java_handle_t *) steo);
209 * These are local overrides for various environment variables in Emacs.
210 * Please do not remove this and leave it at the end of the file, where
211 * Emacs will automagically detect them.
212 * ---------------------------------------------------------------------
215 * indent-tabs-mode: t