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__
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>
23 // We declare these here to avoid including gcj/cni.h.
24 extern "C" void _Jv_InitClass (jclass klass);
25 extern "C" void _Jv_RegisterClasses (jclass *classes);
27 // This must be predefined with "C" linkage.
28 extern "C" void *_Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface,
31 // These are the possible values for the `state' field of the class
32 // structure. Note that ordering is important here. Whenever the
33 // state changes, one should notify all waiters of this class.
36 JV_STATE_NOTHING = 0, // Set by compiler.
38 JV_STATE_PRELOADING = 1, // Can do _Jv_FindClass.
39 JV_STATE_LOADING = 3, // Has super installed.
40 JV_STATE_LOADED = 5, // Is complete.
42 JV_STATE_COMPILED = 6, // This was a compiled class.
44 JV_STATE_PREPARED = 7, // Layout & static init done.
45 JV_STATE_LINKED = 9, // Strings interned.
47 JV_STATE_IN_PROGRESS = 10, // <Clinit> running.
48 JV_STATE_DONE = 12, //
50 JV_STATE_ERROR = 14 // must be last.
56 struct _Jv_ArrayVTable;
70 _Jv_Utf8Const *signature;
73 // Method's index in the vtable.
75 // Pointer to underlying function.
77 // NULL-terminated list of exception class names; can be NULL if
78 // there are none such.
79 _Jv_Utf8Const **throws;
81 _Jv_Method *getNextMethod ()
85 // Interface Dispatch Tables
86 union _Jv_IDispatchTable
90 // Index into interface's ioffsets.
93 // Class Interface dispatch table.
99 // Offsets into implementation class itables.
104 // Used by _Jv_GetInterfaces ()
112 // Used for vtable pointer manipulation.
119 struct _Jv_MethodSymbol
121 _Jv_Utf8Const *class_name;
123 _Jv_Utf8Const *signature;
126 struct _Jv_OffsetTable
132 #define JV_PRIMITIVE_VTABLE ((_Jv_VTable *) -1)
134 #define JV_CLASS(Obj) ((jclass) (*(_Jv_VTable **) Obj)->clas)
136 class java::lang::Class : public java::lang::Object
139 static jclass forName (jstring className, jboolean initialize,
140 java::lang::ClassLoader *loader);
141 static jclass forName (jstring className);
142 JArray<jclass> *getClasses (void);
144 java::lang::ClassLoader *getClassLoader (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 ();
173 JArray<java::lang::reflect::Field *> *getFields (void);
175 JArray<jclass> *getInterfaces (void);
177 void getSignature (java::lang::StringBuffer *buffer);
178 static jstring getSignature (JArray<jclass> *, jboolean is_constructor);
179 java::lang::reflect::Method *getMethod (jstring, JArray<jclass> *);
180 JArray<java::lang::reflect::Method *> *getMethods (void);
182 inline jint getModifiers (void)
187 jstring getName (void);
189 java::net::URL *getResource (jstring resourceName);
190 java::io::InputStream *getResourceAsStream (jstring resourceName);
191 JArray<jobject> *getSigners (void);
193 inline jclass getSuperclass (void)
198 inline jboolean isArray (void)
200 return name->data[0] == '[';
203 inline jclass getComponentType (void)
205 return isArray () ? (* (jclass *) &methods) : 0;
208 jboolean isAssignableFrom (jclass cls);
209 jboolean isInstance (jobject obj);
211 inline jboolean isInterface (void)
213 return (accflags & java::lang::reflect::Modifier::INTERFACE) != 0;
216 inline jboolean isPrimitive (void)
218 return vtable == JV_PRIMITIVE_VTABLE;
221 jobject newInstance (void);
222 jstring toString (void);
224 // FIXME: this probably shouldn't be public.
227 return size_in_bytes;
233 // This constructor is used to create Class object for the primitive
234 // types. See prims.cc.
237 // C++ ctors set the vtbl pointer to point at an offset inside the vtable
238 // object. That doesn't work for Java, so this hack adjusts it back.
239 ((_Jv_Self *)this)->vtable_ptr -= 2 * sizeof (void *);
242 static java::lang::Class class$;
246 void checkMemberAccess (jint flags);
248 void initializeClass (void);
250 // Friend functions implemented in natClass.cc.
251 friend _Jv_Method *_Jv_GetMethodLocal (jclass klass, _Jv_Utf8Const *name,
252 _Jv_Utf8Const *signature);
253 friend jboolean _Jv_IsAssignableFrom(jclass, jclass);
254 friend jboolean _Jv_InterfaceAssignableFrom (jclass, jclass);
255 friend void *_Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface,
259 _Jv_InitClass (jclass klass)
261 if (__builtin_expect (klass->state == JV_STATE_DONE, true))
263 klass->initializeClass ();
266 friend _Jv_Method* _Jv_LookupDeclaredMethod (jclass, _Jv_Utf8Const *,
268 friend jfieldID JvGetFirstInstanceField (jclass);
269 friend jint JvNumInstanceFields (jclass);
270 friend jfieldID JvGetFirstStaticField (jclass);
271 friend jint JvNumStaticFields (jclass);
273 friend jobject _Jv_AllocObject (jclass, jint);
274 friend void *_Jv_AllocObj (jint, jclass);
275 friend void *_Jv_AllocPtrFreeObj (jint, jclass);
276 friend void *_Jv_AllocArray (jint, jclass);
278 friend jobject _Jv_JNI_ToReflectedField (_Jv_JNIEnv *, jclass, jfieldID,
280 friend jobject _Jv_JNI_ToReflectedMethod (_Jv_JNIEnv *, jclass, jmethodID,
282 friend jfieldID _Jv_FromReflectedField (java::lang::reflect::Field *);
284 friend jmethodID _Jv_FromReflectedMethod (java::lang::reflect::Method *);
285 friend jmethodID _Jv_FromReflectedConstructor (java::lang::reflect::Constructor *);
286 friend jint JvNumMethods (jclass);
287 friend jmethodID JvGetFirstMethod (jclass);
289 // Friends classes and functions to implement the ClassLoader
290 friend class java::lang::ClassLoader;
292 friend class java::io::ObjectOutputStream;
293 friend class java::io::ObjectInputStream;
294 friend class java::io::ObjectStreamClass;
296 friend void _Jv_WaitForState (jclass, int);
297 friend void _Jv_RegisterClasses (jclass *classes);
298 friend void _Jv_RegisterClassHookDefault (jclass klass);
299 friend void _Jv_RegisterInitiatingLoader (jclass,java::lang::ClassLoader*);
300 friend void _Jv_UnregisterClass (jclass);
301 friend jclass _Jv_FindClass (_Jv_Utf8Const *name,
302 java::lang::ClassLoader *loader);
303 friend jclass _Jv_FindClassInCache (_Jv_Utf8Const *name,
304 java::lang::ClassLoader *loader);
305 friend void _Jv_NewArrayClass (jclass element,
306 java::lang::ClassLoader *loader,
307 _Jv_VTable *array_vtable = 0);
308 friend jclass _Jv_NewClass (_Jv_Utf8Const *name, jclass superclass,
309 java::lang::ClassLoader *loader);
312 friend void _Jv_InitPrimClass (jclass, char *, char, int, _Jv_ArrayVTable *);
314 friend void _Jv_PrepareCompiledClass (jclass);
315 friend void _Jv_PrepareConstantTimeTables (jclass);
316 friend jshort _Jv_GetInterfaces (jclass, _Jv_ifaces *);
317 friend void _Jv_GenerateITable (jclass, _Jv_ifaces *, jshort *);
318 friend jstring _Jv_GetMethodString(jclass, _Jv_Utf8Const *);
319 friend jshort _Jv_AppendPartialITable (jclass, jclass, void **, jshort);
320 friend jshort _Jv_FindIIndex (jclass *, jshort *, jshort);
321 friend void _Jv_LinkOffsetTable (jclass);
322 friend void _Jv_LayoutVTableMethods (jclass klass);
323 friend void _Jv_SetVTableEntries (jclass, _Jv_VTable *);
324 friend void _Jv_MakeVTable (jclass);
326 // Return array class corresponding to element type KLASS, creating it if
329 _Jv_GetArrayClass (jclass klass, java::lang::ClassLoader *loader)
331 if (__builtin_expect (!klass->arrayclass, false))
332 _Jv_NewArrayClass (klass, loader);
333 return klass->arrayclass;
337 friend jboolean _Jv_IsInterpretedClass (jclass);
338 friend void _Jv_InitField (jobject, jclass, _Jv_Field*);
339 friend int _Jv_DetermineVTableIndex (jclass, _Jv_Utf8Const *,
341 friend void _Jv_InitField (jobject, jclass, int);
342 friend _Jv_word _Jv_ResolvePoolEntry (jclass, int);
343 friend _Jv_Method *_Jv_SearchMethodInClass (jclass cls, jclass klass,
344 _Jv_Utf8Const *method_name,
345 _Jv_Utf8Const *method_signature);
347 friend void _Jv_PrepareClass (jclass);
349 friend class _Jv_ClassReader;
350 friend class _Jv_InterpClass;
351 friend class _Jv_InterpMethod;
352 friend class _Jv_InterpMethodInvocation;
355 #ifdef JV_MARKOBJ_DECL
356 friend JV_MARKOBJ_DECL;
359 friend class _Jv_BytecodeVerifier;
361 // Chain for class pool.
365 // Access flags for class.
367 // The superclass, or null for Object.
370 _Jv_Constants constants;
371 // Methods. If this is an array class, then this field holds a
372 // pointer to the element type.
374 // Number of methods. If this class is primitive, this holds the
375 // character used to represent this type in a signature.
377 // Number of methods in the vtable.
378 jshort vtable_method_count;
381 // Size of instance fields, in bytes.
383 // Total number of fields (instance and static).
385 // Number of static fields.
386 jshort static_field_count;
387 // The vtbl for all objects of this class.
389 // Virtual method offset table.
390 _Jv_OffsetTable *otable;
391 // Offset table symbols.
392 _Jv_MethodSymbol *otable_syms;
393 // Interfaces implemented by this class.
395 // The class loader for this class.
396 java::lang::ClassLoader *loader;
397 // Number of interfaces.
398 jshort interface_count;
399 // State of this class.
401 // The thread which has locked this class. Used during class
403 java::lang::Thread *thread;
404 // How many levels of "extends" this class is removed from Object.
406 // Vector of this class's superclasses, ordered by decreasing depth.
408 // Interface Dispatch Table.
409 _Jv_IDispatchTable *idt;
410 // Pointer to the class that represents an array of this class.
412 // Security Domain to which this class belongs (or null).
413 java::security::ProtectionDomain *protectionDomain;
416 #endif /* __JAVA_LANG_CLASS_H__ */