source: branches/GNU/src/gcc/libjava/java/lang/Class.h@ 1391

Last change on this file since 1391 was 1391, checked in by bird, 22 years ago

GCC v3.3.3 sources.

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