OSDN Git Service

* java/lang/Class.h (_getDeclaredMethod): Declare.
[pf3gnuchains/gcc-fork.git] / libjava / java / lang / Class.h
1 // Class.h - Header file for java.lang.Class.  -*- c++ -*-
2
3 /* Copyright (C) 1998, 1999, 2000, 2001, 2002  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 #include <java/lang/reflect/Modifier.h>
21 #include <java/security/ProtectionDomain.h>
22 #include <java/lang/Package.h>
23
24 // We declare these here to avoid including gcj/cni.h.
25 extern "C" void _Jv_InitClass (jclass klass);
26 extern "C" void _Jv_RegisterClasses (jclass *classes);
27
28 // This must be predefined with "C" linkage.
29 extern "C" void *_Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface, 
30                                                int meth_idx);
31
32 // These are the possible values for the `state' field of the class
33 // structure.  Note that ordering is important here.  Whenever the
34 // state changes, one should notify all waiters of this class.
35 enum
36 {
37   JV_STATE_NOTHING = 0,         // Set by compiler.
38
39   JV_STATE_PRELOADING = 1,      // Can do _Jv_FindClass.
40   JV_STATE_LOADING = 3,         // Has super installed.
41   JV_STATE_LOADED = 5,          // Is complete.
42     
43   JV_STATE_COMPILED = 6,        // This was a compiled class.
44
45   JV_STATE_PREPARED = 7,        // Layout & static init done.
46   JV_STATE_LINKED = 9,          // Strings interned.
47
48   JV_STATE_IN_PROGRESS = 10,    // <Clinit> running.
49   JV_STATE_DONE = 12,           // 
50
51   JV_STATE_ERROR = 14           // must be last.
52 };
53
54 struct _Jv_Field;
55 struct _Jv_VTable;
56 union _Jv_word;
57 struct _Jv_ArrayVTable;
58
59 struct _Jv_Constants
60 {
61   jint size;
62   jbyte *tags;
63   _Jv_word *data;
64 };
65
66 struct _Jv_Method
67 {
68   // Method name.
69   _Jv_Utf8Const *name;
70   // Method signature.
71   _Jv_Utf8Const *signature;
72   // Access flags.
73   _Jv_ushort accflags;
74   // Method's index in the vtable.
75   _Jv_ushort index;
76   // Pointer to underlying function.
77   void *ncode;
78   // NULL-terminated list of exception class names; can be NULL if
79   // there are none such.
80   _Jv_Utf8Const **throws;
81
82   _Jv_Method *getNextMethod ()
83   { return this + 1; }
84 };
85
86 // Interface Dispatch Tables 
87 union _Jv_IDispatchTable
88 {
89   struct
90   {
91     // Index into interface's ioffsets.
92     jshort iindex;
93     jshort itable_length;
94     // Class Interface dispatch table.
95     void **itable;
96   } cls;
97
98   struct
99   {
100     // Offsets into implementation class itables.
101     jshort *ioffsets;
102   } iface;
103 };
104
105 // Used by _Jv_GetInterfaces ()
106 struct _Jv_ifaces
107 {
108   jclass *list;
109   jshort len;
110   jshort count;
111 };
112
113 struct _Jv_MethodSymbol
114 {
115   _Jv_Utf8Const *class_name;
116   _Jv_Utf8Const *name;
117   _Jv_Utf8Const *signature;
118 };
119
120 struct _Jv_OffsetTable
121 {
122   jint state;
123   jint offsets[];
124 };
125
126 #define JV_PRIMITIVE_VTABLE ((_Jv_VTable *) -1)
127
128 #define JV_CLASS(Obj) ((jclass) (*(_Jv_VTable **) Obj)->clas)
129
130 class java::lang::Class : public java::lang::Object
131 {
132 public:
133   static jclass forName (jstring className, jboolean initialize, 
134                          java::lang::ClassLoader *loader);
135   static jclass forName (jstring className);
136   JArray<jclass> *getClasses (void);
137
138   java::lang::ClassLoader *getClassLoader (void);
139
140   java::lang::reflect::Constructor *getConstructor (JArray<jclass> *);
141   JArray<java::lang::reflect::Constructor *> *getConstructors (void);
142   java::lang::reflect::Constructor *getDeclaredConstructor (JArray<jclass> *);
143   JArray<java::lang::reflect::Constructor *> *getDeclaredConstructors (void);
144   java::lang::reflect::Field *getDeclaredField (jstring);
145   JArray<java::lang::reflect::Field *> *getDeclaredFields (void);
146   java::lang::reflect::Method *getDeclaredMethod (jstring, JArray<jclass> *);
147   JArray<java::lang::reflect::Method *> *getDeclaredMethods (void);
148
149   JArray<jclass> *getDeclaredClasses (void);
150   jclass getDeclaringClass (void);
151
152   java::lang::reflect::Field *getField (jstring);
153 private:
154   jint _getFields (JArray<java::lang::reflect::Field *> *result, jint offset);
155   JArray<java::lang::reflect::Constructor *> *_getConstructors (jboolean);
156   java::lang::reflect::Field *getField (jstring, jint);
157   jint _getMethods (JArray<java::lang::reflect::Method *> *result,
158                     jint offset);
159   java::lang::reflect::Field *getPrivateField (jstring);
160   java::lang::reflect::Method *getPrivateMethod (jstring, JArray<jclass> *);
161   java::security::ProtectionDomain *getProtectionDomain0 ();
162
163   java::lang::reflect::Method *_getMethod (jstring, JArray<jclass> *);
164   java::lang::reflect::Method *_getDeclaredMethod (jstring, JArray<jclass> *);
165
166 public:
167   JArray<java::lang::reflect::Field *> *getFields (void);
168
169   JArray<jclass> *getInterfaces (void);
170
171   void getSignature (java::lang::StringBuffer *buffer);
172   static jstring getSignature (JArray<jclass> *, jboolean is_constructor);
173   JArray<java::lang::reflect::Method *> *getMethods (void);
174
175   inline jint getModifiers (void)
176     {
177       return accflags;
178     }
179
180   jstring getName (void);
181
182   java::net::URL        *getResource (jstring resourceName);
183   java::io::InputStream *getResourceAsStream (jstring resourceName);
184   JArray<jobject> *getSigners (void);
185
186   inline jclass getSuperclass (void)
187     {
188       return superclass;
189     }
190
191   inline jboolean isArray (void)
192     {
193       return name->data[0] == '[';
194     }
195
196   inline jclass getComponentType (void)
197     {
198       return isArray () ? (* (jclass *) &methods) : 0;
199     }
200
201   jboolean isAssignableFrom (jclass cls);
202   jboolean isInstance (jobject obj);
203
204   inline jboolean isInterface (void)
205   {
206     return (accflags & java::lang::reflect::Modifier::INTERFACE) != 0;
207   }
208   
209   inline jboolean isPrimitive (void)
210     {
211       return vtable == JV_PRIMITIVE_VTABLE;
212     }
213
214   jobject newInstance (void);
215   java::security::ProtectionDomain *getProtectionDomain (void);
216   java::lang::Package *getPackage (void);
217   jstring toString (void);
218   jboolean desiredAssertionStatus (void);
219
220   // FIXME: this probably shouldn't be public.
221   jint size (void)
222     {
223       return size_in_bytes;
224     }
225     
226   // finalization
227   void finalize ();
228
229   // This constructor is used to create Class object for the primitive
230   // types. See prims.cc.
231   Class ();
232
233   static java::lang::Class class$;
234
235 private:   
236
237   void checkMemberAccess (jint flags);
238
239   void initializeClass (void);
240
241   static jstring getPackagePortion (jstring);
242
243   // Friend functions implemented in natClass.cc.
244   friend _Jv_Method *_Jv_GetMethodLocal (jclass klass, _Jv_Utf8Const *name,
245                                          _Jv_Utf8Const *signature);
246   friend jboolean _Jv_IsAssignableFrom(jclass, jclass);
247   friend jboolean _Jv_InterfaceAssignableFrom (jclass, jclass);
248   friend void *_Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface, 
249                                              int method_idx);
250
251   inline friend void 
252   _Jv_InitClass (jclass klass)
253   {
254     if (__builtin_expect (klass->state == JV_STATE_DONE, true))
255       return;
256     klass->initializeClass ();  
257   }
258
259   friend _Jv_Method* _Jv_LookupDeclaredMethod (jclass, _Jv_Utf8Const *, 
260                                                _Jv_Utf8Const*);
261   friend jfieldID JvGetFirstInstanceField (jclass);
262   friend jint JvNumInstanceFields (jclass);
263   friend jfieldID JvGetFirstStaticField (jclass);
264   friend jint JvNumStaticFields (jclass);
265
266   friend jobject _Jv_AllocObject (jclass, jint);
267   friend void *_Jv_AllocObj (jint, jclass);
268   friend void *_Jv_AllocPtrFreeObj (jint, jclass);
269   friend void *_Jv_AllocArray (jint, jclass);
270
271   friend jobject _Jv_JNI_ToReflectedField (_Jv_JNIEnv *, jclass, jfieldID,
272                                            jboolean);
273   friend jobject _Jv_JNI_ToReflectedMethod (_Jv_JNIEnv *, jclass, jmethodID,
274                                             jboolean);
275   friend jfieldID _Jv_FromReflectedField (java::lang::reflect::Field *);
276
277   friend jmethodID _Jv_FromReflectedMethod (java::lang::reflect::Method *);
278   friend jmethodID _Jv_FromReflectedConstructor (java::lang::reflect::Constructor *);
279   friend jint JvNumMethods (jclass);
280   friend jmethodID JvGetFirstMethod (jclass);
281
282   // Friends classes and functions to implement the ClassLoader
283   friend class java::lang::ClassLoader;
284
285   friend class java::io::ObjectOutputStream;
286   friend class java::io::ObjectInputStream;
287   friend class java::io::ObjectStreamClass;
288
289   friend void _Jv_WaitForState (jclass, int);
290   friend void _Jv_RegisterClasses (jclass *classes);
291   friend void _Jv_RegisterClassHookDefault (jclass klass);
292   friend void _Jv_RegisterInitiatingLoader (jclass,java::lang::ClassLoader*);
293   friend void _Jv_UnregisterClass (jclass);
294   friend jclass _Jv_FindClass (_Jv_Utf8Const *name,
295                                java::lang::ClassLoader *loader);
296   friend jclass _Jv_FindClassInCache (_Jv_Utf8Const *name,
297                                       java::lang::ClassLoader *loader);
298   friend void _Jv_NewArrayClass (jclass element,
299                                  java::lang::ClassLoader *loader,
300                                  _Jv_VTable *array_vtable = 0);
301   friend jclass _Jv_NewClass (_Jv_Utf8Const *name, jclass superclass,
302                               java::lang::ClassLoader *loader);
303   friend void _Jv_InitNewClassFields (jclass klass);
304
305   // in prims.cc
306   friend void _Jv_InitPrimClass (jclass, char *, char, int, _Jv_ArrayVTable *);
307
308   friend void _Jv_PrepareCompiledClass (jclass);
309   friend void _Jv_PrepareConstantTimeTables (jclass);
310   friend jshort _Jv_GetInterfaces (jclass, _Jv_ifaces *);
311   friend void _Jv_GenerateITable (jclass, _Jv_ifaces *, jshort *);
312   friend jstring _Jv_GetMethodString(jclass, _Jv_Utf8Const *);
313   friend jshort _Jv_AppendPartialITable (jclass, jclass, void **, jshort);
314   friend jshort _Jv_FindIIndex (jclass *, jshort *, jshort);
315   friend void _Jv_LinkOffsetTable (jclass);
316   friend void _Jv_LayoutVTableMethods (jclass klass);
317   friend void _Jv_SetVTableEntries (jclass, _Jv_VTable *);
318   friend void _Jv_MakeVTable (jclass);
319
320   // Return array class corresponding to element type KLASS, creating it if
321   // necessary.
322   inline friend jclass
323   _Jv_GetArrayClass (jclass klass, java::lang::ClassLoader *loader)
324   {
325     if (__builtin_expect (!klass->arrayclass, false))
326       _Jv_NewArrayClass (klass, loader);
327     return klass->arrayclass;
328   }
329
330 #ifdef INTERPRETER
331   friend jboolean _Jv_IsInterpretedClass (jclass);
332   friend void _Jv_InitField (jobject, jclass, _Jv_Field*);
333   friend int _Jv_DetermineVTableIndex (jclass, _Jv_Utf8Const *, 
334                                        _Jv_Utf8Const*);
335   friend void _Jv_InitField (jobject, jclass, int);
336   friend _Jv_word _Jv_ResolvePoolEntry (jclass, int);
337   friend _Jv_Method *_Jv_SearchMethodInClass (jclass cls, jclass klass, 
338                                               _Jv_Utf8Const *method_name, 
339                                               _Jv_Utf8Const *method_signature);
340
341   friend void _Jv_PrepareClass (jclass);
342
343   friend class _Jv_ClassReader; 
344   friend class _Jv_InterpClass;
345   friend class _Jv_InterpMethod;
346 #endif
347
348 #ifdef JV_MARKOBJ_DECL
349   friend JV_MARKOBJ_DECL;
350 #endif
351
352   friend class _Jv_BytecodeVerifier;
353
354   // Chain for class pool.
355   jclass next;
356   // Name of class.
357   _Jv_Utf8Const *name;
358   // Access flags for class.
359   _Jv_ushort accflags;
360   // The superclass, or null for Object.
361   jclass superclass;
362   // Class constants.
363   _Jv_Constants constants;
364   // Methods.  If this is an array class, then this field holds a
365   // pointer to the element type.
366   _Jv_Method *methods;
367   // Number of methods.  If this class is primitive, this holds the
368   // character used to represent this type in a signature.
369   jshort method_count;
370   // Number of methods in the vtable.
371   jshort vtable_method_count;
372   // The fields.
373   _Jv_Field *fields;
374   // Size of instance fields, in bytes.
375   jint size_in_bytes;
376   // Total number of fields (instance and static).
377   jshort field_count;
378   // Number of static fields.
379   jshort static_field_count;
380   // The vtbl for all objects of this class.
381   _Jv_VTable *vtable;
382   // Virtual method offset table.
383   _Jv_OffsetTable *otable;
384   // Offset table symbols.
385   _Jv_MethodSymbol *otable_syms;
386   // Interfaces implemented by this class.
387   jclass *interfaces;
388   // The class loader for this class.
389   java::lang::ClassLoader *loader;
390   // Number of interfaces.
391   jshort interface_count;
392   // State of this class.
393   jbyte state;
394   // The thread which has locked this class.  Used during class
395   // initialization.
396   java::lang::Thread *thread;
397   // How many levels of "extends" this class is removed from Object.
398   jshort depth;
399   // Vector of this class's superclasses, ordered by decreasing depth.
400   jclass *ancestors;
401   // Interface Dispatch Table.
402   _Jv_IDispatchTable *idt;
403   // Pointer to the class that represents an array of this class.
404   jclass arrayclass;
405   // Security Domain to which this class belongs (or null).
406   java::security::ProtectionDomain *protectionDomain;
407 };
408
409 #endif /* __JAVA_LANG_CLASS_H__ */