Merged gcj-eclipse branch to trunk.
[official-gcc.git] / libjava / include / jvm.h
blob203e0d95356547e6ae5b56299225ec1a251db8c6
1 // jvm.h - Header file for private implementation information. -*- c++ -*-
3 /* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 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 *);
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 /* Explicitly throw an out-of-memory exception. */
345 void _Jv_ThrowNoMemory() __attribute__((__noreturn__));
346 /* Allocate an object with a single pointer. The first word is reserved
347 for the GC, and the second word is the traced pointer. */
348 void *_Jv_AllocTraceOne (jsize size /* incl. reserved slot */);
349 /* Ditto, but for two traced pointers. */
350 void *_Jv_AllocTraceTwo (jsize size /* incl. reserved slot */);
351 /* Initialize the GC. */
352 void _Jv_InitGC (void);
353 /* Register a finalizer. */
354 void _Jv_RegisterFinalizer (void *object, _Jv_FinalizerFunc *method);
355 /* Compute the GC descriptor for a class */
356 void * _Jv_BuildGCDescr(jclass);
358 /* Allocate some unscanned, unmoveable memory. Return NULL if out of
359 memory. */
360 void *_Jv_MallocUnchecked (jsize size) __attribute__((__malloc__));
362 /* Initialize finalizers. The argument is a function to be called
363 when a finalizer is ready to be run. */
364 void _Jv_GCInitializeFinalizers (void (*notifier) (void));
365 /* Run finalizers for objects ready to be finalized.. */
366 void _Jv_RunFinalizers (void);
367 /* Run all finalizers. Should be called only before exit. */
368 void _Jv_RunAllFinalizers (void);
369 /* Perform a GC. */
370 void _Jv_RunGC (void);
371 /* Disable and enable GC. */
372 void _Jv_DisableGC (void);
373 void _Jv_EnableGC (void);
374 /* Register a disappearing link. This is a field F which should be
375 cleared when *F is found to be inaccessible. This is used in the
376 implementation of java.lang.ref.Reference. */
377 void _Jv_GCRegisterDisappearingLink (jobject *objp);
378 /* Return true if OBJECT should be reclaimed. This is used to
379 implement soft references. */
380 jboolean _Jv_GCCanReclaimSoftReference (jobject obj);
382 /* Register a finalizer for a String object. This is only used by
383 the intern() implementation. */
384 void _Jv_RegisterStringFinalizer (jobject str);
385 /* This is called to actually finalize a possibly-intern()d String. */
386 void _Jv_FinalizeString (jobject str);
388 /* Return approximation of total size of heap. */
389 long _Jv_GCTotalMemory (void);
390 /* Return approximation of total free memory. */
391 long _Jv_GCFreeMemory (void);
393 /* Set initial heap size. If SIZE==0, ignore. Should be run before
394 _Jv_InitGC. Not required to have any actual effect. */
395 void _Jv_GCSetInitialHeapSize (size_t size);
397 /* Set maximum heap size. If SIZE==0, unbounded. Should be run
398 before _Jv_InitGC. Not required to have any actual effect. */
399 void _Jv_GCSetMaximumHeapSize (size_t size);
401 /* External interface to setting the heap size. Parses ARG (a number
402 which can optionally have "k" or "m" appended and calls
403 _Jv_GCSetInitialHeapSize. */
404 void _Jv_SetInitialHeapSize (const char *arg);
406 /* External interface to setting the maximum heap size. Parses ARG (a
407 number which can optionally have "k" or "m" appended and calls
408 _Jv_GCSetMaximumHeapSize. */
409 void _Jv_SetMaximumHeapSize (const char *arg);
411 /* Free the method cache, if one was allocated. This is only called
412 during thread deregistration. */
413 void _Jv_FreeMethodCache ();
415 /* Set the stack size for threads. Parses ARG, a number which can
416 optionally have "k" or "m" appended. */
417 void _Jv_SetStackSize (const char *arg);
419 extern "C" void JvRunMain (jclass klass, int argc, const char **argv);
420 extern "C" void JvRunMainName (const char *name, int argc, const char **argv);
422 void _Jv_RunMain (jclass klass, const char *name, int argc, const char **argv,
423 bool is_jar);
425 void _Jv_RunMain (struct _Jv_VMInitArgs *vm_args, jclass klass,
426 const char *name, int argc, const char **argv, bool is_jar);
428 // Delayed until after _Jv_AllocRawObj is declared.
429 inline _Jv_VTable *
430 _Jv_VTable::new_vtable (int count)
432 size_t size = sizeof(_Jv_VTable) + (count - 1) * vtable_elt_size ();
433 return (_Jv_VTable *) _Jv_AllocRawObj (size);
436 // Determine if METH gets an entry in a VTable.
437 static inline jboolean _Jv_isVirtualMethod (_Jv_Method *meth)
439 using namespace java::lang::reflect;
440 return (((meth->accflags & (Modifier::STATIC | Modifier::PRIVATE)) == 0)
441 && meth->name->first() != '<');
444 // This function is used to determine the hash code of an object.
445 inline jint
446 _Jv_HashCode (jobject obj)
448 // This was chosen to yield relatively well distributed results on
449 // both 32- and 64-bit architectures. Note 0x7fffffff is prime.
450 // FIXME: we assume sizeof(long) == sizeof(void *).
451 return (jint) ((unsigned long) obj % 0x7fffffff);
454 // Return a raw pointer to the elements of an array given the array
455 // and its element type. You might think we could just pick a single
456 // array type and use elements() on it, but we can't because we must
457 // account for alignment of the element type. When ARRAY is null, we
458 // obtain the number of bytes taken by the base part of the array.
459 inline char *
460 _Jv_GetArrayElementFromElementType (jobject array,
461 jclass element_type)
463 char *elts;
464 if (element_type == JvPrimClass (byte))
465 elts = (char *) elements ((jbyteArray) array);
466 else if (element_type == JvPrimClass (short))
467 elts = (char *) elements ((jshortArray) array);
468 else if (element_type == JvPrimClass (int))
469 elts = (char *) elements ((jintArray) array);
470 else if (element_type == JvPrimClass (long))
471 elts = (char *) elements ((jlongArray) array);
472 else if (element_type == JvPrimClass (boolean))
473 elts = (char *) elements ((jbooleanArray) array);
474 else if (element_type == JvPrimClass (char))
475 elts = (char *) elements ((jcharArray) array);
476 else if (element_type == JvPrimClass (float))
477 elts = (char *) elements ((jfloatArray) array);
478 else if (element_type == JvPrimClass (double))
479 elts = (char *) elements ((jdoubleArray) array);
480 else
481 elts = (char *) elements ((jobjectArray) array);
482 return elts;
485 extern "C" void _Jv_ThrowBadArrayIndex (jint bad_index)
486 __attribute__((noreturn));
487 extern "C" void _Jv_ThrowNullPointerException (void)
488 __attribute__((noreturn));
489 extern "C" void _Jv_ThrowNoSuchMethodError (void)
490 __attribute__((noreturn));
491 extern "C" void _Jv_ThrowNoSuchFieldError (int)
492 __attribute__((noreturn));
493 extern "C" jobject _Jv_NewArray (jint type, jint size)
494 __attribute__((__malloc__));
495 extern "C" jobject _Jv_NewMultiArray (jclass klass, jint dims, ...)
496 __attribute__((__malloc__));
497 extern "C" void *_Jv_CheckCast (jclass klass, jobject obj);
498 extern "C" void *_Jv_LookupInterfaceMethod (jclass klass, Utf8Const *name,
499 Utf8Const *signature);
500 extern "C" void *_Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface,
501 int meth_idx);
502 extern "C" void _Jv_CheckArrayStore (jobject array, jobject obj);
503 extern "C" void _Jv_RegisterClass (jclass klass);
504 extern "C" void _Jv_RegisterClasses (const jclass *classes);
505 extern "C" void _Jv_RegisterClasses_Counted (const jclass *classes,
506 size_t count);
507 extern "C" void _Jv_RegisterResource (void *vptr);
508 extern void _Jv_UnregisterClass (_Jv_Utf8Const*, java::lang::ClassLoader*);
510 extern "C" jobject _Jv_UnwrapJNIweakReference (jobject);
512 extern jclass _Jv_FindClass (_Jv_Utf8Const *name,
513 java::lang::ClassLoader *loader);
515 extern jclass _Jv_FindClassNoException (_Jv_Utf8Const *name,
516 java::lang::ClassLoader *loader);
518 extern jclass _Jv_FindClassFromSignature (char *,
519 java::lang::ClassLoader *loader,
520 char ** = NULL);
522 extern jclass _Jv_FindClassFromSignatureNoException (char *,
523 java::lang::ClassLoader *loader,
524 char ** = NULL);
526 extern void _Jv_GetTypesFromSignature (jmethodID method,
527 jclass declaringClass,
528 JArray<jclass> **arg_types_out,
529 jclass *return_type_out);
531 extern jboolean _Jv_CheckAccess (jclass self_klass, jclass other_klass,
532 jint flags);
534 extern jobject _Jv_CallAnyMethodA (jobject obj, jclass return_type,
535 jmethodID meth, jboolean is_constructor,
536 JArray<jclass> *parameter_types,
537 jobjectArray args,
538 jclass iface = NULL);
540 union jvalue;
541 extern void _Jv_CallAnyMethodA (jobject obj,
542 jclass return_type,
543 jmethodID meth,
544 jboolean is_constructor,
545 jboolean is_virtual_call,
546 JArray<jclass> *parameter_types,
547 jvalue *args,
548 jvalue *result,
549 jboolean is_jni_call = true,
550 jclass iface = NULL);
552 extern jobject _Jv_NewMultiArray (jclass, jint ndims, jint* dims)
553 __attribute__((__malloc__));
555 extern "C" void _Jv_ThrowAbstractMethodError () __attribute__((__noreturn__));
557 /* Checked divide subroutines. */
558 extern "C"
560 jint _Jv_divI (jint, jint);
561 jint _Jv_remI (jint, jint);
562 jlong _Jv_divJ (jlong, jlong);
563 jlong _Jv_remJ (jlong, jlong);
566 /* Get the number of arguments (cf. argc) or 0 if our argument
567 list was never initialized. */
568 extern int _Jv_GetNbArgs (void);
570 /* Get the specified argument (cf. argv[index]) or "" if either
571 our argument list was never initialized or the specified index
572 is out of bounds. */
573 extern const char * _Jv_GetSafeArg (int index);
575 /* Sets our argument list. Can be used by programs with non-standard
576 entry points. */
577 extern void _Jv_SetArgs (int argc, const char **argv);
579 /* Get the name of the running executable. */
580 extern const char *_Jv_ThisExecutable (void);
582 /* Return a pointer to a symbol in executable or loaded library. */
583 void *_Jv_FindSymbolInExecutable (const char *);
585 /* Initialize JNI. */
586 extern void _Jv_JNI_Init (void);
588 /* Get or set the per-thread JNIEnv used by the invocation API. */
589 _Jv_JNIEnv *_Jv_GetCurrentJNIEnv ();
590 void _Jv_SetCurrentJNIEnv (_Jv_JNIEnv *);
592 /* Free a JNIEnv. */
593 void _Jv_FreeJNIEnv (_Jv_JNIEnv *);
595 /* Free a JNIEnv. */
596 void _Jv_FreeJNIEnv (_Jv_JNIEnv *);
598 struct _Jv_JavaVM;
599 _Jv_JavaVM *_Jv_GetJavaVM ();
601 /* Get a JVMTI environment */
602 struct _Jv_JVMTIEnv;
603 _Jv_JVMTIEnv *_Jv_GetJVMTIEnv (void);
605 /* Initialize JVMTI */
606 extern void _Jv_JVMTI_Init (void);
608 // Some verification functions from defineclass.cc.
609 bool _Jv_VerifyFieldSignature (_Jv_Utf8Const*sig);
610 bool _Jv_VerifyMethodSignature (_Jv_Utf8Const*sig);
611 bool _Jv_VerifyClassName (unsigned char* ptr, _Jv_ushort length);
612 bool _Jv_VerifyClassName (_Jv_Utf8Const *name);
613 bool _Jv_VerifyIdentifier (_Jv_Utf8Const *);
614 bool _Jv_ClassNameSamePackage (_Jv_Utf8Const *name1, _Jv_Utf8Const *name2);
616 struct _Jv_core_chain
618 int name_length;
619 const char *name;
620 int data_length;
621 const void *data;
623 struct _Jv_core_chain *next;
626 // This is called when new core data is loaded.
627 extern void (*_Jv_RegisterCoreHook) (_Jv_core_chain *);
629 _Jv_core_chain *_Jv_FindCore (_Jv_core_chain *node, jstring name);
630 void _Jv_FreeCoreChain (_Jv_core_chain *chain);
632 #ifdef ENABLE_JVMPI
634 #include "jvmpi.h"
636 extern void (*_Jv_JVMPI_Notify_OBJECT_ALLOC) (JVMPI_Event *event);
637 extern void (*_Jv_JVMPI_Notify_THREAD_START) (JVMPI_Event *event);
638 extern void (*_Jv_JVMPI_Notify_THREAD_END) (JVMPI_Event *event);
639 #endif
641 /* FIXME: this should really be defined in some more generic place */
642 #define ROUND(V, A) (((((unsigned) (V))-1) | ((A)-1))+1)
644 extern void _Jv_RegisterBootstrapPackages ();
646 #define FLAG_BINARYCOMPAT_ABI (1<<31) /* Class is built with the BC-ABI. */
648 #define FLAG_BOOTSTRAP_LOADER (1<<30) /* Used when defining a class that
649 should be loaded by the bootstrap
650 loader. */
652 // These are used to find ABI versions we recognize.
653 #define GCJ_CXX_ABI_VERSION (__GNUC__ * 100000 + __GNUC_MINOR__ * 1000)
655 // This is the old-style BC version ID used by GCJ 4.0.0.
656 #define OLD_GCJ_40_BC_ABI_VERSION (4 * 10000 + 0 * 10 + 5)
658 // New style version IDs used by GCJ 4.0.1 and later.
659 #define GCJ_40_BC_ABI_VERSION (4 * 100000 + 0 * 1000)
661 void _Jv_CheckABIVersion (unsigned long value);
664 inline bool
665 _Jv_ClassForBootstrapLoader (unsigned long value)
667 return (value & FLAG_BOOTSTRAP_LOADER);
670 // It makes the source cleaner if we simply always define this
671 // function. If the interpreter is not built, it will never return
672 // 'true'.
673 extern inline jboolean
674 _Jv_IsInterpretedClass (jclass c)
676 return (c->accflags & java::lang::reflect::Modifier::INTERPRETED) != 0;
679 // Return true if the class was compiled with the BC ABI.
680 extern inline jboolean
681 _Jv_IsBinaryCompatibilityABI (jclass c)
683 // There isn't really a better test for the ABI type at this point,
684 // that will work once the class has been registered.
685 return c->otable_syms || c->atable_syms || c->itable_syms;
688 // Returns whether the given class does not really exists (ie. we have no
689 // bytecode) but still allows us to do some very conservative actions.
690 // E.g. throwing a NoClassDefFoundError with the name of the missing
691 // class.
692 extern inline jboolean
693 _Jv_IsPhantomClass (jclass c)
695 return c->state == JV_STATE_PHANTOM;
698 // A helper function defined in prims.cc.
699 char* _Jv_PrependVersionedLibdir (char* libpath);
702 // An enum for use with JvSetThreadState. We use a C++ enum rather
703 // than the Java enum to avoid problems with class initialization
704 // during VM bootstrap.
705 typedef enum
707 JV_BLOCKED,
708 JV_NEW,
709 JV_RUNNABLE,
710 JV_TERMINATED,
711 JV_TIMED_WAITING,
712 JV_WAITING
713 } JvThreadState;
715 // Temporarily set the thread's state.
716 class JvSetThreadState
718 private:
719 ::java::lang::Thread *thread;
720 jint saved;
722 public:
724 // Note that 'cthread' could be NULL -- during VM startup there may
725 // not be a Thread available.
726 JvSetThreadState(::java::lang::Thread *cthread, JvThreadState nstate)
727 : thread (cthread),
728 saved (cthread ? cthread->state : (jint)JV_NEW)
730 if (thread)
731 thread->state = nstate;
734 ~JvSetThreadState()
736 if (thread)
737 thread->state = saved;
741 // This structure is used to represent all the data the native side
742 // needs. An object of this type is assigned to the `data' member of
743 // the Thread class.
744 struct natThread
746 // A thread is either alive, dead, or being sent a signal; if it is
747 // being sent a signal, it is also alive. Thus, if you want to know
748 // if a thread is alive, it is sufficient to test alive_status !=
749 // THREAD_DEAD.
750 volatile obj_addr_t alive_flag;
752 // These are used to interrupt sleep and join calls. We can share a
753 // condition variable here since it only ever gets notified when the thread
754 // exits.
755 _Jv_Mutex_t join_mutex;
756 _Jv_ConditionVariable_t join_cond;
758 // These are used by Unsafe.park() and Unsafe.unpark().
759 ParkHelper park_helper;
761 // This is private data for the thread system layer.
762 _Jv_Thread_t *thread;
764 // Each thread has its own JNI object.
765 void *jni_env;
768 #endif /* __JAVA_JVM_H__ */