natField.cc (BooleanClass): Don't define.
[gcc.git] / libjava / java / lang / Class.h
1 // Class.h - Header file for java.lang.Class. -*- c++ -*-
2
3 /* Copyright (C) 1998, 1999, 2000 Free Software Foundation
4
5 This file is part of libgcj.
6
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9 details. */
10
11 // Written primary using compiler source and Class.java as guides.
12 #ifndef __JAVA_LANG_CLASS_H__
13 #define __JAVA_LANG_CLASS_H__
14
15 #pragma interface
16
17 #include <java/lang/Object.h>
18 #include <java/lang/String.h>
19 #include <java/net/URL.h>
20
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);
24
25 // This must be predefined with "C" linkage.
26 extern "C" void *_Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface,
27 int meth_idx);
28
29 // These are the possible values for the `state' field of the class
30 // structure. Note that ordering is important here. Whenever the
31 // state changes, one should notify all waiters of this class.
32 enum
33 {
34 JV_STATE_NOTHING = 0, // Set by compiler.
35
36 JV_STATE_PRELOADING = 1, // Can do _Jv_FindClass.
37 JV_STATE_LOADING = 3, // Has super installed.
38 JV_STATE_LOADED = 5, // Is complete.
39
40 JV_STATE_COMPILED = 6, // This was a compiled class.
41
42 JV_STATE_PREPARED = 7, // Layout & static init done.
43 JV_STATE_LINKED = 9, // Strings interned.
44
45 JV_STATE_IN_PROGRESS = 10, // <Clinit> running.
46 JV_STATE_DONE = 12, //
47
48 JV_STATE_ERROR = 14 // must be last.
49 };
50
51 struct _Jv_Field;
52 struct _Jv_VTable;
53 union _Jv_word;
54
55 struct _Jv_Constants
56 {
57 jint size;
58 jbyte *tags;
59 _Jv_word *data;
60 };
61
62 struct _Jv_Method
63 {
64 _Jv_Utf8Const *name;
65 _Jv_Utf8Const *signature;
66 _Jv_ushort accflags;
67 void *ncode;
68 _Jv_Method *getNextMethod ()
69 { return this + 1; }
70 };
71
72 // Interface Dispatch Tables
73 union _Jv_IDispatchTable
74 {
75 struct
76 {
77 // Index into interface's ioffsets.
78 jshort iindex;
79 jshort itable_length;
80 // Class Interface dispatch table.
81 void **itable;
82 } cls;
83
84 struct
85 {
86 // Offsets into implementation class itables.
87 jshort *ioffsets;
88 } iface;
89 };
90
91 // Used by _Jv_GetInterfaces ()
92 struct _Jv_ifaces
93 {
94 jclass *list;
95 jshort len;
96 jshort count;
97 };
98
99 #define JV_PRIMITIVE_VTABLE ((_Jv_VTable *) -1)
100
101 #define JV_CLASS(Obj) ((jclass) (*(_Jv_VTable **) Obj)->clas)
102
103 class java::lang::Class : public java::lang::Object
104 {
105 public:
106 static jclass forName (jstring className);
107 JArray<jclass> *getClasses (void);
108
109 java::lang::ClassLoader *getClassLoader (void)
110 {
111 return loader;
112 }
113
114 java::lang::reflect::Constructor *getConstructor (JArray<jclass> *);
115 JArray<java::lang::reflect::Constructor *> *getConstructors (void);
116 java::lang::reflect::Constructor *getDeclaredConstructor (JArray<jclass> *);
117 JArray<java::lang::reflect::Constructor *> *getDeclaredConstructors (void);
118 java::lang::reflect::Field *getDeclaredField (jstring);
119 JArray<java::lang::reflect::Field *> *getDeclaredFields (void);
120 java::lang::reflect::Method *getDeclaredMethod (jstring, JArray<jclass> *);
121 JArray<java::lang::reflect::Method *> *getDeclaredMethods (void);
122
123 JArray<jclass> *getDeclaredClasses (void);
124 jclass getDeclaringClass (void);
125
126 java::lang::reflect::Field *getField (jstring);
127 private:
128 jint _getFields (JArray<java::lang::reflect::Field *> *result, jint offset);
129 JArray<java::lang::reflect::Constructor *> *_getConstructors (jboolean);
130 java::lang::reflect::Field *getField (jstring, jint);
131 jint _getMethods (JArray<java::lang::reflect::Method *> *result,
132 jint offset);
133 java::lang::reflect::Field *getPrivateField (jstring);
134 java::lang::reflect::Method *getPrivateMethod (jstring, JArray<jclass> *);
135
136 public:
137 JArray<java::lang::reflect::Field *> *getFields (void);
138
139 JArray<jclass> *getInterfaces (void);
140
141 void getSignature (java::lang::StringBuffer *buffer);
142 static jstring getSignature (JArray<jclass> *, jboolean is_constructor);
143 java::lang::reflect::Method *getMethod (jstring, JArray<jclass> *);
144 JArray<java::lang::reflect::Method *> *getMethods (void);
145
146 inline jint getModifiers (void)
147 {
148 return accflags;
149 }
150
151 jstring getName (void);
152
153 java::net::URL *getResource (jstring resourceName);
154 java::io::InputStream *getResourceAsStream (jstring resourceName);
155 JArray<jobject> *getSigners (void);
156
157 inline jclass getSuperclass (void)
158 {
159 return superclass;
160 }
161
162 inline jboolean isArray (void)
163 {
164 return name->data[0] == '[';
165 }
166
167 inline jclass getComponentType (void)
168 {
169 return isArray () ? (* (jclass *) &methods) : 0;
170 }
171
172 jboolean isAssignableFrom (jclass cls);
173 jboolean isInstance (jobject obj);
174 jboolean isInterface (void);
175
176 inline jboolean isPrimitive (void)
177 {
178 return vtable == JV_PRIMITIVE_VTABLE;
179 }
180
181 jobject newInstance (void);
182 jstring toString (void);
183
184 // FIXME: this probably shouldn't be public.
185 jint size (void)
186 {
187 return size_in_bytes;
188 }
189
190 // finalization
191 void finalize ();
192
193 static java::lang::Class class$;
194
195 private:
196
197 void checkMemberAccess (jint flags);
198
199 void initializeClass (void);
200
201 // Friend functions implemented in natClass.cc.
202 friend _Jv_Method *_Jv_GetMethodLocal (jclass klass, _Jv_Utf8Const *name,
203 _Jv_Utf8Const *signature);
204 friend jboolean _Jv_IsAssignableFrom(jclass, jclass);
205 friend jboolean _Jv_InterfaceAssignableFrom (jclass, jclass);
206 friend void *_Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface,
207 int method_idx);
208
209 inline friend void
210 _Jv_InitClass (jclass klass)
211 {
212 if (klass->state == JV_STATE_DONE)
213 return;
214 klass->initializeClass ();
215 }
216
217 friend _Jv_Method* _Jv_LookupDeclaredMethod (jclass, _Jv_Utf8Const *,
218 _Jv_Utf8Const*);
219 friend jfieldID JvGetFirstInstanceField (jclass);
220 friend jint JvNumInstanceFields (jclass);
221 friend jfieldID JvGetFirstStaticField (jclass);
222 friend jint JvNumStaticFields (jclass);
223
224 friend jobject _Jv_AllocObject (jclass, jint);
225 friend void *_Jv_AllocObj (jint, jclass);
226 friend void *_Jv_AllocArray (jint, jclass);
227
228 friend jobject _Jv_JNI_ToReflectedField (_Jv_JNIEnv *, jclass, jfieldID,
229 jboolean);
230 friend jobject _Jv_JNI_ToReflectedMethod (_Jv_JNIEnv *, jclass, jmethodID,
231 jboolean);
232 friend jfieldID _Jv_FromReflectedField (java::lang::reflect::Field *);
233
234 friend jmethodID _Jv_FromReflectedMethod (java::lang::reflect::Method *);
235 friend jmethodID _Jv_FromReflectedConstructor (java::lang::reflect::Constructor *);
236 friend jint JvNumMethods (jclass);
237 friend jmethodID JvGetFirstMethod (jclass);
238
239 friend class _Jv_PrimClass;
240
241 // Friends classes and functions to implement the ClassLoader
242 friend class java::lang::ClassLoader;
243
244 friend class java::io::ObjectOutputStream;
245 friend class java::io::ObjectInputStream;
246 friend class java::io::ObjectStreamClass;
247
248 friend void _Jv_WaitForState (jclass, int);
249 friend void _Jv_RegisterClasses (jclass *classes);
250 friend void _Jv_RegisterInitiatingLoader (jclass,java::lang::ClassLoader*);
251 friend void _Jv_UnregisterClass (jclass);
252 friend jclass _Jv_FindClass (_Jv_Utf8Const *name,
253 java::lang::ClassLoader *loader);
254 friend jclass _Jv_FindClassInCache (_Jv_Utf8Const *name,
255 java::lang::ClassLoader *loader);
256 friend jclass _Jv_FindArrayClass (jclass element,
257 java::lang::ClassLoader *loader,
258 _Jv_VTable *array_vtable = 0);
259 friend jclass _Jv_NewClass (_Jv_Utf8Const *name, jclass superclass,
260 java::lang::ClassLoader *loader);
261
262 friend void _Jv_PrepareCompiledClass (jclass);
263 friend void _Jv_PrepareConstantTimeTables (jclass);
264 friend jshort _Jv_GetInterfaces (jclass, _Jv_ifaces *);
265 friend void _Jv_GenerateITable (jclass, _Jv_ifaces *, jshort *);
266 friend jstring _Jv_GetMethodString(jclass, _Jv_Utf8Const *);
267 friend jshort _Jv_AppendPartialITable (jclass, jclass, void **, jshort);
268 friend jshort _Jv_FindIIndex (jclass *, jshort *, jshort);
269
270 #ifdef INTERPRETER
271 friend jboolean _Jv_IsInterpretedClass (jclass);
272 friend void _Jv_InitField (jobject, jclass, _Jv_Field*);
273 friend int _Jv_DetermineVTableIndex (jclass, _Jv_Utf8Const *,
274 _Jv_Utf8Const*);
275 friend void _Jv_InitField (jobject, jclass, int);
276 friend _Jv_word _Jv_ResolvePoolEntry (jclass, int);
277 friend _Jv_Method *_Jv_SearchMethodInClass (jclass cls, jclass klass,
278 _Jv_Utf8Const *method_name,
279 _Jv_Utf8Const *method_signature);
280
281 friend void _Jv_PrepareClass (jclass);
282
283 friend class _Jv_ClassReader;
284 friend class _Jv_InterpClass;
285 friend class _Jv_InterpMethod;
286 friend class _Jv_InterpMethodInvocation;
287 #endif
288
289 #ifdef JV_MARKOBJ_DECL
290 friend JV_MARKOBJ_DECL;
291 #endif
292
293 // Chain for class pool.
294 jclass next;
295 // Name of class.
296 _Jv_Utf8Const *name;
297 // Access flags for class.
298 _Jv_ushort accflags;
299 // The superclass, or null for Object.
300 jclass superclass;
301 // Class constants.
302 _Jv_Constants constants;
303 // Methods. If this is an array class, then this field holds a
304 // pointer to the element type. If this is a primitive class, this
305 // is used to cache a pointer to the appropriate array type.
306 _Jv_Method *methods;
307 // Number of methods. If this class is primitive, this holds the
308 // character used to represent this type in a signature.
309 jshort method_count;
310 // Number of methods in the vtable.
311 jshort vtable_method_count;
312 // The fields.
313 _Jv_Field *fields;
314 // Size of instance fields, in bytes.
315 jint size_in_bytes;
316 // Total number of fields (instance and static).
317 jshort field_count;
318 // Number of static fields.
319 jshort static_field_count;
320 // The vtbl for all objects of this class.
321 _Jv_VTable *vtable;
322 // Interfaces implemented by this class.
323 jclass *interfaces;
324 // The class loader for this class.
325 java::lang::ClassLoader *loader;
326 // Number of interfaces.
327 jshort interface_count;
328 // State of this class.
329 jbyte state;
330 // The thread which has locked this class. Used during class
331 // initialization.
332 java::lang::Thread *thread;
333 // How many levels of "extends" this class is removed from Object.
334 jshort depth;
335 // Vector of this class's superclasses, ordered by decreasing depth.
336 jclass *ancestors;
337 // Interface Dispatch Table.
338 _Jv_IDispatchTable *idt;
339 };
340
341 #endif /* __JAVA_LANG_CLASS_H__ */