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