2006-02-01 Robert Schuster <robertschuster@fsfe.org>
[gcc.git] / libjava / include / jvm.h
1 // jvm.h - Header file for private implementation information. -*- c++ -*-
2
3 /* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 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 #ifndef __JAVA_JVM_H__
12 #define __JAVA_JVM_H__
13
14 // Define this before including jni.h.
15 // jni.h is included by jvmpi.h, which might be included. We define
16 // this unconditionally because it is convenient and it lets other
17 // files include jni.h without difficulty.
18 #define __GCJ_JNI_IMPL__
19
20 #include <gcj/javaprims.h>
21
22 #include <java-assert.h>
23 #include <java-threads.h>
24 // Must include java-gc.h before Object.h for the implementation.
25 #include <java-gc.h>
26
27 #include <java/lang/Object.h>
28
29 // Include cni.h before field.h to enable all definitions. FIXME.
30 #include <gcj/cni.h>
31 #include <gcj/field.h>
32
33 /* Macro for possible unused arguments. */
34 #define MAYBE_UNUSED __attribute__((__unused__))
35
36 /* Structure of the virtual table. */
37 struct _Jv_VTable
38 {
39 #ifdef __ia64__
40 typedef struct { void *pc, *gp; } vtable_elt;
41 #else
42 typedef void *vtable_elt;
43 #endif
44 jclass clas;
45 void *gc_descr;
46
47 // This must be last, as derived classes "extend" this by
48 // adding new data members.
49 vtable_elt method[1];
50
51 #ifdef __ia64__
52 void *get_method(int i) { return &method[i]; }
53 void set_method(int i, void *fptr) { method[i] = *(vtable_elt *)fptr; }
54 void *get_finalizer()
55 {
56 // We know that get_finalizer is only used for checking whether
57 // this object needs to have a finalizer registered. So it is
58 // safe to simply return just the PC component of the vtable
59 // slot.
60 return ((vtable_elt *)(get_method(0)))->pc;
61 }
62 #else
63 void *get_method(int i) { return method[i]; }
64 void set_method(int i, void *fptr) { method[i] = fptr; }
65 void *get_finalizer() { return get_method(0); }
66 #endif
67
68 static size_t vtable_elt_size() { return sizeof(vtable_elt); }
69
70 // Given a method index, return byte offset from the vtable pointer.
71 static jint idx_to_offset (int index)
72 {
73 return (2 * sizeof (void *)) + (index * vtable_elt_size ());
74 }
75 static _Jv_VTable *new_vtable (int count);
76 };
77
78 union _Jv_word
79 {
80 jobject o;
81 jint i; // Also stores smaller integral types.
82 jfloat f;
83 jint ia[1]; // Half of _Jv_word2.
84 void* p;
85
86 #if SIZEOF_VOID_P == 8
87 // We can safely put a long or a double in here without increasing
88 // the size of _Jv_Word; we take advantage of this in the interpreter.
89 jlong l;
90 jdouble d;
91 #endif
92
93 jclass clazz;
94 jstring string;
95 struct _Jv_Field *field;
96 struct _Jv_Utf8Const *utf8;
97 struct _Jv_ResolvedMethod *rmethod;
98 };
99
100 union _Jv_word2
101 {
102 jint ia[2];
103 jlong l;
104 jdouble d;
105 };
106
107 union _Jv_value
108 {
109 jbyte byte_value;
110 jshort short_value;
111 jchar char_value;
112 jint int_value;
113 jlong long_value;
114 jfloat float_value;
115 jdouble double_value;
116 jobject object_value;
117 };
118
119 /* Extract a character from a Java-style Utf8 string.
120 * PTR points to the current character.
121 * LIMIT points to the end of the Utf8 string.
122 * PTR is incremented to point after the character thta gets returns.
123 * On an error, -1 is returned. */
124 #define UTF8_GET(PTR, LIMIT) \
125 ((PTR) >= (LIMIT) ? -1 \
126 : *(PTR) < 128 ? *(PTR)++ \
127 : (*(PTR)&0xE0) == 0xC0 && ((PTR)+=2)<=(LIMIT) && ((PTR)[-1]&0xC0) == 0x80 \
128 ? (((PTR)[-2] & 0x1F) << 6) + ((PTR)[-1] & 0x3F) \
129 : (*(PTR) & 0xF0) == 0xE0 && ((PTR) += 3) <= (LIMIT) \
130 && ((PTR)[-2] & 0xC0) == 0x80 && ((PTR)[-1] & 0xC0) == 0x80 \
131 ? (((PTR)[-3]&0x0F) << 12) + (((PTR)[-2]&0x3F) << 6) + ((PTR)[-1]&0x3F) \
132 : ((PTR)++, -1))
133
134 extern int _Jv_strLengthUtf8(char* str, int len);
135
136 typedef struct _Jv_Utf8Const Utf8Const;
137 _Jv_Utf8Const *_Jv_makeUtf8Const (char *s, int len);
138 _Jv_Utf8Const *_Jv_makeUtf8Const (jstring string);
139 extern jboolean _Jv_equalUtf8Consts (const _Jv_Utf8Const *, const _Jv_Utf8Const *);
140 extern jboolean _Jv_equal (_Jv_Utf8Const *, jstring, jint);
141 extern jboolean _Jv_equaln (_Jv_Utf8Const *, jstring, jint);
142
143 /* Helper class which converts a jstring to a temporary char*.
144 Uses the supplied buffer, if non-null. Otherwise, allocates
145 the buffer on the heap. Use the JV_TEMP_UTF_STRING macro,
146 which follows, to automatically allocate a stack buffer if
147 the string is small enough. */
148 class _Jv_TempUTFString
149 {
150 public:
151 _Jv_TempUTFString(jstring jstr, char* buf=0);
152 ~_Jv_TempUTFString();
153
154 // Accessors
155 operator const char*() const
156 {
157 return buf_;
158 }
159 const char* buf() const
160 {
161 return buf_;
162 }
163 char* buf()
164 {
165 return buf_;
166 }
167
168 private:
169 char* buf_;
170 bool heapAllocated_;
171 };
172
173 inline _Jv_TempUTFString::_Jv_TempUTFString (jstring jstr, char* buf)
174 : buf_(0), heapAllocated_(false)
175 {
176 if (!jstr) return;
177 jsize len = JvGetStringUTFLength (jstr);
178 if (buf)
179 buf_ = buf;
180 else
181 {
182 buf_ = (char*) _Jv_Malloc (len+1);
183 heapAllocated_ = true;
184 }
185
186 JvGetStringUTFRegion (jstr, 0, jstr->length(), buf_);
187 buf_[len] = '\0';
188 }
189
190 inline _Jv_TempUTFString::~_Jv_TempUTFString ()
191 {
192 if (heapAllocated_)
193 _Jv_Free (buf_);
194 }
195
196 /* Macro which uses _Jv_TempUTFString. Allocates a stack-based
197 buffer if the string and its null terminator are <= 256
198 characters in length. Otherwise, a heap-based buffer is
199 used. The parameters to this macro are the variable name
200 which is an instance of _Jv_TempUTFString (above) and a
201 jstring.
202
203 Sample Usage:
204
205 jstring jstr = getAJString();
206 JV_TEMP_UTF_STRING(utfstr, jstr);
207 printf("The string is: %s\n", utfstr.buf());
208
209 */
210 #define JV_TEMP_UTF_STRING(utfstr, jstr) \
211 jstring utfstr##thejstr = (jstr); \
212 jsize utfstr##_len = utfstr##thejstr ? JvGetStringUTFLength (utfstr##thejstr) + 1 : 0; \
213 char utfstr##_buf[utfstr##_len <= 256 ? utfstr##_len : 0]; \
214 _Jv_TempUTFString utfstr(utfstr##thejstr, sizeof(utfstr##_buf)==0 ? 0 : utfstr##_buf)
215
216 namespace gcj
217 {
218 /* Some constants used during lookup of special class methods. */
219 extern _Jv_Utf8Const *void_signature; /* "()V" */
220 extern _Jv_Utf8Const *clinit_name; /* "<clinit>" */
221 extern _Jv_Utf8Const *init_name; /* "<init>" */
222 extern _Jv_Utf8Const *finit_name; /* "finit$", */
223
224 /* Set to true by _Jv_CreateJavaVM. */
225 extern bool runtimeInitialized;
226
227 /* Print out class names as they are initialized. */
228 extern bool verbose_class_flag;
229
230 /* When true, enable the bytecode verifier and BC-ABI verification. */
231 extern bool verifyClasses;
232
233 /* Thread stack size specified by the -Xss runtime argument. */
234 extern size_t stack_size;
235 }
236
237 // This class handles all aspects of class preparation and linking.
238 class _Jv_Linker
239 {
240 private:
241 static _Jv_Field *find_field_helper(jclass, _Jv_Utf8Const *, _Jv_Utf8Const *,
242 jclass, jclass *);
243 static _Jv_Field *find_field(jclass, jclass, jclass *, _Jv_Utf8Const *,
244 _Jv_Utf8Const *);
245 static void prepare_constant_time_tables(jclass);
246 static jshort get_interfaces(jclass, _Jv_ifaces *);
247 static void link_symbol_table(jclass);
248 static void link_exception_table(jclass);
249 static void layout_interface_methods(jclass);
250 static void layout_vtable_methods(jclass);
251 static void set_vtable_entries(jclass, _Jv_VTable *);
252 static void make_vtable(jclass);
253 static void ensure_fields_laid_out(jclass);
254 static void ensure_class_linked(jclass);
255 static void ensure_supers_installed(jclass);
256 static void add_miranda_methods(jclass, jclass);
257 static void ensure_method_table_complete(jclass);
258 static void verify_class(jclass);
259 static jshort find_iindex(jclass *, jshort *, jshort);
260 static jshort indexof(void *, void **, jshort);
261 static int get_alignment_from_class(jclass);
262 static void generate_itable(jclass, _Jv_ifaces *, jshort *);
263 static jshort append_partial_itable(jclass, jclass, void **, jshort);
264 static _Jv_Method *search_method_in_class (jclass, jclass,
265 _Jv_Utf8Const *,
266 _Jv_Utf8Const *);
267
268 public:
269
270 static bool has_field_p (jclass, _Jv_Utf8Const *);
271 static void print_class_loaded (jclass);
272 static void resolve_class_ref (jclass, jclass *);
273 static void wait_for_state(jclass, int);
274 static _Jv_word resolve_pool_entry (jclass, int, bool =false);
275 static void resolve_field (_Jv_Field *, java::lang::ClassLoader *);
276 static void verify_type_assertions (jclass);
277 };
278
279 /* Type of pointer used as finalizer. */
280 typedef void _Jv_FinalizerFunc (jobject);
281
282 /* Allocate space for a new Java object. */
283 void *_Jv_AllocObj (jsize size, jclass cl) __attribute__((__malloc__));
284 /* Allocate space for a potentially uninitialized pointer-free object.
285 Interesting only with JV_HASH_SYNCHRONIZATION. */
286 void *_Jv_AllocPtrFreeObj (jsize size, jclass cl) __attribute__((__malloc__));
287 /* Allocate space for an array of Java objects. */
288 void *_Jv_AllocArray (jsize size, jclass cl) __attribute__((__malloc__));
289 /* Allocate space that is known to be pointer-free. */
290 void *_Jv_AllocBytes (jsize size) __attribute__((__malloc__));
291 /* Allocate space for a new non-Java object, which does not have the usual
292 Java object header but may contain pointers to other GC'ed objects. */
293 void *_Jv_AllocRawObj (jsize size) __attribute__((__malloc__));
294 /* Explicitly throw an out-of-memory exception. */
295 void _Jv_ThrowNoMemory() __attribute__((__noreturn__));
296 /* Allocate an object with a single pointer. The first word is reserved
297 for the GC, and the second word is the traced pointer. */
298 void *_Jv_AllocTraceOne (jsize size /* incl. reserved slot */);
299 /* Ditto, but for two traced pointers. */
300 void *_Jv_AllocTraceTwo (jsize size /* incl. reserved slot */);
301 /* Initialize the GC. */
302 void _Jv_InitGC (void);
303 /* Register a finalizer. */
304 void _Jv_RegisterFinalizer (void *object, _Jv_FinalizerFunc *method);
305 /* Compute the GC descriptor for a class */
306 void * _Jv_BuildGCDescr(jclass);
307
308 /* Allocate some unscanned, unmoveable memory. Return NULL if out of
309 memory. */
310 void *_Jv_MallocUnchecked (jsize size) __attribute__((__malloc__));
311
312 /* Initialize finalizers. The argument is a function to be called
313 when a finalizer is ready to be run. */
314 void _Jv_GCInitializeFinalizers (void (*notifier) (void));
315 /* Run finalizers for objects ready to be finalized.. */
316 void _Jv_RunFinalizers (void);
317 /* Run all finalizers. Should be called only before exit. */
318 void _Jv_RunAllFinalizers (void);
319 /* Perform a GC. */
320 void _Jv_RunGC (void);
321 /* Disable and enable GC. */
322 void _Jv_DisableGC (void);
323 void _Jv_EnableGC (void);
324 /* Register a disappearing link. This is a field F which should be
325 cleared when *F is found to be inaccessible. This is used in the
326 implementation of java.lang.ref.Reference. */
327 void _Jv_GCRegisterDisappearingLink (jobject *objp);
328 /* Return true if OBJECT should be reclaimed. This is used to
329 implement soft references. */
330 jboolean _Jv_GCCanReclaimSoftReference (jobject obj);
331
332 /* Register a finalizer for a String object. This is only used by
333 the intern() implementation. */
334 void _Jv_RegisterStringFinalizer (jobject str);
335 /* This is called to actually finalize a possibly-intern()d String. */
336 void _Jv_FinalizeString (jobject str);
337
338 /* Return approximation of total size of heap. */
339 long _Jv_GCTotalMemory (void);
340 /* Return approximation of total free memory. */
341 long _Jv_GCFreeMemory (void);
342
343 /* Set initial heap size. If SIZE==0, ignore. Should be run before
344 _Jv_InitGC. Not required to have any actual effect. */
345 void _Jv_GCSetInitialHeapSize (size_t size);
346
347 /* Set maximum heap size. If SIZE==0, unbounded. Should be run
348 before _Jv_InitGC. Not required to have any actual effect. */
349 void _Jv_GCSetMaximumHeapSize (size_t size);
350
351 /* External interface to setting the heap size. Parses ARG (a number
352 which can optionally have "k" or "m" appended and calls
353 _Jv_GCSetInitialHeapSize. */
354 void _Jv_SetInitialHeapSize (const char *arg);
355
356 /* External interface to setting the maximum heap size. Parses ARG (a
357 number which can optionally have "k" or "m" appended and calls
358 _Jv_GCSetMaximumHeapSize. */
359 void _Jv_SetMaximumHeapSize (const char *arg);
360
361 /* Free the method cache, if one was allocated. This is only called
362 during thread deregistration. */
363 void _Jv_FreeMethodCache ();
364
365 /* Set the stack size for threads. Parses ARG, a number which can
366 optionally have "k" or "m" appended. */
367 void _Jv_SetStackSize (const char *arg);
368
369 extern "C" void JvRunMain (jclass klass, int argc, const char **argv);
370 void _Jv_RunMain (jclass klass, const char *name, int argc, const char **argv,
371 bool is_jar);
372
373 void _Jv_RunMain (struct _Jv_VMInitArgs *vm_args, jclass klass,
374 const char *name, int argc, const char **argv, bool is_jar);
375
376 // Delayed until after _Jv_AllocBytes is declared.
377 //
378 // Note that we allocate this as unscanned memory -- the vtables
379 // are handled specially by the GC.
380
381 inline _Jv_VTable *
382 _Jv_VTable::new_vtable (int count)
383 {
384 size_t size = sizeof(_Jv_VTable) + (count - 1) * vtable_elt_size ();
385 return (_Jv_VTable *) _Jv_AllocBytes (size);
386 }
387
388 // Determine if METH gets an entry in a VTable.
389 static inline jboolean _Jv_isVirtualMethod (_Jv_Method *meth)
390 {
391 using namespace java::lang::reflect;
392 return (((meth->accflags & (Modifier::STATIC | Modifier::PRIVATE)) == 0)
393 && meth->name->first() != '<');
394 }
395
396 // This function is used to determine the hash code of an object.
397 inline jint
398 _Jv_HashCode (jobject obj)
399 {
400 // This was chosen to yield relatively well distributed results on
401 // both 32- and 64-bit architectures. Note 0x7fffffff is prime.
402 // FIXME: we assume sizeof(long) == sizeof(void *).
403 return (jint) ((unsigned long) obj % 0x7fffffff);
404 }
405
406 // Return a raw pointer to the elements of an array given the array
407 // and its element type. You might think we could just pick a single
408 // array type and use elements() on it, but we can't because we must
409 // account for alignment of the element type. When ARRAY is null, we
410 // obtain the number of bytes taken by the base part of the array.
411 inline char *
412 _Jv_GetArrayElementFromElementType (jobject array,
413 jclass element_type)
414 {
415 char *elts;
416 if (element_type == JvPrimClass (byte))
417 elts = (char *) elements ((jbyteArray) array);
418 else if (element_type == JvPrimClass (short))
419 elts = (char *) elements ((jshortArray) array);
420 else if (element_type == JvPrimClass (int))
421 elts = (char *) elements ((jintArray) array);
422 else if (element_type == JvPrimClass (long))
423 elts = (char *) elements ((jlongArray) array);
424 else if (element_type == JvPrimClass (boolean))
425 elts = (char *) elements ((jbooleanArray) array);
426 else if (element_type == JvPrimClass (char))
427 elts = (char *) elements ((jcharArray) array);
428 else if (element_type == JvPrimClass (float))
429 elts = (char *) elements ((jfloatArray) array);
430 else if (element_type == JvPrimClass (double))
431 elts = (char *) elements ((jdoubleArray) array);
432 else
433 elts = (char *) elements ((jobjectArray) array);
434 return elts;
435 }
436
437 extern "C" void _Jv_ThrowBadArrayIndex (jint bad_index)
438 __attribute__((noreturn));
439 extern "C" void _Jv_ThrowNullPointerException (void)
440 __attribute__((noreturn));
441 extern "C" void _Jv_ThrowNoSuchMethodError (void)
442 __attribute__((noreturn));
443 extern "C" void _Jv_ThrowNoSuchFieldError (int)
444 __attribute__((noreturn));
445 extern "C" jobject _Jv_NewArray (jint type, jint size)
446 __attribute__((__malloc__));
447 extern "C" jobject _Jv_NewMultiArray (jclass klass, jint dims, ...)
448 __attribute__((__malloc__));
449 extern "C" void *_Jv_CheckCast (jclass klass, jobject obj);
450 extern "C" void *_Jv_LookupInterfaceMethod (jclass klass, Utf8Const *name,
451 Utf8Const *signature);
452 extern "C" void *_Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface,
453 int meth_idx);
454 extern "C" void _Jv_CheckArrayStore (jobject array, jobject obj);
455 extern "C" void _Jv_RegisterClass (jclass klass);
456 extern "C" void _Jv_RegisterClasses (const jclass *classes);
457 extern "C" void _Jv_RegisterClasses_Counted (const jclass *classes,
458 size_t count);
459 extern "C" void _Jv_RegisterResource (void *vptr);
460 extern void _Jv_UnregisterClass (_Jv_Utf8Const*, java::lang::ClassLoader*);
461
462 extern "C" jobject _Jv_UnwrapJNIweakReference (jobject);
463
464 extern jclass _Jv_FindClass (_Jv_Utf8Const *name,
465 java::lang::ClassLoader *loader);
466
467 extern jclass _Jv_FindClassNoException (_Jv_Utf8Const *name,
468 java::lang::ClassLoader *loader);
469
470 extern jclass _Jv_FindClassFromSignature (char *,
471 java::lang::ClassLoader *loader,
472 char ** = NULL);
473
474 extern jclass _Jv_FindClassFromSignatureNoException (char *,
475 java::lang::ClassLoader *loader,
476 char ** = NULL);
477
478 extern void _Jv_GetTypesFromSignature (jmethodID method,
479 jclass declaringClass,
480 JArray<jclass> **arg_types_out,
481 jclass *return_type_out);
482
483 extern jboolean _Jv_CheckAccess (jclass self_klass, jclass other_klass,
484 jint flags);
485
486 extern jobject _Jv_CallAnyMethodA (jobject obj, jclass return_type,
487 jmethodID meth, jboolean is_constructor,
488 JArray<jclass> *parameter_types,
489 jobjectArray args,
490 jclass iface = NULL);
491
492 union jvalue;
493 extern void _Jv_CallAnyMethodA (jobject obj,
494 jclass return_type,
495 jmethodID meth,
496 jboolean is_constructor,
497 jboolean is_virtual_call,
498 JArray<jclass> *parameter_types,
499 jvalue *args,
500 jvalue *result,
501 jboolean is_jni_call = true,
502 jclass iface = NULL);
503
504 extern jobject _Jv_NewMultiArray (jclass, jint ndims, jint* dims)
505 __attribute__((__malloc__));
506
507 extern "C" void _Jv_ThrowAbstractMethodError () __attribute__((__noreturn__));
508
509 /* Checked divide subroutines. */
510 extern "C"
511 {
512 jint _Jv_divI (jint, jint);
513 jint _Jv_remI (jint, jint);
514 jlong _Jv_divJ (jlong, jlong);
515 jlong _Jv_remJ (jlong, jlong);
516 }
517
518 /* Get the number of arguments (cf. argc) or 0 if our argument
519 list was never initialized. */
520 extern int _Jv_GetNbArgs (void);
521
522 /* Get the specified argument (cf. argv[index]) or "" if either
523 our argument list was never initialized or the specified index
524 is out of bounds. */
525 extern const char * _Jv_GetSafeArg (int index);
526
527 /* Sets our argument list. Can be used by programs with non-standard
528 entry points. */
529 extern void _Jv_SetArgs (int argc, const char **argv);
530
531 /* Get the name of the running executable. */
532 extern const char *_Jv_ThisExecutable (void);
533
534 /* Return a pointer to a symbol in executable or loaded library. */
535 void *_Jv_FindSymbolInExecutable (const char *);
536
537 /* Initialize JNI. */
538 extern void _Jv_JNI_Init (void);
539
540 /* Get or set the per-thread JNIEnv used by the invocation API. */
541 _Jv_JNIEnv *_Jv_GetCurrentJNIEnv ();
542 void _Jv_SetCurrentJNIEnv (_Jv_JNIEnv *);
543
544 /* Free a JNIEnv. */
545 void _Jv_FreeJNIEnv (_Jv_JNIEnv *);
546
547 /* Free a JNIEnv. */
548 void _Jv_FreeJNIEnv (_Jv_JNIEnv *);
549
550 struct _Jv_JavaVM;
551 _Jv_JavaVM *_Jv_GetJavaVM ();
552
553 // Some verification functions from defineclass.cc.
554 bool _Jv_VerifyFieldSignature (_Jv_Utf8Const*sig);
555 bool _Jv_VerifyMethodSignature (_Jv_Utf8Const*sig);
556 bool _Jv_VerifyClassName (unsigned char* ptr, _Jv_ushort length);
557 bool _Jv_VerifyClassName (_Jv_Utf8Const *name);
558 bool _Jv_VerifyIdentifier (_Jv_Utf8Const *);
559 bool _Jv_ClassNameSamePackage (_Jv_Utf8Const *name1, _Jv_Utf8Const *name2);
560
561 struct _Jv_core_chain
562 {
563 int name_length;
564 const char *name;
565 int data_length;
566 const void *data;
567
568 struct _Jv_core_chain *next;
569 };
570
571 // This is called when new core data is loaded.
572 extern void (*_Jv_RegisterCoreHook) (_Jv_core_chain *);
573
574 _Jv_core_chain *_Jv_FindCore (_Jv_core_chain *node, jstring name);
575 void _Jv_FreeCoreChain (_Jv_core_chain *chain);
576
577 #ifdef ENABLE_JVMPI
578
579 #include "jvmpi.h"
580
581 extern void (*_Jv_JVMPI_Notify_OBJECT_ALLOC) (JVMPI_Event *event);
582 extern void (*_Jv_JVMPI_Notify_THREAD_START) (JVMPI_Event *event);
583 extern void (*_Jv_JVMPI_Notify_THREAD_END) (JVMPI_Event *event);
584 #endif
585
586 /* FIXME: this should really be defined in some more generic place */
587 #define ROUND(V, A) (((((unsigned) (V))-1) | ((A)-1))+1)
588
589 extern void _Jv_RegisterBootstrapPackages ();
590
591 #define FLAG_BINARYCOMPAT_ABI (1<<31) /* Class is built with the BC-ABI. */
592
593 #define FLAG_BOOTSTRAP_LOADER (1<<30) /* Used when defining a class that
594 should be loaded by the bootstrap
595 loader. */
596
597 // These are used to find ABI versions we recognize.
598 #define GCJ_CXX_ABI_VERSION (__GNUC__ * 100000 + __GNUC_MINOR__ * 1000)
599
600 // This is the old-style BC version ID used by GCJ 4.0.0.
601 #define OLD_GCJ_40_BC_ABI_VERSION (4 * 10000 + 0 * 10 + 5)
602
603 // New style version IDs used by GCJ 4.0.1 and later.
604 #define GCJ_40_BC_ABI_VERSION (4 * 100000 + 0 * 1000)
605
606 inline bool
607 _Jv_CheckABIVersion (unsigned long value)
608 {
609 // We are compatible with GCJ 4.0.0 BC-ABI classes. This release used a
610 // different format for the version ID string.
611 if (value == OLD_GCJ_40_BC_ABI_VERSION)
612 return true;
613
614 // The 20 low-end bits are used for the version number.
615 unsigned long version = value & 0xfffff;
616
617 if (value & FLAG_BINARYCOMPAT_ABI)
618 {
619 int abi_rev = version % 100;
620 int abi_ver = version - abi_rev;
621 if (abi_ver == GCJ_40_BC_ABI_VERSION && abi_rev <= 0)
622 return true;
623 }
624 else
625 // C++ ABI
626 return version == GCJ_CXX_ABI_VERSION;
627
628 return false;
629 }
630
631 inline bool
632 _Jv_ClassForBootstrapLoader (unsigned long value)
633 {
634 return (value & FLAG_BOOTSTRAP_LOADER);
635 }
636
637 // It makes the source cleaner if we simply always define this
638 // function. If the interpreter is not built, it will never return
639 // 'true'.
640 extern inline jboolean
641 _Jv_IsInterpretedClass (jclass c)
642 {
643 return (c->accflags & java::lang::reflect::Modifier::INTERPRETED) != 0;
644 }
645
646 // Return true if the class was compiled with the BC ABI.
647 extern inline jboolean
648 _Jv_IsBinaryCompatibilityABI (jclass c)
649 {
650 // There isn't really a better test for the ABI type at this point,
651 // that will work once the class has been registered.
652 return c->otable_syms || c->atable_syms || c->itable_syms;
653 }
654
655 // Returns whether the given class does not really exists (ie. we have no
656 // bytecode) but still allows us to do some very conservative actions.
657 // E.g. throwing a NoClassDefFoundError with the name of the missing
658 // class.
659 extern inline jboolean
660 _Jv_IsPhantomClass (jclass c)
661 {
662 return c->state == JV_STATE_PHANTOM;
663 }
664
665 #endif /* __JAVA_JVM_H__ */