* src/native/vm/openjdk/jvm.cpp (JVM_CurrentClassLoader): Implemented.
[cacao.git] / src / vm / jit / stacktrace.hpp
1 /* src/vm/jit/stacktrace.hpp - header file for stacktrace generation
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _STACKTRACE_HPP
27 #define _STACKTRACE_HPP
28
29 /* forward typedefs ***********************************************************/
30
31 typedef struct stackframeinfo_t   stackframeinfo_t;
32 typedef struct stacktrace_entry_t stacktrace_entry_t;
33 typedef struct stacktrace_t       stacktrace_t;
34
35 #include "config.h"
36
37 #include <stdint.h>
38
39 #include "vm/types.h"
40
41 #include "md-abi.h"
42
43 #include "threads/thread.hpp"
44
45 #include "vm/class.hpp"
46 #include "vm/global.h"
47
48 #include "vm/jit/code.hpp"
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_t {
59         stackframeinfo_t *prev;             /* pointer to prev stackframeinfo     */
60         codeinfo         *code;             /* codeinfo of current method         */
61         void             *pv;               /* PV of current function             */
62         void             *sp;               /* SP of parent Java function         */
63         void             *ra;               /* RA to parent Java function         */
64         void             *xpc;              /* XPC (for inline stubs)             */
65 #if defined(ENABLE_GC_CACAO)
66         /* 
67          * The exact GC needs to be able to recover saved registers, so the
68          * native-stub saves these registers here
69          */
70 # if defined(HAS_ADDRESS_REGISTER_FILE)
71         uintptr_t         adrregs[ADR_SAV_CNT];
72 # else
73         uintptr_t         intregs[INT_SAV_CNT];
74 # endif
75 #endif
76 };
77
78
79 /* stacktrace_entry_t *********************************************************/
80
81 struct stacktrace_entry_t {
82         codeinfo *code;                     /* codeinfo pointer of this method    */
83         void     *pc;                       /* PC in this method                  */
84 };
85
86
87 /* stacktrace_t ***************************************************************/
88
89 struct stacktrace_t {
90         int32_t            length;          /* length of the entries array        */
91         stacktrace_entry_t entries[1];      /* stacktrace entries                 */
92 };
93
94
95 /* function prototypes ********************************************************/
96
97 // FIXME Use C-linkage for now.
98 #ifdef __cplusplus
99 extern "C" {
100 #endif
101
102 void                       stacktrace_stackframeinfo_add(stackframeinfo_t* sfi, void* pv, void* sp, void* ra, void* xpc);
103 void                       stacktrace_stackframeinfo_remove(stackframeinfo_t *sfi);
104
105 java_handle_bytearray_t   *stacktrace_get(stackframeinfo_t *sfi);
106 java_handle_bytearray_t   *stacktrace_get_current(void);
107
108 #if defined(ENABLE_JAVASE)
109 java_handle_t*             stacktrace_get_StackTraceElement(stacktrace_t *st, int32_t index);
110 java_handle_objectarray_t* stacktrace_get_StackTraceElements(stacktrace_t *st);
111 classinfo                 *stacktrace_get_caller_class(int depth);
112 classloader_t             *stacktrace_first_nonnull_classloader(void);
113 classloader_t             *stacktrace_first_nonsystem_classloader(void);
114 java_handle_objectarray_t *stacktrace_getClassContext(void);
115 classinfo                 *stacktrace_get_current_class(void);
116 java_handle_objectarray_t *stacktrace_get_stack(void);
117 #endif
118
119 void                       stacktrace_print(stacktrace_t *st);
120 void                       stacktrace_print_current(void);
121
122 #if defined(ENABLE_THREADS)
123 stacktrace_t*              stacktrace_get_of_thread(threadobject *t);
124 void                       stacktrace_print_of_thread(threadobject *t);
125 #endif
126
127 void                       stacktrace_print_exception(java_handle_t *h);
128
129 /* machine dependent functions (code in ARCH_DIR/md.c) */
130
131 #if defined(ENABLE_JIT)
132 # if defined(__SPARC_64__)
133 u1 *md_get_framepointer(u1 *sp);
134 u1 *md_get_pv_from_stackframe(u1 *sp);
135 # endif
136 #endif
137
138 #if defined(ENABLE_INTRP)
139 void* intrp_md_stacktrace_get_returnaddress(void* sp, int32_t framesize);
140 #endif
141
142 #if defined(ENABLE_CYCLES_STATS)
143 void stacktrace_print_cycles_stats(FILE *file);
144 #endif
145
146 #ifdef __cplusplus
147 }
148 #endif
149
150 #endif // _STACKTRACE_HPP
151
152
153 /*
154  * These are local overrides for various environment variables in Emacs.
155  * Please do not remove this and leave it at the end of the file, where
156  * Emacs will automagically detect them.
157  * ---------------------------------------------------------------------
158  * Local variables:
159  * mode: c++
160  * indent-tabs-mode: t
161  * c-basic-offset: 4
162  * tab-width: 4
163  * End:
164  * vim:noexpandtab:sw=4:ts=4:
165  */