OSDN Git Service

2005-03-15 Andreas Tobler <a.tobler@schweiz.ch>
[pf3gnuchains/gcc-fork.git] / libjava / include / java-stack.h
1 // java-stack.h - Definitions for unwinding & inspecting the call stack.
2
3 /* Copyright (C) 2005  Free Software Foundation
4
5    This file is part of libgcj.
6
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
9 details.  */
10
11 #ifndef __JV_STACKTRACE_H__
12 #define __JV_STACKTRACE_H__
13
14 #include <unwind.h>
15
16 #include <gcj/cni.h>
17 #include <gcj/javaprims.h>
18
19 #include <java-interp.h>
20
21 #include <java/lang/Class.h>
22 #include <java/lang/StackTraceElement.h>
23 #include <java/lang/Throwable.h>
24 #include <java/lang/Thread.h>
25
26 #include <gnu/gcj/runtime/NameFinder.h>
27
28 using namespace gnu::gcj::runtime;
29 using namespace java::lang;
30
31 enum _Jv_FrameType
32 {
33   frame_native,
34   frame_interpreter
35 };
36
37 #ifdef INTERPRETER
38 struct _Jv_InterpFrameInfo
39 {
40   _Jv_InterpMethod *meth;
41   pc_t pc;
42 };
43 #endif
44
45 union _Jv_FrameInfo
46 {
47 };
48
49 struct _Jv_StackFrame
50 {
51   _Jv_FrameType type;   /* Native or interpreted.  */
52   union {
53 #ifdef INTERPRETER
54     _Jv_InterpFrameInfo interp;
55 #endif
56     struct {
57       void *ip;
58       void *start_ip;
59     };
60   };
61 //  _Jv_FrameInfo info;   /* Frame-type specific data.  */
62   jclass klass;
63   _Jv_Method *meth;
64 };
65
66 typedef struct _Jv_UnwindState;
67 typedef _Unwind_Reason_Code (*_Jv_TraceFn) (_Jv_UnwindState *);
68
69 struct _Jv_UnwindState
70 {
71   jint length;                   // length of FRAMES
72   jint pos;                      // current position in FRAMES
73   _Jv_StackFrame *frames;        // array of stack frame data to be filled.
74 #ifdef INTERPRETER
75   _Jv_InterpFrame *interp_frame; // current frame in the interpreter stack.
76 #endif
77   _Jv_TraceFn trace_function;    // function to call back after each frame
78                                  // is enumerated. May be NULL.
79   void *trace_data;              // additional state data for trace_function.
80   
81   _Jv_UnwindState (jint ln)
82     {
83       length = ln;
84       pos = 0;
85       frames = NULL;
86       Thread *thread = Thread::currentThread();
87       // Check for NULL currentThread(), in case an exception is created 
88       // very early during the runtime startup.
89 #ifdef INTERPRETER
90       if (thread)
91         interp_frame = (_Jv_InterpFrame *) thread->interp_frame;
92 #endif
93       trace_function = NULL;
94       trace_data = NULL;
95     }
96 };
97
98 class _Jv_StackTrace
99 {
100 private:
101   int length;
102   _Jv_StackFrame frames[];
103
104   static void UpdateNCodeMap ();
105   static jclass ClassForFrame (_Jv_StackFrame *frame);
106   static void FillInFrameInfo (_Jv_StackFrame *frame);
107   static void getLineNumberForFrame(_Jv_StackFrame *frame, NameFinder *finder, 
108                              jstring *sourceFileName, jint *lineNum);
109   
110   static _Unwind_Reason_Code UnwindTraceFn (struct _Unwind_Context *context, 
111     void *state_ptr);
112     
113   static _Unwind_Reason_Code calling_class_trace_fn (_Jv_UnwindState *state);
114   static _Unwind_Reason_Code non_system_trace_fn (_Jv_UnwindState *state);
115
116 public:
117   static _Jv_StackTrace *GetStackTrace (void);
118   static JArray< ::java::lang::StackTraceElement *>*
119     GetStackTraceElements (_Jv_StackTrace *trace, 
120     java::lang::Throwable *throwable);
121   static jclass GetCallingClass (jclass);
122   static void GetCallerInfo (jclass checkClass, jclass *, _Jv_Method **);
123   static JArray<jclass> *GetClassContext (jclass checkClass);
124   static ClassLoader *GetFirstNonSystemClassLoader (void);
125   
126 };
127
128
129 #endif /* __JV_STACKTRACE_H__ */