1 // java-interp.h - Header file for the bytecode interpreter. -*- c++ -*-
3 /* Copyright (C) 1999, 2000 Red Hat, Inc.
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>
23 #include <gnu/gcj/runtime/MethodInvocation.h>
29 extern inline jboolean
30 _Jv_IsInterpretedClass (jclass c
)
32 return (c
->loader
!= 0);
35 struct _Jv_ResolvedMethod
;
37 void _Jv_VerifyFieldSignature (_Jv_Utf8Const
*sig
);
38 void _Jv_VerifyMethodSignature (_Jv_Utf8Const
*sig
);
39 void _Jv_VerifyClassName (unsigned char* ptr
, _Jv_ushort length
);
40 void _Jv_VerifyClassName (_Jv_Utf8Const
*name
);
41 void _Jv_VerifyIdentifier (_Jv_Utf8Const
*);
42 bool _Jv_ClassNameSamePackage (_Jv_Utf8Const
*name1
, _Jv_Utf8Const
*name2
);
43 void _Jv_DefineClass (jclass
, jbyteArray
, jint
, jint
);
44 void _Jv_ResolveField (_Jv_Field
*, java::lang::ClassLoader
*);
46 void _Jv_InitField (jobject
, jclass
, int);
47 void * _Jv_AllocMethodInvocation (jsize size
);
49 /* FIXME: this should really be defined in some more generic place */
50 #define ROUND(V, A) (((((unsigned) (V))-1) | ((A)-1))+1)
52 /* the interpreter is written in C++, primarily because it makes it easy for
53 * the entire thing to be "friend" with class Class. */
55 class _Jv_InterpClass
;
56 class _Jv_InterpMethod
;
57 class _Jv_InterpMethodInvocation
;
59 class _Jv_InterpException
{
65 friend class _Jv_ClassReader
;
66 friend class _Jv_InterpMethod
;
69 // Base class for method representations. Subclasses are interpreted
74 // The class which defined this method.
75 _Jv_InterpClass
*defining_class
;
77 // The method description.
80 // Size of raw arguments.
81 _Jv_ushort args_raw_size
;
84 class _Jv_InterpMethod
: public _Jv_MethodBase
87 _Jv_ushort max_locals
;
92 unsigned char* bytecode ()
95 ((unsigned char*)this)
96 + ROUND((sizeof (_Jv_InterpMethod
)
97 + exc_count
*sizeof (_Jv_InterpException
)), 4);
100 _Jv_InterpException
* exceptions ()
102 return (_Jv_InterpException
*) (this+1);
105 static size_t size (int exc_count
, int code_length
)
108 ROUND ((sizeof (_Jv_InterpMethod
)
109 + (exc_count
* sizeof (_Jv_InterpException
))), 4)
113 // return the method's invocation pointer (a stub).
115 void continue1 (_Jv_InterpMethodInvocation
*inv
);
117 static void run_normal (ffi_cif
*, void*, ffi_raw
*, void*);
118 static void run_synch_object (ffi_cif
*, void*, ffi_raw
*, void*);
119 static void run_synch_class (ffi_cif
*, void*, ffi_raw
*, void*);
121 inline jobject
run (ffi_cif
*, void*, ffi_raw
*,
122 _Jv_InterpMethodInvocation
*);
124 bool find_exception (jobject ex
,
125 _Jv_InterpMethodInvocation
*inv
);
128 static void dump_object(jobject o
);
130 friend class _Jv_ClassReader
;
131 friend class _Jv_InterpMethodInvocation
;
132 friend class gnu::gcj::runtime::MethodInvocation
;
134 friend void _Jv_PrepareClass(jclass
);
137 class _Jv_InterpMethodInvocation
{
138 _Jv_InterpMethod
*running
;
143 _Jv_word
* stack_base () { return &state
[0]; }
144 _Jv_word
* local_base () { return &state
[running
->max_stack
]; }
146 friend class _Jv_InterpMethod
;
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 friend void* _Jv_MarkObj (void *, void *, void *, void *);
161 struct _Jv_ResolvedMethod
{
162 jint stack_item_count
;
167 // a resolved method holds the cif in-line, so that _Jv_MarkObj just needs
168 // to mark the resolved method to hold on to the cif. Some memory could be
169 // saved by keeping a cache of cif's, since many will be the same.
171 ffi_type
* arg_types
[0];
174 class _Jv_JNIMethod
: public _Jv_MethodBase
176 // The underlying function. If NULL we have to look for the
180 // This is the CIF used by the JNI function.
183 // These are the argument types used by the JNI function.
184 ffi_type
**jni_arg_types
;
186 // This function is used when making a JNI call from the interpreter.
187 static void call (ffi_cif
*, void *, ffi_raw
*, void *);
191 friend class _Jv_ClassReader
;
192 friend void _Jv_PrepareClass(jclass
);
195 #endif /* INTERPRETER */
197 #endif /* __JAVA_INTERP_H__ */