* include/java-interp.h (_Jv_InterpMethod::dump_object): Removed
[official-gcc.git] / libjava / include / java-interp.h
blob58d2e8c1abfaa0aee120e5b9e9715313cebc65e1
1 // java-interp.h - Header file for the bytecode interpreter. -*- c++ -*-
3 /* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9 details. */
11 #ifndef __JAVA_INTERP_H__
12 #define __JAVA_INTERP_H__
14 #include <jvm.h>
15 #include <java-cpool.h>
16 #include <gnu/gcj/runtime/NameFinder.h>
18 #ifdef INTERPRETER
20 #pragma interface
22 #include <java/lang/Class.h>
23 #include <java/lang/ClassLoader.h>
24 #include <java/lang/reflect/Modifier.h>
25 #include <java/lang/Thread.h>
26 #include <gnu/gcj/RawData.h>
28 // Define this to get the direct-threaded interpreter. If undefined,
29 // we revert to a basic bytecode interpreter. The former is faster
30 // but uses more memory.
31 #define DIRECT_THREADED
33 #include <ffi.h>
35 struct _Jv_ResolvedMethod;
37 void _Jv_InitInterpreter ();
38 void _Jv_DefineClass (jclass, jbyteArray, jint, jint,
39 java::security::ProtectionDomain *,
40 _Jv_Utf8Const **);
42 void _Jv_InitField (jobject, jclass, int);
43 void * _Jv_AllocMethodInvocation (jsize size);
44 int _Jv_count_arguments (_Jv_Utf8Const *signature,
45 jboolean staticp = true);
46 void _Jv_VerifyMethod (_Jv_InterpMethod *method);
47 void _Jv_CompileMethod (_Jv_InterpMethod* method);
49 /* the interpreter is written in C++, primarily because it makes it easy for
50 * the entire thing to be "friend" with class Class. */
52 class _Jv_InterpClass;
53 class _Jv_InterpMethod;
55 // Before a method is "compiled" we store values as the bytecode PC,
56 // an int. Afterwards we store them as pointers into the prepared
57 // code itself.
58 union _Jv_InterpPC
60 int i;
61 void *p;
64 class _Jv_InterpException
66 _Jv_InterpPC start_pc;
67 _Jv_InterpPC end_pc;
68 _Jv_InterpPC handler_pc;
69 _Jv_InterpPC handler_type;
71 friend class _Jv_ClassReader;
72 friend class _Jv_InterpMethod;
73 friend class _Jv_BytecodeVerifier;
76 // Base class for method representations. Subclasses are interpreted
77 // and JNI methods.
78 class _Jv_MethodBase
80 protected:
81 // The class which defined this method.
82 jclass defining_class;
84 // The method description.
85 _Jv_Method *self;
87 // Size of raw arguments.
88 _Jv_ushort args_raw_size;
90 friend class _Jv_InterpreterEngine;
92 public:
93 _Jv_Method *get_method ()
95 return self;
99 // The type of the PC depends on whether we're doing direct threading
100 // or a more ordinary bytecode interpreter.
101 #ifdef DIRECT_THREADED
102 // Slot in the "compiled" form of the bytecode.
103 union insn_slot
105 // Address of code.
106 void *insn;
107 // An integer value used by an instruction.
108 jint int_val;
109 // A pointer value used by an instruction.
110 void *datum;
113 typedef insn_slot *pc_t;
114 #else
115 typedef unsigned char *pc_t;
116 #endif
119 // This structure holds the bytecode pc and corresponding source code
120 // line number. An array (plus length field) of this structure is put
121 // in each _Jv_InterpMethod and used to resolve the (internal) program
122 // counter of the interpreted method to an actual java source file
123 // line.
124 struct _Jv_LineTableEntry
126 union
128 pc_t pc;
129 int bytecode_pc;
131 int line;
134 class _Jv_InterpMethod : public _Jv_MethodBase
136 _Jv_ushort max_stack;
137 _Jv_ushort max_locals;
138 int code_length;
140 _Jv_ushort exc_count;
141 bool is_15;
143 // Length of the line_table - when this is zero then line_table is NULL.
144 int line_table_len;
145 _Jv_LineTableEntry *line_table;
147 void *prepared;
148 int number_insn_slots;
150 unsigned char* bytecode ()
152 return
153 ((unsigned char*)this)
154 + ROUND((sizeof (_Jv_InterpMethod)
155 + exc_count*sizeof (_Jv_InterpException)), 4);
158 _Jv_InterpException * exceptions ()
160 return (_Jv_InterpException*) (this+1);
163 static size_t size (int exc_count, int code_length)
165 return
166 ROUND ((sizeof (_Jv_InterpMethod)
167 + (exc_count * sizeof (_Jv_InterpException))), 4)
168 + code_length;
171 // return the method's invocation pointer (a stub).
172 void *ncode ();
173 void compile (const void * const *);
175 static void run_normal (ffi_cif*, void*, ffi_raw*, void*);
176 static void run_synch_object (ffi_cif*, void*, ffi_raw*, void*);
177 static void run_class (ffi_cif*, void*, ffi_raw*, void*);
178 static void run_synch_class (ffi_cif*, void*, ffi_raw*, void*);
180 static void run (void*, ffi_raw *, _Jv_InterpMethod *);
182 // Returns source file line number for given PC value, or -1 if line
183 // number info is unavailable.
184 int get_source_line(pc_t mpc);
186 #ifdef DIRECT_THREADED
187 // Convenience function for indexing bytecode PC/insn slots in
188 // line tables for JDWP
189 jlong insn_index (pc_t pc);
190 #endif
192 public:
194 /* Get the line table for this method.
195 * start is the lowest index in the method
196 * end is the highest index in the method
197 * line_numbers is an array to hold the list of source line numbers
198 * code_indices is an array to hold the corresponding list of code indices
200 void get_line_table (jlong& start, jlong& end, jintArray& line_numbers,
201 jlongArray& code_indices);
203 #ifdef DIRECT_THREADED
204 friend void _Jv_CompileMethod (_Jv_InterpMethod*);
205 #endif
207 friend class _Jv_ClassReader;
208 friend class _Jv_BytecodeVerifier;
209 friend class _Jv_StackTrace;
210 friend class _Jv_InterpreterEngine;
212 #ifdef JV_MARKOBJ_DECL
213 friend JV_MARKOBJ_DECL;
214 #endif
217 class _Jv_InterpClass
219 _Jv_MethodBase **interpreted_methods;
220 _Jv_ushort *field_initializers;
221 jstring source_file_name;
223 friend class _Jv_ClassReader;
224 friend class _Jv_InterpMethod;
225 friend class _Jv_StackTrace;
226 friend class _Jv_InterpreterEngine;
228 friend void _Jv_InitField (jobject, jclass, int);
229 #ifdef JV_MARKOBJ_DECL
230 friend JV_MARKOBJ_DECL;
231 #endif
233 friend _Jv_MethodBase ** _Jv_GetFirstMethod (_Jv_InterpClass *klass);
236 extern inline _Jv_MethodBase **
237 _Jv_GetFirstMethod (_Jv_InterpClass *klass)
239 return klass->interpreted_methods;
242 struct _Jv_ResolvedMethod
244 jint stack_item_count;
245 jclass klass;
246 _Jv_Method* method;
248 // a resolved method holds the cif in-line, so that _Jv_MarkObj just needs
249 // to mark the resolved method to hold on to the cif. Some memory could be
250 // saved by keeping a cache of cif's, since many will be the same.
251 ffi_cif cif;
252 ffi_type * arg_types[0];
255 class _Jv_JNIMethod : public _Jv_MethodBase
257 // The underlying function. If NULL we have to look for the
258 // function.
259 void *function;
261 // This is the CIF used by the JNI function.
262 ffi_cif jni_cif;
264 // These are the argument types used by the JNI function.
265 ffi_type **jni_arg_types;
267 // This function is used when making a JNI call from the interpreter.
268 static void call (ffi_cif *, void *, ffi_raw *, void *);
270 void *ncode ();
272 friend class _Jv_ClassReader;
273 friend class _Jv_InterpreterEngine;
275 #ifdef JV_MARKOBJ_DECL
276 friend JV_MARKOBJ_DECL;
277 #endif
279 public:
280 // FIXME: this is ugly.
281 void set_function (void *f)
283 function = f;
287 // The interpreted call stack, represented by a linked list of frames.
288 struct _Jv_InterpFrame
290 _Jv_InterpMethod *self;
291 java::lang::Thread *thread;
292 _Jv_InterpFrame *next;
293 pc_t pc;
295 _Jv_InterpFrame (_Jv_InterpMethod *s, java::lang::Thread *thr)
297 self = s;
298 thread = thr;
299 next = (_Jv_InterpFrame *) thr->interp_frame;
300 thr->interp_frame = (gnu::gcj::RawData *) this;
301 pc = NULL;
304 ~_Jv_InterpFrame ()
306 thread->interp_frame = (gnu::gcj::RawData *) next;
310 #endif /* INTERPRETER */
312 #endif /* __JAVA_INTERP_H__ */