Merged revisions 7407-7440 via svnmerge from
[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, 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: stacktrace.h 7441 2007-03-02 23:13:10Z michi $
26
27 */
28
29
30 #ifndef _STACKTRACE_H
31 #define _STACKTRACE_H
32
33 /* forward typedefs ***********************************************************/
34
35 typedef struct stackframeinfo stackframeinfo;
36 typedef struct stacktracebuffer stacktracebuffer;
37 typedef struct stacktrace_entry stacktrace_entry;
38
39 #include "config.h"
40 #include "vm/types.h"
41
42 #if defined(ENABLE_THREADS)
43 # include "threads/native/threads.h"
44 #else
45 # include "threads/none/threads.h"
46 #endif
47
48 #include "vmcore/class.h"
49 #include "vmcore/method.h"
50
51
52 /* stackframeinfo **************************************************************
53
54    ATTENTION: Keep the number of elements of this structure even, to
55    make sure that the stack keeps aligned (e.g. 16-bytes for x86_64).
56
57 *******************************************************************************/
58
59 struct stackframeinfo {
60         stackframeinfo *prev;               /* pointer to prev stackframeinfo     */
61         methodinfo     *method;             /* methodinfo of current function     */
62         u1             *pv;                 /* PV of current function             */
63         u1             *sp;                 /* SP of parent Java function         */
64         u1             *ra;                 /* RA to parent Java function         */
65         u1             *xpc;                /* XPC (for inline stubs)             */
66 #if defined(ENABLE_GC_CACAO)
67         /* 
68          * The exact GC needs to be able to recover saved registers, so the
69          * native-stub saves these registers here
70          */
71         ptrint          intregs[INT_SAV_CNT];
72 #endif
73 };
74
75
76 /* stacktrace_entry ***********************************************************/
77
78 struct stacktrace_entry {
79 #if SIZEOF_VOID_P == 8
80         u8          linenumber;
81 #else
82         u4          linenumber;
83 #endif
84         methodinfo *method;
85 };
86
87
88 /* stacktracebuffer ***********************************************************/
89
90 #define STACKTRACE_CAPACITY_DEFAULT      80
91 #define STACKTRACE_CAPACITY_INCREMENT    80
92
93 struct stacktracebuffer {
94         s4                capacity;         /* size of the buffer                 */
95         s4                used;             /* current entries in the buffer      */
96         stacktrace_entry *entries;          /* the actual entries                 */
97 };
98
99
100 /* stacktracecontainer ********************************************************
101
102    ATTENTION: Use the stacktracecontainer to place a stacktrace onto the heap
103    with stacktrace_fillInStackTrace() so that the GC does not get confused.
104
105 *******************************************************************************/
106
107 typedef struct stacktracecontainer {
108         java_arrayheader        header;     /* default array header for the GC    */
109         struct stacktracebuffer stb;        /* let entries point to data below    */
110         stacktrace_entry        data[1];    /* the actual array of entries        */
111 } stacktracecontainer;
112
113
114 /* function prototypes ********************************************************/
115
116 #if defined(ENABLE_INTRP)
117 void stacktrace_create_stackframeinfo(stackframeinfo *sfi, u1 *pv, u1 *sp,
118                                                                           u1 *ra);
119 #endif
120
121 void stacktrace_create_inline_stackframeinfo(stackframeinfo *sfi, u1 *pv,
122                                                                                          u1 *sp, u1 *ra, u1 *xpc);
123
124 void stacktrace_create_extern_stackframeinfo(stackframeinfo *sfi, u1 *pv,
125                                                                                          u1 *sp, u1 *ra, u1 *xpc);
126
127 void stacktrace_create_native_stackframeinfo(stackframeinfo *sfi, u1 *pv,
128                                                                                          u1 *sp, u1 *ra);
129
130 void stacktrace_remove_stackframeinfo(stackframeinfo *sfi);
131
132 /* inline exception creating functions */
133 java_objectheader *stacktrace_inline_arithmeticexception(u1 *pv, u1 *sp, u1 *ra,
134                                                                                                                  u1 *xpc);
135 #define STACKTRACE_inline_arithmeticexception \
136     (functionptr) stacktrace_inline_arithmeticexception
137                                                                                                 
138
139 java_objectheader *stacktrace_inline_arrayindexoutofboundsexception(u1 *pv,
140                                                                                                                                         u1 *sp,
141                                                                                                                                         u1 *ra,
142                                                                                                                                         u1 *xpc,
143                                                                                                                                         s4 index);
144 #define STACKTRACE_inline_arrayindexoutofboundsexception \
145     (functionptr) stacktrace_inline_arrayindexoutofboundsexception
146
147 java_objectheader *stacktrace_inline_arraystoreexception(u1 *pv, u1 *sp, u1 *ra,
148                                                                                                                  u1 *xpc);
149 #define STACKTRACE_inline_arraystoreexception \
150     (functionptr) stacktrace_inline_arraystoreexception
151
152 java_objectheader *stacktrace_inline_classcastexception(u1 *pv, u1 *sp, u1 *ra,
153                                                                                                                 u1 *xpc,
154                                                                                                                 java_objectheader *o);
155 #define STACKTRACE_inline_classcastexception \
156     (functionptr) stacktrace_inline_classcastexception
157
158 java_objectheader *stacktrace_inline_nullpointerexception(u1 *pv, u1 *sp,
159                                                                                                                   u1 *ra, u1 *xpc);
160 #define STACKTRACE_inline_nullpointerexception \
161     (functionptr) stacktrace_inline_nullpointerexception
162
163 /* refill the stacktrace of an existing exception */
164 java_objectheader *stacktrace_inline_fillInStackTrace(u1 *pv, u1 *sp, u1 *ra,
165                                                                                                           u1 *xpc);
166 #define STACKTRACE_inline_fillInStackTrace \
167     (functionptr) stacktrace_inline_fillInStackTrace
168
169
170 /* hardware exception creating functions */
171 java_objectheader *stacktrace_hardware_arithmeticexception(u1 *pv, u1 *sp,
172                                                                                                                    u1 *ra, u1 *xpc);
173
174 java_objectheader *stacktrace_hardware_nullpointerexception(u1 *pv, u1 *sp,
175                                                                                                                         u1 *ra, u1 *xpc);
176
177
178 stacktracecontainer *stacktrace_fillInStackTrace(void);
179
180 #if defined(ENABLE_JAVASE)
181 java_objectarray    *stacktrace_getClassContext(void);
182 classinfo           *stacktrace_getCurrentClass(void);
183 java_objectarray    *stacktrace_getStack(void);
184 #endif
185
186 void stacktrace_dump_trace(threadobject *thread);
187 void stacktrace_print_trace(java_objectheader *xptr);
188
189
190 /* machine dependent functions (code in ARCH_DIR/md.c) */
191
192 #if defined(ENABLE_JIT)
193 u1 *md_stacktrace_get_returnaddress(u1 *sp, u4 framesize);
194 # if defined(__SPARC_64__)
195 u1 *md_get_framepointer(u1 *sp);
196 u1 *md_get_pv_from_stackframe(u1 *sp);
197 # endif
198 #endif
199
200 #if defined(ENABLE_INTRP)
201 u1 *intrp_md_stacktrace_get_returnaddress(u1 *sp, u4 framesize);
202 #endif
203
204 #if defined(ENABLE_CYCLES_STATS)
205 void stacktrace_print_cycles_stats(FILE *file);
206 #endif
207
208 #endif /* _STACKTRACE_H */
209
210
211 /*
212  * These are local overrides for various environment variables in Emacs.
213  * Please do not remove this and leave it at the end of the file, where
214  * Emacs will automagically detect them.
215  * ---------------------------------------------------------------------
216  * Local variables:
217  * mode: c
218  * indent-tabs-mode: t
219  * c-basic-offset: 4
220  * tab-width: 4
221  * End:
222  * vim:noexpandtab:sw=4:ts=4:
223  */