OSDN Git Service

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