1 // java-interp.h - Header file for the bytecode interpreter. -*- c++ -*-
3 /* Copyright (C) 1999 Cygnus Solutions
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__
17 #include <java-cpool.h>
23 #include <java/lang/Class.h>
24 #include <java/lang/ClassLoader.h>
25 #include <gnu/gcj/runtime/MethodInvocation.h>
31 extern inline jboolean
32 _Jv_IsInterpretedClass (jclass c
)
34 return (c
->loader
!= 0);
37 struct _Jv_ResolvedMethod
;
39 void _Jv_VerifyFieldSignature (_Jv_Utf8Const
*sig
);
40 void _Jv_VerifyMethodSignature (_Jv_Utf8Const
*sig
);
41 void _Jv_VerifyClassName (unsigned char* ptr
, _Jv_ushort length
);
42 void _Jv_VerifyClassName (_Jv_Utf8Const
*name
);
43 void _Jv_VerifyIdentifier (_Jv_Utf8Const
*);
44 bool _Jv_ClassNameSamePackage (_Jv_Utf8Const
*name1
, _Jv_Utf8Const
*name2
);
45 void _Jv_DefineClass (jclass
, jbyteArray
, jint
, jint
);
46 void _Jv_ResolveField (_Jv_Field
*, java::lang::ClassLoader
*);
48 void _Jv_InitField (jobject
, jclass
, int);
49 void * _Jv_AllocMethodInvocation (jsize size
);
51 /* FIXME: this should really be defined in some more generic place */
52 #define ROUND(V, A) (((((unsigned) (V))-1) | ((A)-1))+1)
54 /* the interpreter is written in C++, primarily because it makes it easy for
55 * the entire thing to be "friend" with class Class. */
57 class _Jv_InterpClass
;
58 class _Jv_InterpMethod
;
59 class _Jv_InterpMethodInvocation
;
61 class _Jv_InterpException
{
67 friend class _Jv_ClassReader
;
68 friend class _Jv_InterpMethod
;
71 class _Jv_InterpMethod
{
74 _Jv_ushort max_locals
;
78 _Jv_ushort args_raw_size
;
80 _Jv_InterpClass
*defining_class
;
83 unsigned char* bytecode ()
86 ((unsigned char*)this)
87 + ROUND((sizeof (_Jv_InterpMethod
)
88 + exc_count
*sizeof (_Jv_InterpException
)), 4);
91 _Jv_InterpException
* exceptions ()
93 return (_Jv_InterpException
*) (this+1);
96 static size_t size (int exc_count
, int code_length
)
99 ROUND ((sizeof (_Jv_InterpMethod
)
100 + (exc_count
* sizeof (_Jv_InterpException
))), 4)
104 // return the method's invocation pointer (a stub).
106 void continue1 (_Jv_InterpMethodInvocation
*inv
);
108 static void run_normal (ffi_cif
*, void*, ffi_raw
*, void*);
109 static void run_synch_object (ffi_cif
*, void*, ffi_raw
*, void*);
110 static void run_synch_class (ffi_cif
*, void*, ffi_raw
*, void*);
112 inline jobject
run (ffi_cif
*, void*, ffi_raw
*,
113 _Jv_InterpMethodInvocation
*);
115 bool find_exception (jobject ex
,
116 _Jv_InterpMethodInvocation
*inv
);
119 static void dump_object(jobject o
);
121 friend class _Jv_ClassReader
;
122 friend class _Jv_InterpMethodInvocation
;
123 friend class gnu::gcj::runtime::MethodInvocation
;
125 friend void _Jv_PrepareClass(jclass
);
128 class _Jv_InterpMethodInvocation
{
129 _Jv_InterpMethod
*running
;
134 _Jv_word
* stack_base () { return &state
[0]; }
135 _Jv_word
* local_base () { return &state
[running
->max_stack
]; }
137 friend class _Jv_InterpMethod
;
140 class _Jv_InterpClass
: public java::lang::Class
142 _Jv_InterpMethod
**interpreted_methods
;
143 _Jv_ushort
*field_initializers
;
145 friend class _Jv_ClassReader
;
146 friend class _Jv_InterpMethod
;
147 friend void _Jv_PrepareClass(jclass
);
148 friend void _Jv_InitField (jobject
, jclass
, int);
149 friend void* _Jv_MarkObj (void *, void *, void *, void *);
152 struct _Jv_ResolvedMethod
{
153 jint stack_item_count
;
158 // a resolved method holds the cif in-line, so that _Jv_MarkObj just needs
159 // to mark the resolved method to hold on to the cif. Some memory could be
160 // saved by keeping a cache of cif's, since many will be the same.
162 ffi_type
* arg_types
[0];
165 #endif /* INTERPRETER */
167 #endif /* __JAVA_INTERP_H__ */