* src/vm/jit/codegen-common.h (branchref): Removed.
[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 4615 2006-03-15 16:36:43Z 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 #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 /* 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 /* function prototypes ********************************************************/
101
102 #if defined(ENABLE_INTRP)
103 void stacktrace_create_stackframeinfo(stackframeinfo *sfi, u1 *pv, u1 *sp,
104                                                                           u1 *ra);
105 #endif
106
107 void stacktrace_create_inline_stackframeinfo(stackframeinfo *sfi, u1 *pv,
108                                                                                          u1 *sp, u1 *ra, u1 *xpc);
109
110 void stacktrace_create_extern_stackframeinfo(stackframeinfo *sfi, u1 *pv,
111                                                                                          u1 *sp, u1 *ra, u1 *xpc);
112
113 void stacktrace_create_native_stackframeinfo(stackframeinfo *sfi, u1 *pv,
114                                                                                          u1 *sp, u1 *ra);
115
116 void stacktrace_remove_stackframeinfo(stackframeinfo *sfi);
117
118 /* inline exception creating functions */
119 java_objectheader *stacktrace_inline_arithmeticexception(u1 *pv, u1 *sp, u1 *ra,
120                                                                                                                  u1 *xpc);
121 #define STACKTRACE_inline_arithmeticexception \
122     (functionptr) stacktrace_inline_arithmeticexception
123                                                                                                 
124
125 java_objectheader *stacktrace_inline_arrayindexoutofboundsexception(u1 *pv,
126                                                                                                                                         u1 *sp,
127                                                                                                                                         u1 *ra,
128                                                                                                                                         u1 *xpc,
129                                                                                                                                         s4 index);
130 #define STACKTRACE_inline_arrayindexoutofboundsexception \
131     (functionptr) stacktrace_inline_arrayindexoutofboundsexception
132
133 java_objectheader *stacktrace_inline_arraystoreexception(u1 *pv, u1 *sp, u1 *ra,
134                                                                                                                  u1 *xpc);
135 #define STACKTRACE_inline_arraystoreexception \
136     (functionptr) stacktrace_inline_arraystoreexception
137
138 java_objectheader *stacktrace_inline_classcastexception(u1 *pv, u1 *sp, u1 *ra,
139                                                                                                                 u1 *xpc);
140 #define STACKTRACE_inline_classcastexception \
141     (functionptr) stacktrace_inline_classcastexception
142
143 java_objectheader *stacktrace_inline_nullpointerexception(u1 *pv, u1 *sp,
144                                                                                                                   u1 *ra, u1 *xpc);
145 #define STACKTRACE_inline_nullpointerexception \
146     (functionptr) stacktrace_inline_nullpointerexception
147
148 /* refill the stacktrace of an existing exception */
149 java_objectheader *stacktrace_inline_fillInStackTrace(u1 *pv, u1 *sp, u1 *ra,
150                                                                                                           u1 *xpc);
151 #define STACKTRACE_inline_fillInStackTrace \
152     (functionptr) stacktrace_inline_fillInStackTrace
153
154
155 /* hardware exception creating functions */
156 java_objectheader *stacktrace_hardware_arithmeticexception(u1 *pv, u1 *sp,
157                                                                                                                    u1 *ra, u1 *xpc);
158
159 java_objectheader *stacktrace_hardware_nullpointerexception(u1 *pv, u1 *sp,
160                                                                                                                         u1 *ra, u1 *xpc);
161
162
163 stacktracebuffer  *stacktrace_fillInStackTrace(void);
164 java_objectarray  *stacktrace_getClassContext(void);
165 classinfo         *stacktrace_getCurrentClass(void);
166 java_objectarray  *stacktrace_getStack(void);
167
168 void stacktrace_dump_trace(void);
169 void stacktrace_print_trace(java_objectheader *xptr);
170
171
172 /* machine dependent functions (code in ARCH_DIR/md.c) */
173
174 #if defined(ENABLE_JIT)
175 u1 *md_stacktrace_get_returnaddress(u1 *sp, u4 framesize);
176 #endif
177
178 #if defined(ENABLE_INTRP)
179 u1 *intrp_md_stacktrace_get_returnaddress(u1 *sp, u4 framesize);
180 #endif
181
182 #endif /* _STACKTRACE_H */
183
184
185 /*
186  * These are local overrides for various environment variables in Emacs.
187  * Please do not remove this and leave it at the end of the file, where
188  * Emacs will automagically detect them.
189  * ---------------------------------------------------------------------
190  * Local variables:
191  * mode: c
192  * indent-tabs-mode: t
193  * c-basic-offset: 4
194  * tab-width: 4
195  * End:
196  */