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__
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>
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
);
28 // This must be predefined with "C" linkage.
29 extern "C" void *_Jv_LookupInterfaceMethodIdx (jclass klass
, jclass iface
,
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.
37 JV_STATE_NOTHING
= 0, // Set by compiler.
39 JV_STATE_PRELOADING
= 1, // Can do _Jv_FindClass.
40 JV_STATE_LOADING
= 3, // Has super installed.
41 JV_STATE_LOADED
= 5, // Is complete.
43 JV_STATE_COMPILED
= 6, // This was a compiled class.
45 JV_STATE_PREPARED
= 7, // Layout & static init done.
46 JV_STATE_LINKED
= 9, // Strings interned.
48 JV_STATE_IN_PROGRESS
= 10, // <Clinit> running.
49 JV_STATE_DONE
= 12, //
51 JV_STATE_ERROR
= 14 // must be last.
68 _Jv_Utf8Const
*signature
;
71 _Jv_Method
*getNextMethod ()
75 // Interface Dispatch Tables
76 union _Jv_IDispatchTable
80 // Index into interface's ioffsets.
83 // Class Interface dispatch table.
89 // Offsets into implementation class itables.
94 // Used by _Jv_GetInterfaces ()
102 // Used for vtable pointer manipulation.
109 #define JV_PRIMITIVE_VTABLE ((_Jv_VTable *) -1)
111 #define JV_CLASS(Obj) ((jclass) (*(_Jv_VTable **) Obj)->clas)
113 class java::lang::Class
: public java::lang::Object
116 static jclass
forName (jstring className
, jboolean initialize
,
117 java::lang::ClassLoader
*loader
);
118 static jclass
forName (jstring className
);
119 JArray
<jclass
> *getClasses (void);
121 java::lang::ClassLoader
*getClassLoader (void)
126 java::lang::reflect::Constructor
*getConstructor (JArray
<jclass
> *);
127 JArray
<java::lang::reflect::Constructor
*> *getConstructors (void);
128 java::lang::reflect::Constructor
*getDeclaredConstructor (JArray
<jclass
> *);
129 JArray
<java::lang::reflect::Constructor
*> *getDeclaredConstructors (void);
130 java::lang::reflect::Field
*getDeclaredField (jstring
);
131 JArray
<java::lang::reflect::Field
*> *getDeclaredFields (void);
132 java::lang::reflect::Method
*getDeclaredMethod (jstring
, JArray
<jclass
> *);
133 JArray
<java::lang::reflect::Method
*> *getDeclaredMethods (void);
135 JArray
<jclass
> *getDeclaredClasses (void);
136 jclass
getDeclaringClass (void);
138 java::lang::reflect::Field
*getField (jstring
);
140 jint
_getFields (JArray
<java::lang::reflect::Field
*> *result
, jint offset
);
141 JArray
<java::lang::reflect::Constructor
*> *_getConstructors (jboolean
);
142 java::lang::reflect::Field
*getField (jstring
, jint
);
143 jint
_getMethods (JArray
<java::lang::reflect::Method
*> *result
,
145 java::lang::reflect::Field
*getPrivateField (jstring
);
146 java::lang::reflect::Method
*getPrivateMethod (jstring
, JArray
<jclass
> *);
147 java::security::ProtectionDomain
*getProtectionDomain0 ();
150 JArray
<java::lang::reflect::Field
*> *getFields (void);
152 JArray
<jclass
> *getInterfaces (void);
154 void getSignature (java::lang::StringBuffer
*buffer
);
155 static jstring
getSignature (JArray
<jclass
> *, jboolean is_constructor
);
156 java::lang::reflect::Method
*getMethod (jstring
, JArray
<jclass
> *);
157 JArray
<java::lang::reflect::Method
*> *getMethods (void);
159 inline jint
getModifiers (void)
164 jstring
getName (void);
166 java::net::URL
*getResource (jstring resourceName
);
167 java::io::InputStream
*getResourceAsStream (jstring resourceName
);
168 JArray
<jobject
> *getSigners (void);
170 inline jclass
getSuperclass (void)
175 inline jboolean
isArray (void)
177 return name
->data
[0] == '[';
180 inline jclass
getComponentType (void)
182 return isArray () ? (* (jclass
*) &methods
) : 0;
185 jboolean
isAssignableFrom (jclass cls
);
186 jboolean
isInstance (jobject obj
);
188 inline jboolean
isInterface (void)
190 return (accflags
& java::lang::reflect::Modifier::INTERFACE
) != 0;
193 inline jboolean
isPrimitive (void)
195 return vtable
== JV_PRIMITIVE_VTABLE
;
198 jobject
newInstance (void);
199 jstring
toString (void);
201 // FIXME: this probably shouldn't be public.
204 return size_in_bytes
;
212 // This constructor is used to create Class object for the primitive
213 // types. See prims.cc.
214 Class (jobject cname
, jbyte sig
, jint len
, jobject array_vtable
)
216 using namespace java::lang::reflect
;
217 _Jv_Utf8Const
*_Jv_makeUtf8Const (char *s
, int len
);
219 // C++ ctors set the vtbl pointer to point at an offset inside the vtable
220 // object. That doesn't work for Java, so this hack adjusts it back.
221 ((_Jv_Self
*)this)->vtable_ptr
-= 2 * sizeof (void *);
223 // We must initialize every field of the class. We do this in the
224 // same order they are declared in Class.h, except for fields that
225 // are initialized to NULL.
226 name
= _Jv_makeUtf8Const ((char *) cname
, -1);
227 accflags
= Modifier::PUBLIC
| Modifier::FINAL
| Modifier::ABSTRACT
;
230 vtable
= JV_PRIMITIVE_VTABLE
;
231 state
= JV_STATE_DONE
;
233 if (method_count
!= 'V')
234 _Jv_NewArrayClass (this, NULL
, (_Jv_VTable
*) array_vtable
);
237 static java::lang::Class
class$
;
241 void checkMemberAccess (jint flags
);
243 void initializeClass (void);
245 // Friend functions implemented in natClass.cc.
246 friend _Jv_Method
*_Jv_GetMethodLocal (jclass klass
, _Jv_Utf8Const
*name
,
247 _Jv_Utf8Const
*signature
);
248 friend jboolean
_Jv_IsAssignableFrom(jclass
, jclass
);
249 friend jboolean
_Jv_InterfaceAssignableFrom (jclass
, jclass
);
250 friend void *_Jv_LookupInterfaceMethodIdx (jclass klass
, jclass iface
,
254 _Jv_InitClass (jclass klass
)
256 if (__builtin_expect (klass
->state
== JV_STATE_DONE
, true))
258 klass
->initializeClass ();
261 friend _Jv_Method
* _Jv_LookupDeclaredMethod (jclass
, _Jv_Utf8Const
*,
263 friend jfieldID
JvGetFirstInstanceField (jclass
);
264 friend jint
JvNumInstanceFields (jclass
);
265 friend jfieldID
JvGetFirstStaticField (jclass
);
266 friend jint
JvNumStaticFields (jclass
);
268 friend jobject
_Jv_AllocObject (jclass
, jint
);
269 friend void *_Jv_AllocObj (jint
, jclass
);
270 friend void *_Jv_AllocArray (jint
, jclass
);
272 friend jobject
_Jv_JNI_ToReflectedField (_Jv_JNIEnv
*, jclass
, jfieldID
,
274 friend jobject
_Jv_JNI_ToReflectedMethod (_Jv_JNIEnv
*, jclass
, jmethodID
,
276 friend jfieldID
_Jv_FromReflectedField (java::lang::reflect::Field
*);
278 friend jmethodID
_Jv_FromReflectedMethod (java::lang::reflect::Method
*);
279 friend jmethodID
_Jv_FromReflectedConstructor (java::lang::reflect::Constructor
*);
280 friend jint
JvNumMethods (jclass
);
281 friend jmethodID
JvGetFirstMethod (jclass
);
283 // Friends classes and functions to implement the ClassLoader
284 friend class java::lang::ClassLoader
;
286 friend class java::io::ObjectOutputStream
;
287 friend class java::io::ObjectInputStream
;
288 friend class java::io::ObjectStreamClass
;
290 friend void _Jv_WaitForState (jclass
, int);
291 friend void _Jv_RegisterClasses (jclass
*classes
);
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
);
304 friend void _Jv_PrepareCompiledClass (jclass
);
305 friend void _Jv_PrepareConstantTimeTables (jclass
);
306 friend jshort
_Jv_GetInterfaces (jclass
, _Jv_ifaces
*);
307 friend void _Jv_GenerateITable (jclass
, _Jv_ifaces
*, jshort
*);
308 friend jstring
_Jv_GetMethodString(jclass
, _Jv_Utf8Const
*);
309 friend jshort
_Jv_AppendPartialITable (jclass
, jclass
, void **, jshort
);
310 friend jshort
_Jv_FindIIndex (jclass
*, jshort
*, jshort
);
312 // Return array class corresponding to element type KLASS, creating it if
315 _Jv_GetArrayClass (jclass klass
, java::lang::ClassLoader
*loader
)
317 if (__builtin_expect (!klass
->arrayclass
, false))
318 _Jv_NewArrayClass (klass
, loader
);
319 return klass
->arrayclass
;
323 friend jboolean
_Jv_IsInterpretedClass (jclass
);
324 friend void _Jv_InitField (jobject
, jclass
, _Jv_Field
*);
325 friend int _Jv_DetermineVTableIndex (jclass
, _Jv_Utf8Const
*,
327 friend void _Jv_InitField (jobject
, jclass
, int);
328 friend _Jv_word
_Jv_ResolvePoolEntry (jclass
, int);
329 friend _Jv_Method
*_Jv_SearchMethodInClass (jclass cls
, jclass klass
,
330 _Jv_Utf8Const
*method_name
,
331 _Jv_Utf8Const
*method_signature
);
333 friend void _Jv_PrepareClass (jclass
);
335 friend class _Jv_ClassReader
;
336 friend class _Jv_InterpClass
;
337 friend class _Jv_InterpMethod
;
338 friend class _Jv_InterpMethodInvocation
;
341 #ifdef JV_MARKOBJ_DECL
342 friend JV_MARKOBJ_DECL
;
345 // Chain for class pool.
349 // Access flags for class.
351 // The superclass, or null for Object.
354 _Jv_Constants constants
;
355 // Methods. If this is an array class, then this field holds a
356 // pointer to the element type.
358 // Number of methods. If this class is primitive, this holds the
359 // character used to represent this type in a signature.
361 // Number of methods in the vtable.
362 jshort vtable_method_count
;
365 // Size of instance fields, in bytes.
367 // Total number of fields (instance and static).
369 // Number of static fields.
370 jshort static_field_count
;
371 // The vtbl for all objects of this class.
373 // Interfaces implemented by this class.
375 // The class loader for this class.
376 java::lang::ClassLoader
*loader
;
377 // Number of interfaces.
378 jshort interface_count
;
379 // State of this class.
381 // The thread which has locked this class. Used during class
383 java::lang::Thread
*thread
;
384 // How many levels of "extends" this class is removed from Object.
386 // Vector of this class's superclasses, ordered by decreasing depth.
388 // Interface Dispatch Table.
389 _Jv_IDispatchTable
*idt
;
390 // Pointer to the class that represents an array of this class.
392 // Security Domain to which this class belongs (or null).
393 java::security::ProtectionDomain
*protectionDomain
;
396 #endif /* __JAVA_LANG_CLASS_H__ */