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