1 // java-interp.h - Header file for the bytecode interpreter. -*- c++ -*-
3 /* Copyright (C) 1999, 2000, 2001, 2002 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>
16 #include <gnu/gcj/runtime/NameFinder.h>
22 #include <java/lang/Class.h>
23 #include <java/lang/ClassLoader.h>
24 #include <gnu/gcj/runtime/StackTrace.h>
30 extern inline jboolean
31 _Jv_IsInterpretedClass (jclass c
)
33 return (c
->loader
!= 0);
36 struct _Jv_ResolvedMethod
;
38 void _Jv_DefineClass (jclass
, jbyteArray
, jint
, jint
);
40 void _Jv_InitField (jobject
, jclass
, int);
41 void * _Jv_AllocMethodInvocation (jsize size
);
42 int _Jv_count_arguments (_Jv_Utf8Const
*signature
,
43 jboolean staticp
= true);
44 void _Jv_VerifyMethod (_Jv_InterpMethod
*method
);
46 /* FIXME: this should really be defined in some more generic place */
47 #define ROUND(V, A) (((((unsigned) (V))-1) | ((A)-1))+1)
49 /* the interpreter is written in C++, primarily because it makes it easy for
50 * the entire thing to be "friend" with class Class. */
52 class _Jv_InterpClass
;
53 class _Jv_InterpMethod
;
55 // Before a method is "compiled" we store values as the bytecode PC,
56 // an int. Afterwards we store them as pointers into the prepared
64 class _Jv_InterpException
66 _Jv_InterpPC start_pc
;
68 _Jv_InterpPC handler_pc
;
69 _Jv_InterpPC handler_type
;
71 friend class _Jv_ClassReader
;
72 friend class _Jv_InterpMethod
;
73 friend class _Jv_BytecodeVerifier
;
76 // Base class for method representations. Subclasses are interpreted
81 // The class which defined this method.
82 _Jv_InterpClass
*defining_class
;
84 // The method description.
87 // Size of raw arguments.
88 _Jv_ushort args_raw_size
;
91 _Jv_Method
*get_method ()
97 class _Jv_InterpMethod
: public _Jv_MethodBase
100 _Jv_ushort max_locals
;
103 _Jv_ushort exc_count
;
107 unsigned char* bytecode ()
110 ((unsigned char*)this)
111 + ROUND((sizeof (_Jv_InterpMethod
)
112 + exc_count
*sizeof (_Jv_InterpException
)), 4);
115 _Jv_InterpException
* exceptions ()
117 return (_Jv_InterpException
*) (this+1);
120 static size_t size (int exc_count
, int code_length
)
123 ROUND ((sizeof (_Jv_InterpMethod
)
124 + (exc_count
* sizeof (_Jv_InterpException
))), 4)
128 // return the method's invocation pointer (a stub).
130 void compile (const void * const *);
132 static void run_normal (ffi_cif
*, void*, ffi_raw
*, void*);
133 static void run_synch_object (ffi_cif
*, void*, ffi_raw
*, void*);
134 static void run_synch_class (ffi_cif
*, void*, ffi_raw
*, void*);
136 void run (void*, ffi_raw
*);
139 static void dump_object(jobject o
);
141 friend class _Jv_ClassReader
;
142 friend class _Jv_BytecodeVerifier
;
143 friend class gnu::gcj::runtime::NameFinder
;
144 friend class gnu::gcj::runtime::StackTrace
;
146 friend void _Jv_PrepareClass(jclass
);
149 class _Jv_InterpClass
: public java::lang::Class
151 _Jv_MethodBase
**interpreted_methods
;
152 _Jv_ushort
*field_initializers
;
154 friend class _Jv_ClassReader
;
155 friend class _Jv_InterpMethod
;
156 friend void _Jv_PrepareClass(jclass
);
157 friend void _Jv_InitField (jobject
, jclass
, int);
158 #ifdef JV_MARKOBJ_DECL
159 friend JV_MARKOBJ_DECL
;
162 friend _Jv_MethodBase
** _Jv_GetFirstMethod (_Jv_InterpClass
*klass
);
165 extern inline _Jv_MethodBase
**
166 _Jv_GetFirstMethod (_Jv_InterpClass
*klass
)
168 return klass
->interpreted_methods
;
171 struct _Jv_ResolvedMethod
{
172 jint stack_item_count
;
177 // a resolved method holds the cif in-line, so that _Jv_MarkObj just needs
178 // to mark the resolved method to hold on to the cif. Some memory could be
179 // saved by keeping a cache of cif's, since many will be the same.
181 ffi_type
* arg_types
[0];
184 class _Jv_JNIMethod
: public _Jv_MethodBase
186 // The underlying function. If NULL we have to look for the
190 // This is the CIF used by the JNI function.
193 // These are the argument types used by the JNI function.
194 ffi_type
**jni_arg_types
;
196 // This function is used when making a JNI call from the interpreter.
197 static void call (ffi_cif
*, void *, ffi_raw
*, void *);
201 friend class _Jv_ClassReader
;
202 friend void _Jv_PrepareClass(jclass
);
205 // FIXME: this is ugly.
206 void set_function (void *f
)
212 // A structure of this type is used to link together interpreter
213 // invocations on the stack.
214 struct _Jv_MethodChain
216 const _Jv_InterpMethod
*self
;
217 _Jv_MethodChain
**ptr
;
218 _Jv_MethodChain
*next
;
220 _Jv_MethodChain (const _Jv_InterpMethod
*s
, _Jv_MethodChain
**n
)
234 #endif /* INTERPRETER */
236 #endif /* __JAVA_INTERP_H__ */