1 // Class.h - Header file for java.lang.Class. -*- c++ -*-
3 /* Copyright (C) 1998, 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 // Written primary using compiler source and Class.java as guides.
12 #ifndef __JAVA_LANG_CLASS_H__
13 #define __JAVA_LANG_CLASS_H__
18 #include <java/lang/Object.h>
19 #include <java/lang/String.h>
20 #include <java/net/URL.h>
21 #include <java/lang/reflect/Modifier.h>
22 #include <java/security/ProtectionDomain.h>
24 // We declare these here to avoid including gcj/cni.h.
25 extern "C" void _Jv_InitClass (jclass klass
);
26 extern "C" void _Jv_RegisterClasses (jclass
*classes
);
28 // This must be predefined with "C" linkage.
29 extern "C" void *_Jv_LookupInterfaceMethodIdx (jclass klass
, jclass iface
,
32 // These are the possible values for the `state' field of the class
33 // structure. Note that ordering is important here. Whenever the
34 // state changes, one should notify all waiters of this class.
37 JV_STATE_NOTHING
= 0, // Set by compiler.
39 JV_STATE_PRELOADING
= 1, // Can do _Jv_FindClass.
40 JV_STATE_LOADING
= 3, // Has super installed.
41 JV_STATE_LOADED
= 5, // Is complete.
43 JV_STATE_COMPILED
= 6, // This was a compiled class.
45 JV_STATE_PREPARED
= 7, // Layout & static init done.
46 JV_STATE_LINKED
= 9, // Strings interned.
48 JV_STATE_IN_PROGRESS
= 10, // <Clinit> running.
49 JV_STATE_DONE
= 12, //
51 JV_STATE_ERROR
= 14 // must be last.
70 _Jv_Utf8Const
*signature
;
73 // Pointer to underlying function.
75 // NULL-terminated list of exception class names; can be NULL if
76 // there are none such.
77 _Jv_Utf8Const
**throws
;
79 _Jv_Method
*getNextMethod ()
83 // Interface Dispatch Tables
84 union _Jv_IDispatchTable
88 // Index into interface's ioffsets.
91 // Class Interface dispatch table.
97 // Offsets into implementation class itables.
102 // Used by _Jv_GetInterfaces ()
110 // Used for vtable pointer manipulation.
117 #define JV_PRIMITIVE_VTABLE ((_Jv_VTable *) -1)
119 #define JV_CLASS(Obj) ((jclass) (*(_Jv_VTable **) Obj)->clas)
121 class java::lang::Class
: public java::lang::Object
124 static jclass
forName (jstring className
, jboolean initialize
,
125 java::lang::ClassLoader
*loader
);
126 static jclass
forName (jstring className
);
127 JArray
<jclass
> *getClasses (void);
129 java::lang::ClassLoader
*getClassLoader (void)
134 java::lang::reflect::Constructor
*getConstructor (JArray
<jclass
> *);
135 JArray
<java::lang::reflect::Constructor
*> *getConstructors (void);
136 java::lang::reflect::Constructor
*getDeclaredConstructor (JArray
<jclass
> *);
137 JArray
<java::lang::reflect::Constructor
*> *getDeclaredConstructors (void);
138 java::lang::reflect::Field
*getDeclaredField (jstring
);
139 JArray
<java::lang::reflect::Field
*> *getDeclaredFields (void);
140 java::lang::reflect::Method
*getDeclaredMethod (jstring
, JArray
<jclass
> *);
141 JArray
<java::lang::reflect::Method
*> *getDeclaredMethods (void);
143 JArray
<jclass
> *getDeclaredClasses (void);
144 jclass
getDeclaringClass (void);
146 java::lang::reflect::Field
*getField (jstring
);
148 jint
_getFields (JArray
<java::lang::reflect::Field
*> *result
, jint offset
);
149 JArray
<java::lang::reflect::Constructor
*> *_getConstructors (jboolean
);
150 java::lang::reflect::Field
*getField (jstring
, jint
);
151 jint
_getMethods (JArray
<java::lang::reflect::Method
*> *result
,
153 java::lang::reflect::Field
*getPrivateField (jstring
);
154 java::lang::reflect::Method
*getPrivateMethod (jstring
, JArray
<jclass
> *);
155 java::security::ProtectionDomain
*getProtectionDomain0 ();
158 JArray
<java::lang::reflect::Field
*> *getFields (void);
160 JArray
<jclass
> *getInterfaces (void);
162 void getSignature (java::lang::StringBuffer
*buffer
);
163 static jstring
getSignature (JArray
<jclass
> *, jboolean is_constructor
);
164 java::lang::reflect::Method
*getMethod (jstring
, JArray
<jclass
> *);
165 JArray
<java::lang::reflect::Method
*> *getMethods (void);
167 inline jint
getModifiers (void)
172 jstring
getName (void);
174 java::net::URL
*getResource (jstring resourceName
);
175 java::io::InputStream
*getResourceAsStream (jstring resourceName
);
176 JArray
<jobject
> *getSigners (void);
178 inline jclass
getSuperclass (void)
183 inline jboolean
isArray (void)
185 return name
->data
[0] == '[';
188 inline jclass
getComponentType (void)
190 return isArray () ? (* (jclass
*) &methods
) : 0;
193 jboolean
isAssignableFrom (jclass cls
);
194 jboolean
isInstance (jobject obj
);
196 inline jboolean
isInterface (void)
198 return (accflags
& java::lang::reflect::Modifier::INTERFACE
) != 0;
201 inline jboolean
isPrimitive (void)
203 return vtable
== JV_PRIMITIVE_VTABLE
;
206 jobject
newInstance (void);
207 jstring
toString (void);
209 // FIXME: this probably shouldn't be public.
212 return size_in_bytes
;
218 // This constructor is used to create Class object for the primitive
219 // types. See prims.cc.
220 Class (jobject cname
, jbyte sig
, jint len
, jobject array_vtable
)
222 using namespace java::lang::reflect
;
223 _Jv_Utf8Const
*_Jv_makeUtf8Const (char *s
, int len
);
225 // C++ ctors set the vtbl pointer to point at an offset inside the vtable
226 // object. That doesn't work for Java, so this hack adjusts it back.
227 ((_Jv_Self
*)this)->vtable_ptr
-= 2 * sizeof (void *);
229 // We must initialize every field of the class. We do this in the
230 // same order they are declared in Class.h, except for fields that
231 // are initialized to NULL.
232 name
= _Jv_makeUtf8Const ((char *) cname
, -1);
233 accflags
= Modifier::PUBLIC
| Modifier::FINAL
| Modifier::ABSTRACT
;
236 vtable
= JV_PRIMITIVE_VTABLE
;
237 state
= JV_STATE_DONE
;
239 if (method_count
!= 'V')
240 _Jv_NewArrayClass (this, NULL
, (_Jv_VTable
*) array_vtable
);
243 static java::lang::Class
class$
;
249 void checkMemberAccess (jint flags
);
251 void initializeClass (void);
253 // Friend functions implemented in natClass.cc.
254 friend _Jv_Method
*_Jv_GetMethodLocal (jclass klass
, _Jv_Utf8Const
*name
,
255 _Jv_Utf8Const
*signature
);
256 friend jboolean
_Jv_IsAssignableFrom(jclass
, jclass
);
257 friend jboolean
_Jv_InterfaceAssignableFrom (jclass
, jclass
);
258 friend void *_Jv_LookupInterfaceMethodIdx (jclass klass
, jclass iface
,
262 _Jv_InitClass (jclass klass
)
264 if (__builtin_expect (klass
->state
== JV_STATE_DONE
, true))
266 klass
->initializeClass ();
269 friend _Jv_Method
* _Jv_LookupDeclaredMethod (jclass
, _Jv_Utf8Const
*,
271 friend jfieldID
JvGetFirstInstanceField (jclass
);
272 friend jint
JvNumInstanceFields (jclass
);
273 friend jfieldID
JvGetFirstStaticField (jclass
);
274 friend jint
JvNumStaticFields (jclass
);
276 friend jobject
_Jv_AllocObject (jclass
, jint
);
277 friend void *_Jv_AllocObj (jint
, jclass
);
278 friend void *_Jv_AllocPtrFreeObj (jint
, jclass
);
279 friend void *_Jv_AllocArray (jint
, jclass
);
281 friend jobject
_Jv_JNI_ToReflectedField (_Jv_JNIEnv
*, jclass
, jfieldID
,
283 friend jobject
_Jv_JNI_ToReflectedMethod (_Jv_JNIEnv
*, jclass
, jmethodID
,
285 friend jfieldID
_Jv_FromReflectedField (java::lang::reflect::Field
*);
287 friend jmethodID
_Jv_FromReflectedMethod (java::lang::reflect::Method
*);
288 friend jmethodID
_Jv_FromReflectedConstructor (java::lang::reflect::Constructor
*);
289 friend jint
JvNumMethods (jclass
);
290 friend jmethodID
JvGetFirstMethod (jclass
);
292 // Friends classes and functions to implement the ClassLoader
293 friend class java::lang::ClassLoader
;
295 friend class java::io::ObjectOutputStream
;
296 friend class java::io::ObjectInputStream
;
297 friend class java::io::ObjectStreamClass
;
299 friend void _Jv_WaitForState (jclass
, int);
300 friend void _Jv_RegisterClasses (jclass
*classes
);
301 friend void _Jv_RegisterInitiatingLoader (jclass
,java::lang::ClassLoader
*);
302 friend void _Jv_UnregisterClass (jclass
);
303 friend jclass
_Jv_FindClass (_Jv_Utf8Const
*name
,
304 java::lang::ClassLoader
*loader
);
305 friend jclass
_Jv_FindClassInCache (_Jv_Utf8Const
*name
,
306 java::lang::ClassLoader
*loader
);
307 friend void _Jv_NewArrayClass (jclass element
,
308 java::lang::ClassLoader
*loader
,
309 _Jv_VTable
*array_vtable
= 0);
310 friend jclass
_Jv_NewClass (_Jv_Utf8Const
*name
, jclass superclass
,
311 java::lang::ClassLoader
*loader
);
313 friend void _Jv_PrepareCompiledClass (jclass
);
314 friend void _Jv_PrepareConstantTimeTables (jclass
);
315 friend jshort
_Jv_GetInterfaces (jclass
, _Jv_ifaces
*);
316 friend void _Jv_GenerateITable (jclass
, _Jv_ifaces
*, jshort
*);
317 friend jstring
_Jv_GetMethodString(jclass
, _Jv_Utf8Const
*);
318 friend jshort
_Jv_AppendPartialITable (jclass
, jclass
, void **, jshort
);
319 friend jshort
_Jv_FindIIndex (jclass
*, jshort
*, jshort
);
321 // Return array class corresponding to element type KLASS, creating it if
324 _Jv_GetArrayClass (jclass klass
, java::lang::ClassLoader
*loader
)
326 if (__builtin_expect (!klass
->arrayclass
, false))
327 _Jv_NewArrayClass (klass
, loader
);
328 return klass
->arrayclass
;
332 friend jboolean
_Jv_IsInterpretedClass (jclass
);
333 friend void _Jv_InitField (jobject
, jclass
, _Jv_Field
*);
334 friend int _Jv_DetermineVTableIndex (jclass
, _Jv_Utf8Const
*,
336 friend void _Jv_InitField (jobject
, jclass
, int);
337 friend _Jv_word
_Jv_ResolvePoolEntry (jclass
, int);
338 friend _Jv_Method
*_Jv_SearchMethodInClass (jclass cls
, jclass klass
,
339 _Jv_Utf8Const
*method_name
,
340 _Jv_Utf8Const
*method_signature
);
342 friend void _Jv_PrepareClass (jclass
);
344 friend class _Jv_ClassReader
;
345 friend class _Jv_InterpClass
;
346 friend class _Jv_InterpMethod
;
347 friend class _Jv_InterpMethodInvocation
;
350 #ifdef JV_MARKOBJ_DECL
351 friend JV_MARKOBJ_DECL
;
354 // Chain for class pool.
358 // Access flags for class.
360 // The superclass, or null for Object.
363 _Jv_Constants constants
;
364 // Methods. If this is an array class, then this field holds a
365 // pointer to the element type.
367 // Number of methods. If this class is primitive, this holds the
368 // character used to represent this type in a signature.
370 // Number of methods in the vtable.
371 jshort vtable_method_count
;
374 // Size of instance fields, in bytes.
376 // Total number of fields (instance and static).
378 // Number of static fields.
379 jshort static_field_count
;
380 // The vtbl for all objects of this class.
382 // Interfaces implemented by this class.
384 // The class loader for this class.
385 java::lang::ClassLoader
*loader
;
386 // Number of interfaces.
387 jshort interface_count
;
388 // State of this class.
390 // The thread which has locked this class. Used during class
392 java::lang::Thread
*thread
;
393 // How many levels of "extends" this class is removed from Object.
395 // Vector of this class's superclasses, ordered by decreasing depth.
397 // Interface Dispatch Table.
398 _Jv_IDispatchTable
*idt
;
399 // Pointer to the class that represents an array of this class.
401 // Security Domain to which this class belongs (or null).
402 java::security::ProtectionDomain
*protectionDomain
;
405 #endif /* __JAVA_LANG_CLASS_H__ */