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
);
47 /* FIXME: this should really be defined in some more generic place */
48 #define ROUND(V, A) (((((unsigned) (V))-1) | ((A)-1))+1)
50 /* the interpreter is written in C++, primarily because it makes it easy for
51 * the entire thing to be "friend" with class Class. */
53 class _Jv_InterpClass
;
54 class _Jv_InterpMethod
;
55 class _Jv_InterpMethodInvocation
;
57 class _Jv_InterpException
{
63 friend class _Jv_ClassReader
;
64 friend class _Jv_InterpMethod
;
67 // Base class for method representations. Subclasses are interpreted
72 // The class which defined this method.
73 _Jv_InterpClass
*defining_class
;
75 // The method description.
78 // Size of raw arguments.
79 _Jv_ushort args_raw_size
;
82 _Jv_Method
*get_method ()
88 class _Jv_InterpMethod
: public _Jv_MethodBase
91 _Jv_ushort max_locals
;
96 unsigned char* bytecode ()
99 ((unsigned char*)this)
100 + ROUND((sizeof (_Jv_InterpMethod
)
101 + exc_count
*sizeof (_Jv_InterpException
)), 4);
104 _Jv_InterpException
* exceptions ()
106 return (_Jv_InterpException
*) (this+1);
109 static size_t size (int exc_count
, int code_length
)
112 ROUND ((sizeof (_Jv_InterpMethod
)
113 + (exc_count
* sizeof (_Jv_InterpException
))), 4)
117 // return the method's invocation pointer (a stub).
119 void continue1 (_Jv_InterpMethodInvocation
*inv
);
121 static void run_normal (ffi_cif
*, void*, ffi_raw
*, void*);
122 static void run_synch_object (ffi_cif
*, void*, ffi_raw
*, void*);
123 static void run_synch_class (ffi_cif
*, void*, ffi_raw
*, void*);
125 inline jobject
run (ffi_cif
*, void*, ffi_raw
*,
126 _Jv_InterpMethodInvocation
*);
128 bool find_exception (jobject ex
,
129 _Jv_InterpMethodInvocation
*inv
);
132 static void dump_object(jobject o
);
134 friend class _Jv_ClassReader
;
135 friend class _Jv_InterpMethodInvocation
;
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 friend void* _Jv_MarkObj (void *, void *, void *, void *);
163 friend _Jv_MethodBase
** _Jv_GetFirstMethod (_Jv_InterpClass
*klass
);
166 extern inline _Jv_MethodBase
**
167 _Jv_GetFirstMethod (_Jv_InterpClass
*klass
)
169 return klass
->interpreted_methods
;
172 struct _Jv_ResolvedMethod
{
173 jint stack_item_count
;
178 // a resolved method holds the cif in-line, so that _Jv_MarkObj just needs
179 // to mark the resolved method to hold on to the cif. Some memory could be
180 // saved by keeping a cache of cif's, since many will be the same.
182 ffi_type
* arg_types
[0];
185 class _Jv_JNIMethod
: public _Jv_MethodBase
187 // The underlying function. If NULL we have to look for the
191 // This is the CIF used by the JNI function.
194 // These are the argument types used by the JNI function.
195 ffi_type
**jni_arg_types
;
197 // This function is used when making a JNI call from the interpreter.
198 static void call (ffi_cif
*, void *, ffi_raw
*, void *);
202 friend class _Jv_ClassReader
;
203 friend void _Jv_PrepareClass(jclass
);
206 // FIXME: this is ugly.
207 void set_function (void *f
)
213 #endif /* INTERPRETER */
215 #endif /* __JAVA_INTERP_H__ */