1 // Class.h - Header file for java.lang.Class. -*- c++ -*-
3 /* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 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>
23 #include <java/lang/Package.h>
24 #include <gnu/gcj/runtime/StackTrace.h>
26 // We declare these here to avoid including gcj/cni.h.
27 extern "C" void _Jv_InitClass (jclass klass);
28 extern "C" void _Jv_RegisterClasses (const jclass *classes);
29 extern "C" void _Jv_RegisterClasses_Counted (const jclass *classes,
32 // This must be predefined with "C" linkage.
33 extern "C" void *_Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface,
36 // These are the possible values for the `state' field of the class
37 // structure. Note that ordering is important here. Whenever the
38 // state changes, one should notify all waiters of this class.
41 JV_STATE_NOTHING = 0, // Set by compiler.
43 JV_STATE_PRELOADING = 1, // Can do _Jv_FindClass.
44 JV_STATE_LOADING = 3, // Has super installed.
45 JV_STATE_COMPILED = 5, // This was a compiled class.
47 JV_STATE_LOADED = 6, // Is complete.
48 JV_STATE_PREPARED = 7, // Layout & static init done.
49 JV_STATE_LINKED = 9, // Strings interned.
51 JV_STATE_IN_PROGRESS = 10, // <Clinit> running.
55 JV_STATE_DONE = 14 // Must be last.
61 struct _Jv_ArrayVTable;
75 _Jv_Utf8Const *signature;
78 // Method's index in the vtable.
80 // Pointer to underlying function.
82 // NULL-terminated list of exception class names; can be NULL if
83 // there are none such.
84 _Jv_Utf8Const **throws;
86 _Jv_Method *getNextMethod ()
90 // Interface Dispatch Tables
91 union _Jv_IDispatchTable
95 // Index into interface's ioffsets.
98 // Class Interface dispatch table.
104 // Offsets into implementation class itables.
109 // Used by _Jv_GetInterfaces ()
117 struct _Jv_MethodSymbol
119 _Jv_Utf8Const *class_name;
121 _Jv_Utf8Const *signature;
124 struct _Jv_OffsetTable
130 struct _Jv_AddressTable
136 struct _Jv_CatchClass
138 java::lang::Class **address;
139 _Jv_Utf8Const *classname;
142 #define JV_PRIMITIVE_VTABLE ((_Jv_VTable *) -1)
144 #define JV_CLASS(Obj) ((jclass) (*(_Jv_VTable **) Obj)->clas)
146 class java::lang::Class : public java::lang::Object
149 static jclass forName (jstring className, jboolean initialize,
150 java::lang::ClassLoader *loader);
151 static jclass forName (jstring className);
152 JArray<jclass> *getClasses (void);
154 java::lang::ClassLoader *getClassLoader (void);
156 // This is an internal method that circumvents the usual security
157 // checks when getting the class loader.
158 java::lang::ClassLoader *getClassLoaderInternal (void)
163 java::lang::reflect::Constructor *getConstructor (JArray<jclass> *);
164 JArray<java::lang::reflect::Constructor *> *getConstructors (void);
165 java::lang::reflect::Constructor *getDeclaredConstructor (JArray<jclass> *);
166 JArray<java::lang::reflect::Constructor *> *getDeclaredConstructors (void);
167 java::lang::reflect::Field *getDeclaredField (jstring);
168 JArray<java::lang::reflect::Field *> *getDeclaredFields ();
169 JArray<java::lang::reflect::Field *> *getDeclaredFields (jboolean);
170 java::lang::reflect::Method *getDeclaredMethod (jstring, JArray<jclass> *);
171 JArray<java::lang::reflect::Method *> *getDeclaredMethods (void);
173 JArray<jclass> *getDeclaredClasses (void);
174 jclass getDeclaringClass (void);
176 java::lang::reflect::Field *getField (jstring);
178 JArray<java::lang::reflect::Field *> internalGetFields ();
179 JArray<java::lang::reflect::Constructor *> *_getConstructors (jboolean);
180 java::lang::reflect::Field *getField (jstring, jint);
181 jint _getMethods (JArray<java::lang::reflect::Method *> *result,
183 java::lang::reflect::Field *getPrivateField (jstring);
184 java::lang::reflect::Method *getPrivateMethod (jstring, JArray<jclass> *);
185 java::security::ProtectionDomain *getProtectionDomain0 ();
187 java::lang::reflect::Method *_getMethod (jstring, JArray<jclass> *);
188 java::lang::reflect::Method *_getDeclaredMethod (jstring, JArray<jclass> *);
191 JArray<java::lang::reflect::Field *> *getFields (void);
193 JArray<jclass> *getInterfaces (void);
195 void getSignature (java::lang::StringBuffer *buffer);
196 static jstring getSignature (JArray<jclass> *, jboolean is_constructor);
197 JArray<java::lang::reflect::Method *> *getMethods (void);
199 inline jint getModifiers (void)
201 return accflags & java::lang::reflect::Modifier::ALL_FLAGS;
204 jstring getName (void);
206 java::net::URL *getResource (jstring resourceName);
207 java::io::InputStream *getResourceAsStream (jstring resourceName);
208 JArray<jobject> *getSigners (void);
209 void setSigners(JArray<jobject> *);
211 inline jclass getSuperclass (void)
216 inline jboolean isArray (void)
218 return name->first() == '[';
221 inline jclass getComponentType (void)
223 return isArray () ? (* (jclass *) &methods) : 0;
226 jboolean isAssignableFrom (jclass cls);
227 jboolean isInstance (jobject obj);
229 inline jboolean isInterface (void)
231 return (accflags & java::lang::reflect::Modifier::INTERFACE) != 0;
234 inline jboolean isPrimitive (void)
236 return vtable == JV_PRIMITIVE_VTABLE;
239 jobject newInstance (void);
240 java::security::ProtectionDomain *getProtectionDomain (void);
241 java::lang::Package *getPackage (void);
242 jstring toString (void);
243 jboolean desiredAssertionStatus (void);
245 // FIXME: this probably shouldn't be public.
248 return size_in_bytes;
254 // This constructor is used to create Class object for the primitive
255 // types. See prims.cc.
258 static java::lang::Class class$;
262 void memberAccessCheck (jint flags);
264 void initializeClass (void);
266 static jstring getPackagePortion (jstring);
268 // Friend functions implemented in natClass.cc.
269 friend _Jv_Method *_Jv_GetMethodLocal (jclass klass, _Jv_Utf8Const *name,
270 _Jv_Utf8Const *signature);
271 friend jboolean _Jv_IsAssignableFrom(jclass, jclass);
272 friend jboolean _Jv_InterfaceAssignableFrom (jclass, jclass);
273 friend void *_Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface,
277 _Jv_InitClass (jclass klass)
279 if (__builtin_expect (klass->state == JV_STATE_DONE, true))
281 klass->initializeClass ();
284 friend _Jv_Method* _Jv_LookupDeclaredMethod (jclass, _Jv_Utf8Const *,
286 friend jfieldID JvGetFirstInstanceField (jclass);
287 friend jint JvNumInstanceFields (jclass);
288 friend jfieldID JvGetFirstStaticField (jclass);
289 friend jint JvNumStaticFields (jclass);
291 friend jobject _Jv_AllocObject (jclass);
292 friend void *_Jv_AllocObj (jint, jclass);
293 friend void *_Jv_AllocPtrFreeObj (jint, jclass);
294 friend void *_Jv_AllocArray (jint, jclass);
296 friend jobject _Jv_JNI_ToReflectedField (_Jv_JNIEnv *, jclass, jfieldID,
298 friend jobject _Jv_JNI_ToReflectedMethod (_Jv_JNIEnv *, jclass, jmethodID,
300 friend jfieldID _Jv_FromReflectedField (java::lang::reflect::Field *);
302 friend jmethodID _Jv_FromReflectedMethod (java::lang::reflect::Method *);
303 friend jmethodID _Jv_FromReflectedConstructor (java::lang::reflect::Constructor *);
304 friend jint JvNumMethods (jclass);
305 friend jmethodID JvGetFirstMethod (jclass);
307 // Friends classes and functions to implement the ClassLoader
308 friend class java::lang::ClassLoader;
309 friend class java::lang::VMClassLoader;
311 friend class java::io::ObjectOutputStream;
312 friend class java::io::ObjectInputStream;
313 friend class java::io::ObjectStreamClass;
315 friend void _Jv_WaitForState (jclass, int);
316 friend void _Jv_RegisterClasses (const jclass *classes);
317 friend void _Jv_RegisterClasses_Counted (const jclass *classes,
319 friend void _Jv_RegisterClassHookDefault (jclass klass);
320 friend void _Jv_RegisterInitiatingLoader (jclass,java::lang::ClassLoader*);
321 friend void _Jv_UnregisterClass (jclass);
322 friend jclass _Jv_FindClass (_Jv_Utf8Const *name,
323 java::lang::ClassLoader *loader);
324 friend jclass _Jv_FindClassInCache (_Jv_Utf8Const *name,
325 java::lang::ClassLoader *loader);
326 friend jclass _Jv_PopClass (void);
327 friend void _Jv_PushClass (jclass k);
328 friend void _Jv_NewArrayClass (jclass element,
329 java::lang::ClassLoader *loader,
330 _Jv_VTable *array_vtable = 0);
331 friend jclass _Jv_NewClass (_Jv_Utf8Const *name, jclass superclass,
332 java::lang::ClassLoader *loader);
333 friend void _Jv_InitNewClassFields (jclass klass);
336 friend void _Jv_InitPrimClass (jclass, char *, char, int);
338 friend void _Jv_PrepareCompiledClass (jclass);
339 friend void _Jv_PrepareConstantTimeTables (jclass);
340 friend jshort _Jv_GetInterfaces (jclass, _Jv_ifaces *);
341 friend void _Jv_GenerateITable (jclass, _Jv_ifaces *, jshort *);
342 friend jstring _Jv_GetMethodString(jclass, _Jv_Utf8Const *);
343 friend jshort _Jv_AppendPartialITable (jclass, jclass, void **, jshort);
344 friend jshort _Jv_FindIIndex (jclass *, jshort *, jshort);
345 friend void _Jv_LinkSymbolTable (jclass);
346 friend void _Jv_LayoutInterfaceMethods (jclass);
347 friend void _Jv_LayoutVTableMethods (jclass klass);
348 friend void _Jv_SetVTableEntries (jclass, _Jv_VTable *, jboolean *);
349 friend void _Jv_MakeVTable (jclass);
350 friend void _Jv_linkExceptionClassTable (jclass);
352 friend jboolean _Jv_CheckAccess (jclass self_klass, jclass other_klass,
355 // Return array class corresponding to element type KLASS, creating it if
358 _Jv_GetArrayClass (jclass klass, java::lang::ClassLoader *loader)
360 extern void _Jv_NewArrayClass (jclass element,
361 java::lang::ClassLoader *loader,
362 _Jv_VTable *array_vtable = 0);
363 if (__builtin_expect (!klass->arrayclass, false))
364 _Jv_NewArrayClass (klass, loader);
365 return klass->arrayclass;
369 friend jboolean _Jv_IsInterpretedClass (jclass);
370 friend void _Jv_InitField (jobject, jclass, _Jv_Field*);
371 friend void _Jv_InitField (jobject, jclass, int);
372 friend _Jv_word _Jv_ResolvePoolEntry (jclass, int);
373 friend _Jv_Method *_Jv_SearchMethodInClass (jclass cls, jclass klass,
374 _Jv_Utf8Const *method_name,
375 _Jv_Utf8Const *method_signature);
377 friend void _Jv_PrepareClass (jclass);
378 friend void _Jv_PrepareMissingMethods (jclass base, jclass iface_class);
380 friend void _Jv_Defer_Resolution (void *cl, _Jv_Method *meth, void **);
382 friend class _Jv_ClassReader;
383 friend class _Jv_InterpClass;
384 friend class _Jv_InterpMethod;
387 #ifdef JV_MARKOBJ_DECL
388 friend JV_MARKOBJ_DECL;
391 friend class _Jv_BytecodeVerifier;
392 friend class _Jv_StackTrace;
393 friend class gnu::gcj::runtime::StackTrace;
394 friend class java::io::VMObjectStreamClass;
396 friend void _Jv_sharedlib_register_hook (jclass klass);
398 // Chain for class pool.
402 // Access flags for class.
404 // The superclass, or null for Object.
407 _Jv_Constants constants;
408 // Methods. If this is an array class, then this field holds a
409 // pointer to the element type.
411 // Number of methods. If this class is primitive, this holds the
412 // character used to represent this type in a signature.
414 // Number of methods in the vtable.
415 jshort vtable_method_count;
418 // Size of instance fields, in bytes.
420 // Total number of fields (instance and static).
422 // Number of static fields.
423 jshort static_field_count;
424 // The vtbl for all objects of this class.
426 // Virtual method offset table.
427 _Jv_OffsetTable *otable;
428 // Offset table symbols.
429 _Jv_MethodSymbol *otable_syms;
430 _Jv_AddressTable *atable;
431 _Jv_MethodSymbol *atable_syms;
432 _Jv_CatchClass *catch_classes;
433 // Interfaces implemented by this class.
435 // The class loader for this class.
436 java::lang::ClassLoader *loader;
437 // Number of interfaces.
438 jshort interface_count;
439 // State of this class.
441 // The thread which has locked this class. Used during class
443 java::lang::Thread *thread;
444 // How many levels of "extends" this class is removed from Object.
446 // Vector of this class's superclasses, ordered by decreasing depth.
448 // Interface Dispatch Table.
449 _Jv_IDispatchTable *idt;
450 // Pointer to the class that represents an array of this class.
452 // Security Domain to which this class belongs (or null).
453 java::security::ProtectionDomain *protectionDomain;
454 // Signers of this class (or null).
455 JArray<jobject> *hack_signers;
456 // Used by Jv_PopClass and _Jv_PushClass to communicate with StackTrace.
458 // Additional data, specific to the generator (JIT, native, interpreter) of this
463 #endif /* __JAVA_LANG_CLASS_H__ */