1 // Class.h - Header file for java.lang.Class. -*- c++ -*-
3 /* Copyright (C) 1998, 1999, 2000, 2001, 2002 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>
20 #include <java/lang/reflect/Modifier.h>
21 #include <java/security/ProtectionDomain.h>
22 #include <java/lang/Package.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.
57 struct _Jv_ArrayVTable;
71 _Jv_Utf8Const *signature;
74 // Method's index in the vtable.
76 // Pointer to underlying function.
78 // NULL-terminated list of exception class names; can be NULL if
79 // there are none such.
80 _Jv_Utf8Const **throws;
82 _Jv_Method *getNextMethod ()
86 // Interface Dispatch Tables
87 union _Jv_IDispatchTable
91 // Index into interface's ioffsets.
94 // Class Interface dispatch table.
100 // Offsets into implementation class itables.
105 // Used by _Jv_GetInterfaces ()
113 struct _Jv_MethodSymbol
115 _Jv_Utf8Const *class_name;
117 _Jv_Utf8Const *signature;
120 struct _Jv_OffsetTable
126 #define JV_PRIMITIVE_VTABLE ((_Jv_VTable *) -1)
128 #define JV_CLASS(Obj) ((jclass) (*(_Jv_VTable **) Obj)->clas)
130 class java::lang::Class : public java::lang::Object
133 static jclass forName (jstring className, jboolean initialize,
134 java::lang::ClassLoader *loader);
135 static jclass forName (jstring className);
136 JArray<jclass> *getClasses (void);
138 java::lang::ClassLoader *getClassLoader (void);
140 java::lang::reflect::Constructor *getConstructor (JArray<jclass> *);
141 JArray<java::lang::reflect::Constructor *> *getConstructors (void);
142 java::lang::reflect::Constructor *getDeclaredConstructor (JArray<jclass> *);
143 JArray<java::lang::reflect::Constructor *> *getDeclaredConstructors (void);
144 java::lang::reflect::Field *getDeclaredField (jstring);
145 JArray<java::lang::reflect::Field *> *getDeclaredFields (void);
146 java::lang::reflect::Method *getDeclaredMethod (jstring, JArray<jclass> *);
147 JArray<java::lang::reflect::Method *> *getDeclaredMethods (void);
149 JArray<jclass> *getDeclaredClasses (void);
150 jclass getDeclaringClass (void);
152 java::lang::reflect::Field *getField (jstring);
154 jint _getFields (JArray<java::lang::reflect::Field *> *result, jint offset);
155 JArray<java::lang::reflect::Constructor *> *_getConstructors (jboolean);
156 java::lang::reflect::Field *getField (jstring, jint);
157 jint _getMethods (JArray<java::lang::reflect::Method *> *result,
159 java::lang::reflect::Field *getPrivateField (jstring);
160 java::lang::reflect::Method *getPrivateMethod (jstring, JArray<jclass> *);
161 java::security::ProtectionDomain *getProtectionDomain0 ();
163 java::lang::reflect::Method *_getMethod (jstring, JArray<jclass> *);
164 java::lang::reflect::Method *_getDeclaredMethod (jstring, JArray<jclass> *);
167 JArray<java::lang::reflect::Field *> *getFields (void);
169 JArray<jclass> *getInterfaces (void);
171 void getSignature (java::lang::StringBuffer *buffer);
172 static jstring getSignature (JArray<jclass> *, jboolean is_constructor);
173 JArray<java::lang::reflect::Method *> *getMethods (void);
175 inline jint getModifiers (void)
180 jstring getName (void);
182 java::net::URL *getResource (jstring resourceName);
183 java::io::InputStream *getResourceAsStream (jstring resourceName);
184 JArray<jobject> *getSigners (void);
186 inline jclass getSuperclass (void)
191 inline jboolean isArray (void)
193 return name->data[0] == '[';
196 inline jclass getComponentType (void)
198 return isArray () ? (* (jclass *) &methods) : 0;
201 jboolean isAssignableFrom (jclass cls);
202 jboolean isInstance (jobject obj);
204 inline jboolean isInterface (void)
206 return (accflags & java::lang::reflect::Modifier::INTERFACE) != 0;
209 inline jboolean isPrimitive (void)
211 return vtable == JV_PRIMITIVE_VTABLE;
214 jobject newInstance (void);
215 java::security::ProtectionDomain *getProtectionDomain (void);
216 java::lang::Package *getPackage (void);
217 jstring toString (void);
218 jboolean desiredAssertionStatus (void);
220 // FIXME: this probably shouldn't be public.
223 return size_in_bytes;
229 // This constructor is used to create Class object for the primitive
230 // types. See prims.cc.
233 static java::lang::Class class$;
237 void checkMemberAccess (jint flags);
239 void initializeClass (void);
241 static jstring getPackagePortion (jstring);
243 // Friend functions implemented in natClass.cc.
244 friend _Jv_Method *_Jv_GetMethodLocal (jclass klass, _Jv_Utf8Const *name,
245 _Jv_Utf8Const *signature);
246 friend jboolean _Jv_IsAssignableFrom(jclass, jclass);
247 friend jboolean _Jv_InterfaceAssignableFrom (jclass, jclass);
248 friend void *_Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface,
252 _Jv_InitClass (jclass klass)
254 if (__builtin_expect (klass->state == JV_STATE_DONE, true))
256 klass->initializeClass ();
259 friend _Jv_Method* _Jv_LookupDeclaredMethod (jclass, _Jv_Utf8Const *,
261 friend jfieldID JvGetFirstInstanceField (jclass);
262 friend jint JvNumInstanceFields (jclass);
263 friend jfieldID JvGetFirstStaticField (jclass);
264 friend jint JvNumStaticFields (jclass);
266 friend jobject _Jv_AllocObject (jclass, jint);
267 friend void *_Jv_AllocObj (jint, jclass);
268 friend void *_Jv_AllocPtrFreeObj (jint, jclass);
269 friend void *_Jv_AllocArray (jint, jclass);
271 friend jobject _Jv_JNI_ToReflectedField (_Jv_JNIEnv *, jclass, jfieldID,
273 friend jobject _Jv_JNI_ToReflectedMethod (_Jv_JNIEnv *, jclass, jmethodID,
275 friend jfieldID _Jv_FromReflectedField (java::lang::reflect::Field *);
277 friend jmethodID _Jv_FromReflectedMethod (java::lang::reflect::Method *);
278 friend jmethodID _Jv_FromReflectedConstructor (java::lang::reflect::Constructor *);
279 friend jint JvNumMethods (jclass);
280 friend jmethodID JvGetFirstMethod (jclass);
282 // Friends classes and functions to implement the ClassLoader
283 friend class java::lang::ClassLoader;
285 friend class java::io::ObjectOutputStream;
286 friend class java::io::ObjectInputStream;
287 friend class java::io::ObjectStreamClass;
289 friend void _Jv_WaitForState (jclass, int);
290 friend void _Jv_RegisterClasses (jclass *classes);
291 friend void _Jv_RegisterClassHookDefault (jclass klass);
292 friend void _Jv_RegisterInitiatingLoader (jclass,java::lang::ClassLoader*);
293 friend void _Jv_UnregisterClass (jclass);
294 friend jclass _Jv_FindClass (_Jv_Utf8Const *name,
295 java::lang::ClassLoader *loader);
296 friend jclass _Jv_FindClassInCache (_Jv_Utf8Const *name,
297 java::lang::ClassLoader *loader);
298 friend void _Jv_NewArrayClass (jclass element,
299 java::lang::ClassLoader *loader,
300 _Jv_VTable *array_vtable = 0);
301 friend jclass _Jv_NewClass (_Jv_Utf8Const *name, jclass superclass,
302 java::lang::ClassLoader *loader);
303 friend void _Jv_InitNewClassFields (jclass klass);
306 friend void _Jv_InitPrimClass (jclass, char *, char, int, _Jv_ArrayVTable *);
308 friend void _Jv_PrepareCompiledClass (jclass);
309 friend void _Jv_PrepareConstantTimeTables (jclass);
310 friend jshort _Jv_GetInterfaces (jclass, _Jv_ifaces *);
311 friend void _Jv_GenerateITable (jclass, _Jv_ifaces *, jshort *);
312 friend jstring _Jv_GetMethodString(jclass, _Jv_Utf8Const *);
313 friend jshort _Jv_AppendPartialITable (jclass, jclass, void **, jshort);
314 friend jshort _Jv_FindIIndex (jclass *, jshort *, jshort);
315 friend void _Jv_LinkOffsetTable (jclass);
316 friend void _Jv_LayoutVTableMethods (jclass klass);
317 friend void _Jv_SetVTableEntries (jclass, _Jv_VTable *);
318 friend void _Jv_MakeVTable (jclass);
320 // Return array class corresponding to element type KLASS, creating it if
323 _Jv_GetArrayClass (jclass klass, java::lang::ClassLoader *loader)
325 if (__builtin_expect (!klass->arrayclass, false))
326 _Jv_NewArrayClass (klass, loader);
327 return klass->arrayclass;
331 friend jboolean _Jv_IsInterpretedClass (jclass);
332 friend void _Jv_InitField (jobject, jclass, _Jv_Field*);
333 friend int _Jv_DetermineVTableIndex (jclass, _Jv_Utf8Const *,
335 friend void _Jv_InitField (jobject, jclass, int);
336 friend _Jv_word _Jv_ResolvePoolEntry (jclass, int);
337 friend _Jv_Method *_Jv_SearchMethodInClass (jclass cls, jclass klass,
338 _Jv_Utf8Const *method_name,
339 _Jv_Utf8Const *method_signature);
341 friend void _Jv_PrepareClass (jclass);
343 friend class _Jv_ClassReader;
344 friend class _Jv_InterpClass;
345 friend class _Jv_InterpMethod;
348 #ifdef JV_MARKOBJ_DECL
349 friend JV_MARKOBJ_DECL;
352 friend class _Jv_BytecodeVerifier;
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 // Virtual method offset table.
383 _Jv_OffsetTable *otable;
384 // Offset table symbols.
385 _Jv_MethodSymbol *otable_syms;
386 // Interfaces implemented by this class.
388 // The class loader for this class.
389 java::lang::ClassLoader *loader;
390 // Number of interfaces.
391 jshort interface_count;
392 // State of this class.
394 // The thread which has locked this class. Used during class
396 java::lang::Thread *thread;
397 // How many levels of "extends" this class is removed from Object.
399 // Vector of this class's superclasses, ordered by decreasing depth.
401 // Interface Dispatch Table.
402 _Jv_IDispatchTable *idt;
403 // Pointer to the class that represents an array of this class.
405 // Security Domain to which this class belongs (or null).
406 java::security::ProtectionDomain *protectionDomain;
409 #endif /* __JAVA_LANG_CLASS_H__ */