d27a4cac88a44ad443dcf7d3f8539124bc33ecb8
[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 8318 2007-08-16 10:05:34Z 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 "vmcore/class.h"
43 #include "vmcore/method.h"
44
45
46 /* stackframeinfo **************************************************************
47
48    ATTENTION: Keep the number of elements of this structure even, to
49    make sure that the stack keeps aligned (e.g. 16-bytes for x86_64).
50
51 *******************************************************************************/
52
53 struct stackframeinfo {
54         stackframeinfo *prev;               /* pointer to prev stackframeinfo     */
55         methodinfo     *method;             /* methodinfo of current function     */
56         u1             *pv;                 /* PV of current function             */
57         u1             *sp;                 /* SP of parent Java function         */
58         u1             *ra;                 /* RA to parent Java function         */
59         u1             *xpc;                /* XPC (for inline stubs)             */
60 };
61
62
63 /* stacktrace_entry ***********************************************************/
64
65 struct stacktrace_entry {
66 #if SIZEOF_VOID_P == 8
67         u8          linenumber;
68 #else
69         u4          linenumber;
70 #endif
71         methodinfo *method;
72 };
73
74
75 /* stacktracebuffer ***********************************************************/
76
77 #define STACKTRACE_CAPACITY_DEFAULT      80
78 #define STACKTRACE_CAPACITY_INCREMENT    80
79
80 struct stacktracebuffer {
81         s4                capacity;         /* size of the buffer                 */
82         s4                used;             /* current entries in the buffer      */
83         stacktrace_entry *entries;          /* the actual entries                 */
84 };
85
86
87 /* stacktracecontainer ********************************************************
88
89    ATTENTION: Use the stacktracecontainer to place a stacktrace onto the heap
90    with stacktrace_fillInStackTrace() so that the GC does not get confused.
91
92 *******************************************************************************/
93
94 typedef struct stacktracecontainer {
95         java_array_t            header;     /* default array header for the GC    */
96         struct stacktracebuffer stb;        /* let entries point to data below    */
97         stacktrace_entry        data[1];    /* the actual array of entries        */
98 } stacktracecontainer;
99
100
101 /* function prototypes ********************************************************/
102
103 #if defined(ENABLE_INTRP)
104 void stacktrace_create_stackframeinfo(stackframeinfo *sfi, u1 *pv, u1 *sp,
105                                                                           u1 *ra);
106 #endif
107
108 void stacktrace_create_extern_stackframeinfo(stackframeinfo *sfi, u1 *pv,
109                                                                                          u1 *sp, u1 *ra, u1 *xpc);
110
111 void stacktrace_create_native_stackframeinfo(stackframeinfo *sfi, u1 *pv,
112                                                                                          u1 *sp, u1 *ra);
113
114 void stacktrace_remove_stackframeinfo(stackframeinfo *sfi);
115
116
117 stacktracebuffer *stacktrace_create(stackframeinfo *sfi);
118
119 stacktracecontainer *stacktrace_fillInStackTrace(void);
120
121 #if defined(ENABLE_JAVASE)
122 java_handle_objectarray_t *stacktrace_getClassContext(void);
123 classinfo                 *stacktrace_getCurrentClass(void);
124 java_handle_objectarray_t *stacktrace_getStack(void);
125 #endif
126
127 void stacktrace_print_trace_from_buffer(stacktracebuffer *stb);
128 void stacktrace_print_trace(java_handle_t *xptr);
129
130 /* machine dependent functions (code in ARCH_DIR/md.c) */
131
132 #if defined(ENABLE_JIT)
133 u1 *md_stacktrace_get_returnaddress(u1 *sp, u4 framesize);
134 # if defined(__SPARC_64__)
135 u1 *md_get_framepointer(u1 *sp);
136 u1 *md_get_pv_from_stackframe(u1 *sp);
137 # endif
138 #endif
139
140 #if defined(ENABLE_INTRP)
141 u1 *intrp_md_stacktrace_get_returnaddress(u1 *sp, u4 framesize);
142 #endif
143
144 #if defined(ENABLE_CYCLES_STATS)
145 void stacktrace_print_cycles_stats(FILE *file);
146 #endif
147
148 #endif /* _STACKTRACE_H */
149
150
151 /*
152  * These are local overrides for various environment variables in Emacs.
153  * Please do not remove this and leave it at the end of the file, where
154  * Emacs will automagically detect them.
155  * ---------------------------------------------------------------------
156  * Local variables:
157  * mode: c
158  * indent-tabs-mode: t
159  * c-basic-offset: 4
160  * tab-width: 4
161  * End:
162  */