Class.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. // Class.h - Header file for java.lang.Class. -*- c++ -*-
  2. /* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation
  3. This file is part of libgcj.
  4. This software is copyrighted work licensed under the terms of the
  5. Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
  6. details. */
  7. // Written primary using compiler source and Class.java as guides.
  8. #ifndef __JAVA_LANG_CLASS_H__
  9. #define __JAVA_LANG_CLASS_H__
  10. #pragma interface
  11. #include <stddef.h>
  12. #include <java/lang/Object.h>
  13. #include <java/lang/String.h>
  14. #include <java/net/URL.h>
  15. #include <java/lang/reflect/Modifier.h>
  16. #include <java/security/ProtectionDomain.h>
  17. #include <java/lang/Package.h>
  18. // Avoid including SystemClassLoader.h.
  19. extern "Java"
  20. {
  21. namespace gnu
  22. {
  23. namespace gcj
  24. {
  25. namespace runtime
  26. {
  27. class SystemClassLoader;
  28. }
  29. }
  30. }
  31. }
  32. // We declare these here to avoid including gcj/cni.h.
  33. extern "C" void _Jv_InitClass (jclass klass);
  34. extern "C" jclass _Jv_NewClassFromInitializer
  35. (const char *class_initializer);
  36. extern "C" void _Jv_RegisterNewClasses (char **classes);
  37. extern "C" void _Jv_RegisterClasses (const jclass *classes);
  38. extern "C" void _Jv_RegisterClasses_Counted (const jclass *classes,
  39. size_t count);
  40. // This must be predefined with "C" linkage.
  41. extern "C" void *_Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface,
  42. int meth_idx);
  43. extern "C" void *_Jv_ResolvePoolEntry (jclass this_class, jint index);
  44. // These are the possible values for the `state' field of the class
  45. // structure. Note that ordering is important here. Whenever the
  46. // state changes, one should notify all waiters of this class.
  47. enum
  48. {
  49. JV_STATE_NOTHING = 0, // Set by compiler.
  50. JV_STATE_PRELOADING = 1, // Can do _Jv_FindClass.
  51. // There is an invariant through libgcj that a class will always be
  52. // at a state greater than or equal to JV_STATE_LOADING when it is
  53. // returned by a class loader to user code. Hence, defineclass.cc
  54. // installs supers before returning a class, C++-ABI-compiled
  55. // classes are created with supers installed, and BC-ABI-compiled
  56. // classes are linked to this state before being returned by their
  57. // class loader.
  58. JV_STATE_LOADING = 3, // Has super installed.
  59. JV_STATE_READ = 4, // Has been completely defined.
  60. JV_STATE_LOADED = 5, // Has Miranda methods defined.
  61. JV_STATE_COMPILED = 6, // This was a compiled class.
  62. JV_STATE_PREPARED = 7, // Layout & static init done.
  63. JV_STATE_LINKED = 9, // Strings interned.
  64. JV_STATE_IN_PROGRESS = 10, // <clinit> running.
  65. JV_STATE_ERROR = 12,
  66. JV_STATE_PHANTOM = 13, // Bytecode is missing. In many cases we can
  67. // work around that. If not, throw a
  68. // NoClassDefFoundError.
  69. JV_STATE_DONE = 14, // Must be last.
  70. };
  71. struct _Jv_Field;
  72. struct _Jv_VTable;
  73. union _Jv_word;
  74. struct _Jv_ArrayVTable;
  75. class _Jv_Linker;
  76. class _Jv_ExecutionEngine;
  77. class _Jv_CompiledEngine;
  78. class _Jv_IndirectCompiledEngine;
  79. #ifdef INTERPRETER
  80. class _Jv_InterpreterEngine;
  81. class _Jv_ClassReader;
  82. class _Jv_InterpClass;
  83. class _Jv_InterpMethod;
  84. #endif
  85. class _Jv_ClosureList
  86. {
  87. _Jv_ClosureList *next;
  88. void *ptr;
  89. public:
  90. void registerClosure (jclass klass, void *ptr);
  91. static void releaseClosures (_Jv_ClosureList **closures);
  92. };
  93. struct _Jv_Constants
  94. {
  95. jint size;
  96. jbyte *tags;
  97. _Jv_word *data;
  98. };
  99. struct _Jv_Method
  100. {
  101. // Method name.
  102. _Jv_Utf8Const *name;
  103. // Method signature.
  104. _Jv_Utf8Const *signature;
  105. // Access flags.
  106. _Jv_ushort accflags;
  107. // Method's index in the vtable.
  108. _Jv_ushort index;
  109. // Pointer to underlying function.
  110. void *ncode;
  111. // NULL-terminated list of exception class names; can be NULL if
  112. // there are none such.
  113. _Jv_Utf8Const **throws;
  114. _Jv_Method *getNextMethod ()
  115. { return this + 1; }
  116. };
  117. // The table used to resolve interface calls.
  118. struct _Jv_IDispatchTable
  119. {
  120. // Index into interface's ioffsets.
  121. jshort iindex;
  122. jshort itable_length;
  123. // Class Interface dispatch table.
  124. void *itable[0];
  125. };
  126. // Used by _Jv_Linker::get_interfaces ()
  127. struct _Jv_ifaces
  128. {
  129. jclass *list;
  130. jshort len;
  131. jshort count;
  132. };
  133. struct _Jv_MethodSymbol
  134. {
  135. _Jv_Utf8Const *class_name;
  136. _Jv_Utf8Const *name;
  137. _Jv_Utf8Const *signature;
  138. };
  139. struct _Jv_OffsetTable
  140. {
  141. jint state;
  142. jint offsets[];
  143. };
  144. struct _Jv_AddressTable
  145. {
  146. jint state;
  147. void *addresses[];
  148. };
  149. struct _Jv_CatchClass
  150. {
  151. java::lang::Class **address;
  152. _Jv_Utf8Const *classname;
  153. };
  154. // Possible values for the assertion_code field in the type assertion table.
  155. enum
  156. {
  157. JV_ASSERT_END_OF_TABLE = 0,
  158. JV_ASSERT_TYPES_COMPATIBLE = 1,
  159. JV_ASSERT_IS_INSTANTIABLE = 2
  160. };
  161. // Entry in the type assertion table, used to validate type constraints
  162. // for binary compatibility.
  163. struct _Jv_TypeAssertion
  164. {
  165. jint assertion_code;
  166. _Jv_Utf8Const *op1;
  167. _Jv_Utf8Const *op2;
  168. };
  169. typedef enum
  170. {
  171. JV_CLASS_ATTR,
  172. JV_METHOD_ATTR,
  173. JV_FIELD_ATTR,
  174. JV_DONE_ATTR
  175. } jv_attr_type;
  176. typedef enum
  177. {
  178. JV_INNER_CLASSES_KIND,
  179. JV_ENCLOSING_METHOD_KIND,
  180. JV_SIGNATURE_KIND,
  181. JV_ANNOTATIONS_KIND,
  182. JV_PARAMETER_ANNOTATIONS_KIND,
  183. JV_ANNOTATION_DEFAULT_KIND
  184. } jv_attr_kind;
  185. #define JV_PRIMITIVE_VTABLE ((_Jv_VTable *) -1)
  186. #define JV_CLASS(Obj) ((jclass) (*(_Jv_VTable **) Obj)->clas)
  187. // Forward declarations for friends of java::lang::Class
  188. // Friend functions implemented in natClass.cc.
  189. _Jv_Method *_Jv_GetMethodLocal (jclass klass, _Jv_Utf8Const *name,
  190. _Jv_Utf8Const *signature);
  191. jboolean _Jv_IsAssignableFrom (jclass, jclass);
  192. jboolean _Jv_IsAssignableFromSlow (jclass, jclass);
  193. jboolean _Jv_InterfaceAssignableFrom (jclass, jclass);
  194. _Jv_Method* _Jv_LookupDeclaredMethod (jclass, _Jv_Utf8Const *,
  195. _Jv_Utf8Const*, jclass * = NULL);
  196. java::lang::reflect::Method *_Jv_GetReflectedMethod (jclass klass,
  197. _Jv_Utf8Const *name,
  198. _Jv_Utf8Const *signature);
  199. jfieldID JvGetFirstInstanceField (jclass);
  200. jint JvNumInstanceFields (jclass);
  201. jfieldID JvGetFirstStaticField (jclass);
  202. jint JvNumStaticFields (jclass);
  203. jobject _Jv_AllocObject (jclass);
  204. void *_Jv_AllocObj (jint, jclass);
  205. void *_Jv_AllocPtrFreeObj (jint, jclass);
  206. void *_Jv_AllocArray (jint, jclass);
  207. bool _Jv_getInterfaceMethod(jclass, jclass&, int&,
  208. const _Jv_Utf8Const*,
  209. const _Jv_Utf8Const*);
  210. jobject JNICALL _Jv_JNI_ToReflectedField (_Jv_JNIEnv *, jclass, jfieldID,
  211. jboolean);
  212. jobject JNICALL _Jv_JNI_ToReflectedMethod (_Jv_JNIEnv *, jclass, jmethodID,
  213. jboolean);
  214. jfieldID _Jv_FromReflectedField (java::lang::reflect::Field *);
  215. jmethodID _Jv_FromReflectedMethod (java::lang::reflect::Method *);
  216. jmethodID _Jv_FromReflectedConstructor (java::lang::reflect::Constructor *);
  217. jint JvNumMethods (jclass);
  218. jmethodID JvGetFirstMethod (jclass);
  219. _Jv_Utf8Const *_Jv_GetClassNameUtf8 (jclass);
  220. #ifdef INTERPRETER
  221. // Finds a desired interpreter method in the given class or NULL if not found
  222. class _Jv_MethodBase;
  223. _Jv_MethodBase *_Jv_FindInterpreterMethod (jclass, jmethodID);
  224. jstring _Jv_GetInterpClassSourceFile (jclass);
  225. #endif
  226. jbyte _Jv_GetClassState (jclass);
  227. void _Jv_RegisterClassHookDefault (jclass klass);
  228. void _Jv_RegisterInitiatingLoader (jclass,java::lang::ClassLoader*);
  229. void _Jv_UnregisterInitiatingLoader (jclass,java::lang::ClassLoader*);
  230. void _Jv_UnregisterClass (jclass);
  231. jclass _Jv_FindClassNoException (_Jv_Utf8Const *name,
  232. java::lang::ClassLoader *loader);
  233. jclass _Jv_FindClass (_Jv_Utf8Const *name,
  234. java::lang::ClassLoader *loader);
  235. jclass _Jv_FindClassInCache (_Jv_Utf8Const *name);
  236. jclass _Jv_PopClass (void);
  237. void _Jv_PushClass (jclass k);
  238. void _Jv_NewArrayClass (jclass element,
  239. java::lang::ClassLoader *loader,
  240. _Jv_VTable *array_vtable = 0);
  241. jclass _Jv_NewClass (_Jv_Utf8Const *name, jclass superclass,
  242. java::lang::ClassLoader *loader);
  243. void _Jv_InitNewClassFields (jclass klass);
  244. // Friend functions and classes in prims.cc
  245. void _Jv_InitPrimClass (jclass, const char *, char, int);
  246. jstring _Jv_GetMethodString (jclass, _Jv_Method *, jclass = NULL);
  247. jboolean _Jv_CheckAccess (jclass self_klass, jclass other_klass,
  248. jint flags);
  249. jclass _Jv_GetArrayClass (jclass klass, java::lang::ClassLoader *loader);
  250. jboolean _Jv_IsInterpretedClass (jclass);
  251. jboolean _Jv_IsBinaryCompatibilityABI (jclass);
  252. jboolean _Jv_IsPhantomClass (jclass);
  253. void _Jv_CopyClassesToSystemLoader (gnu::gcj::runtime::SystemClassLoader *);
  254. #ifdef INTERPRETER
  255. void _Jv_InitField (jobject, jclass, int);
  256. #endif
  257. class _Jv_StackTrace;
  258. class _Jv_BytecodeVerifier;
  259. void _Jv_sharedlib_register_hook (jclass klass);
  260. /* Find the class that defines the given method. Returns NULL
  261. if it cannot be found. Searches both interpreted and native
  262. classes. */
  263. jclass _Jv_GetMethodDeclaringClass (jmethodID method);
  264. class java::lang::Class : public java::lang::Object
  265. {
  266. public:
  267. static jclass forName (jstring className, jboolean initialize,
  268. java::lang::ClassLoader *loader);
  269. static jclass forName (jstring className);
  270. JArray<jclass> *getClasses (void);
  271. java::lang::ClassLoader *getClassLoader (void);
  272. private:
  273. java::lang::ClassLoader *getClassLoader (jclass caller);
  274. public:
  275. // This is an internal method that circumvents the usual security
  276. // checks when getting the class loader.
  277. java::lang::ClassLoader *getClassLoaderInternal (void)
  278. {
  279. return loader;
  280. }
  281. java::lang::reflect::Constructor *getConstructor (JArray<jclass> *);
  282. JArray<java::lang::reflect::Constructor *> *getConstructors (void);
  283. java::lang::reflect::Constructor *getDeclaredConstructor (JArray<jclass> *);
  284. JArray<java::lang::reflect::Constructor *> *getDeclaredConstructors (jboolean);
  285. java::lang::reflect::Field *getDeclaredField (jstring);
  286. JArray<java::lang::reflect::Field *> *getDeclaredFields ();
  287. JArray<java::lang::reflect::Field *> *getDeclaredFields (jboolean);
  288. java::lang::reflect::Method *getDeclaredMethod (jstring, JArray<jclass> *);
  289. JArray<java::lang::reflect::Method *> *getDeclaredMethods (void);
  290. JArray<jclass> *getDeclaredClasses (void);
  291. JArray<jclass> *getDeclaredClasses (jboolean);
  292. jclass getDeclaringClass (void);
  293. java::lang::reflect::Field *getField (jstring);
  294. private:
  295. JArray<java::lang::reflect::Field *> internalGetFields ();
  296. java::lang::reflect::Field *getField (jstring, jint);
  297. jint _getMethods (JArray<java::lang::reflect::Method *> *result,
  298. jint offset);
  299. java::lang::reflect::Field *getPrivateField (jstring);
  300. java::lang::reflect::Method *getPrivateMethod (jstring, JArray<jclass> *);
  301. java::security::ProtectionDomain *getProtectionDomain0 ();
  302. java::lang::reflect::Method *_getMethod (jstring, JArray<jclass> *);
  303. java::lang::reflect::Method *_getDeclaredMethod (jstring, JArray<jclass> *);
  304. jstring getReflectionSignature (jint /*jv_attr_type*/ type,
  305. jint obj_index);
  306. jstring getReflectionSignature (::java::lang::reflect::Method *);
  307. jstring getReflectionSignature (::java::lang::reflect::Constructor *);
  308. jstring getReflectionSignature (::java::lang::reflect::Field *);
  309. jstring getClassSignature();
  310. jobject getMethodDefaultValue (::java::lang::reflect::Method *);
  311. public:
  312. JArray<java::lang::reflect::Field *> *getFields (void);
  313. JArray<jclass> *getInterfaces (void);
  314. void getSignature (java::lang::StringBuffer *buffer);
  315. static jstring getSignature (JArray<jclass> *, jboolean is_constructor);
  316. JArray<java::lang::reflect::Method *> *getMethods (void);
  317. inline jint getModifiers (void)
  318. {
  319. return accflags & java::lang::reflect::Modifier::ALL_FLAGS;
  320. }
  321. jstring getName (void);
  322. java::net::URL *getResource (jstring resourceName);
  323. java::io::InputStream *getResourceAsStream (jstring resourceName);
  324. JArray<jobject> *getSigners (void);
  325. void setSigners(JArray<jobject> *);
  326. inline jclass getSuperclass (void)
  327. {
  328. return superclass;
  329. }
  330. inline jclass getInterface (jint n)
  331. {
  332. return interfaces[n];
  333. }
  334. inline jboolean isArray (void)
  335. {
  336. return name->first() == '[';
  337. }
  338. inline jclass getComponentType (void)
  339. {
  340. return isArray () ? element_type : 0;
  341. }
  342. jboolean isAssignableFrom (jclass cls);
  343. jboolean isInstance (jobject obj);
  344. inline jboolean isInterface (void)
  345. {
  346. return (accflags & java::lang::reflect::Modifier::INTERFACE) != 0;
  347. }
  348. inline jboolean isPrimitive (void)
  349. {
  350. return vtable == JV_PRIMITIVE_VTABLE;
  351. }
  352. jobject newInstance (void);
  353. java::security::ProtectionDomain *getProtectionDomain (void);
  354. java::lang::Package *getPackage (void);
  355. jstring toString (void);
  356. jboolean desiredAssertionStatus (void);
  357. JArray<java::lang::reflect::TypeVariable *> *getTypeParameters (void);
  358. jint getEnclosingMethodData(void);
  359. java::lang::Class *getEnclosingClass (void);
  360. java::lang::reflect::Constructor *getEnclosingConstructor (void);
  361. java::lang::reflect::Method *getEnclosingMethod (void);
  362. jobjectArray getDeclaredAnnotations(jint, jint, jint);
  363. jobjectArray getDeclaredAnnotations(::java::lang::reflect::Method *,
  364. jboolean);
  365. jobjectArray getDeclaredAnnotations(::java::lang::reflect::Constructor *,
  366. jboolean);
  367. jobjectArray getDeclaredAnnotations(::java::lang::reflect::Field *);
  368. JArray< ::java::lang::annotation::Annotation *> *getDeclaredAnnotationsInternal();
  369. jboolean isEnum (void)
  370. {
  371. return (accflags & 0x4000) != 0;
  372. }
  373. jboolean isSynthetic (void)
  374. {
  375. return (accflags & 0x1000) != 0;
  376. }
  377. jboolean isAnnotation (void)
  378. {
  379. return (accflags & 0x2000) != 0;
  380. }
  381. jboolean isAnonymousClass();
  382. jboolean isLocalClass();
  383. jboolean isMemberClass();
  384. // FIXME: this probably shouldn't be public.
  385. jint size (void)
  386. {
  387. return size_in_bytes;
  388. }
  389. // The index of the first method we declare ourself (as opposed to
  390. // inheriting).
  391. inline jint firstMethodIndex (void)
  392. {
  393. return vtable_method_count - method_count;
  394. }
  395. // finalization
  396. void finalize ();
  397. // This constructor is used to create Class object for the primitive
  398. // types. See prims.cc.
  399. Class ();
  400. // Given the BC ABI version, return the size of an Class initializer.
  401. static jlong initializerSize (jlong ABI)
  402. {
  403. unsigned long version = ABI & 0xfffff;
  404. int abi_rev = version % 100;
  405. // The reflection_data field was added by abi_rev 1.
  406. if (abi_rev == 0)
  407. return ((char*)(&::java::lang::Class::class$.reflection_data)
  408. - (char*)&::java::lang::Class::class$);
  409. return sizeof (::java::lang::Class);
  410. }
  411. static java::lang::Class class$;
  412. private:
  413. void memberAccessCheck (jint flags);
  414. void initializeClass (void);
  415. static jstring getPackagePortion (jstring);
  416. void set_state (jint nstate)
  417. {
  418. state = nstate;
  419. notifyAll ();
  420. }
  421. jint findInnerClassAttribute();
  422. jint findDeclaredClasses(JArray<jclass> *, jboolean, jint);
  423. // Friend functions implemented in natClass.cc.
  424. friend _Jv_Method *::_Jv_GetMethodLocal (jclass klass, _Jv_Utf8Const *name,
  425. _Jv_Utf8Const *signature);
  426. friend jboolean (::_Jv_IsAssignableFrom) (jclass, jclass);
  427. friend jboolean (::_Jv_IsAssignableFromSlow) (jclass, jclass);
  428. friend jboolean (::_Jv_InterfaceAssignableFrom) (jclass, jclass);
  429. friend void *::_Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface,
  430. int method_idx);
  431. friend void ::_Jv_InitClass (jclass klass);
  432. friend java::lang::Class* ::_Jv_NewClassFromInitializer (const char *class_initializer);
  433. friend void _Jv_RegisterNewClasses (void **classes);
  434. friend _Jv_Method* ::_Jv_LookupDeclaredMethod (jclass, _Jv_Utf8Const *,
  435. _Jv_Utf8Const*, jclass *);
  436. friend java::lang::reflect::Method* ::_Jv_GetReflectedMethod (jclass klass,
  437. _Jv_Utf8Const *name,
  438. _Jv_Utf8Const *signature);
  439. friend jfieldID (::JvGetFirstInstanceField) (jclass);
  440. friend jint (::JvNumInstanceFields) (jclass);
  441. friend jfieldID (::JvGetFirstStaticField) (jclass);
  442. friend jint (::JvNumStaticFields) (jclass);
  443. friend jobject (::_Jv_AllocObject) (jclass);
  444. friend void *::_Jv_AllocObj (jint, jclass);
  445. friend void *::_Jv_AllocPtrFreeObj (jint, jclass);
  446. friend void *::_Jv_AllocArray (jint, jclass);
  447. friend jobject JNICALL (::_Jv_JNI_ToReflectedField) (_Jv_JNIEnv *, jclass, jfieldID,
  448. jboolean);
  449. friend jobject (::_Jv_JNI_ToReflectedMethod) (_Jv_JNIEnv *, jclass, jmethodID,
  450. jboolean);
  451. friend jfieldID (::_Jv_FromReflectedField) (java::lang::reflect::Field *);
  452. friend jmethodID (::_Jv_FromReflectedMethod) (java::lang::reflect::Method *);
  453. friend jmethodID (::_Jv_FromReflectedConstructor) (java::lang::reflect::Constructor *);
  454. friend jint (::JvNumMethods) (jclass);
  455. friend jmethodID (::JvGetFirstMethod) (jclass);
  456. friend _Jv_Utf8Const *::_Jv_GetClassNameUtf8 (jclass);
  457. #ifdef INTERPRETER
  458. friend _Jv_MethodBase *(::_Jv_FindInterpreterMethod) (jclass klass,
  459. jmethodID desired_method);
  460. friend jstring ::_Jv_GetInterpClassSourceFile (jclass);
  461. #endif
  462. friend jbyte (::_Jv_GetClassState) (jclass klass);
  463. // Friends classes and functions to implement the ClassLoader
  464. friend class java::lang::ClassLoader;
  465. friend class java::lang::VMClassLoader;
  466. friend class java::io::ObjectOutputStream;
  467. friend class java::io::ObjectInputStream;
  468. friend class java::io::ObjectStreamClass;
  469. friend void ::_Jv_RegisterClasses (const jclass *classes);
  470. friend void ::_Jv_RegisterClasses_Counted (const jclass *classes,
  471. size_t count);
  472. friend void ::_Jv_RegisterClassHookDefault (jclass klass);
  473. friend void ::_Jv_RegisterInitiatingLoader (jclass,java::lang::ClassLoader*);
  474. friend void ::_Jv_UnregisterInitiatingLoader (jclass,java::lang::ClassLoader*);
  475. friend void ::_Jv_UnregisterClass (jclass);
  476. friend jclass (::_Jv_FindClassNoException) (_Jv_Utf8Const *name,
  477. java::lang::ClassLoader *loader);
  478. friend jclass (::_Jv_FindClass) (_Jv_Utf8Const *name,
  479. java::lang::ClassLoader *loader);
  480. friend jclass (::_Jv_FindClassInCache) (_Jv_Utf8Const *name);
  481. friend jclass (::_Jv_PopClass) (void);
  482. friend void ::_Jv_PushClass (jclass k);
  483. friend void ::_Jv_NewArrayClass (jclass element,
  484. java::lang::ClassLoader *loader,
  485. _Jv_VTable *array_vtable);
  486. friend jclass (::_Jv_NewClass) (_Jv_Utf8Const *name, jclass superclass,
  487. java::lang::ClassLoader *loader);
  488. friend void ::_Jv_InitNewClassFields (jclass klass);
  489. // in prims.cc
  490. friend void ::_Jv_InitPrimClass (jclass, const char *, char, int);
  491. friend jstring (::_Jv_GetMethodString) (jclass, _Jv_Method *, jclass);
  492. friend jboolean (::_Jv_CheckAccess) (jclass self_klass, jclass other_klass,
  493. jint flags);
  494. friend bool (::_Jv_getInterfaceMethod) (jclass, jclass&, int&,
  495. const _Jv_Utf8Const*,
  496. const _Jv_Utf8Const*);
  497. friend jclass (::_Jv_GetArrayClass) (jclass klass,
  498. java::lang::ClassLoader *loader);
  499. friend jboolean (::_Jv_IsInterpretedClass) (jclass);
  500. friend jboolean (::_Jv_IsBinaryCompatibilityABI) (jclass);
  501. friend jboolean (::_Jv_IsPhantomClass) (jclass);
  502. #ifdef INTERPRETER
  503. friend void ::_Jv_InitField (jobject, jclass, int);
  504. friend class ::_Jv_ClassReader;
  505. friend class ::_Jv_InterpClass;
  506. friend class ::_Jv_InterpMethod;
  507. friend class ::_Jv_InterpreterEngine;
  508. #endif
  509. friend class ::_Jv_StackTrace;
  510. #ifdef JV_MARKOBJ_DECL
  511. friend JV_MARKOBJ_DECL;
  512. #endif
  513. friend class ::_Jv_BytecodeVerifier;
  514. friend class java::io::VMObjectStreamClass;
  515. friend class ::_Jv_Linker;
  516. friend class ::_Jv_ExecutionEngine;
  517. friend class ::_Jv_CompiledEngine;
  518. friend class ::_Jv_IndirectCompiledEngine;
  519. friend class ::_Jv_ClosureList;
  520. friend void ::_Jv_sharedlib_register_hook (jclass klass);
  521. friend void *::_Jv_ResolvePoolEntry (jclass this_class, jint index);
  522. friend void ::_Jv_CopyClassesToSystemLoader (gnu::gcj::runtime::SystemClassLoader *);
  523. friend class java::lang::reflect::Field;
  524. friend class java::lang::reflect::Method;
  525. friend class java::lang::reflect::Constructor;
  526. friend class java::lang::reflect::VMProxy;
  527. // Chain for class pool. This also doubles as the ABI version
  528. // number. It is only used for this purpose at class registration
  529. // time, and only for precompiled classes.
  530. jclass next_or_version;
  531. // Name of class.
  532. _Jv_Utf8Const *name;
  533. // Access flags for class.
  534. _Jv_ushort accflags;
  535. // The superclass, or null for Object.
  536. jclass superclass;
  537. // Class constants.
  538. _Jv_Constants constants;
  539. // Methods. If this is an array class, then this field holds a
  540. // pointer to the element type.
  541. union
  542. {
  543. _Jv_Method *methods;
  544. jclass element_type;
  545. };
  546. // Number of methods. If this class is primitive, this holds the
  547. // character used to represent this type in a signature.
  548. jshort method_count;
  549. // Number of methods in the vtable.
  550. jshort vtable_method_count;
  551. // The fields.
  552. _Jv_Field *fields;
  553. // Size of instance fields, in bytes.
  554. jint size_in_bytes;
  555. // Total number of fields (instance and static).
  556. jshort field_count;
  557. // Number of static fields.
  558. jshort static_field_count;
  559. // The vtbl for all objects of this class.
  560. _Jv_VTable *vtable;
  561. // Virtual method offset table.
  562. _Jv_OffsetTable *otable;
  563. // Offset table symbols.
  564. _Jv_MethodSymbol *otable_syms;
  565. // Address table
  566. _Jv_AddressTable *atable;
  567. _Jv_MethodSymbol *atable_syms;
  568. // Interface table
  569. _Jv_AddressTable *itable;
  570. _Jv_MethodSymbol *itable_syms;
  571. _Jv_CatchClass *catch_classes;
  572. // Interfaces implemented by this class.
  573. jclass *interfaces;
  574. // The class loader for this class.
  575. java::lang::ClassLoader *loader;
  576. // Number of interfaces.
  577. jshort interface_count;
  578. // State of this class.
  579. jbyte state;
  580. // The thread which has locked this class. Used during class
  581. // initialization.
  582. java::lang::Thread *thread;
  583. // How many levels of "extends" this class is removed from Object.
  584. jshort depth;
  585. // Vector of this class's superclasses, ordered by decreasing depth.
  586. jclass *ancestors;
  587. // In a regular class, this field points to the Class Interface Dispatch
  588. // Table. In an interface, it points to the ioffsets table.
  589. union
  590. {
  591. _Jv_IDispatchTable *idt;
  592. jshort *ioffsets;
  593. };
  594. // Pointer to the class that represents an array of this class.
  595. jclass arrayclass;
  596. // Security Domain to which this class belongs (or null).
  597. java::security::ProtectionDomain *protectionDomain;
  598. // Pointer to the type assertion table for this class.
  599. _Jv_TypeAssertion *assertion_table;
  600. // Signers of this class (or null).
  601. JArray<jobject> *hack_signers;
  602. // Used by Jv_PopClass and _Jv_PushClass to communicate with StackTrace.
  603. jclass chain;
  604. // Additional data, specific to the generator (JIT, native,
  605. // interpreter) of this class.
  606. void *aux_info;
  607. // Execution engine.
  608. _Jv_ExecutionEngine *engine;
  609. // Reflection data.
  610. unsigned char *reflection_data;
  611. };
  612. // Inline functions that are friends of java::lang::Class
  613. inline void _Jv_InitClass (jclass klass)
  614. {
  615. if (__builtin_expect (klass->state == JV_STATE_DONE, true))
  616. return;
  617. klass->initializeClass ();
  618. }
  619. // Return array class corresponding to element type KLASS, creating it if
  620. // necessary.
  621. inline jclass
  622. _Jv_GetArrayClass (jclass klass, java::lang::ClassLoader *loader)
  623. {
  624. extern void _Jv_NewArrayClass (jclass element,
  625. java::lang::ClassLoader *loader,
  626. _Jv_VTable *array_vtable = 0);
  627. if (__builtin_expect (!klass->arrayclass, false))
  628. _Jv_NewArrayClass (klass, loader);
  629. return klass->arrayclass;
  630. }
  631. #endif /* __JAVA_LANG_CLASS_H__ */