1 // Class.h - Header file for java.lang.Class. -*- c++ -*-
3 /* Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
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>
21 // We declare these here to avoid including gcj/cni.h.
22 extern "C" void _Jv_InitClass (jclass klass);
23 extern "C" void _Jv_RegisterClasses (jclass *classes);
25 // These are the possible values for the `state' field of the class
26 // structure. Note that ordering is important here. Whenever the
27 // state changes, one should notify all waiters of this class.
30 JV_STATE_NOTHING = 0, // Set by compiler.
32 JV_STATE_PRELOADING = 1, // Can do _Jv_FindClass.
33 JV_STATE_LOADING = 3, // Has super installed.
34 JV_STATE_LOADED = 5, // Is complete.
36 JV_STATE_COMPILED = 6, // This was a compiled class.
38 JV_STATE_PREPARED = 7, // Layout & static init done.
39 JV_STATE_LINKED = 9, // Strings interned.
41 JV_STATE_IN_PROGRESS = 10, // <Clinit> running.
42 JV_STATE_DONE = 12, //
44 JV_STATE_ERROR = 14 // must be last.
60 _Jv_Utf8Const *signature;
61 unsigned short accflags;
64 _Jv_Method *getNextMethod ()
68 #define JV_PRIMITIVE_VTABLE ((_Jv_VTable *) -1)
70 class java::lang::Class : public java::lang::Object
73 static jclass forName (jstring className);
74 JArray<jclass> *getClasses (void);
76 java::lang::ClassLoader *getClassLoader (void)
81 jclass getComponentType (void)
83 return isArray () ? (* (jclass *) &methods) : 0;
86 java::lang::reflect::Constructor *getConstructor (JArray<jclass> *);
87 JArray<java::lang::reflect::Constructor *> *getConstructors (void);
88 java::lang::reflect::Constructor *getDeclaredConstructor (JArray<jclass> *);
89 JArray<java::lang::reflect::Constructor *> *getDeclaredConstructors (void);
90 java::lang::reflect::Field *getDeclaredField (jstring);
91 JArray<java::lang::reflect::Field *> *getDeclaredFields (void);
92 java::lang::reflect::Method *getDeclaredMethod (jstring, JArray<jclass> *);
93 JArray<java::lang::reflect::Method *> *getDeclaredMethods (void);
95 JArray<jclass> *getDeclaredClasses (void);
96 jclass getDeclaringClass (void);
98 java::lang::reflect::Field *getField (jstring);
100 jint _getFields (JArray<java::lang::reflect::Field *> *result, jint offset);
101 JArray<java::lang::reflect::Constructor *> *_getConstructors (jboolean);
102 java::lang::reflect::Field *getField (jstring, jint);
103 jint _getMethods (JArray<java::lang::reflect::Method *> *result,
106 JArray<java::lang::reflect::Field *> *getFields (void);
108 JArray<jclass> *getInterfaces (void);
110 void getSignature (java::lang::StringBuffer *buffer);
111 static jstring getSignature (JArray<jclass> *, jboolean is_constructor);
112 java::lang::reflect::Method *getMethod (jstring, JArray<jclass> *);
113 JArray<java::lang::reflect::Method *> *getMethods (void);
115 jint getModifiers (void)
120 jstring getName (void);
122 java::net::URL *getResource (jstring resourceName);
123 java::io::InputStream *getResourceAsStream (jstring resourceName);
124 JArray<jobject> *getSigners (void);
126 jclass getSuperclass (void)
131 jboolean isArray (void)
133 return name->data[0] == '[';
136 jboolean isAssignableFrom (jclass cls);
137 jboolean isInstance (jobject obj);
138 jboolean isInterface (void);
140 jboolean isPrimitive (void)
142 return vtable == JV_PRIMITIVE_VTABLE;
145 jobject newInstance (void);
146 jstring toString (void);
148 // FIXME: this probably shouldn't be public.
151 return size_in_bytes;
158 void checkMemberAccess (jint flags);
160 // Various functions to handle class initialization.
161 java::lang::Throwable *hackTrampoline (jint, java::lang::Throwable *);
162 void hackRunInitializers (void);
163 void initializeClass (void);
165 // Friend functions implemented in natClass.cc.
166 friend _Jv_Method *_Jv_GetMethodLocal (jclass klass, _Jv_Utf8Const *name,
167 _Jv_Utf8Const *signature);
168 friend _Jv_Method* _Jv_LookupDeclaredMethod (jclass, _Jv_Utf8Const *,
170 friend void _Jv_InitClass (jclass klass);
172 friend jfieldID JvGetFirstInstanceField (jclass);
173 friend jint JvNumInstanceFields (jclass);
174 friend jfieldID JvGetFirstStaticField (jclass);
175 friend jint JvNumStaticFields (jclass);
177 friend jobject _Jv_AllocObject (jclass, jint);
178 friend jobjectArray _Jv_NewObjectArray (jsize, jclass, jobject);
179 friend jobject _Jv_NewPrimArray (jclass, jint);
180 friend jobject _Jv_JNI_ToReflectedField (_Jv_JNIEnv *, jclass, jfieldID);
181 friend jfieldID _Jv_FromReflectedField (java::lang::reflect::Field *);
183 friend jmethodID _Jv_FromReflectedMethod (java::lang::reflect::Method *);
184 friend jmethodID _Jv_FromReflectedConstructor (java::lang::reflect::Constructor *);
185 friend jint JvNumMethods (jclass);
186 friend jmethodID JvGetFirstMethod (jclass);
188 friend class _Jv_PrimClass;
190 // Friends classes and functions to implement the ClassLoader
191 friend class java::lang::ClassLoader;
193 friend void _Jv_WaitForState (jclass, int);
194 friend void _Jv_RegisterClasses (jclass *classes);
195 friend void _Jv_RegisterInitiatingLoader (jclass,java::lang::ClassLoader*);
196 friend void _Jv_UnregisterClass (jclass);
197 friend jclass _Jv_FindClass (_Jv_Utf8Const *name,
198 java::lang::ClassLoader *loader);
199 friend jclass _Jv_FindClassInCache (_Jv_Utf8Const *name,
200 java::lang::ClassLoader *loader);
201 friend jclass _Jv_FindArrayClass (jclass element,
202 java::lang::ClassLoader *loader);
203 friend jclass _Jv_NewClass (_Jv_Utf8Const *name, jclass superclass,
204 java::lang::ClassLoader *loader);
206 friend void _Jv_PrepareCompiledClass (jclass);
209 friend jboolean _Jv_IsInterpretedClass (jclass);
210 friend void _Jv_InitField (jobject, jclass, _Jv_Field*);
211 friend int _Jv_DetermineVTableIndex (jclass, _Jv_Utf8Const *,
213 friend void _Jv_InitField (jobject, jclass, int);
214 friend _Jv_word _Jv_ResolvePoolEntry (jclass, int);
215 friend void _Jv_PrepareClass (jclass);
217 friend class _Jv_ClassReader;
218 friend class _Jv_InterpClass;
219 friend class _Jv_InterpMethod;
220 friend class _Jv_InterpMethodInvocation;
223 #ifdef JV_MARKOBJ_DECL
224 friend JV_MARKOBJ_DECL;
227 // Chain for class pool.
231 // Access flags for class.
232 unsigned short accflags;
233 // The superclass, or null for Object.
236 _Jv_Constants constants;
237 // Methods. If this is an array class, then this field holds a
238 // pointer to the element type. If this is a primitive class, this
239 // is used to cache a pointer to the appropriate array type.
241 // Number of methods. If this class is primitive, this holds the
242 // character used to represent this type in a signature.
244 // Number of methods in the vtable.
245 short vtable_method_count;
248 // Size of instance fields, in bytes.
250 // Total number of fields (instance and static).
252 // Number of static fields.
253 short static_field_count;
254 // The vtbl for all objects of this class.
256 // Interfaces implemented by this class.
258 // The class loader for this class.
259 java::lang::ClassLoader *loader;
260 // Number of interfaces.
261 short interface_count;
262 // State of this class.
264 // The thread which has locked this class. Used during class
266 java::lang::Thread *thread;
271 JvNumMethods (jclass klass)
273 return klass->method_count;
276 extern inline jmethodID
277 JvGetFirstMethod (jclass klass)
279 return &klass->methods[0];
282 #endif /* __JAVA_LANG_CLASS_H__ */