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