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