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>
23 #include <gnu/gcj/runtime/StackTrace.h>
25 // We declare these here to avoid including gcj/cni.h.
26 extern "C" void _Jv_InitClass (jclass klass);
27 extern "C" void _Jv_RegisterClasses (jclass *classes);
29 // This must be predefined with "C" linkage.
30 extern "C" void *_Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface,
33 // These are the possible values for the `state' field of the class
34 // structure. Note that ordering is important here. Whenever the
35 // state changes, one should notify all waiters of this class.
38 JV_STATE_NOTHING = 0, // Set by compiler.
40 JV_STATE_PRELOADING = 1, // Can do _Jv_FindClass.
41 JV_STATE_LOADING = 3, // Has super installed.
42 JV_STATE_LOADED = 5, // Is complete.
44 JV_STATE_COMPILED = 6, // This was a compiled class.
46 JV_STATE_PREPARED = 7, // Layout & static init done.
47 JV_STATE_LINKED = 9, // Strings interned.
49 JV_STATE_IN_PROGRESS = 10, // <Clinit> running.
53 JV_STATE_DONE = 14 // Must be last.
59 struct _Jv_ArrayVTable;
73 _Jv_Utf8Const *signature;
76 // Method's index in the vtable.
78 // Pointer to underlying function.
80 // NULL-terminated list of exception class names; can be NULL if
81 // there are none such.
82 _Jv_Utf8Const **throws;
84 _Jv_Method *getNextMethod ()
88 // Interface Dispatch Tables
89 union _Jv_IDispatchTable
93 // Index into interface's ioffsets.
96 // Class Interface dispatch table.
102 // Offsets into implementation class itables.
107 // Used by _Jv_GetInterfaces ()
115 struct _Jv_MethodSymbol
117 _Jv_Utf8Const *class_name;
119 _Jv_Utf8Const *signature;
122 struct _Jv_OffsetTable
128 #define JV_PRIMITIVE_VTABLE ((_Jv_VTable *) -1)
130 #define JV_CLASS(Obj) ((jclass) (*(_Jv_VTable **) Obj)->clas)
132 class java::lang::Class : public java::lang::Object
135 static jclass forName (jstring className, jboolean initialize,
136 java::lang::ClassLoader *loader);
137 static jclass forName (jstring className);
138 JArray<jclass> *getClasses (void);
140 java::lang::ClassLoader *getClassLoader (void);
142 // This is an internal method that circumvents the usual security
143 // checks when getting the class loader.
144 java::lang::ClassLoader *getClassLoaderInternal (void)
149 java::lang::reflect::Constructor *getConstructor (JArray<jclass> *);
150 JArray<java::lang::reflect::Constructor *> *getConstructors (void);
151 java::lang::reflect::Constructor *getDeclaredConstructor (JArray<jclass> *);
152 JArray<java::lang::reflect::Constructor *> *getDeclaredConstructors (void);
153 java::lang::reflect::Field *getDeclaredField (jstring);
154 JArray<java::lang::reflect::Field *> *getDeclaredFields (void);
155 java::lang::reflect::Method *getDeclaredMethod (jstring, JArray<jclass> *);
156 JArray<java::lang::reflect::Method *> *getDeclaredMethods (void);
158 JArray<jclass> *getDeclaredClasses (void);
159 jclass getDeclaringClass (void);
161 java::lang::reflect::Field *getField (jstring);
163 jint _getFields (JArray<java::lang::reflect::Field *> *result, jint offset);
164 JArray<java::lang::reflect::Constructor *> *_getConstructors (jboolean);
165 java::lang::reflect::Field *getField (jstring, jint);
166 jint _getMethods (JArray<java::lang::reflect::Method *> *result,
168 java::lang::reflect::Field *getPrivateField (jstring);
169 java::lang::reflect::Method *getPrivateMethod (jstring, JArray<jclass> *);
170 java::security::ProtectionDomain *getProtectionDomain0 ();
172 java::lang::reflect::Method *_getMethod (jstring, JArray<jclass> *);
173 java::lang::reflect::Method *_getDeclaredMethod (jstring, JArray<jclass> *);
176 JArray<java::lang::reflect::Field *> *getFields (void);
178 JArray<jclass> *getInterfaces (void);
180 void getSignature (java::lang::StringBuffer *buffer);
181 static jstring getSignature (JArray<jclass> *, jboolean is_constructor);
182 JArray<java::lang::reflect::Method *> *getMethods (void);
184 inline jint getModifiers (void)
186 return accflags & java::lang::reflect::Modifier::ALL_FLAGS;
189 jstring getName (void);
191 java::net::URL *getResource (jstring resourceName);
192 java::io::InputStream *getResourceAsStream (jstring resourceName);
193 JArray<jobject> *getSigners (void);
195 inline jclass getSuperclass (void)
200 inline jboolean isArray (void)
202 return name->data[0] == '[';
205 inline jclass getComponentType (void)
207 return isArray () ? (* (jclass *) &methods) : 0;
210 jboolean isAssignableFrom (jclass cls);
211 jboolean isInstance (jobject obj);
213 inline jboolean isInterface (void)
215 return (accflags & java::lang::reflect::Modifier::INTERFACE) != 0;
218 inline jboolean isPrimitive (void)
220 return vtable == JV_PRIMITIVE_VTABLE;
223 jobject newInstance (void);
224 java::security::ProtectionDomain *getProtectionDomain (void);
225 java::lang::Package *getPackage (void);
226 jstring toString (void);
227 jboolean desiredAssertionStatus (void);
229 // FIXME: this probably shouldn't be public.
232 return size_in_bytes;
238 // This constructor is used to create Class object for the primitive
239 // types. See prims.cc.
242 static java::lang::Class class$;
246 void checkMemberAccess (jint flags);
248 void initializeClass (void);
250 static jstring getPackagePortion (jstring);
252 // Friend functions implemented in natClass.cc.
253 friend _Jv_Method *_Jv_GetMethodLocal (jclass klass, _Jv_Utf8Const *name,
254 _Jv_Utf8Const *signature);
255 friend jboolean _Jv_IsAssignableFrom(jclass, jclass);
256 friend jboolean _Jv_InterfaceAssignableFrom (jclass, jclass);
257 friend void *_Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface,
261 _Jv_InitClass (jclass klass)
263 if (__builtin_expect (klass->state == JV_STATE_DONE, true))
265 klass->initializeClass ();
268 friend _Jv_Method* _Jv_LookupDeclaredMethod (jclass, _Jv_Utf8Const *,
270 friend jfieldID JvGetFirstInstanceField (jclass);
271 friend jint JvNumInstanceFields (jclass);
272 friend jfieldID JvGetFirstStaticField (jclass);
273 friend jint JvNumStaticFields (jclass);
275 friend jobject _Jv_AllocObject (jclass, jint);
276 friend void *_Jv_AllocObj (jint, jclass);
277 friend void *_Jv_AllocPtrFreeObj (jint, jclass);
278 friend void *_Jv_AllocArray (jint, jclass);
280 friend jobject _Jv_JNI_ToReflectedField (_Jv_JNIEnv *, jclass, jfieldID,
282 friend jobject _Jv_JNI_ToReflectedMethod (_Jv_JNIEnv *, jclass, jmethodID,
284 friend jfieldID _Jv_FromReflectedField (java::lang::reflect::Field *);
286 friend jmethodID _Jv_FromReflectedMethod (java::lang::reflect::Method *);
287 friend jmethodID _Jv_FromReflectedConstructor (java::lang::reflect::Constructor *);
288 friend jint JvNumMethods (jclass);
289 friend jmethodID JvGetFirstMethod (jclass);
291 // Friends classes and functions to implement the ClassLoader
292 friend class java::lang::ClassLoader;
294 friend class java::io::ObjectOutputStream;
295 friend class java::io::ObjectInputStream;
296 friend class java::io::ObjectStreamClass;
298 friend void _Jv_WaitForState (jclass, int);
299 friend void _Jv_RegisterClasses (jclass *classes);
300 friend void _Jv_RegisterClassHookDefault (jclass klass);
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 jclass _Jv_PopClass (void);
308 friend void _Jv_PushClass (jclass k);
309 friend void _Jv_NewArrayClass (jclass element,
310 java::lang::ClassLoader *loader,
311 _Jv_VTable *array_vtable = 0);
312 friend jclass _Jv_NewClass (_Jv_Utf8Const *name, jclass superclass,
313 java::lang::ClassLoader *loader);
314 friend void _Jv_InitNewClassFields (jclass klass);
317 friend void _Jv_InitPrimClass (jclass, char *, char, int, _Jv_ArrayVTable *);
319 friend void _Jv_PrepareCompiledClass (jclass);
320 friend void _Jv_PrepareConstantTimeTables (jclass);
321 friend jshort _Jv_GetInterfaces (jclass, _Jv_ifaces *);
322 friend void _Jv_GenerateITable (jclass, _Jv_ifaces *, jshort *);
323 friend jstring _Jv_GetMethodString(jclass, _Jv_Utf8Const *);
324 friend jshort _Jv_AppendPartialITable (jclass, jclass, void **, jshort);
325 friend jshort _Jv_FindIIndex (jclass *, jshort *, jshort);
326 friend void _Jv_LinkOffsetTable (jclass);
327 friend void _Jv_LayoutVTableMethods (jclass klass);
328 friend void _Jv_SetVTableEntries (jclass, _Jv_VTable *, jboolean *);
329 friend void _Jv_MakeVTable (jclass);
331 // Return array class corresponding to element type KLASS, creating it if
334 _Jv_GetArrayClass (jclass klass, java::lang::ClassLoader *loader)
336 if (__builtin_expect (!klass->arrayclass, false))
337 _Jv_NewArrayClass (klass, loader);
338 return klass->arrayclass;
342 friend jboolean _Jv_IsInterpretedClass (jclass);
343 friend void _Jv_InitField (jobject, jclass, _Jv_Field*);
344 friend void _Jv_InitField (jobject, jclass, int);
345 friend _Jv_word _Jv_ResolvePoolEntry (jclass, int);
346 friend _Jv_Method *_Jv_SearchMethodInClass (jclass cls, jclass klass,
347 _Jv_Utf8Const *method_name,
348 _Jv_Utf8Const *method_signature);
350 friend void _Jv_PrepareClass (jclass);
351 friend void _Jv_PrepareMissingMethods (jclass base, jclass iface_class);
353 friend class _Jv_ClassReader;
354 friend class _Jv_InterpClass;
355 friend class _Jv_InterpMethod;
358 #ifdef JV_MARKOBJ_DECL
359 friend JV_MARKOBJ_DECL;
362 friend class _Jv_BytecodeVerifier;
363 friend class gnu::gcj::runtime::StackTrace;
365 // Chain for class pool.
369 // Access flags for class.
371 // The superclass, or null for Object.
374 _Jv_Constants constants;
375 // Methods. If this is an array class, then this field holds a
376 // pointer to the element type.
378 // Number of methods. If this class is primitive, this holds the
379 // character used to represent this type in a signature.
381 // Number of methods in the vtable.
382 jshort vtable_method_count;
385 // Size of instance fields, in bytes.
387 // Total number of fields (instance and static).
389 // Number of static fields.
390 jshort static_field_count;
391 // The vtbl for all objects of this class.
393 // Virtual method offset table.
394 _Jv_OffsetTable *otable;
395 // Offset table symbols.
396 _Jv_MethodSymbol *otable_syms;
397 // Interfaces implemented by this class.
399 // The class loader for this class.
400 java::lang::ClassLoader *loader;
401 // Number of interfaces.
402 jshort interface_count;
403 // State of this class.
405 // The thread which has locked this class. Used during class
407 java::lang::Thread *thread;
408 // How many levels of "extends" this class is removed from Object.
410 // Vector of this class's superclasses, ordered by decreasing depth.
412 // Interface Dispatch Table.
413 _Jv_IDispatchTable *idt;
414 // Pointer to the class that represents an array of this class.
416 // Security Domain to which this class belongs (or null).
417 java::security::ProtectionDomain *protectionDomain;
418 // Used by Jv_PopClass and _Jv_PushClass to communicate with StackTrace.
422 #endif /* __JAVA_LANG_CLASS_H__ */