* src/vm/jit/stacktrace.c: Java ME changes.
[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 6248 2006-12-27 22:39:39Z 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 stacktrace_entry stacktrace_entry;
44
45 #include "config.h"
46 #include "vm/types.h"
47
48 #if defined(ENABLE_THREADS)
49 # include "threads/native/threads.h"
50 #else
51 # include "threads/none/threads.h"
52 #endif
53
54 #include "vm/method.h"
55
56
57 /* stackframeinfo **************************************************************
58
59    ATTENTION: Keep the number of elements of this structure even, to
60    make sure that the stack keeps aligned (e.g. 16-bytes for x86_64).
61
62 *******************************************************************************/
63
64 struct stackframeinfo {
65         stackframeinfo *prev;               /* pointer to prev stackframeinfo     */
66         methodinfo     *method;             /* methodinfo of current function     */
67         u1             *pv;                 /* PV of current function             */
68         u1             *sp;                 /* SP of parent Java function         */
69         u1             *ra;                 /* RA to parent Java function         */
70         u1             *xpc;                /* XPC (for inline stubs)             */
71 };
72
73 #if defined(ENABLE_THREADS)
74 #define STACKFRAMEINFO    (&(THREADOBJECT->_stackframeinfo))
75 #else
76 extern stackframeinfo *_no_threads_stackframeinfo;
77
78 #define STACKFRAMEINFO    (&_no_threads_stackframeinfo)
79 #endif
80
81
82 /* stacktrace_entry ***********************************************************/
83
84 struct stacktrace_entry {
85 #if SIZEOF_VOID_P == 8
86         u8          linenumber;
87 #else
88         u4          linenumber;
89 #endif
90         methodinfo *method;
91 };
92
93
94 /* stacktracebuffer ***********************************************************/
95
96 #define STACKTRACE_CAPACITY_DEFAULT      80
97 #define STACKTRACE_CAPACITY_INCREMENT    80
98
99 struct stacktracebuffer {
100         s4                capacity;         /* size of the buffer                 */
101         s4                used;             /* current entries in the buffer      */
102         stacktrace_entry *entries;          /* the actual entries                 */
103 };
104
105
106 /* stacktracecontainer ********************************************************
107
108    ATTENTION: Use the stacktracecontainer to place a stacktrace onto the heap
109    with stacktrace_fillInStackTrace() so that the GC does not get confused.
110
111 *******************************************************************************/
112
113 typedef struct stacktracecontainer {
114         java_arrayheader        header;     /* default array header for the GC    */
115         struct stacktracebuffer stb;        /* let entries point to data below    */
116         stacktrace_entry        data[1];    /* the actual array of entries        */
117 } stacktracecontainer;
118
119
120 /* function prototypes ********************************************************/
121
122 #if defined(ENABLE_INTRP)
123 void stacktrace_create_stackframeinfo(stackframeinfo *sfi, u1 *pv, u1 *sp,
124                                                                           u1 *ra);
125 #endif
126
127 void stacktrace_create_inline_stackframeinfo(stackframeinfo *sfi, u1 *pv,
128                                                                                          u1 *sp, u1 *ra, u1 *xpc);
129
130 void stacktrace_create_extern_stackframeinfo(stackframeinfo *sfi, u1 *pv,
131                                                                                          u1 *sp, u1 *ra, u1 *xpc);
132
133 void stacktrace_create_native_stackframeinfo(stackframeinfo *sfi, u1 *pv,
134                                                                                          u1 *sp, u1 *ra);
135
136 void stacktrace_remove_stackframeinfo(stackframeinfo *sfi);
137
138 /* inline exception creating functions */
139 java_objectheader *stacktrace_inline_arithmeticexception(u1 *pv, u1 *sp, u1 *ra,
140                                                                                                                  u1 *xpc);
141 #define STACKTRACE_inline_arithmeticexception \
142     (functionptr) stacktrace_inline_arithmeticexception
143                                                                                                 
144
145 java_objectheader *stacktrace_inline_arrayindexoutofboundsexception(u1 *pv,
146                                                                                                                                         u1 *sp,
147                                                                                                                                         u1 *ra,
148                                                                                                                                         u1 *xpc,
149                                                                                                                                         s4 index);
150 #define STACKTRACE_inline_arrayindexoutofboundsexception \
151     (functionptr) stacktrace_inline_arrayindexoutofboundsexception
152
153 java_objectheader *stacktrace_inline_arraystoreexception(u1 *pv, u1 *sp, u1 *ra,
154                                                                                                                  u1 *xpc);
155 #define STACKTRACE_inline_arraystoreexception \
156     (functionptr) stacktrace_inline_arraystoreexception
157
158 java_objectheader *stacktrace_inline_classcastexception(u1 *pv, u1 *sp, u1 *ra,
159                                                                                                                 u1 *xpc,
160                                                                                                                 java_objectheader *o);
161 #define STACKTRACE_inline_classcastexception \
162     (functionptr) stacktrace_inline_classcastexception
163
164 java_objectheader *stacktrace_inline_nullpointerexception(u1 *pv, u1 *sp,
165                                                                                                                   u1 *ra, u1 *xpc);
166 #define STACKTRACE_inline_nullpointerexception \
167     (functionptr) stacktrace_inline_nullpointerexception
168
169 /* refill the stacktrace of an existing exception */
170 java_objectheader *stacktrace_inline_fillInStackTrace(u1 *pv, u1 *sp, u1 *ra,
171                                                                                                           u1 *xpc);
172 #define STACKTRACE_inline_fillInStackTrace \
173     (functionptr) stacktrace_inline_fillInStackTrace
174
175
176 /* hardware exception creating functions */
177 java_objectheader *stacktrace_hardware_arithmeticexception(u1 *pv, u1 *sp,
178                                                                                                                    u1 *ra, u1 *xpc);
179
180 java_objectheader *stacktrace_hardware_nullpointerexception(u1 *pv, u1 *sp,
181                                                                                                                         u1 *ra, u1 *xpc);
182
183
184 stacktracecontainer *stacktrace_fillInStackTrace(void);
185
186 #if defined(ENABLE_JAVASE)
187 java_objectarray    *stacktrace_getClassContext(void);
188 classinfo           *stacktrace_getCurrentClass(void);
189 java_objectarray    *stacktrace_getStack(void);
190 #endif
191
192 void stacktrace_dump_trace(threadobject *thread);
193 void stacktrace_print_trace(java_objectheader *xptr);
194
195
196 /* machine dependent functions (code in ARCH_DIR/md.c) */
197
198 #if defined(ENABLE_JIT)
199 u1 *md_stacktrace_get_returnaddress(u1 *sp, u4 framesize);
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  */