re PR libgcj/23367 (_Jv_FindMethodInCache is not thread-safe)
[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
238 // This class handles all aspects of class preparation and linking.
239 class _Jv_Linker
240 {
241 private:
242 static _Jv_Field *find_field_helper(jclass, _Jv_Utf8Const *, _Jv_Utf8Const *,
243 jclass *);
244 static _Jv_Field *find_field(jclass, jclass, jclass *, _Jv_Utf8Const *,
245 _Jv_Utf8Const *);
246 static void prepare_constant_time_tables(jclass);
247 static jshort get_interfaces(jclass, _Jv_ifaces *);
248 static void link_symbol_table(jclass);
249 static void link_exception_table(jclass);
250 static void layout_interface_methods(jclass);
251 static void layout_vtable_methods(jclass);
252 static void set_vtable_entries(jclass, _Jv_VTable *);
253 static void make_vtable(jclass);
254 static void ensure_fields_laid_out(jclass);
255 static void ensure_class_linked(jclass);
256 static void ensure_supers_installed(jclass);
257 static void add_miranda_methods(jclass, jclass);
258 static void ensure_method_table_complete(jclass);
259 static void verify_class(jclass);
260 static jshort find_iindex(jclass *, jshort *, jshort);
261 static jshort indexof(void *, void **, jshort);
262 static int get_alignment_from_class(jclass);
263 static void generate_itable(jclass, _Jv_ifaces *, jshort *);
264 static jshort append_partial_itable(jclass, jclass, void **, jshort);
265 static _Jv_Method *search_method_in_class (jclass, jclass,
266 _Jv_Utf8Const *,
267 _Jv_Utf8Const *);
268
269 public:
270
271 static bool has_field_p (jclass, _Jv_Utf8Const *);
272 static void print_class_loaded (jclass);
273 static void resolve_class_ref (jclass, jclass *);
274 static void wait_for_state(jclass, int);
275 static _Jv_word resolve_pool_entry (jclass, int);
276 static void resolve_field (_Jv_Field *, java::lang::ClassLoader *);
277 static void verify_type_assertions (jclass);
278 };
279
280 /* Type of pointer used as finalizer. */
281 typedef void _Jv_FinalizerFunc (jobject);
282
283 /* Allocate space for a new Java object. */
284 void *_Jv_AllocObj (jsize size, jclass cl) __attribute__((__malloc__));
285 /* Allocate space for a potentially uninitialized pointer-free object.
286 Interesting only with JV_HASH_SYNCHRONIZATION. */
287 void *_Jv_AllocPtrFreeObj (jsize size, jclass cl) __attribute__((__malloc__));
288 /* Allocate space for an array of Java objects. */
289 void *_Jv_AllocArray (jsize size, jclass cl) __attribute__((__malloc__));
290 /* Allocate space that is known to be pointer-free. */
291 void *_Jv_AllocBytes (jsize size) __attribute__((__malloc__));
292 /* Allocate space for a new non-Java object, which does not have the usual
293 Java object header but may contain pointers to other GC'ed objects. */
294 void *_Jv_AllocRawObj (jsize size) __attribute__((__malloc__));
295 /* Explicitly throw an out-of-memory exception. */
296 void _Jv_ThrowNoMemory() __attribute__((__noreturn__));
297 /* Allocate an object with a single pointer. The first word is reserved
298 for the GC, and the second word is the traced pointer. */
299 void *_Jv_AllocTraceOne (jsize size /* incl. reserved slot */);
300 /* Ditto, but for two traced pointers. */
301 void *_Jv_AllocTraceTwo (jsize size /* incl. reserved slot */);
302 /* Initialize the GC. */
303 void _Jv_InitGC (void);
304 /* Register a finalizer. */
305 void _Jv_RegisterFinalizer (void *object, _Jv_FinalizerFunc *method);
306 /* Compute the GC descriptor for a class */
307 void * _Jv_BuildGCDescr(jclass);
308
309 /* Allocate some unscanned, unmoveable memory. Return NULL if out of
310 memory. */
311 void *_Jv_MallocUnchecked (jsize size) __attribute__((__malloc__));
312
313 /* Initialize finalizers. The argument is a function to be called
314 when a finalizer is ready to be run. */
315 void _Jv_GCInitializeFinalizers (void (*notifier) (void));
316 /* Run finalizers for objects ready to be finalized.. */
317 void _Jv_RunFinalizers (void);
318 /* Run all finalizers. Should be called only before exit. */
319 void _Jv_RunAllFinalizers (void);
320 /* Perform a GC. */
321 void _Jv_RunGC (void);
322 /* Disable and enable GC. */
323 void _Jv_DisableGC (void);
324 void _Jv_EnableGC (void);
325 /* Register a disappearing link. This is a field F which should be
326 cleared when *F is found to be inaccessible. This is used in the
327 implementation of java.lang.ref.Reference. */
328 void _Jv_GCRegisterDisappearingLink (jobject *objp);
329 /* Return true if OBJECT should be reclaimed. This is used to
330 implement soft references. */
331 jboolean _Jv_GCCanReclaimSoftReference (jobject obj);
332
333 /* Register a finalizer for a String object. This is only used by
334 the intern() implementation. */
335 void _Jv_RegisterStringFinalizer (jobject str);
336 /* This is called to actually finalize a possibly-intern()d String. */
337 void _Jv_FinalizeString (jobject str);
338
339 /* Return approximation of total size of heap. */
340 long _Jv_GCTotalMemory (void);
341 /* Return approximation of total free memory. */
342 long _Jv_GCFreeMemory (void);
343
344 /* Set initial heap size. If SIZE==0, ignore. Should be run before
345 _Jv_InitGC. Not required to have any actual effect. */
346 void _Jv_GCSetInitialHeapSize (size_t size);
347
348 /* Set maximum heap size. If SIZE==0, unbounded. Should be run
349 before _Jv_InitGC. Not required to have any actual effect. */
350 void _Jv_GCSetMaximumHeapSize (size_t size);
351
352 /* External interface to setting the heap size. Parses ARG (a number
353 which can optionally have "k" or "m" appended and calls
354 _Jv_GCSetInitialHeapSize. */
355 void _Jv_SetInitialHeapSize (const char *arg);
356
357 /* External interface to setting the maximum heap size. Parses ARG (a
358 number which can optionally have "k" or "m" appended and calls
359 _Jv_GCSetMaximumHeapSize. */
360 void _Jv_SetMaximumHeapSize (const char *arg);
361
362 /* Free the method cache, if one was allocated. This is only called
363 during thread deregistration. */
364 void _Jv_FreeMethodCache ();
365
366 extern "C" void JvRunMain (jclass klass, int argc, const char **argv);
367 void _Jv_RunMain (jclass klass, const char *name, int argc, const char **argv,
368 bool is_jar);
369
370 void _Jv_RunMain (struct _Jv_VMInitArgs *vm_args, jclass klass,
371 const char *name, int argc, const char **argv, bool is_jar);
372
373 // Delayed until after _Jv_AllocBytes is declared.
374 //
375 // Note that we allocate this as unscanned memory -- the vtables
376 // are handled specially by the GC.
377
378 inline _Jv_VTable *
379 _Jv_VTable::new_vtable (int count)
380 {
381 size_t size = sizeof(_Jv_VTable) + (count - 1) * vtable_elt_size ();
382 return (_Jv_VTable *) _Jv_AllocBytes (size);
383 }
384
385 // Determine if METH gets an entry in a VTable.
386 static inline jboolean _Jv_isVirtualMethod (_Jv_Method *meth)
387 {
388 using namespace java::lang::reflect;
389 return (((meth->accflags & (Modifier::STATIC | Modifier::PRIVATE)) == 0)
390 && meth->name->first() != '<');
391 }
392
393 // This function is used to determine the hash code of an object.
394 inline jint
395 _Jv_HashCode (jobject obj)
396 {
397 // This was chosen to yield relatively well distributed results on
398 // both 32- and 64-bit architectures. Note 0x7fffffff is prime.
399 // FIXME: we assume sizeof(long) == sizeof(void *).
400 return (jint) ((unsigned long) obj % 0x7fffffff);
401 }
402
403 // Return a raw pointer to the elements of an array given the array
404 // and its element type. You might think we could just pick a single
405 // array type and use elements() on it, but we can't because we must
406 // account for alignment of the element type. When ARRAY is null, we
407 // obtain the number of bytes taken by the base part of the array.
408 inline char *
409 _Jv_GetArrayElementFromElementType (jobject array,
410 jclass element_type)
411 {
412 char *elts;
413 if (element_type == JvPrimClass (byte))
414 elts = (char *) elements ((jbyteArray) array);
415 else if (element_type == JvPrimClass (short))
416 elts = (char *) elements ((jshortArray) array);
417 else if (element_type == JvPrimClass (int))
418 elts = (char *) elements ((jintArray) array);
419 else if (element_type == JvPrimClass (long))
420 elts = (char *) elements ((jlongArray) array);
421 else if (element_type == JvPrimClass (boolean))
422 elts = (char *) elements ((jbooleanArray) array);
423 else if (element_type == JvPrimClass (char))
424 elts = (char *) elements ((jcharArray) array);
425 else if (element_type == JvPrimClass (float))
426 elts = (char *) elements ((jfloatArray) array);
427 else if (element_type == JvPrimClass (double))
428 elts = (char *) elements ((jdoubleArray) array);
429 else
430 elts = (char *) elements ((jobjectArray) array);
431 return elts;
432 }
433
434 extern "C" void _Jv_ThrowBadArrayIndex (jint bad_index)
435 __attribute__((noreturn));
436 extern "C" void _Jv_ThrowNullPointerException (void)
437 __attribute__((noreturn));
438 extern "C" jobject _Jv_NewArray (jint type, jint size)
439 __attribute__((__malloc__));
440 extern "C" jobject _Jv_NewMultiArray (jclass klass, jint dims, ...)
441 __attribute__((__malloc__));
442 extern "C" void *_Jv_CheckCast (jclass klass, jobject obj);
443 extern "C" void *_Jv_LookupInterfaceMethod (jclass klass, Utf8Const *name,
444 Utf8Const *signature);
445 extern "C" void *_Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface,
446 int meth_idx);
447 extern "C" void _Jv_CheckArrayStore (jobject array, jobject obj);
448 extern "C" void _Jv_RegisterClass (jclass klass);
449 extern "C" void _Jv_RegisterClasses (const jclass *classes);
450 extern "C" void _Jv_RegisterClasses_Counted (const jclass *classes,
451 size_t count);
452 extern "C" void _Jv_RegisterResource (void *vptr);
453 extern void _Jv_UnregisterClass (_Jv_Utf8Const*, java::lang::ClassLoader*);
454
455 extern jclass _Jv_FindClass (_Jv_Utf8Const *name,
456 java::lang::ClassLoader *loader);
457 extern jclass _Jv_FindClassFromSignature (char *,
458 java::lang::ClassLoader *loader,
459 char ** = NULL);
460 extern void _Jv_GetTypesFromSignature (jmethodID method,
461 jclass declaringClass,
462 JArray<jclass> **arg_types_out,
463 jclass *return_type_out);
464
465 extern jboolean _Jv_CheckAccess (jclass self_klass, jclass other_klass,
466 jint flags);
467
468 extern jobject _Jv_CallAnyMethodA (jobject obj, jclass return_type,
469 jmethodID meth, jboolean is_constructor,
470 JArray<jclass> *parameter_types,
471 jobjectArray args,
472 jclass iface = NULL);
473
474 union jvalue;
475 extern void _Jv_CallAnyMethodA (jobject obj,
476 jclass return_type,
477 jmethodID meth,
478 jboolean is_constructor,
479 jboolean is_virtual_call,
480 JArray<jclass> *parameter_types,
481 jvalue *args,
482 jvalue *result,
483 jboolean is_jni_call = true,
484 jclass iface = NULL);
485
486 extern jobject _Jv_NewMultiArray (jclass, jint ndims, jint* dims)
487 __attribute__((__malloc__));
488
489 extern "C" void _Jv_ThrowAbstractMethodError () __attribute__((__noreturn__));
490
491 /* Checked divide subroutines. */
492 extern "C"
493 {
494 jint _Jv_divI (jint, jint);
495 jint _Jv_remI (jint, jint);
496 jlong _Jv_divJ (jlong, jlong);
497 jlong _Jv_remJ (jlong, jlong);
498 }
499
500 /* Get the number of arguments (cf. argc) or 0 if our argument
501 list was never initialized. */
502 extern int _Jv_GetNbArgs (void);
503
504 /* Get the specified argument (cf. argv[index]) or "" if either
505 our argument list was never initialized or the specified index
506 is out of bounds. */
507 extern const char * _Jv_GetSafeArg (int index);
508
509 /* Sets our argument list. Can be used by programs with non-standard
510 entry points. */
511 extern void _Jv_SetArgs (int argc, const char **argv);
512
513 /* Get the name of the running executable. */
514 extern const char *_Jv_ThisExecutable (void);
515
516 /* Return a pointer to a symbol in executable or loaded library. */
517 void *_Jv_FindSymbolInExecutable (const char *);
518
519 /* Initialize JNI. */
520 extern void _Jv_JNI_Init (void);
521
522 /* Get or set the per-thread JNIEnv used by the invocation API. */
523 _Jv_JNIEnv *_Jv_GetCurrentJNIEnv ();
524 void _Jv_SetCurrentJNIEnv (_Jv_JNIEnv *);
525
526 /* Free a JNIEnv. */
527 void _Jv_FreeJNIEnv (_Jv_JNIEnv *);
528
529 /* Free a JNIEnv. */
530 void _Jv_FreeJNIEnv (_Jv_JNIEnv *);
531
532 struct _Jv_JavaVM;
533 _Jv_JavaVM *_Jv_GetJavaVM ();
534
535 // Some verification functions from defineclass.cc.
536 bool _Jv_VerifyFieldSignature (_Jv_Utf8Const*sig);
537 bool _Jv_VerifyMethodSignature (_Jv_Utf8Const*sig);
538 bool _Jv_VerifyClassName (unsigned char* ptr, _Jv_ushort length);
539 bool _Jv_VerifyClassName (_Jv_Utf8Const *name);
540 bool _Jv_VerifyIdentifier (_Jv_Utf8Const *);
541 bool _Jv_ClassNameSamePackage (_Jv_Utf8Const *name1, _Jv_Utf8Const *name2);
542
543 struct _Jv_core_chain
544 {
545 int name_length;
546 const char *name;
547 int data_length;
548 const void *data;
549
550 struct _Jv_core_chain *next;
551 };
552
553 // This is called when new core data is loaded.
554 extern void (*_Jv_RegisterCoreHook) (_Jv_core_chain *);
555
556 _Jv_core_chain *_Jv_FindCore (_Jv_core_chain *node, jstring name);
557 void _Jv_FreeCoreChain (_Jv_core_chain *chain);
558
559 #ifdef ENABLE_JVMPI
560
561 #include "jvmpi.h"
562
563 extern void (*_Jv_JVMPI_Notify_OBJECT_ALLOC) (JVMPI_Event *event);
564 extern void (*_Jv_JVMPI_Notify_THREAD_START) (JVMPI_Event *event);
565 extern void (*_Jv_JVMPI_Notify_THREAD_END) (JVMPI_Event *event);
566 #endif
567
568 /* FIXME: this should really be defined in some more generic place */
569 #define ROUND(V, A) (((((unsigned) (V))-1) | ((A)-1))+1)
570
571 extern void _Jv_RegisterBootstrapPackages ();
572
573 #define FLAG_BINARYCOMPAT_ABI (1<<31) /* Class is built with the BC-ABI. */
574
575 #define FLAG_BOOTSTRAP_LOADER (1<<30) /* Used when defining a class that
576 should be loaded by the bootstrap
577 loader. */
578
579 // These are used to find ABI versions we recognize.
580 #define GCJ_CXX_ABI_VERSION (__GNUC__ * 100000 + __GNUC_MINOR__ * 1000)
581
582 // This is the old-style BC version ID used by GCJ 4.0.0.
583 #define OLD_GCJ_40_BC_ABI_VERSION (4 * 10000 + 0 * 10 + 5)
584
585 // New style version IDs used by GCJ 4.0.1 and later.
586 #define GCJ_40_BC_ABI_VERSION (4 * 100000 + 0 * 1000)
587
588 inline bool
589 _Jv_CheckABIVersion (unsigned long value)
590 {
591 // We are compatible with GCJ 4.0.0 BC-ABI classes. This release used a
592 // different format for the version ID string.
593 if (value == OLD_GCJ_40_BC_ABI_VERSION)
594 return true;
595
596 // The 20 low-end bits are used for the version number.
597 unsigned long version = value & 0xfffff;
598
599 if (value & FLAG_BINARYCOMPAT_ABI)
600 {
601 int abi_rev = version % 100;
602 int abi_ver = version - abi_rev;
603 if (abi_ver == GCJ_40_BC_ABI_VERSION && abi_rev <= 0)
604 return true;
605 }
606 else
607 // C++ ABI
608 return version == GCJ_CXX_ABI_VERSION;
609
610 return false;
611 }
612
613 inline bool
614 _Jv_ClassForBootstrapLoader (unsigned long value)
615 {
616 return (value & FLAG_BOOTSTRAP_LOADER);
617 }
618
619 // It makes the source cleaner if we simply always define this
620 // function. If the interpreter is not built, it will never return
621 // 'true'.
622 extern inline jboolean
623 _Jv_IsInterpretedClass (jclass c)
624 {
625 return (c->accflags & java::lang::reflect::Modifier::INTERPRETED) != 0;
626 }
627
628 // Return true if the class was compiled with the BC ABI.
629 extern inline jboolean
630 _Jv_IsBinaryCompatibilityABI (jclass c)
631 {
632 // There isn't really a better test for the ABI type at this point,
633 // that will work once the class has been registered.
634 return c->otable_syms || c->atable_syms || c->itable_syms;
635 }
636
637 #endif /* __JAVA_JVM_H__ */