1 // Class.h - Header file for java.lang.Class. -*- c++ -*-
3 /* Copyright (C) 1998, 1999, 2000 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 // Written primary using compiler source and Class.java as guides.
12 #ifndef __JAVA_LANG_CLASS_H__
13 #define __JAVA_LANG_CLASS_H__
17 #include <java/lang/Object.h>
18 #include <java/lang/String.h>
19 #include <java/net/URL.h>
21 // We declare these here to avoid including gcj/cni.h.
22 extern "C" void _Jv_InitClass (jclass klass
);
23 extern "C" void _Jv_RegisterClasses (jclass
*classes
);
25 // This must be predefined with "C" linkage.
26 extern "C" void *_Jv_LookupInterfaceMethodIdx (jclass klass
, jclass iface
,
29 // These are the possible values for the `state' field of the class
30 // structure. Note that ordering is important here. Whenever the
31 // state changes, one should notify all waiters of this class.
34 JV_STATE_NOTHING
= 0, // Set by compiler.
36 JV_STATE_PRELOADING
= 1, // Can do _Jv_FindClass.
37 JV_STATE_LOADING
= 3, // Has super installed.
38 JV_STATE_LOADED
= 5, // Is complete.
40 JV_STATE_COMPILED
= 6, // This was a compiled class.
42 JV_STATE_PREPARED
= 7, // Layout & static init done.
43 JV_STATE_LINKED
= 9, // Strings interned.
45 JV_STATE_IN_PROGRESS
= 10, // <Clinit> running.
46 JV_STATE_DONE
= 12, //
48 JV_STATE_ERROR
= 14 // must be last.
65 _Jv_Utf8Const
*signature
;
68 _Jv_Method
*getNextMethod ()
72 // Interface Dispatch Tables
73 union _Jv_IDispatchTable
77 // Index into interface's ioffsets.
80 // Class Interface dispatch table.
86 // Offsets into implementation class itables.
91 // Used by _Jv_GetInterfaces ()
99 #define JV_PRIMITIVE_VTABLE ((_Jv_VTable *) -1)
101 #define JV_CLASS(Obj) ((jclass) (*(_Jv_VTable **) Obj)->clas)
103 class java::lang::Class
: public java::lang::Object
106 static jclass
forName (jstring className
);
107 JArray
<jclass
> *getClasses (void);
109 java::lang::ClassLoader
*getClassLoader (void)
114 java::lang::reflect::Constructor
*getConstructor (JArray
<jclass
> *);
115 JArray
<java::lang::reflect::Constructor
*> *getConstructors (void);
116 java::lang::reflect::Constructor
*getDeclaredConstructor (JArray
<jclass
> *);
117 JArray
<java::lang::reflect::Constructor
*> *getDeclaredConstructors (void);
118 java::lang::reflect::Field
*getDeclaredField (jstring
);
119 JArray
<java::lang::reflect::Field
*> *getDeclaredFields (void);
120 java::lang::reflect::Method
*getDeclaredMethod (jstring
, JArray
<jclass
> *);
121 JArray
<java::lang::reflect::Method
*> *getDeclaredMethods (void);
123 JArray
<jclass
> *getDeclaredClasses (void);
124 jclass
getDeclaringClass (void);
126 java::lang::reflect::Field
*getField (jstring
);
128 jint
_getFields (JArray
<java::lang::reflect::Field
*> *result
, jint offset
);
129 JArray
<java::lang::reflect::Constructor
*> *_getConstructors (jboolean
);
130 java::lang::reflect::Field
*getField (jstring
, jint
);
131 jint
_getMethods (JArray
<java::lang::reflect::Method
*> *result
,
133 java::lang::reflect::Field
*getPrivateField (jstring
);
134 java::lang::reflect::Method
*getPrivateMethod (jstring
, JArray
<jclass
> *);
137 JArray
<java::lang::reflect::Field
*> *getFields (void);
139 JArray
<jclass
> *getInterfaces (void);
141 void getSignature (java::lang::StringBuffer
*buffer
);
142 static jstring
getSignature (JArray
<jclass
> *, jboolean is_constructor
);
143 java::lang::reflect::Method
*getMethod (jstring
, JArray
<jclass
> *);
144 JArray
<java::lang::reflect::Method
*> *getMethods (void);
146 inline jint
getModifiers (void)
151 jstring
getName (void);
153 java::net::URL
*getResource (jstring resourceName
);
154 java::io::InputStream
*getResourceAsStream (jstring resourceName
);
155 JArray
<jobject
> *getSigners (void);
157 inline jclass
getSuperclass (void)
162 inline jboolean
isArray (void)
164 return name
->data
[0] == '[';
167 inline jclass
getComponentType (void)
169 return isArray () ? (* (jclass
*) &methods
) : 0;
172 jboolean
isAssignableFrom (jclass cls
);
173 jboolean
isInstance (jobject obj
);
174 jboolean
isInterface (void);
176 inline jboolean
isPrimitive (void)
178 return vtable
== JV_PRIMITIVE_VTABLE
;
181 jobject
newInstance (void);
182 jstring
toString (void);
184 // FIXME: this probably shouldn't be public.
187 return size_in_bytes
;
193 static java::lang::Class
class$
;
197 void checkMemberAccess (jint flags
);
199 void initializeClass (void);
201 // Friend functions implemented in natClass.cc.
202 friend _Jv_Method
*_Jv_GetMethodLocal (jclass klass
, _Jv_Utf8Const
*name
,
203 _Jv_Utf8Const
*signature
);
204 friend jboolean
_Jv_IsAssignableFrom(jclass
, jclass
);
205 friend jboolean
_Jv_InterfaceAssignableFrom (jclass
, jclass
);
206 friend void *_Jv_LookupInterfaceMethodIdx (jclass klass
, jclass iface
,
210 _Jv_InitClass (jclass klass
)
212 if (klass
->state
== JV_STATE_DONE
)
214 klass
->initializeClass ();
217 friend _Jv_Method
* _Jv_LookupDeclaredMethod (jclass
, _Jv_Utf8Const
*,
219 friend jfieldID
JvGetFirstInstanceField (jclass
);
220 friend jint
JvNumInstanceFields (jclass
);
221 friend jfieldID
JvGetFirstStaticField (jclass
);
222 friend jint
JvNumStaticFields (jclass
);
224 friend jobject
_Jv_AllocObject (jclass
, jint
);
225 friend void *_Jv_AllocObj (jint
, jclass
);
226 friend void *_Jv_AllocArray (jint
, jclass
);
228 friend jobject
_Jv_JNI_ToReflectedField (_Jv_JNIEnv
*, jclass
, jfieldID
,
230 friend jobject
_Jv_JNI_ToReflectedMethod (_Jv_JNIEnv
*, jclass
, jmethodID
,
232 friend jfieldID
_Jv_FromReflectedField (java::lang::reflect::Field
*);
234 friend jmethodID
_Jv_FromReflectedMethod (java::lang::reflect::Method
*);
235 friend jmethodID
_Jv_FromReflectedConstructor (java::lang::reflect::Constructor
*);
236 friend jint
JvNumMethods (jclass
);
237 friend jmethodID
JvGetFirstMethod (jclass
);
239 friend class _Jv_PrimClass
;
241 // Friends classes and functions to implement the ClassLoader
242 friend class java::lang::ClassLoader
;
244 friend class java::io::ObjectOutputStream
;
245 friend class java::io::ObjectInputStream
;
246 friend class java::io::ObjectStreamClass
;
248 friend void _Jv_WaitForState (jclass
, int);
249 friend void _Jv_RegisterClasses (jclass
*classes
);
250 friend void _Jv_RegisterInitiatingLoader (jclass
,java::lang::ClassLoader
*);
251 friend void _Jv_UnregisterClass (jclass
);
252 friend jclass
_Jv_FindClass (_Jv_Utf8Const
*name
,
253 java::lang::ClassLoader
*loader
);
254 friend jclass
_Jv_FindClassInCache (_Jv_Utf8Const
*name
,
255 java::lang::ClassLoader
*loader
);
256 friend jclass
_Jv_FindArrayClass (jclass element
,
257 java::lang::ClassLoader
*loader
,
258 _Jv_VTable
*array_vtable
= 0);
259 friend jclass
_Jv_NewClass (_Jv_Utf8Const
*name
, jclass superclass
,
260 java::lang::ClassLoader
*loader
);
262 friend void _Jv_PrepareCompiledClass (jclass
);
263 friend void _Jv_PrepareConstantTimeTables (jclass
);
264 friend jshort
_Jv_GetInterfaces (jclass
, _Jv_ifaces
*);
265 friend void _Jv_GenerateITable (jclass
, _Jv_ifaces
*, jshort
*);
266 friend jstring
_Jv_GetMethodString(jclass
, _Jv_Utf8Const
*);
267 friend jshort
_Jv_AppendPartialITable (jclass
, jclass
, void **, jshort
);
268 friend jshort
_Jv_FindIIndex (jclass
*, jshort
*, jshort
);
271 friend jboolean
_Jv_IsInterpretedClass (jclass
);
272 friend void _Jv_InitField (jobject
, jclass
, _Jv_Field
*);
273 friend int _Jv_DetermineVTableIndex (jclass
, _Jv_Utf8Const
*,
275 friend void _Jv_InitField (jobject
, jclass
, int);
276 friend _Jv_word
_Jv_ResolvePoolEntry (jclass
, int);
277 friend _Jv_Method
*_Jv_SearchMethodInClass (jclass cls
, jclass klass
,
278 _Jv_Utf8Const
*method_name
,
279 _Jv_Utf8Const
*method_signature
);
281 friend void _Jv_PrepareClass (jclass
);
283 friend class _Jv_ClassReader
;
284 friend class _Jv_InterpClass
;
285 friend class _Jv_InterpMethod
;
286 friend class _Jv_InterpMethodInvocation
;
289 #ifdef JV_MARKOBJ_DECL
290 friend JV_MARKOBJ_DECL
;
293 // Chain for class pool.
297 // Access flags for class.
299 // The superclass, or null for Object.
302 _Jv_Constants constants
;
303 // Methods. If this is an array class, then this field holds a
304 // pointer to the element type. If this is a primitive class, this
305 // is used to cache a pointer to the appropriate array type.
307 // Number of methods. If this class is primitive, this holds the
308 // character used to represent this type in a signature.
310 // Number of methods in the vtable.
311 jshort vtable_method_count
;
314 // Size of instance fields, in bytes.
316 // Total number of fields (instance and static).
318 // Number of static fields.
319 jshort static_field_count
;
320 // The vtbl for all objects of this class.
322 // Interfaces implemented by this class.
324 // The class loader for this class.
325 java::lang::ClassLoader
*loader
;
326 // Number of interfaces.
327 jshort interface_count
;
328 // State of this class.
330 // The thread which has locked this class. Used during class
332 java::lang::Thread
*thread
;
333 // How many levels of "extends" this class is removed from Object.
335 // Vector of this class's superclasses, ordered by decreasing depth.
337 // Interface Dispatch Table.
338 _Jv_IDispatchTable
*idt
;
341 #endif /* __JAVA_LANG_CLASS_H__ */