* src/native/vm/cldc1.1/com_sun_cldc_io_ResourceInputStream.cpp
[cacao.git] / src / native / vm / gnuclasspath / gnu_classpath_VMStackWalker.cpp
1 /* src/native/vm/gnuclasspath/gnu_classpath_VMStackWalker.cpp
2
3    Copyright (C) 1996-2005, 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 <stdint.h>
29
30 #include "native/jni.h"
31 #include "native/native.h"
32
33 #include "native/include/java_lang_Class.h"
34 #include "native/include/java_lang_ClassLoader.h"
35
36 // FIXME
37 extern "C" {
38 #include "native/include/gnu_classpath_VMStackWalker.h"
39 }
40
41 #include "vm/global.h"
42
43 #include "vm/jit/stacktrace.hpp"
44
45 #include "vmcore/class.h"
46 #include "vmcore/utf8.h"
47
48
49 // Native functions are exported as C functions.
50 extern "C" {
51
52 /*
53  * Class:     gnu/classpath/VMStackWalker
54  * Method:    getClassContext
55  * Signature: ()[Ljava/lang/Class;
56  */
57 JNIEXPORT java_handle_objectarray_t* JNICALL Java_gnu_classpath_VMStackWalker_getClassContext(JNIEnv *env, jclass clazz)
58 {
59         java_handle_objectarray_t *oa;
60
61         oa = stacktrace_getClassContext();
62
63         return oa;
64 }
65
66
67 /*
68  * Class:     gnu/classpath/VMStackWalker
69  * Method:    getCallingClass
70  * Signature: ()Ljava/lang/Class;
71  */
72 JNIEXPORT java_lang_Class* JNICALL Java_gnu_classpath_VMStackWalker_getCallingClass(JNIEnv *env, jclass clazz)
73 {
74         classinfo *c;
75
76         c = stacktrace_get_caller_class(2);
77
78         return (java_lang_Class *) c;
79 }
80
81
82 /*
83  * Class:     gnu/classpath/VMStackWalker
84  * Method:    getCallingClassLoader
85  * Signature: ()Ljava/lang/ClassLoader;
86  */
87 JNIEXPORT java_lang_ClassLoader* JNICALL Java_gnu_classpath_VMStackWalker_getCallingClassLoader(JNIEnv *env, jclass clazz)
88 {
89         classinfo     *c;
90         classloader_t *cl;
91
92         c  = stacktrace_get_caller_class(2);
93         cl = class_get_classloader(c);
94
95         return (java_lang_ClassLoader *) cl;
96 }
97
98
99 /*
100  * Class:     gnu/classpath/VMStackWalker
101  * Method:    firstNonNullClassLoader
102  * Signature: ()Ljava/lang/ClassLoader;
103  */
104 JNIEXPORT java_lang_ClassLoader* JNICALL Java_gnu_classpath_VMStackWalker_firstNonNullClassLoader(JNIEnv *env, jclass clazz)
105 {
106         classloader_t *cl;
107
108         cl = stacktrace_first_nonnull_classloader();
109
110         return (java_lang_ClassLoader *) cl;
111 }
112
113 } // extern "C"
114
115
116 /* native methods implemented by this file ************************************/
117
118 static JNINativeMethod methods[] = {
119         { (char*) "getClassContext",         (char*) "()[Ljava/lang/Class;",      (void*) (uintptr_t) &Java_gnu_classpath_VMStackWalker_getClassContext         },
120         { (char*) "getCallingClass",         (char*) "()Ljava/lang/Class;",       (void*) (uintptr_t) &Java_gnu_classpath_VMStackWalker_getCallingClass         },
121         { (char*) "getCallingClassLoader",   (char*) "()Ljava/lang/ClassLoader;", (void*) (uintptr_t) &Java_gnu_classpath_VMStackWalker_getCallingClassLoader   },
122         { (char*) "firstNonNullClassLoader", (char*) "()Ljava/lang/ClassLoader;", (void*) (uintptr_t) &Java_gnu_classpath_VMStackWalker_firstNonNullClassLoader },
123 };
124
125
126 /* _Jv_gnu_classpath_VMStackWalker_init ****************************************
127
128    Register native functions.
129
130 *******************************************************************************/
131
132 // FIXME
133 extern "C" {
134 void _Jv_gnu_classpath_VMStackWalker_init(void)
135 {
136         utf *u;
137
138         u = utf_new_char("gnu/classpath/VMStackWalker");
139
140         native_method_register(u, methods, NATIVE_METHODS_COUNT);
141 }
142 }
143
144
145 /*
146  * These are local overrides for various environment variables in Emacs.
147  * Please do not remove this and leave it at the end of the file, where
148  * Emacs will automagically detect them.
149  * ---------------------------------------------------------------------
150  * Local variables:
151  * mode: c++
152  * indent-tabs-mode: t
153  * c-basic-offset: 4
154  * tab-width: 4
155  * End:
156  * vim:noexpandtab:sw=4:ts=4:
157  */