* tests/regression/resolving (svn:ignore): Added.
[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 7297 2007-02-07 14:59:56Z twisti $
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/options.h"
44
45
46 /*
47  * Class:     gnu/classpath/VMStackWalker
48  * Method:    getClassContext
49  * Signature: ()[Ljava/lang/Class;
50  */
51 JNIEXPORT java_objectarray* JNICALL Java_gnu_classpath_VMStackWalker_getClassContext(JNIEnv *env, jclass clazz)
52 {
53         java_objectarray *oa;
54
55         oa = stacktrace_getClassContext();
56
57         return oa;
58 }
59
60
61 /*
62  * Class:     gnu/classpath/VMStackWalker
63  * Method:    getCallingClass
64  * Signature: ()Ljava/lang/Class;
65  */
66 JNIEXPORT java_lang_Class* JNICALL Java_gnu_classpath_VMStackWalker_getCallingClass(JNIEnv *env, jclass clazz)
67 {
68         java_objectarray *oa;
69
70         oa = stacktrace_getClassContext();
71
72         if (oa == NULL)
73                 return NULL;
74
75         if (oa->header.size < 2)
76                 return NULL;
77
78         return (java_lang_Class *) oa->data[1];
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         java_objectarray  *oa;
90         classinfo         *c;
91         java_objectheader *cl;
92
93         oa = stacktrace_getClassContext();
94
95         if (oa == NULL)
96                 return NULL;
97
98         if (oa->header.size < 2)
99                 return NULL;
100          
101         c  = (classinfo *) oa->data[1];
102         cl = c->classloader;
103
104         return (java_lang_ClassLoader *) cl;
105 }
106
107
108 /*
109  * Class:     gnu/classpath/VMStackWalker
110  * Method:    firstNonNullClassLoader
111  * Signature: ()Ljava/lang/ClassLoader;
112  */
113 JNIEXPORT java_lang_ClassLoader* JNICALL Java_gnu_classpath_VMStackWalker_firstNonNullClassLoader(JNIEnv *env, jclass clazz)
114 {
115         java_objectarray  *oa;
116         classinfo         *c;
117         java_objectheader *cl;
118         s4                 i;
119
120         oa = stacktrace_getClassContext();
121
122         if (oa == NULL)
123                 return NULL;
124
125         for (i = 0; i < oa->header.size; i++) {
126                 c  = (classinfo *) oa->data[i];
127                 cl = c->classloader;
128
129                 if (cl != NULL)
130                         return (java_lang_ClassLoader *) cl;
131         }
132
133         return NULL;
134 }
135
136
137 /*
138  * These are local overrides for various environment variables in Emacs.
139  * Please do not remove this and leave it at the end of the file, where
140  * Emacs will automagically detect them.
141  * ---------------------------------------------------------------------
142  * Local variables:
143  * mode: c
144  * indent-tabs-mode: t
145  * c-basic-offset: 4
146  * tab-width: 4
147  * End:
148  * vim:noexpandtab:sw=4:ts=4:
149  */