a689d86ae3da47bb3353c56c2793da53908931f1
[cacao.git] / src / native / vm / cldc1.1 / java_lang_Throwable.c
1 /* src/native/vm/cldc1.1/java_lang_Throwable.c - java/lang/Throwable
2
3    Copyright (C) 2006, 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
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.
12
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.
17
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
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27
28 #include <assert.h>
29 #include <stdint.h>
30
31 #include "native/jni.h"
32 #include "native/llni.h"
33 #include "native/native.h"
34
35 #include "native/include/java_lang_Object.h"
36 #include "native/include/java_lang_Throwable.h"
37
38 #include "vm/exceptions.hpp"
39 #include "vm/jit/stacktrace.hpp"
40
41
42 /* native methods implemented by this file ************************************/
43  
44 static JNINativeMethod methods[] = {
45         { "printStackTrace",  "()V", (void *) (uintptr_t) &Java_java_lang_Throwable_printStackTrace  },
46         { "fillInStackTrace", "()V", (void *) (uintptr_t) &Java_java_lang_Throwable_fillInStackTrace },
47 };
48
49
50 /* _Jv_java_lang_Throwable_init ************************************************
51  
52    Register native functions.
53  
54 *******************************************************************************/
55  
56 void _Jv_java_lang_Throwable_init(void)
57 {
58         utf *u;
59  
60         u = utf_new_char("java/lang/Throwable");
61  
62         native_method_register(u, methods, NATIVE_METHODS_COUNT);
63 }
64
65
66 /*
67  * Class:     java/lang/Throwable
68  * Method:    printStackTrace
69  * Signature: ()V
70  */
71 JNIEXPORT void JNICALL Java_java_lang_Throwable_printStackTrace(JNIEnv *env, java_lang_Throwable *this)
72 {
73         java_handle_t *o;
74
75         o = (java_handle_t *) this;
76
77         exceptions_print_exception(o);
78         stacktrace_print_exception(o);
79 }
80
81
82 /*
83  * Class:     java/lang/Throwable
84  * Method:    fillInStackTrace
85  * Signature: ()V
86  */
87 JNIEXPORT void JNICALL Java_java_lang_Throwable_fillInStackTrace(JNIEnv *env, java_lang_Throwable *this)
88 {
89         java_handle_bytearray_t *ba;
90
91         ba = stacktrace_get_current();
92
93         if (ba == NULL)
94                 return;
95
96         LLNI_field_set_ref(this, backtrace, (java_lang_Object *) ba);
97 }
98
99
100 /*
101  * These are local overrides for various environment variables in Emacs.
102  * Please do not remove this and leave it at the end of the file, where
103  * Emacs will automagically detect them.
104  * ---------------------------------------------------------------------
105  * Local variables:
106  * mode: c
107  * indent-tabs-mode: t
108  * c-basic-offset: 4
109  * tab-width: 4
110  * End:
111  */