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 bool _Jv_VerifyFieldSignature (_Jv_Utf8Const
*sig
);
37 bool _Jv_VerifyMethodSignature (_Jv_Utf8Const
*sig
);
38 bool _Jv_VerifyClassName (unsigned char* ptr
, _Jv_ushort length
);
39 bool _Jv_VerifyClassName (_Jv_Utf8Const
*name
);
40 bool _Jv_VerifyIdentifier (_Jv_Utf8Const
*);
41 bool _Jv_ClassNameSamePackage (_Jv_Utf8Const
*name1
, _Jv_Utf8Const
*name2
);
42 void _Jv_DefineClass (jclass
, jbyteArray
, jint
, jint
);
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
);
50 /* FIXME: this should really be defined in some more generic place */
51 #define ROUND(V, A) (((((unsigned) (V))-1) | ((A)-1))+1)
53 /* the interpreter is written in C++, primarily because it makes it easy for
54 * the entire thing to be "friend" with class Class. */
56 class _Jv_InterpClass
;
57 class _Jv_InterpMethod
;
58 class _Jv_InterpMethodInvocation
;
60 class _Jv_InterpException
67 friend class _Jv_ClassReader
;
68 friend class _Jv_InterpMethod
;
69 friend class _Jv_BytecodeVerifier
;
72 // Base class for method representations. Subclasses are interpreted
77 // The class which defined this method.
78 _Jv_InterpClass
*defining_class
;
80 // The method description.
83 // Size of raw arguments.
84 _Jv_ushort args_raw_size
;
87 _Jv_Method
*get_method ()
93 class _Jv_InterpMethod
: public _Jv_MethodBase
96 _Jv_ushort max_locals
;
101 unsigned char* bytecode ()
104 ((unsigned char*)this)
105 + ROUND((sizeof (_Jv_InterpMethod
)
106 + exc_count
*sizeof (_Jv_InterpException
)), 4);
109 _Jv_InterpException
* exceptions ()
111 return (_Jv_InterpException
*) (this+1);
114 static size_t size (int exc_count
, int code_length
)
117 ROUND ((sizeof (_Jv_InterpMethod
)
118 + (exc_count
* sizeof (_Jv_InterpException
))), 4)
122 // return the method's invocation pointer (a stub).
124 void continue1 (_Jv_InterpMethodInvocation
*inv
);
126 static void run_normal (ffi_cif
*, void*, ffi_raw
*, void*);
127 static void run_synch_object (ffi_cif
*, void*, ffi_raw
*, void*);
128 static void run_synch_class (ffi_cif
*, void*, ffi_raw
*, void*);
130 inline jobject
run (ffi_cif
*, void*, ffi_raw
*,
131 _Jv_InterpMethodInvocation
*);
133 bool find_exception (jobject ex
,
134 _Jv_InterpMethodInvocation
*inv
);
137 static void dump_object(jobject o
);
139 friend class _Jv_ClassReader
;
140 friend class _Jv_InterpMethodInvocation
;
141 friend class _Jv_BytecodeVerifier
;
143 friend void _Jv_PrepareClass(jclass
);
146 class _Jv_InterpMethodInvocation
{
147 _Jv_InterpMethod
*running
;
152 _Jv_word
* stack_base () { return &state
[0]; }
153 _Jv_word
* local_base () { return &state
[running
->max_stack
]; }
155 friend class _Jv_InterpMethod
;
158 class _Jv_InterpClass
: public java::lang::Class
160 _Jv_MethodBase
**interpreted_methods
;
161 _Jv_ushort
*field_initializers
;
163 friend class _Jv_ClassReader
;
164 friend class _Jv_InterpMethod
;
165 friend void _Jv_PrepareClass(jclass
);
166 friend void _Jv_InitField (jobject
, jclass
, int);
167 #ifdef JV_MARKOBJ_DECL
168 friend JV_MARKOBJ_DECL
;
171 friend _Jv_MethodBase
** _Jv_GetFirstMethod (_Jv_InterpClass
*klass
);
174 extern inline _Jv_MethodBase
**
175 _Jv_GetFirstMethod (_Jv_InterpClass
*klass
)
177 return klass
->interpreted_methods
;
180 struct _Jv_ResolvedMethod
{
181 jint stack_item_count
;
186 // a resolved method holds the cif in-line, so that _Jv_MarkObj just needs
187 // to mark the resolved method to hold on to the cif. Some memory could be
188 // saved by keeping a cache of cif's, since many will be the same.
190 ffi_type
* arg_types
[0];
193 class _Jv_JNIMethod
: public _Jv_MethodBase
195 // The underlying function. If NULL we have to look for the
199 // This is the CIF used by the JNI function.
202 // These are the argument types used by the JNI function.
203 ffi_type
**jni_arg_types
;
205 // This function is used when making a JNI call from the interpreter.
206 static void call (ffi_cif
*, void *, ffi_raw
*, void *);
210 friend class _Jv_ClassReader
;
211 friend void _Jv_PrepareClass(jclass
);
214 // FIXME: this is ugly.
215 void set_function (void *f
)
221 #endif /* INTERPRETER */
223 #endif /* __JAVA_INTERP_H__ */