1 // Class.h - Header file for java.lang.Class. -*- c++ -*-
3 /* Copyright (C) 1998, 1999 Cygnus Solutions
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
;
65 #define JV_PRIMITIVE_VTABLE ((_Jv_VTable *) -1)
67 class java::lang::Class
: public java::lang::Object
70 static jclass
forName (jstring className
);
71 JArray
<jclass
> *getClasses (void);
73 java::lang::ClassLoader
*getClassLoader (void)
78 jclass
getComponentType (void)
80 return isArray () ? (* (jclass
*) &methods
) : 0;
83 java::lang::reflect::Constructor
*getConstructor (JArray
<jclass
> *);
84 JArray
<java::lang::reflect::Constructor
*> *getConstructors (void);
85 java::lang::reflect::Constructor
*getDeclaredConstructor (JArray
<jclass
> *);
86 JArray
<java::lang::reflect::Constructor
*> *getDeclaredConstructors (void);
87 java::lang::reflect::Field
*getDeclaredField (jstring
);
88 JArray
<java::lang::reflect::Field
*> *getDeclaredFields (void);
89 java::lang::reflect::Method
*getDeclaredMethod (jstring
, JArray
<jclass
> *);
90 JArray
<java::lang::reflect::Method
*> *getDeclaredMethods (void);
92 JArray
<jclass
> *getDeclaredClasses (void);
93 jclass
getDeclaringClass (void);
95 java::lang::reflect::Field
*getField (jstring
);
97 java::lang::reflect::Field
*getField (jstring
, jint
);
99 JArray
<java::lang::reflect::Field
*> *getFields (void);
101 JArray
<jclass
> *getInterfaces (void);
103 java::lang::reflect::Method
*getMethod (jstring
, JArray
<jclass
> *);
104 JArray
<java::lang::reflect::Method
*> *getMethods (void);
106 jint
getModifiers (void)
111 jstring
getName (void);
113 java::net::URL
*getResource (jstring resourceName
);
114 java::io::InputStream
*getResourceAsStream (jstring resourceName
);
115 JArray
<jobject
> *getSigners (void);
117 jclass
getSuperclass (void)
122 jboolean
isArray (void)
124 return name
->data
[0] == '[';
127 jboolean
isAssignableFrom (jclass cls
);
128 jboolean
isInstance (jobject obj
);
129 jboolean
isInterface (void);
131 jboolean
isPrimitive (void)
133 return vtable
== JV_PRIMITIVE_VTABLE
;
136 jobject
newInstance (void);
137 jstring
toString (void);
139 // FIXME: this probably shouldn't be public.
142 return size_in_bytes
;
149 void checkMemberAccess (jint flags
);
151 // Various functions to handle class initialization.
152 java::lang::Throwable
*hackTrampoline (jint
, java::lang::Throwable
*);
153 void hackRunInitializers (void);
154 void initializeClass (void);
156 // Friend functions implemented in natClass.cc.
157 friend _Jv_Method
*_Jv_GetMethodLocal (jclass klass
, _Jv_Utf8Const
*name
,
158 _Jv_Utf8Const
*signature
);
159 friend void _Jv_InitClass (jclass klass
);
161 friend jfieldID
JvGetFirstInstanceField (jclass
);
162 friend jint
JvNumInstanceFields (jclass
);
163 friend jobject
_Jv_AllocObject (jclass
, jint
);
164 friend jobjectArray
_Jv_NewObjectArray (jsize
, jclass
, jobject
);
165 friend jobject
_Jv_NewPrimArray (jclass
, jint
);
166 friend jobject
_Jv_JNI_ToReflectedField (_Jv_JNIEnv
*, jclass
, jfieldID
);
167 friend jfieldID
_Jv_FromReflectedField (java::lang::reflect::Field
*);
168 friend jmethodID
_Jv_FromReflectedMethod (java::lang::reflect::Method
*);
170 friend class _Jv_PrimClass
;
172 // Friends classes and functions to implement the ClassLoader
173 friend class java::lang::ClassLoader
;
175 friend void _Jv_WaitForState (jclass
, int);
176 friend void _Jv_RegisterClasses (jclass
*classes
);
177 friend void _Jv_RegisterInitiatingLoader (jclass
,java::lang::ClassLoader
*);
178 friend void _Jv_UnregisterClass (jclass
);
179 friend jclass
_Jv_FindClass (_Jv_Utf8Const
*name
,
180 java::lang::ClassLoader
*loader
);
181 friend jclass
_Jv_FindClassInCache (_Jv_Utf8Const
*name
,
182 java::lang::ClassLoader
*loader
);
183 friend jclass
_Jv_FindArrayClass (jclass element
,
184 java::lang::ClassLoader
*loader
);
185 friend jclass
_Jv_NewClass (_Jv_Utf8Const
*name
, jclass superclass
,
186 java::lang::ClassLoader
*loader
);
188 friend void _Jv_PrepareCompiledClass (jclass
);
191 friend jboolean
_Jv_IsInterpretedClass (jclass
);
192 friend void _Jv_InitField (jobject
, jclass
, _Jv_Field
*);
193 friend _Jv_Method
* _Jv_LookupDeclaredMethod (jclass
, _Jv_Utf8Const
*,
195 friend int _Jv_DetermineVTableIndex (jclass
, _Jv_Utf8Const
*,
197 friend void _Jv_InitField (jobject
, jclass
, int);
198 friend _Jv_word
_Jv_ResolvePoolEntry (jclass
, int);
199 friend void _Jv_PrepareClass (jclass
);
201 friend class _Jv_ClassReader
;
202 friend class _Jv_InterpClass
;
203 friend class _Jv_InterpMethod
;
204 friend class _Jv_InterpMethodInvocation
;
207 #ifdef JV_MARKOBJ_DECL
208 friend JV_MARKOBJ_DECL
;
211 // Chain for class pool.
215 // Access flags for class.
216 unsigned short accflags
;
217 // The superclass, or null for Object.
220 _Jv_Constants constants
;
221 // Methods. If this is an array class, then this field holds a
222 // pointer to the element type. If this is a primitive class, this
223 // is used to cache a pointer to the appropriate array type.
225 // Number of methods. If this class is primitive, this holds the
226 // character used to represent this type in a signature.
228 // Number of methods in the vtable.
229 short vtable_method_count
;
232 // Size of instance fields, in bytes.
234 // Total number of fields (instance and static).
236 // Number of static fields.
237 short static_field_count
;
238 // The vtbl for all objects of this class.
240 // Interfaces implemented by this class.
242 // The class loader for this class.
243 java::lang::ClassLoader
*loader
;
244 // Number of interfaces.
245 short interface_count
;
246 // State of this class.
248 // The thread which has locked this class. Used during class
250 java::lang::Thread
*thread
;
253 #endif /* __JAVA_LANG_CLASS_H__ */