* This is a rather huge commit, which changes the build order of
[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 7246 2007-01-29 18:49:05Z twisti $
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 };
67
68
69 /* stacktrace_entry ***********************************************************/
70
71 struct stacktrace_entry {
72 #if SIZEOF_VOID_P == 8
73         u8          linenumber;
74 #else
75         u4          linenumber;
76 #endif
77         methodinfo *method;
78 };
79
80
81 /* stacktracebuffer ***********************************************************/
82
83 #define STACKTRACE_CAPACITY_DEFAULT      80
84 #define STACKTRACE_CAPACITY_INCREMENT    80
85
86 struct stacktracebuffer {
87         s4                capacity;         /* size of the buffer                 */
88         s4                used;             /* current entries in the buffer      */
89         stacktrace_entry *entries;          /* the actual entries                 */
90 };
91
92
93 /* stacktracecontainer ********************************************************
94
95    ATTENTION: Use the stacktracecontainer to place a stacktrace onto the heap
96    with stacktrace_fillInStackTrace() so that the GC does not get confused.
97
98 *******************************************************************************/
99
100 typedef struct stacktracecontainer {
101         java_arrayheader        header;     /* default array header for the GC    */
102         struct stacktracebuffer stb;        /* let entries point to data below    */
103         stacktrace_entry        data[1];    /* the actual array of entries        */
104 } stacktracecontainer;
105
106
107 /* function prototypes ********************************************************/
108
109 #if defined(ENABLE_INTRP)
110 void stacktrace_create_stackframeinfo(stackframeinfo *sfi, u1 *pv, u1 *sp,
111                                                                           u1 *ra);
112 #endif
113
114 void stacktrace_create_inline_stackframeinfo(stackframeinfo *sfi, u1 *pv,
115                                                                                          u1 *sp, u1 *ra, u1 *xpc);
116
117 void stacktrace_create_extern_stackframeinfo(stackframeinfo *sfi, u1 *pv,
118                                                                                          u1 *sp, u1 *ra, u1 *xpc);
119
120 void stacktrace_create_native_stackframeinfo(stackframeinfo *sfi, u1 *pv,
121                                                                                          u1 *sp, u1 *ra);
122
123 void stacktrace_remove_stackframeinfo(stackframeinfo *sfi);
124
125 /* inline exception creating functions */
126 java_objectheader *stacktrace_inline_arithmeticexception(u1 *pv, u1 *sp, u1 *ra,
127                                                                                                                  u1 *xpc);
128 #define STACKTRACE_inline_arithmeticexception \
129     (functionptr) stacktrace_inline_arithmeticexception
130                                                                                                 
131
132 java_objectheader *stacktrace_inline_arrayindexoutofboundsexception(u1 *pv,
133                                                                                                                                         u1 *sp,
134                                                                                                                                         u1 *ra,
135                                                                                                                                         u1 *xpc,
136                                                                                                                                         s4 index);
137 #define STACKTRACE_inline_arrayindexoutofboundsexception \
138     (functionptr) stacktrace_inline_arrayindexoutofboundsexception
139
140 java_objectheader *stacktrace_inline_arraystoreexception(u1 *pv, u1 *sp, u1 *ra,
141                                                                                                                  u1 *xpc);
142 #define STACKTRACE_inline_arraystoreexception \
143     (functionptr) stacktrace_inline_arraystoreexception
144
145 java_objectheader *stacktrace_inline_classcastexception(u1 *pv, u1 *sp, u1 *ra,
146                                                                                                                 u1 *xpc,
147                                                                                                                 java_objectheader *o);
148 #define STACKTRACE_inline_classcastexception \
149     (functionptr) stacktrace_inline_classcastexception
150
151 java_objectheader *stacktrace_inline_nullpointerexception(u1 *pv, u1 *sp,
152                                                                                                                   u1 *ra, u1 *xpc);
153 #define STACKTRACE_inline_nullpointerexception \
154     (functionptr) stacktrace_inline_nullpointerexception
155
156 /* refill the stacktrace of an existing exception */
157 java_objectheader *stacktrace_inline_fillInStackTrace(u1 *pv, u1 *sp, u1 *ra,
158                                                                                                           u1 *xpc);
159 #define STACKTRACE_inline_fillInStackTrace \
160     (functionptr) stacktrace_inline_fillInStackTrace
161
162
163 /* hardware exception creating functions */
164 java_objectheader *stacktrace_hardware_arithmeticexception(u1 *pv, u1 *sp,
165                                                                                                                    u1 *ra, u1 *xpc);
166
167 java_objectheader *stacktrace_hardware_nullpointerexception(u1 *pv, u1 *sp,
168                                                                                                                         u1 *ra, u1 *xpc);
169
170
171 stacktracecontainer *stacktrace_fillInStackTrace(void);
172
173 #if defined(ENABLE_JAVASE)
174 java_objectarray    *stacktrace_getClassContext(void);
175 classinfo           *stacktrace_getCurrentClass(void);
176 java_objectarray    *stacktrace_getStack(void);
177 #endif
178
179 void stacktrace_dump_trace(threadobject *thread);
180 void stacktrace_print_trace(java_objectheader *xptr);
181
182
183 /* machine dependent functions (code in ARCH_DIR/md.c) */
184
185 #if defined(ENABLE_JIT)
186 u1 *md_stacktrace_get_returnaddress(u1 *sp, u4 framesize);
187 #endif
188
189 #if defined(ENABLE_INTRP)
190 u1 *intrp_md_stacktrace_get_returnaddress(u1 *sp, u4 framesize);
191 #endif
192
193 #if defined(ENABLE_CYCLES_STATS)
194 void stacktrace_print_cycles_stats(FILE *file);
195 #endif
196
197 #endif /* _STACKTRACE_H */
198
199
200 /*
201  * These are local overrides for various environment variables in Emacs.
202  * Please do not remove this and leave it at the end of the file, where
203  * Emacs will automagically detect them.
204  * ---------------------------------------------------------------------
205  * Local variables:
206  * mode: c
207  * indent-tabs-mode: t
208  * c-basic-offset: 4
209  * tab-width: 4
210  * End:
211  */