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