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/gnu_classpath_Pointer.h"
37 #include "native/include/java_lang_Class.h"
38 #include "native/include/java_lang_StackTraceElement.h"
39 #include "native/include/java_lang_Throwable.h"
41 #include "native/include/java_lang_VMThrowable.h"
43 #include "native/vm/java_lang_Class.h"
46 #include "vm/builtin.h"
47 #include "vm/exceptions.h"
48 #include "vm/stringlocal.h"
50 #include "vm/jit/code.h"
51 #include "vm/jit/linenumbertable.h"
52 #include "vm/jit/stacktrace.h"
54 #include "vmcore/class.h"
55 #include "vmcore/loader.h"
58 /* native methods implemented by this file ************************************/
60 static JNINativeMethod methods[] = {
61 { "fillInStackTrace", "(Ljava/lang/Throwable;)Ljava/lang/VMThrowable;", (void *) (ptrint) &Java_java_lang_VMThrowable_fillInStackTrace },
62 { "getStackTrace", "(Ljava/lang/Throwable;)[Ljava/lang/StackTraceElement;", (void *) (ptrint) &Java_java_lang_VMThrowable_getStackTrace },
66 /* _Jv_java_lang_VMThrowable_init **********************************************
68 Register native functions.
70 *******************************************************************************/
72 void _Jv_java_lang_VMThrowable_init(void)
76 u = utf_new_char("java/lang/VMThrowable");
78 native_method_register(u, methods, NATIVE_METHODS_COUNT);
83 * Class: java/lang/VMThrowable
84 * Method: fillInStackTrace
85 * Signature: (Ljava/lang/Throwable;)Ljava/lang/VMThrowable;
87 JNIEXPORT java_lang_VMThrowable* JNICALL Java_java_lang_VMThrowable_fillInStackTrace(JNIEnv *env, jclass clazz, java_lang_Throwable *t)
89 java_lang_VMThrowable *o;
90 java_handle_bytearray_t *ba;
92 o = (java_lang_VMThrowable *)
93 native_new_and_init(class_java_lang_VMThrowable);
98 ba = stacktrace_get_current();
103 LLNI_field_set_ref(o, vmData, (gnu_classpath_Pointer *) ba);
110 * Class: java/lang/VMThrowable
111 * Method: getStackTrace
112 * Signature: (Ljava/lang/Throwable;)[Ljava/lang/StackTraceElement;
114 JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_VMThrowable_getStackTrace(JNIEnv *env, java_lang_VMThrowable *this, java_lang_Throwable *t)
116 java_handle_bytearray_t *ba;
118 stacktrace_entry_t *ste;
119 java_handle_objectarray_t *oa;
120 java_lang_StackTraceElement *o;
123 java_lang_String *filename;
125 java_lang_String *declaringclass;
128 /* get the stacktrace buffer from the VMThrowable object */
130 LLNI_field_get_ref(this, vmData, ba);
132 st = (stacktrace_t *) LLNI_array_data(ba);
138 /* Create the stacktrace element array. */
140 oa = builtin_anewarray(st->length, class_java_lang_StackTraceElement);
145 for (i = 0; i < st->length; i++, ste++) {
146 /* allocate a new stacktrace element */
148 o = (java_lang_StackTraceElement *)
149 builtin_new(class_java_lang_StackTraceElement);
154 /* Get the codeinfo and methodinfo. */
161 if (!(m->flags & ACC_NATIVE)) {
162 if (m->class->sourcefile)
163 filename = (java_lang_String *) javastring_new(m->class->sourcefile);
170 /* get line number */
172 if (m->flags & ACC_NATIVE) {
176 /* FIXME The linenumbertable_linenumber_for_pc could
177 change the methodinfo pointer when hitting an inlined
180 linenumber = linenumbertable_linenumber_for_pc(&m, code, ste->pc);
181 linenumber = (linenumber == 0) ? -1 : linenumber;
184 /* get declaring class name */
187 _Jv_java_lang_Class_getName(LLNI_classinfo_wrap(m->class));
189 /* Fill the java.lang.StackTraceElement object. */
191 LLNI_field_set_ref(o, fileName , filename);
192 LLNI_field_set_val(o, lineNumber , linenumber);
193 LLNI_field_set_ref(o, declaringClass, declaringclass);
194 LLNI_field_set_ref(o, methodName , (java_lang_String *) javastring_new(m->name));
195 LLNI_field_set_val(o, isNative , (m->flags & ACC_NATIVE) ? 1 : 0);
197 array_objectarray_element_set(oa, i, (java_handle_t *) o);
205 * These are local overrides for various environment variables in Emacs.
206 * Please do not remove this and leave it at the end of the file, where
207 * Emacs will automagically detect them.
208 * ---------------------------------------------------------------------
211 * indent-tabs-mode: t