* Updated header: Added 2006. Changed address of FSF. Changed email
[cacao.git] / src / vm / jit / stacktrace.h
1 /* src/vm/jit/stacktrace.h - header file for stacktrace generation
2
3    Copyright (C) 1996-2005, 2006 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    Contact: cacao@cacaojvm.org
26
27    Authors: Christian Thalinger
28
29    Changes:
30
31    $Id: stacktrace.h 4357 2006-01-22 23:33:38Z twisti $
32
33 */
34
35
36 #ifndef _STACKTRACE_H
37 #define _STACKTRACE_H
38
39 /* forward typedefs ***********************************************************/
40
41 typedef struct stackframeinfo stackframeinfo;
42 typedef struct stackTraceBuffer stackTraceBuffer;
43 typedef struct stacktraceelement stacktraceelement;
44
45 #include "config.h"
46 #include "vm/types.h"
47
48 #include "vm/method.h"
49
50
51 /* stackframeinfo **************************************************************
52
53    ATTENTION: Keep the number of elements of this structure even, to
54    make sure that the stack keeps aligned (e.g. 16-bytes for x86_64).
55
56 *******************************************************************************/
57
58 struct stackframeinfo {
59         stackframeinfo *prev;               /* pointer to prev stackframeinfo     */
60         methodinfo     *method;             /* methodinfo of current function     */
61         u1             *pv;                 /* PV of current function             */
62         u1             *sp;                 /* SP of parent Java function         */
63         u1             *ra;                 /* RA to parent Java function         */
64         u1             *xpc;                /* XPC (for inline stubs)             */
65 };
66
67 #if defined(USE_THREADS)
68 #define STACKFRAMEINFO    (stackframeinfo **) (&THREADINFO->_stackframeinfo)
69 #else
70 extern stackframeinfo *_no_threads_stackframeinfo;
71
72 #define STACKFRAMEINFO    (&_no_threads_stackframeinfo)
73 #endif
74
75
76 struct stacktraceelement {
77 #if SIZEOF_VOID_P == 8
78         u8          linenumber;
79 #else
80         u4          linenumber;
81 #endif
82         methodinfo *method;
83 };
84
85
86 struct stackTraceBuffer {
87         s4                 needsFree;
88         stacktraceelement *start;
89         s4                 size;
90         s4                 full;
91 };
92
93
94 /* function prototypes ********************************************************/
95
96 #if defined(ENABLE_INTRP)
97 void stacktrace_create_stackframeinfo(stackframeinfo *sfi, u1 *pv, u1 *sp,
98                                                                           u1 *ra);
99 #endif
100
101 void stacktrace_create_inline_stackframeinfo(stackframeinfo *sfi, u1 *pv,
102                                                                                          u1 *sp, u1 *ra, u1 *xpc);
103
104 void stacktrace_create_extern_stackframeinfo(stackframeinfo *sfi, u1 *pv,
105                                                                                          u1 *sp, u1 *ra, u1 *xpc);
106
107 void stacktrace_create_native_stackframeinfo(stackframeinfo *sfi, u1 *pv,
108                                                                                          u1 *sp, u1 *ra);
109
110 void stacktrace_remove_stackframeinfo(stackframeinfo *sfi);
111
112 /* inline exception creating functions */
113 java_objectheader *stacktrace_inline_arithmeticexception(u1 *pv, u1 *sp, u1 *ra,
114                                                                                                                  u1 *xpc);
115
116 java_objectheader *stacktrace_inline_arrayindexoutofboundsexception(u1 *pv,
117                                                                                                                                         u1 *sp,
118                                                                                                                                         u1 *ra,
119                                                                                                                                         u1 *xpc,
120                                                                                                                                         s4 index);
121
122 java_objectheader *stacktrace_inline_arraystoreexception(u1 *pv, u1 *sp, u1 *ra,
123                                                                                                                  u1 *xpc);
124
125 java_objectheader *stacktrace_inline_classcastexception(u1 *pv, u1 *sp, u1 *ra,
126                                                                                                                 u1 *xpc);
127
128 java_objectheader *stacktrace_inline_nullpointerexception(u1 *pv, u1 *sp,
129                                                                                                                   u1 *ra, u1 *xpc);
130
131
132 /* hardware exception creating functions */
133 java_objectheader *stacktrace_hardware_arithmeticexception(u1 *pv, u1 *sp,
134                                                                                                                    u1 *ra, u1 *xpc);
135
136 java_objectheader *stacktrace_hardware_nullpointerexception(u1 *pv, u1 *sp,
137                                                                                                                         u1 *ra, u1 *xpc);
138
139 /* refill the stacktrace of an existing exception */
140 java_objectheader *stacktrace_inline_fillInStackTrace(u1 *pv, u1 *sp, u1 *ra,
141                                                                                                           u1 *xpc);
142
143 bool cacao_stacktrace_NormalTrace(void **target);
144 java_objectarray *cacao_createClassContextArray(void);
145 java_objectheader *cacao_currentClassLoader(void);
146 java_objectarray *cacao_getStackForVMAccessController(void);
147
148 void stacktrace_dump_trace(void);
149 void stacktrace_print_trace(java_objectheader *xptr);
150
151
152 /* machine dependent functions (code in ARCH_DIR/md.c) */
153
154 #if defined(ENABLE_JIT)
155 u1 *md_stacktrace_get_returnaddress(u1 *sp, u4 framesize);
156 #endif
157
158 #if defined(ENABLE_INTRP)
159 u1 *intrp_md_stacktrace_get_returnaddress(u1 *sp, u4 framesize);
160 #endif
161
162
163 #ifdef ENABLE_JVMTI
164 typedef bool(*CacaoStackTraceCollector)(void **, stackTraceBuffer*);
165
166 bool cacao_stacktrace_fillInStackTrace(void **target,
167                                                                            CacaoStackTraceCollector coll,
168                                                                            threadobject* thread);
169
170 bool stackTraceCollector(void **target, stackTraceBuffer *buffer);
171 #endif
172
173 #endif /* _STACKTRACE_H */
174
175
176 /*
177  * These are local overrides for various environment variables in Emacs.
178  * Please do not remove this and leave it at the end of the file, where
179  * Emacs will automagically detect them.
180  * ---------------------------------------------------------------------
181  * Local variables:
182  * mode: c
183  * indent-tabs-mode: t
184  * c-basic-offset: 4
185  * tab-width: 4
186  * End:
187  */