dbe476bae74870a9ffb36b4b9ea12ab5046009a4
[cacao.git] / src / native / vm / gnu / gnu_classpath_VMStackWalker.c
1 /* src/native/vm/gnu/gnu_classpath_VMStackWalker.c
2
3    Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    $Id: gnu_classpath_VMStackWalker.c 7399 2007-02-23 23:29:13Z michi $
26
27 */
28
29
30 #include "config.h"
31
32 #include "native/jni.h"
33 #include "native/native.h"
34 #include "native/include/java_lang_Class.h"
35 #include "native/include/java_lang_ClassLoader.h"
36
37 #include "vm/builtin.h"
38 #include "vm/global.h"
39
40 #include "vm/jit/stacktrace.h"
41
42 #include "vmcore/class.h"
43 #include "vmcore/loader.h"
44 #include "vmcore/options.h"
45
46
47 /*
48  * Class:     gnu/classpath/VMStackWalker
49  * Method:    getClassContext
50  * Signature: ()[Ljava/lang/Class;
51  */
52 JNIEXPORT java_objectarray* JNICALL Java_gnu_classpath_VMStackWalker_getClassContext(JNIEnv *env, jclass clazz)
53 {
54         java_objectarray *oa;
55
56         oa = stacktrace_getClassContext();
57
58         return oa;
59 }
60
61
62 /*
63  * Class:     gnu/classpath/VMStackWalker
64  * Method:    getCallingClass
65  * Signature: ()Ljava/lang/Class;
66  */
67 JNIEXPORT java_lang_Class* JNICALL Java_gnu_classpath_VMStackWalker_getCallingClass(JNIEnv *env, jclass clazz)
68 {
69         java_objectarray *oa;
70
71         oa = stacktrace_getClassContext();
72
73         if (oa == NULL)
74                 return NULL;
75
76         if (oa->header.size < 2)
77                 return NULL;
78
79         return (java_lang_Class *) oa->data[1];
80 }
81
82
83 /*
84  * Class:     gnu/classpath/VMStackWalker
85  * Method:    getCallingClassLoader
86  * Signature: ()Ljava/lang/ClassLoader;
87  */
88 JNIEXPORT java_lang_ClassLoader* JNICALL Java_gnu_classpath_VMStackWalker_getCallingClassLoader(JNIEnv *env, jclass clazz)
89 {
90         java_objectarray  *oa;
91         classinfo         *c;
92         classloader       *cl;
93
94         oa = stacktrace_getClassContext();
95
96         if (oa == NULL)
97                 return NULL;
98
99         if (oa->header.size < 2)
100                 return NULL;
101          
102         c   = (classinfo *) oa->data[1];
103         cl  = c->classloader;
104
105         if (cl == NULL)
106                 return NULL;
107
108         return (java_lang_ClassLoader *) cl->object;
109 }
110
111
112 /*
113  * Class:     gnu/classpath/VMStackWalker
114  * Method:    firstNonNullClassLoader
115  * Signature: ()Ljava/lang/ClassLoader;
116  */
117 JNIEXPORT java_lang_ClassLoader* JNICALL Java_gnu_classpath_VMStackWalker_firstNonNullClassLoader(JNIEnv *env, jclass clazz)
118 {
119         java_objectarray  *oa;
120         classinfo         *c;
121         classloader       *cl;
122         s4                 i;
123
124         oa = stacktrace_getClassContext();
125
126         if (oa == NULL)
127                 return NULL;
128
129         for (i = 0; i < oa->header.size; i++) {
130                 c  = (classinfo *) oa->data[i];
131                 cl = c->classloader;
132
133                 if (cl != NULL)
134                         return (java_lang_ClassLoader *) cl->object;
135         }
136
137         return NULL;
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  */