Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / include / java-interp.h
blob269e39c5a5ef71bfe6f2d52c7038889fc4055a95
1 // java-interp.h - Header file for the bytecode interpreter. -*- c++ -*-
3 /* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 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>
26 // Define this to get the direct-threaded interpreter. If undefined,
27 // we revert to a basic bytecode interpreter. The former is faster
28 // but uses more memory.
29 #define DIRECT_THREADED
31 extern "C" {
32 #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);
48 /* the interpreter is written in C++, primarily because it makes it easy for
49 * the entire thing to be "friend" with class Class. */
51 class _Jv_InterpClass;
52 class _Jv_InterpMethod;
54 // Before a method is "compiled" we store values as the bytecode PC,
55 // an int. Afterwards we store them as pointers into the prepared
56 // code itself.
57 union _Jv_InterpPC
59 int i;
60 void *p;
63 class _Jv_InterpException
65 _Jv_InterpPC start_pc;
66 _Jv_InterpPC end_pc;
67 _Jv_InterpPC handler_pc;
68 _Jv_InterpPC handler_type;
70 friend class _Jv_ClassReader;
71 friend class _Jv_InterpMethod;
72 friend class _Jv_BytecodeVerifier;
75 // Base class for method representations. Subclasses are interpreted
76 // and JNI methods.
77 class _Jv_MethodBase
79 protected:
80 // The class which defined this method.
81 jclass defining_class;
83 // The method description.
84 _Jv_Method *self;
86 // Size of raw arguments.
87 _Jv_ushort args_raw_size;
89 friend class _Jv_InterpreterEngine;
91 public:
92 _Jv_Method *get_method ()
94 return self;
98 // The type of the PC depends on whether we're doing direct threading
99 // or a more ordinary bytecode interpreter.
100 #ifdef DIRECT_THREADED
101 // Slot in the "compiled" form of the bytecode.
102 union insn_slot
104 // Address of code.
105 void *insn;
106 // An integer value used by an instruction.
107 jint int_val;
108 // A pointer value used by an instruction.
109 void *datum;
112 typedef insn_slot *pc_t;
113 #else
114 typedef unsigned char *pc_t;
115 #endif
118 // This structure holds the bytecode pc and corresponding source code
119 // line number. An array (plus length field) of this structure is put
120 // in each _Jv_InterpMethod and used to resolve the (internal) program
121 // counter of the interpreted method to an actual java source file
122 // line.
123 struct _Jv_LineTableEntry
125 union
127 pc_t pc;
128 int bytecode_pc;
130 int line;
133 class _Jv_InterpMethod : public _Jv_MethodBase
135 _Jv_ushort max_stack;
136 _Jv_ushort max_locals;
137 int code_length;
139 _Jv_ushort exc_count;
140 bool is_15;
142 // Length of the line_table - when this is zero then line_table is NULL.
143 int line_table_len;
144 _Jv_LineTableEntry *line_table;
146 void *prepared;
148 unsigned char* bytecode ()
150 return
151 ((unsigned char*)this)
152 + ROUND((sizeof (_Jv_InterpMethod)
153 + exc_count*sizeof (_Jv_InterpException)), 4);
156 _Jv_InterpException * exceptions ()
158 return (_Jv_InterpException*) (this+1);
161 static size_t size (int exc_count, int code_length)
163 return
164 ROUND ((sizeof (_Jv_InterpMethod)
165 + (exc_count * sizeof (_Jv_InterpException))), 4)
166 + code_length;
169 // return the method's invocation pointer (a stub).
170 void *ncode ();
171 void compile (const void * const *);
173 static void run_normal (ffi_cif*, void*, ffi_raw*, void*);
174 static void run_synch_object (ffi_cif*, void*, ffi_raw*, void*);
175 static void run_class (ffi_cif*, void*, ffi_raw*, void*);
176 static void run_synch_class (ffi_cif*, void*, ffi_raw*, void*);
178 static void run (void*, ffi_raw *, _Jv_InterpMethod *);
180 // Returns source file line number for given PC value, or -1 if line
181 // number info is unavailable.
182 int get_source_line(pc_t mpc);
184 public:
185 static void dump_object(jobject o);
187 friend class _Jv_ClassReader;
188 friend class _Jv_BytecodeVerifier;
189 friend class _Jv_StackTrace;
190 friend class _Jv_InterpreterEngine;
192 #ifdef JV_MARKOBJ_DECL
193 friend JV_MARKOBJ_DECL;
194 #endif
197 class _Jv_InterpClass
199 _Jv_MethodBase **interpreted_methods;
200 _Jv_ushort *field_initializers;
201 jstring source_file_name;
203 friend class _Jv_ClassReader;
204 friend class _Jv_InterpMethod;
205 friend class _Jv_StackTrace;
206 friend class _Jv_InterpreterEngine;
208 friend void _Jv_InitField (jobject, jclass, int);
209 #ifdef JV_MARKOBJ_DECL
210 friend JV_MARKOBJ_DECL;
211 #endif
213 friend _Jv_MethodBase ** _Jv_GetFirstMethod (_Jv_InterpClass *klass);
216 extern inline _Jv_MethodBase **
217 _Jv_GetFirstMethod (_Jv_InterpClass *klass)
219 return klass->interpreted_methods;
222 struct _Jv_ResolvedMethod
224 jint stack_item_count;
225 jint vtable_index;
226 jclass klass;
227 _Jv_Method* method;
229 // a resolved method holds the cif in-line, so that _Jv_MarkObj just needs
230 // to mark the resolved method to hold on to the cif. Some memory could be
231 // saved by keeping a cache of cif's, since many will be the same.
232 ffi_cif cif;
233 ffi_type * arg_types[0];
236 class _Jv_JNIMethod : public _Jv_MethodBase
238 // The underlying function. If NULL we have to look for the
239 // function.
240 void *function;
242 // This is the CIF used by the JNI function.
243 ffi_cif jni_cif;
245 // These are the argument types used by the JNI function.
246 ffi_type **jni_arg_types;
248 // This function is used when making a JNI call from the interpreter.
249 static void call (ffi_cif *, void *, ffi_raw *, void *);
251 void *ncode ();
253 friend class _Jv_ClassReader;
254 friend class _Jv_InterpreterEngine;
256 #ifdef JV_MARKOBJ_DECL
257 friend JV_MARKOBJ_DECL;
258 #endif
260 public:
261 // FIXME: this is ugly.
262 void set_function (void *f)
264 function = f;
268 // The interpreted call stack, represented by a linked list of frames.
269 struct _Jv_InterpFrame
271 _Jv_InterpMethod *self;
272 _Jv_InterpFrame **ptr;
273 _Jv_InterpFrame *next;
274 pc_t pc;
276 _Jv_InterpFrame (_Jv_InterpMethod *s, _Jv_InterpFrame **n)
278 self = s;
279 ptr = n;
280 next = *n;
281 *n = this;
282 pc = NULL;
285 ~_Jv_InterpFrame ()
287 *ptr = next;
291 #endif /* INTERPRETER */
293 #endif /* __JAVA_INTERP_H__ */