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
11 #ifndef __JAVA_INTERP_H__
12 #define __JAVA_INTERP_H__
15 #include <java-cpool.h>
21 #include <java/lang/Class.h>
22 #include <java/lang/ClassLoader.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
61 friend class _Jv_ClassReader
;
62 friend class _Jv_InterpMethod
;
63 friend class _Jv_BytecodeVerifier
;
66 // Base class for method representations. Subclasses are interpreted
71 // The class which defined this method.
72 _Jv_InterpClass
*defining_class
;
74 // The method description.
77 // Size of raw arguments.
78 _Jv_ushort args_raw_size
;
81 _Jv_Method
*get_method ()
87 class _Jv_InterpMethod
: public _Jv_MethodBase
90 _Jv_ushort max_locals
;
95 unsigned char* bytecode ()
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
)
111 ROUND ((sizeof (_Jv_InterpMethod
)
112 + (exc_count
* sizeof (_Jv_InterpException
))), 4)
116 // return the method's invocation pointer (a stub).
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
);
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
;
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
;
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
;
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.
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
193 // This is the CIF used by the JNI function.
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 *);
204 friend class _Jv_ClassReader
;
205 friend void _Jv_PrepareClass(jclass
);
208 // FIXME: this is ugly.
209 void set_function (void *f
)
215 #endif /* INTERPRETER */
217 #endif /* __JAVA_INTERP_H__ */