7d2e0782115e9b18a1b9c0b6e89c74cde6384520
[cacao.git] / src / native / vm / VMStackWalker.c
1 /* src/native/vm/VMStackWalker.c - gnu/classpath/VMStackWalker
2
3    Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    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., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Christian Thalinger
28
29    Changes: 
30
31    $Id: VMStackWalker.c 4180 2006-01-12 23:07:23Z twisti $
32
33 */
34
35
36 #include "config.h"
37
38 #include "native/jni.h"
39 #include "native/native.h"
40 #include "native/include/java_lang_Class.h"
41 #include "native/include/java_lang_ClassLoader.h"
42 #include "vm/builtin.h"
43 #include "vm/class.h"
44 #include "vm/global.h"
45 #include "vm/options.h"
46
47
48 /*
49  * Class:     gnu/classpath/VMStackWalker
50  * Method:    getClassContext
51  * Signature: ()[Ljava/lang/Class;
52  */
53 JNIEXPORT java_objectarray* JNICALL Java_gnu_classpath_VMStackWalker_getClassContext(JNIEnv *env, jclass clazz)
54 {
55 /*      if (cacao_initializing) */
56 /*              return NULL; */
57
58 #if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__X86_64__)
59         /* these JITs support stacktraces, and so does the interpreter */
60
61         return cacao_createClassContextArray();
62
63 #else
64 # if defined(ENABLE_INTRP)
65         /* the interpreter supports stacktraces, even if the JIT does not */
66
67         if (opt_intrp) {
68                 return cacao_createClassContextArray();
69
70         } else
71 # endif
72                 {
73                         return builtin_anewarray(0, class_java_lang_Class);
74                 }
75 #endif
76 }
77
78
79 /*
80  * Class:     gnu/classpath/VMStackWalker
81  * Method:    getCallingClass
82  * Signature: ()Ljava/lang/Class;
83  */
84 JNIEXPORT java_lang_Class* JNICALL Java_gnu_classpath_VMStackWalker_getCallingClass(JNIEnv *env, jclass clazz)
85 {
86 #if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__X86_64__)
87         /* these JITs support stacktraces, and so does the interpreter */
88
89         java_objectarray *oa;
90
91         oa = cacao_createClassContextArray();
92
93         if (oa->header.size < 2)
94                 return NULL;
95
96         return (java_lang_Class *) oa->data[1];
97
98 #else
99 # if defined(ENABLE_INTRP)
100         /* the interpreter supports stacktraces, even if the JIT does not */
101
102         if (opt_intrp) {
103                 java_objectarray *oa;
104
105                 oa = cacao_createClassContextArray();
106
107                 if (oa->header.size < 2)
108                         return NULL;
109
110                 return (java_lang_Class *) oa->data[1];
111
112         } else
113 # endif
114                 {
115                         return NULL;
116                 }
117 #endif
118 }
119
120
121 /*
122  * Class:     gnu/classpath/VMStackWalker
123  * Method:    getCallingClassLoader
124  * Signature: ()Ljava/lang/ClassLoader;
125  */
126 JNIEXPORT java_lang_ClassLoader* JNICALL Java_gnu_classpath_VMStackWalker_getCallingClassLoader(JNIEnv *env, jclass clazz)
127 {
128 #if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__X86_64__)
129         /* these JITs support stacktraces, and so does the interpreter */
130
131         java_objectarray *oa;
132         classinfo        *c;
133
134         oa = cacao_createClassContextArray();
135
136         if (oa->header.size < 2)
137                 return NULL;
138
139         c = (classinfo *) oa->data[1];
140
141         return (java_lang_ClassLoader *) c->classloader;
142
143 #else
144 # if defined(ENABLE_INTRP)
145         /* the interpreter supports stacktraces, even if the JIT does not */
146
147         if (opt_intrp) {
148                 java_objectarray *oa;
149                 classinfo        *c;
150
151                 oa = cacao_createClassContextArray();
152
153                 if (oa->header.size < 2)
154                         return NULL;
155
156                 c = (classinfo *) oa->data[1];
157
158                 return (java_lang_ClassLoader *) c->classloader;
159
160         } else
161 # endif
162                 {
163                         return NULL;
164                 }
165 #endif
166 }
167
168
169 /*
170  * These are local overrides for various environment variables in Emacs.
171  * Please do not remove this and leave it at the end of the file, where
172  * Emacs will automagically detect them.
173  * ---------------------------------------------------------------------
174  * Local variables:
175  * mode: c
176  * indent-tabs-mode: t
177  * c-basic-offset: 4
178  * tab-width: 4
179  * End:
180  */