* gcc.dg/single-precision-constant.c: Tweak for non-C99 runtimes.
[official-gcc.git] / libjava / include / java-interp.h
blobaed642b576d30ec45eb2f510dc6dc9c3e15fdeef
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 extern "C" {
34 #include <ffi.h>
37 struct _Jv_ResolvedMethod;
39 void _Jv_InitInterpreter ();
40 void _Jv_DefineClass (jclass, jbyteArray, jint, jint,
41 java::security::ProtectionDomain *,
42 _Jv_Utf8Const **);
44 void _Jv_InitField (jobject, jclass, int);
45 void * _Jv_AllocMethodInvocation (jsize size);
46 int _Jv_count_arguments (_Jv_Utf8Const *signature,
47 jboolean staticp = true);
48 void _Jv_VerifyMethod (_Jv_InterpMethod *method);
49 void _Jv_CompileMethod (_Jv_InterpMethod* method);
51 /* the interpreter is written in C++, primarily because it makes it easy for
52 * the entire thing to be "friend" with class Class. */
54 class _Jv_InterpClass;
55 class _Jv_InterpMethod;
57 // Before a method is "compiled" we store values as the bytecode PC,
58 // an int. Afterwards we store them as pointers into the prepared
59 // code itself.
60 union _Jv_InterpPC
62 int i;
63 void *p;
66 class _Jv_InterpException
68 _Jv_InterpPC start_pc;
69 _Jv_InterpPC end_pc;
70 _Jv_InterpPC handler_pc;
71 _Jv_InterpPC handler_type;
73 friend class _Jv_ClassReader;
74 friend class _Jv_InterpMethod;
75 friend class _Jv_BytecodeVerifier;
78 // Base class for method representations. Subclasses are interpreted
79 // and JNI methods.
80 class _Jv_MethodBase
82 protected:
83 // The class which defined this method.
84 jclass defining_class;
86 // The method description.
87 _Jv_Method *self;
89 // Size of raw arguments.
90 _Jv_ushort args_raw_size;
92 friend class _Jv_InterpreterEngine;
94 public:
95 _Jv_Method *get_method ()
97 return self;
101 // The type of the PC depends on whether we're doing direct threading
102 // or a more ordinary bytecode interpreter.
103 #ifdef DIRECT_THREADED
104 // Slot in the "compiled" form of the bytecode.
105 union insn_slot
107 // Address of code.
108 void *insn;
109 // An integer value used by an instruction.
110 jint int_val;
111 // A pointer value used by an instruction.
112 void *datum;
115 typedef insn_slot *pc_t;
116 #else
117 typedef unsigned char *pc_t;
118 #endif
121 // This structure holds the bytecode pc and corresponding source code
122 // line number. An array (plus length field) of this structure is put
123 // in each _Jv_InterpMethod and used to resolve the (internal) program
124 // counter of the interpreted method to an actual java source file
125 // line.
126 struct _Jv_LineTableEntry
128 union
130 pc_t pc;
131 int bytecode_pc;
133 int line;
136 class _Jv_InterpMethod : public _Jv_MethodBase
138 _Jv_ushort max_stack;
139 _Jv_ushort max_locals;
140 int code_length;
142 _Jv_ushort exc_count;
143 bool is_15;
145 // Length of the line_table - when this is zero then line_table is NULL.
146 int line_table_len;
147 _Jv_LineTableEntry *line_table;
149 void *prepared;
150 int number_insn_slots;
152 unsigned char* bytecode ()
154 return
155 ((unsigned char*)this)
156 + ROUND((sizeof (_Jv_InterpMethod)
157 + exc_count*sizeof (_Jv_InterpException)), 4);
160 _Jv_InterpException * exceptions ()
162 return (_Jv_InterpException*) (this+1);
165 static size_t size (int exc_count, int code_length)
167 return
168 ROUND ((sizeof (_Jv_InterpMethod)
169 + (exc_count * sizeof (_Jv_InterpException))), 4)
170 + code_length;
173 // return the method's invocation pointer (a stub).
174 void *ncode ();
175 void compile (const void * const *);
177 static void run_normal (ffi_cif*, void*, ffi_raw*, void*);
178 static void run_synch_object (ffi_cif*, void*, ffi_raw*, void*);
179 static void run_class (ffi_cif*, void*, ffi_raw*, void*);
180 static void run_synch_class (ffi_cif*, void*, ffi_raw*, void*);
182 static void run (void*, ffi_raw *, _Jv_InterpMethod *);
184 // Returns source file line number for given PC value, or -1 if line
185 // number info is unavailable.
186 int get_source_line(pc_t mpc);
188 #ifdef DIRECT_THREADED
189 // Convenience function for indexing bytecode PC/insn slots in
190 // line tables for JDWP
191 jlong insn_index (pc_t pc);
192 #endif
194 public:
195 static void dump_object(jobject o);
197 /* Get the line table for this method.
198 * start is the lowest index in the method
199 * end is the highest index in the method
200 * line_numbers is an array to hold the list of source line numbers
201 * code_indices is an array to hold the corresponding list of code indices
203 void get_line_table (jlong& start, jlong& end, jintArray& line_numbers,
204 jlongArray& code_indices);
206 #ifdef DIRECT_THREADED
207 friend void _Jv_CompileMethod (_Jv_InterpMethod*);
208 #endif
210 friend class _Jv_ClassReader;
211 friend class _Jv_BytecodeVerifier;
212 friend class _Jv_StackTrace;
213 friend class _Jv_InterpreterEngine;
215 #ifdef JV_MARKOBJ_DECL
216 friend JV_MARKOBJ_DECL;
217 #endif
220 class _Jv_InterpClass
222 _Jv_MethodBase **interpreted_methods;
223 _Jv_ushort *field_initializers;
224 jstring source_file_name;
226 friend class _Jv_ClassReader;
227 friend class _Jv_InterpMethod;
228 friend class _Jv_StackTrace;
229 friend class _Jv_InterpreterEngine;
231 friend void _Jv_InitField (jobject, jclass, int);
232 #ifdef JV_MARKOBJ_DECL
233 friend JV_MARKOBJ_DECL;
234 #endif
236 friend _Jv_MethodBase ** _Jv_GetFirstMethod (_Jv_InterpClass *klass);
239 extern inline _Jv_MethodBase **
240 _Jv_GetFirstMethod (_Jv_InterpClass *klass)
242 return klass->interpreted_methods;
245 struct _Jv_ResolvedMethod
247 jint stack_item_count;
248 jint vtable_index;
249 jclass klass;
250 _Jv_Method* method;
252 // a resolved method holds the cif in-line, so that _Jv_MarkObj just needs
253 // to mark the resolved method to hold on to the cif. Some memory could be
254 // saved by keeping a cache of cif's, since many will be the same.
255 ffi_cif cif;
256 ffi_type * arg_types[0];
259 class _Jv_JNIMethod : public _Jv_MethodBase
261 // The underlying function. If NULL we have to look for the
262 // function.
263 void *function;
265 // This is the CIF used by the JNI function.
266 ffi_cif jni_cif;
268 // These are the argument types used by the JNI function.
269 ffi_type **jni_arg_types;
271 // This function is used when making a JNI call from the interpreter.
272 static void call (ffi_cif *, void *, ffi_raw *, void *);
274 void *ncode ();
276 friend class _Jv_ClassReader;
277 friend class _Jv_InterpreterEngine;
279 #ifdef JV_MARKOBJ_DECL
280 friend JV_MARKOBJ_DECL;
281 #endif
283 public:
284 // FIXME: this is ugly.
285 void set_function (void *f)
287 function = f;
291 // The interpreted call stack, represented by a linked list of frames.
292 struct _Jv_InterpFrame
294 _Jv_InterpMethod *self;
295 java::lang::Thread *thread;
296 _Jv_InterpFrame *next;
297 pc_t pc;
299 _Jv_InterpFrame (_Jv_InterpMethod *s, java::lang::Thread *thr)
301 self = s;
302 thread = thr;
303 next = (_Jv_InterpFrame *) thr->interp_frame;
304 thr->interp_frame = (gnu::gcj::RawData *) this;
305 pc = NULL;
308 ~_Jv_InterpFrame ()
310 thread->interp_frame = (gnu::gcj::RawData *) next;
314 #endif /* INTERPRETER */
316 #endif /* __JAVA_INTERP_H__ */