* target-def.h (TARGET_CXX_USE_AEABI_ATEXIT): Define.
[official-gcc.git] / libjava / include / java-interp.h
blob061520013d7097c29993cc8bb5f6382df38ff0db
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 *);
41 void _Jv_InitField (jobject, jclass, int);
42 void * _Jv_AllocMethodInvocation (jsize size);
43 int _Jv_count_arguments (_Jv_Utf8Const *signature,
44 jboolean staticp = true);
45 void _Jv_VerifyMethod (_Jv_InterpMethod *method);
47 /* the interpreter is written in C++, primarily because it makes it easy for
48 * the entire thing to be "friend" with class Class. */
50 class _Jv_InterpClass;
51 class _Jv_InterpMethod;
53 // Before a method is "compiled" we store values as the bytecode PC,
54 // an int. Afterwards we store them as pointers into the prepared
55 // code itself.
56 union _Jv_InterpPC
58 int i;
59 void *p;
62 class _Jv_InterpException
64 _Jv_InterpPC start_pc;
65 _Jv_InterpPC end_pc;
66 _Jv_InterpPC handler_pc;
67 _Jv_InterpPC handler_type;
69 friend class _Jv_ClassReader;
70 friend class _Jv_InterpMethod;
71 friend class _Jv_BytecodeVerifier;
74 // Base class for method representations. Subclasses are interpreted
75 // and JNI methods.
76 class _Jv_MethodBase
78 protected:
79 // The class which defined this method.
80 jclass defining_class;
82 // The method description.
83 _Jv_Method *self;
85 // Size of raw arguments.
86 _Jv_ushort args_raw_size;
88 friend class _Jv_InterpreterEngine;
90 public:
91 _Jv_Method *get_method ()
93 return self;
97 // The type of the PC depends on whether we're doing direct threading
98 // or a more ordinary bytecode interpreter.
99 #ifdef DIRECT_THREADED
100 // Slot in the "compiled" form of the bytecode.
101 union insn_slot
103 // Address of code.
104 void *insn;
105 // An integer value used by an instruction.
106 jint int_val;
107 // A pointer value used by an instruction.
108 void *datum;
111 typedef insn_slot *pc_t;
112 #else
113 typedef unsigned char *pc_t;
114 #endif
117 // This structure holds the bytecode pc and corresponding source code
118 // line number. An array (plus length field) of this structure is put
119 // in each _Jv_InterpMethod and used to resolve the (internal) program
120 // counter of the interpreted method to an actual java source file
121 // line.
122 struct _Jv_LineTableEntry
124 union
126 pc_t pc;
127 int bytecode_pc;
129 int line;
132 class _Jv_InterpMethod : public _Jv_MethodBase
134 _Jv_ushort max_stack;
135 _Jv_ushort max_locals;
136 int code_length;
138 _Jv_ushort exc_count;
140 // Length of the line_table - when this is zero then line_table is NULL.
141 int line_table_len;
142 _Jv_LineTableEntry *line_table;
144 void *prepared;
146 unsigned char* bytecode ()
148 return
149 ((unsigned char*)this)
150 + ROUND((sizeof (_Jv_InterpMethod)
151 + exc_count*sizeof (_Jv_InterpException)), 4);
154 _Jv_InterpException * exceptions ()
156 return (_Jv_InterpException*) (this+1);
159 static size_t size (int exc_count, int code_length)
161 return
162 ROUND ((sizeof (_Jv_InterpMethod)
163 + (exc_count * sizeof (_Jv_InterpException))), 4)
164 + code_length;
167 // return the method's invocation pointer (a stub).
168 void *ncode ();
169 void compile (const void * const *);
171 static void run_normal (ffi_cif*, void*, ffi_raw*, void*);
172 static void run_synch_object (ffi_cif*, void*, ffi_raw*, void*);
173 static void run_class (ffi_cif*, void*, ffi_raw*, void*);
174 static void run_synch_class (ffi_cif*, void*, ffi_raw*, void*);
176 static void run (void*, ffi_raw *, _Jv_InterpMethod *);
178 // Returns source file line number for given PC value, or -1 if line
179 // number info is unavailable.
180 int get_source_line(pc_t mpc);
182 public:
183 static void dump_object(jobject o);
185 friend class _Jv_ClassReader;
186 friend class _Jv_BytecodeVerifier;
187 friend class _Jv_StackTrace;
188 friend class _Jv_InterpreterEngine;
190 #ifdef JV_MARKOBJ_DECL
191 friend JV_MARKOBJ_DECL;
192 #endif
195 class _Jv_InterpClass
197 _Jv_MethodBase **interpreted_methods;
198 _Jv_ushort *field_initializers;
199 jstring source_file_name;
201 friend class _Jv_ClassReader;
202 friend class _Jv_InterpMethod;
203 friend class _Jv_StackTrace;
204 friend class _Jv_InterpreterEngine;
206 friend void _Jv_InitField (jobject, jclass, int);
207 #ifdef JV_MARKOBJ_DECL
208 friend JV_MARKOBJ_DECL;
209 #endif
211 friend _Jv_MethodBase ** _Jv_GetFirstMethod (_Jv_InterpClass *klass);
214 extern inline _Jv_MethodBase **
215 _Jv_GetFirstMethod (_Jv_InterpClass *klass)
217 return klass->interpreted_methods;
220 struct _Jv_ResolvedMethod {
221 jint stack_item_count;
222 jint vtable_index;
223 jclass klass;
224 _Jv_Method* method;
226 // a resolved method holds the cif in-line, so that _Jv_MarkObj just needs
227 // to mark the resolved method to hold on to the cif. Some memory could be
228 // saved by keeping a cache of cif's, since many will be the same.
229 ffi_cif cif;
230 ffi_type * arg_types[0];
233 class _Jv_JNIMethod : public _Jv_MethodBase
235 // The underlying function. If NULL we have to look for the
236 // function.
237 void *function;
239 // This is the CIF used by the JNI function.
240 ffi_cif jni_cif;
242 // These are the argument types used by the JNI function.
243 ffi_type **jni_arg_types;
245 // This function is used when making a JNI call from the interpreter.
246 static void call (ffi_cif *, void *, ffi_raw *, void *);
248 void *ncode ();
250 friend class _Jv_ClassReader;
251 friend class _Jv_InterpreterEngine;
253 #ifdef JV_MARKOBJ_DECL
254 friend JV_MARKOBJ_DECL;
255 #endif
257 public:
258 // FIXME: this is ugly.
259 void set_function (void *f)
261 function = f;
265 // The interpreted call stack, represented by a linked list of frames.
266 struct _Jv_InterpFrame
268 _Jv_InterpMethod *self;
269 _Jv_InterpFrame **ptr;
270 _Jv_InterpFrame *next;
271 pc_t pc;
273 _Jv_InterpFrame (_Jv_InterpMethod *s, _Jv_InterpFrame **n)
275 self = s;
276 ptr = n;
277 next = *n;
278 *n = this;
279 pc = NULL;
282 ~_Jv_InterpFrame ()
284 *ptr = next;
288 #endif /* INTERPRETER */
290 #endif /* __JAVA_INTERP_H__ */