* gcc.c-torture/execute/20020307-1.c: New test.
[official-gcc.git] / libjava / include / java-interp.h
blobbc1f3ca1cf4680f79021e1f54bc672e24449c507
1 // java-interp.h - Header file for the bytecode interpreter. -*- c++ -*-
3 /* Copyright (C) 1999, 2000, 2001 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>
17 #ifdef INTERPRETER
19 #pragma interface
21 #include <java/lang/Class.h>
22 #include <java/lang/ClassLoader.h>
24 extern "C" {
25 #include <ffi.h>
28 extern inline jboolean
29 _Jv_IsInterpretedClass (jclass c)
31 return (c->loader != 0);
34 struct _Jv_ResolvedMethod;
36 void _Jv_DefineClass (jclass, jbyteArray, jint, jint);
38 void _Jv_InitField (jobject, jclass, int);
39 void * _Jv_AllocMethodInvocation (jsize size);
40 int _Jv_count_arguments (_Jv_Utf8Const *signature,
41 jboolean staticp = true);
42 void _Jv_VerifyMethod (_Jv_InterpMethod *method);
44 /* FIXME: this should really be defined in some more generic place */
45 #define ROUND(V, A) (((((unsigned) (V))-1) | ((A)-1))+1)
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;
52 class _Jv_InterpMethodInvocation;
54 class _Jv_InterpException
56 int start_pc;
57 int end_pc;
58 int handler_pc;
59 int handler_type;
61 friend class _Jv_ClassReader;
62 friend class _Jv_InterpMethod;
63 friend class _Jv_BytecodeVerifier;
66 // Base class for method representations. Subclasses are interpreted
67 // and JNI methods.
68 class _Jv_MethodBase
70 protected:
71 // The class which defined this method.
72 _Jv_InterpClass *defining_class;
74 // The method description.
75 _Jv_Method *self;
77 // Size of raw arguments.
78 _Jv_ushort args_raw_size;
80 public:
81 _Jv_Method *get_method ()
83 return self;
87 class _Jv_InterpMethod : public _Jv_MethodBase
89 _Jv_ushort max_stack;
90 _Jv_ushort max_locals;
91 int code_length;
93 _Jv_ushort exc_count;
95 unsigned char* bytecode ()
97 return
98 ((unsigned char*)this)
99 + ROUND((sizeof (_Jv_InterpMethod)
100 + exc_count*sizeof (_Jv_InterpException)), 4);
103 _Jv_InterpException * exceptions ()
105 return (_Jv_InterpException*) (this+1);
108 static size_t size (int exc_count, int code_length)
110 return
111 ROUND ((sizeof (_Jv_InterpMethod)
112 + (exc_count * sizeof (_Jv_InterpException))), 4)
113 + code_length;
116 // return the method's invocation pointer (a stub).
117 void *ncode ();
118 void continue1 (_Jv_InterpMethodInvocation *inv);
120 static void run_normal (ffi_cif*, void*, ffi_raw*, void*);
121 static void run_synch_object (ffi_cif*, void*, ffi_raw*, void*);
122 static void run_synch_class (ffi_cif*, void*, ffi_raw*, void*);
124 inline jobject run (ffi_cif*, void*, ffi_raw*,
125 _Jv_InterpMethodInvocation*);
127 bool find_exception (jobject ex,
128 _Jv_InterpMethodInvocation *inv);
130 public:
131 static void dump_object(jobject o);
133 friend class _Jv_ClassReader;
134 friend class _Jv_InterpMethodInvocation;
135 friend class _Jv_BytecodeVerifier;
137 friend void _Jv_PrepareClass(jclass);
140 class _Jv_InterpMethodInvocation {
141 _Jv_InterpMethod *running;
142 _Jv_word *sp;
143 unsigned char *pc;
144 _Jv_word state[0];
146 _Jv_word* stack_base () { return &state[0]; }
147 _Jv_word* local_base () { return &state[running->max_stack]; }
149 friend class _Jv_InterpMethod;
152 class _Jv_InterpClass : public java::lang::Class
154 _Jv_MethodBase **interpreted_methods;
155 _Jv_ushort *field_initializers;
157 friend class _Jv_ClassReader;
158 friend class _Jv_InterpMethod;
159 friend void _Jv_PrepareClass(jclass);
160 friend void _Jv_InitField (jobject, jclass, int);
161 #ifdef JV_MARKOBJ_DECL
162 friend JV_MARKOBJ_DECL;
163 #endif
165 friend _Jv_MethodBase ** _Jv_GetFirstMethod (_Jv_InterpClass *klass);
168 extern inline _Jv_MethodBase **
169 _Jv_GetFirstMethod (_Jv_InterpClass *klass)
171 return klass->interpreted_methods;
174 struct _Jv_ResolvedMethod {
175 jint stack_item_count;
176 jint vtable_index;
177 jclass klass;
178 _Jv_Method* method;
180 // a resolved method holds the cif in-line, so that _Jv_MarkObj just needs
181 // to mark the resolved method to hold on to the cif. Some memory could be
182 // saved by keeping a cache of cif's, since many will be the same.
183 ffi_cif cif;
184 ffi_type * arg_types[0];
187 class _Jv_JNIMethod : public _Jv_MethodBase
189 // The underlying function. If NULL we have to look for the
190 // function.
191 void *function;
193 // This is the CIF used by the JNI function.
194 ffi_cif jni_cif;
196 // These are the argument types used by the JNI function.
197 ffi_type **jni_arg_types;
199 // This function is used when making a JNI call from the interpreter.
200 static void call (ffi_cif *, void *, ffi_raw *, void *);
202 void *ncode ();
204 friend class _Jv_ClassReader;
205 friend void _Jv_PrepareClass(jclass);
207 public:
208 // FIXME: this is ugly.
209 void set_function (void *f)
211 function = f;
215 #endif /* INTERPRETER */
217 #endif /* __JAVA_INTERP_H__ */