Merge -r 127928:132243 from trunk
[official-gcc.git] / libjava / include / jvm.h
blob84847548f01b7ff71646f426a7e3d496aabcc971
1 // jvm.h - Header file for private implementation information. -*- c++ -*-
3 /* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9 details. */
11 #ifndef __JAVA_JVM_H__
12 #define __JAVA_JVM_H__
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__
20 #include <gcj/javaprims.h>
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>
27 #include <java/lang/Object.h>
29 // Include cni.h before field.h to enable all definitions. FIXME.
30 #include <gcj/cni.h>
31 #include <gcj/field.h>
33 #include <java/lang/Thread.h>
35 #include <sysdep/locks.h>
37 /* Macro for possible unused arguments. */
38 #define MAYBE_UNUSED __attribute__((__unused__))
40 /* Structure of the virtual table. */
41 struct _Jv_VTable
43 #ifdef __ia64__
44 typedef struct { void *pc, *gp; } vtable_elt;
45 #else
46 typedef void *vtable_elt;
47 #endif
48 jclass clas;
49 void *gc_descr;
51 // This must be last, as derived classes "extend" this by
52 // adding new data members.
53 vtable_elt method[1];
55 #ifdef __ia64__
56 void *get_method(int i) { return &method[i]; }
57 void set_method(int i, void *fptr) { method[i] = *(vtable_elt *)fptr; }
58 void *get_finalizer()
60 // We know that get_finalizer is only used for checking whether
61 // this object needs to have a finalizer registered. So it is
62 // safe to simply return just the PC component of the vtable
63 // slot.
64 return ((vtable_elt *)(get_method(0)))->pc;
66 #else
67 void *get_method(int i) { return method[i]; }
68 void set_method(int i, void *fptr) { method[i] = fptr; }
69 void *get_finalizer() { return get_method(0); }
70 #endif
72 static size_t vtable_elt_size() { return sizeof(vtable_elt); }
74 // Given a method index, return byte offset from the vtable pointer.
75 static jint idx_to_offset (int index)
77 return (2 * sizeof (void *)) + (index * vtable_elt_size ());
80 static _Jv_VTable *new_vtable (int count);
83 union _Jv_word
85 jobject o;
86 jint i; // Also stores smaller integral types.
87 jfloat f;
88 jint ia[1]; // Half of _Jv_word2.
89 void* p;
91 #if SIZEOF_VOID_P == 8
92 // We can safely put a long or a double in here without increasing
93 // the size of _Jv_Word; we take advantage of this in the interpreter.
94 jlong l;
95 jdouble d;
96 #endif
98 jclass clazz;
99 jstring string;
100 struct _Jv_Field *field;
101 struct _Jv_Utf8Const *utf8;
102 struct _Jv_ResolvedMethod *rmethod;
105 union _Jv_word2
107 jint ia[2];
108 jlong l;
109 jdouble d;
112 union _Jv_value
114 jbyte byte_value;
115 jshort short_value;
116 jchar char_value;
117 jint int_value;
118 jlong long_value;
119 jfloat float_value;
120 jdouble double_value;
121 jobject object_value;
124 /* Extract a character from a Java-style Utf8 string.
125 * PTR points to the current character.
126 * LIMIT points to the end of the Utf8 string.
127 * PTR is incremented to point after the character thta gets returns.
128 * On an error, -1 is returned. */
129 #define UTF8_GET(PTR, LIMIT) \
130 ((PTR) >= (LIMIT) ? -1 \
131 : *(PTR) < 128 ? *(PTR)++ \
132 : (*(PTR)&0xE0) == 0xC0 && ((PTR)+=2)<=(LIMIT) && ((PTR)[-1]&0xC0) == 0x80 \
133 ? (((PTR)[-2] & 0x1F) << 6) + ((PTR)[-1] & 0x3F) \
134 : (*(PTR) & 0xF0) == 0xE0 && ((PTR) += 3) <= (LIMIT) \
135 && ((PTR)[-2] & 0xC0) == 0x80 && ((PTR)[-1] & 0xC0) == 0x80 \
136 ? (((PTR)[-3]&0x0F) << 12) + (((PTR)[-2]&0x3F) << 6) + ((PTR)[-1]&0x3F) \
137 : ((PTR)++, -1))
139 extern int _Jv_strLengthUtf8(const char* str, int len);
141 typedef struct _Jv_Utf8Const Utf8Const;
142 _Jv_Utf8Const *_Jv_makeUtf8Const (const char *s, int len);
143 _Jv_Utf8Const *_Jv_makeUtf8Const (jstring string);
144 static inline _Jv_Utf8Const *_Jv_makeUtf8Const (const char *s)
146 return _Jv_makeUtf8Const (s, strlen (s));
148 extern jboolean _Jv_equalUtf8Consts (const _Jv_Utf8Const *, const _Jv_Utf8Const *);
149 extern jboolean _Jv_equal (_Jv_Utf8Const *, jstring, jint);
150 extern jboolean _Jv_equaln (_Jv_Utf8Const *, jstring, jint);
152 /* Helper class which converts a jstring to a temporary char*.
153 Uses the supplied buffer, if non-null. Otherwise, allocates
154 the buffer on the heap. Use the JV_TEMP_UTF_STRING macro,
155 which follows, to automatically allocate a stack buffer if
156 the string is small enough. */
157 class _Jv_TempUTFString
159 public:
160 _Jv_TempUTFString(jstring jstr, char* buf=0);
161 ~_Jv_TempUTFString();
163 // Accessors
164 operator const char*() const
166 return buf_;
168 const char* buf() const
170 return buf_;
172 char* buf()
174 return buf_;
177 private:
178 char* buf_;
179 bool heapAllocated_;
182 inline _Jv_TempUTFString::_Jv_TempUTFString (jstring jstr, char* buf)
183 : buf_(0), heapAllocated_(false)
185 if (!jstr) return;
186 jsize len = JvGetStringUTFLength (jstr);
187 if (buf)
188 buf_ = buf;
189 else
191 buf_ = (char*) _Jv_Malloc (len+1);
192 heapAllocated_ = true;
195 JvGetStringUTFRegion (jstr, 0, jstr->length(), buf_);
196 buf_[len] = '\0';
199 inline _Jv_TempUTFString::~_Jv_TempUTFString ()
201 if (heapAllocated_)
202 _Jv_Free (buf_);
205 /* Macro which uses _Jv_TempUTFString. Allocates a stack-based
206 buffer if the string and its null terminator are <= 256
207 characters in length. Otherwise, a heap-based buffer is
208 used. The parameters to this macro are the variable name
209 which is an instance of _Jv_TempUTFString (above) and a
210 jstring.
212 Sample Usage:
214 jstring jstr = getAJString();
215 JV_TEMP_UTF_STRING(utfstr, jstr);
216 printf("The string is: %s\n", utfstr.buf());
219 #define JV_TEMP_UTF_STRING(utfstr, jstr) \
220 jstring utfstr##thejstr = (jstr); \
221 jsize utfstr##_len = utfstr##thejstr ? JvGetStringUTFLength (utfstr##thejstr) + 1 : 0; \
222 char utfstr##_buf[utfstr##_len <= 256 ? utfstr##_len : 0]; \
223 _Jv_TempUTFString utfstr(utfstr##thejstr, sizeof(utfstr##_buf)==0 ? 0 : utfstr##_buf)
225 namespace gcj
227 /* Some constants used during lookup of special class methods. */
228 extern _Jv_Utf8Const *void_signature; /* "()V" */
229 extern _Jv_Utf8Const *clinit_name; /* "<clinit>" */
230 extern _Jv_Utf8Const *init_name; /* "<init>" */
231 extern _Jv_Utf8Const *finit_name; /* "finit$", */
233 /* Set to true by _Jv_CreateJavaVM. */
234 extern bool runtimeInitialized;
236 /* Print out class names as they are initialized. */
237 extern bool verbose_class_flag;
239 /* When true, enable the bytecode verifier and BC-ABI verification. */
240 extern bool verifyClasses;
242 /* Thread stack size specified by the -Xss runtime argument. */
243 extern size_t stack_size;
245 /* The start time */
246 extern jlong startTime;
248 /* The VM arguments */
249 extern JArray<jstring>* vmArgs;
251 // Currently loaded classes
252 extern jint loadedClasses;
254 // Unloaded classes
255 extern jlong unloadedClasses;
258 // This class handles all aspects of class preparation and linking.
259 class _Jv_Linker
261 private:
262 typedef unsigned int uaddr __attribute__ ((mode (pointer)));
264 static _Jv_Field *find_field_helper(jclass, _Jv_Utf8Const *, _Jv_Utf8Const *,
265 jclass, jclass *);
266 static _Jv_Field *find_field(jclass, jclass, jclass *, _Jv_Utf8Const *,
267 _Jv_Utf8Const *);
268 static void prepare_constant_time_tables(jclass);
269 static jshort get_interfaces(jclass, _Jv_ifaces *);
270 static void link_symbol_table(jclass);
271 static void link_exception_table(jclass);
272 static void layout_interface_methods(jclass);
273 static void set_vtable_entries(jclass, _Jv_VTable *);
274 static void make_vtable(jclass);
275 static void ensure_fields_laid_out(jclass);
276 static void ensure_class_linked(jclass);
277 static void ensure_supers_installed(jclass);
278 static void add_miranda_methods(jclass, jclass);
279 static void ensure_method_table_complete(jclass);
280 static void verify_class(jclass);
281 static jshort find_iindex(jclass *, jshort *, jshort);
282 static jshort indexof(void *, void **, jshort);
283 static int get_alignment_from_class(jclass);
284 static void generate_itable(jclass, _Jv_ifaces *, jshort *);
285 static jshort append_partial_itable(jclass, jclass, void **, jshort);
286 static _Jv_Method *search_method_in_superclasses (jclass cls, jclass klass,
287 _Jv_Utf8Const *method_name,
288 _Jv_Utf8Const *method_signature,
289 jclass *found_class,
290 bool check_perms = true);
291 static void *create_error_method(_Jv_Utf8Const *, jclass);
293 /* The least significant bit of the signature pointer in a symbol
294 table is set to 1 by the compiler if the reference is "special",
295 i.e. if it is an access to a private field or method. Extract
296 that bit, clearing it in the address and setting the LSB of
297 SPECIAL accordingly. */
298 static void maybe_adjust_signature (_Jv_Utf8Const *&s, uaddr &special)
300 union {
301 _Jv_Utf8Const *signature;
302 uaddr signature_bits;
304 signature = s;
305 special = signature_bits & 1;
306 signature_bits -= special;
307 s = signature;
310 public:
312 static bool has_field_p (jclass, _Jv_Utf8Const *);
313 static void print_class_loaded (jclass);
314 static void resolve_class_ref (jclass, jclass *);
315 static void wait_for_state(jclass, int);
316 static _Jv_Method *resolve_method_entry (jclass, jclass &,
317 int, int,
318 bool, bool);
319 static _Jv_word resolve_pool_entry (jclass, int, bool =false);
320 static void resolve_field (_Jv_Field *, java::lang::ClassLoader *);
321 static void verify_type_assertions (jclass);
322 static _Jv_Method *search_method_in_class (jclass, jclass,
323 _Jv_Utf8Const *,
324 _Jv_Utf8Const *,
325 bool check_perms = true);
326 static void layout_vtable_methods(jclass);
329 /* Type of pointer used as finalizer. */
330 typedef void _Jv_FinalizerFunc (jobject);
332 /* Allocate space for a new Java object. */
333 void *_Jv_AllocObj (jsize size, jclass cl) __attribute__((__malloc__));
334 /* Allocate space for a potentially uninitialized pointer-free object.
335 Interesting only with JV_HASH_SYNCHRONIZATION. */
336 void *_Jv_AllocPtrFreeObj (jsize size, jclass cl) __attribute__((__malloc__));
337 /* Allocate space for an array of Java objects. */
338 void *_Jv_AllocArray (jsize size, jclass cl) __attribute__((__malloc__));
339 /* Allocate space that is known to be pointer-free. */
340 void *_Jv_AllocBytes (jsize size) __attribute__((__malloc__));
341 /* Allocate space for a new non-Java object, which does not have the usual
342 Java object header but may contain pointers to other GC'ed objects. */
343 void *_Jv_AllocRawObj (jsize size) __attribute__((__malloc__));
344 /* Allocate a double-indirect pointer to a _Jv_ClosureList such that
345 the _Jv_ClosureList gets automatically finalized when it is no
346 longer reachable, not even by other finalizable objects. */
347 _Jv_ClosureList **_Jv_ClosureListFinalizer (void) __attribute__((__malloc__));
348 /* Explicitly throw an out-of-memory exception. */
349 void _Jv_ThrowNoMemory() __attribute__((__noreturn__));
350 /* Allocate an object with a single pointer. The first word is reserved
351 for the GC, and the second word is the traced pointer. */
352 void *_Jv_AllocTraceOne (jsize size /* incl. reserved slot */);
353 /* Ditto, but for two traced pointers. */
354 void *_Jv_AllocTraceTwo (jsize size /* incl. reserved slot */);
355 /* Initialize the GC. */
356 void _Jv_InitGC (void);
357 /* Register a finalizer. */
358 void _Jv_RegisterFinalizer (void *object, _Jv_FinalizerFunc *method);
359 /* Compute the GC descriptor for a class */
360 void * _Jv_BuildGCDescr(jclass);
362 /* Allocate some unscanned, unmoveable memory. Return NULL if out of
363 memory. */
364 void *_Jv_MallocUnchecked (jsize size) __attribute__((__malloc__));
366 /* Initialize finalizers. The argument is a function to be called
367 when a finalizer is ready to be run. */
368 void _Jv_GCInitializeFinalizers (void (*notifier) (void));
369 /* Run finalizers for objects ready to be finalized.. */
370 void _Jv_RunFinalizers (void);
371 /* Run all finalizers. Should be called only before exit. */
372 void _Jv_RunAllFinalizers (void);
373 /* Perform a GC. */
374 void _Jv_RunGC (void);
375 /* Disable and enable GC. */
376 void _Jv_DisableGC (void);
377 void _Jv_EnableGC (void);
378 /* Register a disappearing link. This is a field F which should be
379 cleared when *F is found to be inaccessible. This is used in the
380 implementation of java.lang.ref.Reference. */
381 void _Jv_GCRegisterDisappearingLink (jobject *objp);
382 /* Return true if OBJECT should be reclaimed. This is used to
383 implement soft references. */
384 jboolean _Jv_GCCanReclaimSoftReference (jobject obj);
386 /* Register a finalizer for a String object. This is only used by
387 the intern() implementation. */
388 void _Jv_RegisterStringFinalizer (jobject str);
389 /* This is called to actually finalize a possibly-intern()d String. */
390 void _Jv_FinalizeString (jobject str);
392 /* Return approximation of total size of heap. */
393 long _Jv_GCTotalMemory (void);
394 /* Return approximation of total free memory. */
395 long _Jv_GCFreeMemory (void);
397 /* Set initial heap size. If SIZE==0, ignore. Should be run before
398 _Jv_InitGC. Not required to have any actual effect. */
399 void _Jv_GCSetInitialHeapSize (size_t size);
401 /* Set maximum heap size. If SIZE==0, unbounded. Should be run
402 before _Jv_InitGC. Not required to have any actual effect. */
403 void _Jv_GCSetMaximumHeapSize (size_t size);
405 /* External interface to setting the heap size. Parses ARG (a number
406 which can optionally have "k" or "m" appended and calls
407 _Jv_GCSetInitialHeapSize. */
408 void _Jv_SetInitialHeapSize (const char *arg);
410 /* External interface to setting the maximum heap size. Parses ARG (a
411 number which can optionally have "k" or "m" appended and calls
412 _Jv_GCSetMaximumHeapSize. */
413 void _Jv_SetMaximumHeapSize (const char *arg);
415 /* External interface for setting the GC_free_space_divisor. Calls
416 GC_set_free_space_divisor and returns the old value. */
417 int _Jv_SetGCFreeSpaceDivisor (int div);
419 /* Free the method cache, if one was allocated. This is only called
420 during thread deregistration. */
421 void _Jv_FreeMethodCache ();
423 /* Set the stack size for threads. Parses ARG, a number which can
424 optionally have "k" or "m" appended. */
425 void _Jv_SetStackSize (const char *arg);
427 extern "C" void JvRunMain (jclass klass, int argc, const char **argv);
428 extern "C" void JvRunMainName (const char *name, int argc, const char **argv);
430 void _Jv_RunMain (jclass klass, const char *name, int argc, const char **argv,
431 bool is_jar);
433 void _Jv_RunMain (struct _Jv_VMInitArgs *vm_args, jclass klass,
434 const char *name, int argc, const char **argv, bool is_jar);
436 // Delayed until after _Jv_AllocRawObj is declared.
437 inline _Jv_VTable *
438 _Jv_VTable::new_vtable (int count)
440 size_t size = sizeof(_Jv_VTable) + (count - 1) * vtable_elt_size ();
441 return (_Jv_VTable *) _Jv_AllocRawObj (size);
444 // Determine if METH gets an entry in a VTable.
445 static inline jboolean _Jv_isVirtualMethod (_Jv_Method *meth)
447 using namespace java::lang::reflect;
448 return (((meth->accflags & (Modifier::STATIC | Modifier::PRIVATE)) == 0)
449 && meth->name->first() != '<');
452 // This function is used to determine the hash code of an object.
453 inline jint
454 _Jv_HashCode (jobject obj)
456 // This was chosen to yield relatively well distributed results on
457 // both 32- and 64-bit architectures. Note 0x7fffffff is prime.
458 // FIXME: we assume sizeof(long) == sizeof(void *).
459 return (jint) ((unsigned long) obj % 0x7fffffff);
462 // Return a raw pointer to the elements of an array given the array
463 // and its element type. You might think we could just pick a single
464 // array type and use elements() on it, but we can't because we must
465 // account for alignment of the element type. When ARRAY is null, we
466 // obtain the number of bytes taken by the base part of the array.
467 inline char *
468 _Jv_GetArrayElementFromElementType (jobject array,
469 jclass element_type)
471 char *elts;
472 if (element_type == JvPrimClass (byte))
473 elts = (char *) elements ((jbyteArray) array);
474 else if (element_type == JvPrimClass (short))
475 elts = (char *) elements ((jshortArray) array);
476 else if (element_type == JvPrimClass (int))
477 elts = (char *) elements ((jintArray) array);
478 else if (element_type == JvPrimClass (long))
479 elts = (char *) elements ((jlongArray) array);
480 else if (element_type == JvPrimClass (boolean))
481 elts = (char *) elements ((jbooleanArray) array);
482 else if (element_type == JvPrimClass (char))
483 elts = (char *) elements ((jcharArray) array);
484 else if (element_type == JvPrimClass (float))
485 elts = (char *) elements ((jfloatArray) array);
486 else if (element_type == JvPrimClass (double))
487 elts = (char *) elements ((jdoubleArray) array);
488 else
489 elts = (char *) elements ((jobjectArray) array);
490 return elts;
493 extern "C" void _Jv_ThrowBadArrayIndex (jint bad_index)
494 __attribute__((noreturn));
495 extern "C" void _Jv_ThrowNullPointerException (void)
496 __attribute__((noreturn));
497 extern "C" void _Jv_ThrowNoSuchMethodError (void)
498 __attribute__((noreturn));
499 extern "C" void _Jv_ThrowNoSuchFieldError (int)
500 __attribute__((noreturn));
501 extern "C" jobject _Jv_NewArray (jint type, jint size)
502 __attribute__((__malloc__));
503 extern "C" jobject _Jv_NewMultiArray (jclass klass, jint dims, ...)
504 __attribute__((__malloc__));
505 extern "C" void *_Jv_CheckCast (jclass klass, jobject obj);
506 extern "C" void *_Jv_LookupInterfaceMethod (jclass klass, Utf8Const *name,
507 Utf8Const *signature);
508 extern "C" void *_Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface,
509 int meth_idx);
510 extern "C" void _Jv_CheckArrayStore (jobject array, jobject obj);
511 extern "C" void _Jv_RegisterClass (jclass klass);
512 extern "C" void _Jv_RegisterClasses (const jclass *classes);
513 extern "C" void _Jv_RegisterClasses_Counted (const jclass *classes,
514 size_t count);
515 extern "C" void _Jv_RegisterResource (void *vptr);
516 extern void _Jv_UnregisterClass (_Jv_Utf8Const*, java::lang::ClassLoader*);
518 extern "C" jobject _Jv_UnwrapJNIweakReference (jobject);
520 extern jclass _Jv_FindClass (_Jv_Utf8Const *name,
521 java::lang::ClassLoader *loader);
523 extern jclass _Jv_FindClassNoException (_Jv_Utf8Const *name,
524 java::lang::ClassLoader *loader);
526 extern jclass _Jv_FindClassFromSignature (char *,
527 java::lang::ClassLoader *loader,
528 char ** = NULL);
530 extern jclass _Jv_FindClassFromSignatureNoException (char *,
531 java::lang::ClassLoader *loader,
532 char ** = NULL);
534 extern void _Jv_GetTypesFromSignature (jmethodID method,
535 jclass declaringClass,
536 JArray<jclass> **arg_types_out,
537 jclass *return_type_out);
539 extern jboolean _Jv_CheckAccess (jclass self_klass, jclass other_klass,
540 jint flags);
542 extern jobject _Jv_CallAnyMethodA (jobject obj, jclass return_type,
543 jmethodID meth, jboolean is_constructor,
544 JArray<jclass> *parameter_types,
545 jobjectArray args,
546 jclass iface = NULL);
548 union jvalue;
549 extern void _Jv_CallAnyMethodA (jobject obj,
550 jclass return_type,
551 jmethodID meth,
552 jboolean is_constructor,
553 jboolean is_virtual_call,
554 JArray<jclass> *parameter_types,
555 const jvalue *args,
556 jvalue *result,
557 jboolean is_jni_call = true,
558 jclass iface = NULL);
560 extern jobject _Jv_NewMultiArray (jclass, jint ndims, jint* dims)
561 __attribute__((__malloc__));
563 extern "C" void _Jv_ThrowAbstractMethodError () __attribute__((__noreturn__));
565 /* Checked divide subroutines. */
566 extern "C"
568 jint _Jv_divI (jint, jint);
569 jint _Jv_remI (jint, jint);
570 jlong _Jv_divJ (jlong, jlong);
571 jlong _Jv_remJ (jlong, jlong);
574 /* Get the number of arguments (cf. argc) or 0 if our argument
575 list was never initialized. */
576 extern int _Jv_GetNbArgs (void);
578 /* Get the specified argument (cf. argv[index]) or "" if either
579 our argument list was never initialized or the specified index
580 is out of bounds. */
581 extern const char * _Jv_GetSafeArg (int index);
583 /* Sets our argument list. Can be used by programs with non-standard
584 entry points. */
585 extern void _Jv_SetArgs (int argc, const char **argv);
587 /* Get the name of the running executable. */
588 extern const char *_Jv_ThisExecutable (void);
590 /* Return a pointer to a symbol in executable or loaded library. */
591 void *_Jv_FindSymbolInExecutable (const char *);
593 /* Initialize JNI. */
594 extern void _Jv_JNI_Init (void);
596 /* Get or set the per-thread JNIEnv used by the invocation API. */
597 _Jv_JNIEnv *_Jv_GetCurrentJNIEnv ();
598 void _Jv_SetCurrentJNIEnv (_Jv_JNIEnv *);
600 /* Free a JNIEnv. */
601 void _Jv_FreeJNIEnv (_Jv_JNIEnv *);
603 extern "C" void _Jv_JNI_PopSystemFrame (_Jv_JNIEnv *);
604 _Jv_JNIEnv *_Jv_GetJNIEnvNewFrameWithLoader (::java::lang::ClassLoader *);
606 struct _Jv_JavaVM;
607 _Jv_JavaVM *_Jv_GetJavaVM ();
609 /* Get a JVMTI environment */
610 struct _Jv_JVMTIEnv;
611 _Jv_JVMTIEnv *_Jv_GetJVMTIEnv (void);
613 /* Initialize JVMTI */
614 extern void _Jv_JVMTI_Init (void);
616 // Some verification functions from defineclass.cc.
617 bool _Jv_VerifyFieldSignature (_Jv_Utf8Const*sig);
618 bool _Jv_VerifyMethodSignature (_Jv_Utf8Const*sig);
619 bool _Jv_VerifyClassName (unsigned char* ptr, _Jv_ushort length);
620 bool _Jv_VerifyClassName (_Jv_Utf8Const *name);
621 bool _Jv_VerifyIdentifier (_Jv_Utf8Const *);
622 bool _Jv_ClassNameSamePackage (_Jv_Utf8Const *name1, _Jv_Utf8Const *name2);
624 struct _Jv_core_chain
626 int name_length;
627 const char *name;
628 int data_length;
629 const void *data;
631 struct _Jv_core_chain *next;
634 // This is called when new core data is loaded.
635 extern void (*_Jv_RegisterCoreHook) (_Jv_core_chain *);
637 _Jv_core_chain *_Jv_FindCore (_Jv_core_chain *node, jstring name);
638 void _Jv_FreeCoreChain (_Jv_core_chain *chain);
640 #ifdef ENABLE_JVMPI
642 #include "jvmpi.h"
644 extern void (*_Jv_JVMPI_Notify_OBJECT_ALLOC) (JVMPI_Event *event);
645 extern void (*_Jv_JVMPI_Notify_THREAD_START) (JVMPI_Event *event);
646 extern void (*_Jv_JVMPI_Notify_THREAD_END) (JVMPI_Event *event);
647 #endif
649 /* FIXME: this should really be defined in some more generic place */
650 #define ROUND(V, A) (((((unsigned) (V))-1) | ((A)-1))+1)
652 extern void _Jv_RegisterBootstrapPackages ();
654 #define FLAG_BINARYCOMPAT_ABI (1<<31) /* Class is built with the BC-ABI. */
656 #define FLAG_BOOTSTRAP_LOADER (1<<30) /* Used when defining a class that
657 should be loaded by the bootstrap
658 loader. */
660 // These are used to find ABI versions we recognize.
661 #define GCJ_CXX_ABI_VERSION (__GNUC__ * 100000 + __GNUC_MINOR__ * 1000)
663 // This is the old-style BC version ID used by GCJ 4.0.0.
664 #define OLD_GCJ_40_BC_ABI_VERSION (4 * 10000 + 0 * 10 + 5)
666 // New style version IDs used by GCJ 4.0.1 and later.
667 #define GCJ_40_BC_ABI_VERSION (4 * 100000 + 0 * 1000)
669 void _Jv_CheckABIVersion (unsigned long value);
672 inline bool
673 _Jv_ClassForBootstrapLoader (unsigned long value)
675 return (value & FLAG_BOOTSTRAP_LOADER);
678 // It makes the source cleaner if we simply always define this
679 // function. If the interpreter is not built, it will never return
680 // 'true'.
681 extern inline jboolean
682 _Jv_IsInterpretedClass (jclass c)
684 return (c->accflags & java::lang::reflect::Modifier::INTERPRETED) != 0;
687 // Return true if the class was compiled with the BC ABI.
688 extern inline jboolean
689 _Jv_IsBinaryCompatibilityABI (jclass c)
691 // There isn't really a better test for the ABI type at this point,
692 // that will work once the class has been registered.
693 return c->otable_syms || c->atable_syms || c->itable_syms;
696 // Returns whether the given class does not really exists (ie. we have no
697 // bytecode) but still allows us to do some very conservative actions.
698 // E.g. throwing a NoClassDefFoundError with the name of the missing
699 // class.
700 extern inline jboolean
701 _Jv_IsPhantomClass (jclass c)
703 return c->state == JV_STATE_PHANTOM;
706 // A helper function defined in prims.cc.
707 char* _Jv_PrependVersionedLibdir (char* libpath);
710 // An enum for use with JvSetThreadState. We use a C++ enum rather
711 // than the Java enum to avoid problems with class initialization
712 // during VM bootstrap.
713 typedef enum
715 JV_BLOCKED,
716 JV_NEW,
717 JV_RUNNABLE,
718 JV_TERMINATED,
719 JV_TIMED_WAITING,
720 JV_WAITING
721 } JvThreadState;
723 // Temporarily set the thread's state.
724 class JvSetThreadState
726 private:
727 ::java::lang::Thread *thread;
728 jint saved;
730 public:
732 // Note that 'cthread' could be NULL -- during VM startup there may
733 // not be a Thread available.
734 JvSetThreadState(::java::lang::Thread *cthread, JvThreadState nstate)
735 : thread (cthread),
736 saved (cthread ? cthread->state : (jint)JV_NEW)
738 if (thread)
739 thread->state = nstate;
742 ~JvSetThreadState()
744 if (thread)
745 thread->state = saved;
749 // This structure is used to represent all the data the native side
750 // needs. An object of this type is assigned to the `data' member of
751 // the Thread class.
752 struct natThread
754 // A thread is either alive, dead, or being sent a signal; if it is
755 // being sent a signal, it is also alive. Thus, if you want to know
756 // if a thread is alive, it is sufficient to test alive_status !=
757 // THREAD_DEAD.
758 volatile obj_addr_t alive_flag;
760 // These are used to interrupt sleep and join calls. We can share a
761 // condition variable here since it only ever gets notified when the thread
762 // exits.
763 _Jv_Mutex_t join_mutex;
764 _Jv_ConditionVariable_t join_cond;
766 // These are used by Unsafe.park() and Unsafe.unpark().
767 ParkHelper park_helper;
769 // This is private data for the thread system layer.
770 _Jv_Thread_t *thread;
772 // Each thread has its own JNI object.
773 _Jv_JNIEnv *jni_env;
776 #endif /* __JAVA_JVM_H__ */