1 // jvm.h - Header file for private implementation information. -*- c++ -*-
3 /* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 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
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.
27 #include <java/lang/Object.h>
29 // Include cni.h before field.h to enable all definitions. FIXME.
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. */
44 typedef struct { void *pc
, *gp
; } vtable_elt
;
46 typedef void *vtable_elt
;
51 // This must be last, as derived classes "extend" this by
52 // adding new data members.
56 void *get_method(int i
) { return &method
[i
]; }
57 void set_method(int i
, void *fptr
) { method
[i
] = *(vtable_elt
*)fptr
; }
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
64 return ((vtable_elt
*)(get_method(0)))->pc
;
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); }
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
);
86 jint i
; // Also stores smaller integral types.
88 jint ia
[1]; // Half of _Jv_word2.
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.
100 struct _Jv_Field
*field
;
101 struct _Jv_Utf8Const
*utf8
;
102 struct _Jv_ResolvedMethod
*rmethod
;
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) \
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
160 _Jv_TempUTFString(jstring jstr
, char* buf
=0);
161 ~_Jv_TempUTFString();
164 operator const char*() const
168 const char* buf() const
182 inline _Jv_TempUTFString::_Jv_TempUTFString (jstring jstr
, char* buf
)
183 : buf_(0), heapAllocated_(false)
186 jsize len
= JvGetStringUTFLength (jstr
);
191 buf_
= (char*) _Jv_Malloc (len
+1);
192 heapAllocated_
= true;
195 JvGetStringUTFRegion (jstr
, 0, jstr
->length(), buf_
);
199 inline _Jv_TempUTFString::~_Jv_TempUTFString ()
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
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)
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
;
246 extern jlong startTime
;
248 /* The VM arguments */
249 extern JArray
<jstring
>* vmArgs
;
251 // Currently loaded classes
252 extern jint loadedClasses
;
255 extern jlong unloadedClasses
;
258 // This class handles all aspects of class preparation and linking.
262 typedef unsigned int uaddr
__attribute__ ((mode (pointer
)));
264 static _Jv_Field
*find_field_helper(jclass
, _Jv_Utf8Const
*, _Jv_Utf8Const
*,
266 static _Jv_Field
*find_field(jclass
, jclass
, jclass
*, _Jv_Utf8Const
*,
268 static void check_loading_constraints (_Jv_Method
*, jclass
, jclass
);
269 static void prepare_constant_time_tables(jclass
);
270 static jshort
get_interfaces(jclass
, _Jv_ifaces
*);
271 static void link_symbol_table(jclass
);
272 static void link_exception_table(jclass
);
273 static void layout_interface_methods(jclass
);
274 static void set_vtable_entries(jclass
, _Jv_VTable
*);
275 static void make_vtable(jclass
);
276 static void ensure_fields_laid_out(jclass
);
277 static void ensure_class_linked(jclass
);
278 static void ensure_supers_installed(jclass
);
279 static void add_miranda_methods(jclass
, jclass
);
280 static void ensure_method_table_complete(jclass
);
281 static void verify_class(jclass
);
282 static jshort
find_iindex(jclass
*, jshort
*, jshort
);
283 static jshort
indexof(void *, void **, jshort
);
284 static int get_alignment_from_class(jclass
);
285 static void generate_itable(jclass
, _Jv_ifaces
*, jshort
*);
286 static jshort
append_partial_itable(jclass
, jclass
, void **, jshort
);
287 static _Jv_Method
*search_method_in_superclasses (jclass cls
, jclass klass
,
288 _Jv_Utf8Const
*method_name
,
289 _Jv_Utf8Const
*method_signature
,
291 bool check_perms
= true);
292 static void *create_error_method(_Jv_Utf8Const
*, jclass
);
294 /* The least significant bit of the signature pointer in a symbol
295 table is set to 1 by the compiler if the reference is "special",
296 i.e. if it is an access to a private field or method. Extract
297 that bit, clearing it in the address and setting the LSB of
298 SPECIAL accordingly. */
299 static void maybe_adjust_signature (_Jv_Utf8Const
*&s
, uaddr
&special
)
302 _Jv_Utf8Const
*signature
;
303 uaddr signature_bits
;
306 special
= signature_bits
& 1;
307 signature_bits
-= special
;
311 static _Jv_Mutex_t resolve_mutex
;
312 static void init (void) __attribute__((constructor
));
316 static bool has_field_p (jclass
, _Jv_Utf8Const
*);
317 static void print_class_loaded (jclass
);
318 static void resolve_class_ref (jclass
, jclass
*);
319 static void wait_for_state(jclass
, int);
320 static _Jv_Method
*resolve_method_entry (jclass
, jclass
&,
323 static _Jv_word
resolve_pool_entry (jclass
, int, bool =false);
324 static void resolve_field (_Jv_Field
*, java::lang::ClassLoader
*);
325 static void verify_type_assertions (jclass
);
326 static _Jv_Method
*search_method_in_class (jclass
, jclass
,
329 bool check_perms
= true);
330 static void layout_vtable_methods(jclass
);
332 static jbyte
read_cpool_entry (_Jv_word
*data
,
333 const _Jv_Constants
*const pool
,
336 _Jv_MutexLock (&resolve_mutex
);
337 jbyte tags
= pool
->tags
[index
];
338 *data
= pool
->data
[index
];
339 _Jv_MutexUnlock (&resolve_mutex
);
343 static void write_cpool_entry (_Jv_word data
, jbyte tags
,
347 _Jv_MutexLock (&resolve_mutex
);
348 pool
->data
[index
] = data
;
349 pool
->tags
[index
] = tags
;
350 _Jv_MutexUnlock (&resolve_mutex
);
354 /* Type of pointer used as finalizer. */
355 typedef void _Jv_FinalizerFunc (jobject
);
357 /* Allocate space for a new Java object. */
358 void *_Jv_AllocObj (jsize size
, jclass cl
) __attribute__((__malloc__
));
359 /* Allocate space for a potentially uninitialized pointer-free object.
360 Interesting only with JV_HASH_SYNCHRONIZATION. */
361 void *_Jv_AllocPtrFreeObj (jsize size
, jclass cl
) __attribute__((__malloc__
));
362 /* Allocate space for an array of Java objects. */
363 void *_Jv_AllocArray (jsize size
, jclass cl
) __attribute__((__malloc__
));
364 /* Allocate space that is known to be pointer-free. */
365 void *_Jv_AllocBytes (jsize size
) __attribute__((__malloc__
));
366 /* Allocate space for a new non-Java object, which does not have the usual
367 Java object header but may contain pointers to other GC'ed objects. */
368 void *_Jv_AllocRawObj (jsize size
) __attribute__((__malloc__
));
369 /* Allocate a double-indirect pointer to a _Jv_ClosureList such that
370 the _Jv_ClosureList gets automatically finalized when it is no
371 longer reachable, not even by other finalizable objects. */
372 _Jv_ClosureList
**_Jv_ClosureListFinalizer (void) __attribute__((__malloc__
));
373 /* Explicitly throw an out-of-memory exception. */
374 void _Jv_ThrowNoMemory() __attribute__((__noreturn__
));
375 /* Allocate an object with a single pointer. The first word is reserved
376 for the GC, and the second word is the traced pointer. */
377 void *_Jv_AllocTraceOne (jsize size
/* incl. reserved slot */);
378 /* Ditto, but for two traced pointers. */
379 void *_Jv_AllocTraceTwo (jsize size
/* incl. reserved slot */);
380 /* Initialize the GC. */
381 void _Jv_InitGC (void);
382 /* Register a finalizer. */
383 void _Jv_RegisterFinalizer (void *object
, _Jv_FinalizerFunc
*method
);
384 /* Compute the GC descriptor for a class */
385 void * _Jv_BuildGCDescr(jclass
);
387 /* Allocate some unscanned, unmoveable memory. Return NULL if out of
389 void *_Jv_MallocUnchecked (jsize size
) __attribute__((__malloc__
));
391 /* Initialize finalizers. The argument is a function to be called
392 when a finalizer is ready to be run. */
393 void _Jv_GCInitializeFinalizers (void (*notifier
) (void));
394 /* Run finalizers for objects ready to be finalized.. */
395 void _Jv_RunFinalizers (void);
396 /* Run all finalizers. Should be called only before exit. */
397 void _Jv_RunAllFinalizers (void);
399 void _Jv_RunGC (void);
400 /* Disable and enable GC. */
401 void _Jv_DisableGC (void);
402 void _Jv_EnableGC (void);
403 /* Register a disappearing link. This is a field F which should be
404 cleared when *F is found to be inaccessible. This is used in the
405 implementation of java.lang.ref.Reference. */
406 void _Jv_GCRegisterDisappearingLink (jobject
*objp
);
407 /* Return true if OBJECT should be reclaimed. This is used to
408 implement soft references. */
409 jboolean
_Jv_GCCanReclaimSoftReference (jobject obj
);
411 /* Register a finalizer for a String object. This is only used by
412 the intern() implementation. */
413 void _Jv_RegisterStringFinalizer (jobject str
);
414 /* This is called to actually finalize a possibly-intern()d String. */
415 void _Jv_FinalizeString (jobject str
);
417 /* Return approximation of total size of heap. */
418 long _Jv_GCTotalMemory (void);
419 /* Return approximation of total free memory. */
420 long _Jv_GCFreeMemory (void);
422 /* Set initial heap size. If SIZE==0, ignore. Should be run before
423 _Jv_InitGC. Not required to have any actual effect. */
424 void _Jv_GCSetInitialHeapSize (size_t size
);
426 /* Set maximum heap size. If SIZE==0, unbounded. Should be run
427 before _Jv_InitGC. Not required to have any actual effect. */
428 void _Jv_GCSetMaximumHeapSize (size_t size
);
430 /* External interface to setting the heap size. Parses ARG (a number
431 which can optionally have "k" or "m" appended and calls
432 _Jv_GCSetInitialHeapSize. */
433 void _Jv_SetInitialHeapSize (const char *arg
);
435 /* External interface to setting the maximum heap size. Parses ARG (a
436 number which can optionally have "k" or "m" appended and calls
437 _Jv_GCSetMaximumHeapSize. */
438 void _Jv_SetMaximumHeapSize (const char *arg
);
440 /* External interface for setting the GC_free_space_divisor. Calls
441 GC_set_free_space_divisor and returns the old value. */
442 int _Jv_SetGCFreeSpaceDivisor (int div
);
444 /* Free the method cache, if one was allocated. This is only called
445 during thread deregistration. */
446 void _Jv_FreeMethodCache ();
448 /* Set the stack size for threads. Parses ARG, a number which can
449 optionally have "k" or "m" appended. */
450 void _Jv_SetStackSize (const char *arg
);
452 extern "C" void JvRunMain (jclass klass
, int argc
, const char **argv
);
453 extern "C" void JvRunMainName (const char *name
, int argc
, const char **argv
);
455 void _Jv_RunMain (jclass klass
, const char *name
, int argc
, const char **argv
,
458 void _Jv_RunMain (struct _Jv_VMInitArgs
*vm_args
, jclass klass
,
459 const char *name
, int argc
, const char **argv
, bool is_jar
);
461 // Delayed until after _Jv_AllocRawObj is declared.
463 _Jv_VTable::new_vtable (int count
)
465 size_t size
= sizeof(_Jv_VTable
) + (count
- 1) * vtable_elt_size ();
466 return (_Jv_VTable
*) _Jv_AllocRawObj (size
);
469 // Determine if METH gets an entry in a VTable.
470 static inline jboolean
_Jv_isVirtualMethod (_Jv_Method
*meth
)
472 using namespace java::lang::reflect
;
473 return (((meth
->accflags
& (Modifier::STATIC
| Modifier::PRIVATE
)) == 0)
474 && meth
->name
->first() != '<');
477 // This function is used to determine the hash code of an object.
479 _Jv_HashCode (jobject obj
)
481 // This was chosen to yield relatively well distributed results on
482 // both 32- and 64-bit architectures. Note 0x7fffffff is prime.
483 // FIXME: we assume sizeof(long) == sizeof(void *).
484 return (jint
) ((unsigned long) obj
% 0x7fffffff);
487 // Return a raw pointer to the elements of an array given the array
488 // and its element type. You might think we could just pick a single
489 // array type and use elements() on it, but we can't because we must
490 // account for alignment of the element type. When ARRAY is null, we
491 // obtain the number of bytes taken by the base part of the array.
493 _Jv_GetArrayElementFromElementType (jobject array
,
497 if (element_type
== JvPrimClass (byte
))
498 elts
= (char *) elements ((jbyteArray
) array
);
499 else if (element_type
== JvPrimClass (short))
500 elts
= (char *) elements ((jshortArray
) array
);
501 else if (element_type
== JvPrimClass (int))
502 elts
= (char *) elements ((jintArray
) array
);
503 else if (element_type
== JvPrimClass (long))
504 elts
= (char *) elements ((jlongArray
) array
);
505 else if (element_type
== JvPrimClass (boolean
))
506 elts
= (char *) elements ((jbooleanArray
) array
);
507 else if (element_type
== JvPrimClass (char))
508 elts
= (char *) elements ((jcharArray
) array
);
509 else if (element_type
== JvPrimClass (float))
510 elts
= (char *) elements ((jfloatArray
) array
);
511 else if (element_type
== JvPrimClass (double))
512 elts
= (char *) elements ((jdoubleArray
) array
);
514 elts
= (char *) elements ((jobjectArray
) array
);
518 extern "C" void _Jv_ThrowBadArrayIndex (jint bad_index
)
519 __attribute__((noreturn
));
520 extern "C" void _Jv_ThrowNullPointerException (void)
521 __attribute__((noreturn
));
522 extern "C" void _Jv_ThrowNoSuchMethodError (void)
523 __attribute__((noreturn
));
524 extern "C" void _Jv_ThrowNoSuchFieldError (int)
525 __attribute__((noreturn
));
526 extern "C" jobject
_Jv_NewArray (jint type
, jint size
)
527 __attribute__((__malloc__
));
528 extern "C" jobject
_Jv_NewMultiArray (jclass klass
, jint dims
, ...)
529 __attribute__((__malloc__
));
530 extern "C" void *_Jv_CheckCast (jclass klass
, jobject obj
);
531 extern "C" void *_Jv_LookupInterfaceMethod (jclass klass
, Utf8Const
*name
,
532 Utf8Const
*signature
);
533 extern "C" void *_Jv_LookupInterfaceMethodIdx (jclass klass
, jclass iface
,
535 extern "C" void _Jv_CheckArrayStore (jobject array
, jobject obj
);
536 extern "C" void _Jv_RegisterClass (jclass klass
);
537 extern "C" void _Jv_RegisterClasses (const jclass
*classes
);
538 extern "C" void _Jv_RegisterClasses_Counted (const jclass
*classes
,
540 extern "C" void _Jv_RegisterResource (void *vptr
);
541 extern void _Jv_UnregisterClass (_Jv_Utf8Const
*, java::lang::ClassLoader
*);
543 extern "C" jobject
_Jv_UnwrapJNIweakReference (jobject
);
545 extern jclass
_Jv_FindClass (_Jv_Utf8Const
*name
,
546 java::lang::ClassLoader
*loader
);
548 extern jclass
_Jv_FindClassNoException (_Jv_Utf8Const
*name
,
549 java::lang::ClassLoader
*loader
);
551 extern jclass
_Jv_FindClassFromSignature (char *,
552 java::lang::ClassLoader
*loader
,
555 extern jclass
_Jv_FindClassFromSignatureNoException (char *,
556 java::lang::ClassLoader
*loader
,
559 extern void _Jv_GetTypesFromSignature (jmethodID method
,
560 jclass declaringClass
,
561 JArray
<jclass
> **arg_types_out
,
562 jclass
*return_type_out
);
564 extern jboolean
_Jv_CheckAccess (jclass self_klass
, jclass other_klass
,
567 extern jobject
_Jv_CallAnyMethodA (jobject obj
, jclass return_type
,
568 jmethodID meth
, jboolean is_constructor
,
569 JArray
<jclass
> *parameter_types
,
571 jclass iface
= NULL
);
574 extern void _Jv_CallAnyMethodA (jobject obj
,
577 jboolean is_constructor
,
578 jboolean is_virtual_call
,
579 JArray
<jclass
> *parameter_types
,
582 jboolean is_jni_call
= true,
583 jclass iface
= NULL
);
585 extern void _Jv_CheckOrCreateLoadingConstraint (jclass
,
586 java::lang::ClassLoader
*);
588 extern jobject
_Jv_NewMultiArray (jclass
, jint ndims
, jint
* dims
)
589 __attribute__((__malloc__
));
591 extern "C" void _Jv_ThrowAbstractMethodError () __attribute__((__noreturn__
));
593 /* Checked divide subroutines. */
596 jint
_Jv_divI (jint
, jint
);
597 jint
_Jv_remI (jint
, jint
);
598 jlong
_Jv_divJ (jlong
, jlong
);
599 jlong
_Jv_remJ (jlong
, jlong
);
602 /* Get the number of arguments (cf. argc) or 0 if our argument
603 list was never initialized. */
604 extern int _Jv_GetNbArgs (void);
606 /* Get the specified argument (cf. argv[index]) or "" if either
607 our argument list was never initialized or the specified index
609 extern const char * _Jv_GetSafeArg (int index
);
611 /* Sets our argument list. Can be used by programs with non-standard
613 extern void _Jv_SetArgs (int argc
, const char **argv
);
615 /* Get the name of the running executable. */
616 extern const char *_Jv_ThisExecutable (void);
618 /* Return a pointer to a symbol in executable or loaded library. */
619 void *_Jv_FindSymbolInExecutable (const char *);
621 /* Initialize JNI. */
622 extern void _Jv_JNI_Init (void);
624 /* Get or set the per-thread JNIEnv used by the invocation API. */
625 _Jv_JNIEnv
*_Jv_GetCurrentJNIEnv ();
626 void _Jv_SetCurrentJNIEnv (_Jv_JNIEnv
*);
629 void _Jv_FreeJNIEnv (_Jv_JNIEnv
*);
631 extern "C" void _Jv_JNI_PopSystemFrame (_Jv_JNIEnv
*);
632 _Jv_JNIEnv
*_Jv_GetJNIEnvNewFrameWithLoader (::java::lang::ClassLoader
*);
635 _Jv_JavaVM
*_Jv_GetJavaVM ();
637 /* Get a JVMTI environment */
639 _Jv_JVMTIEnv
*_Jv_GetJVMTIEnv (void);
641 /* Initialize JVMTI */
642 extern void _Jv_JVMTI_Init (void);
644 // Some verification functions from defineclass.cc.
645 bool _Jv_VerifyFieldSignature (_Jv_Utf8Const
*sig
);
646 bool _Jv_VerifyMethodSignature (_Jv_Utf8Const
*sig
);
647 bool _Jv_VerifyClassName (unsigned char* ptr
, _Jv_ushort length
);
648 bool _Jv_VerifyClassName (_Jv_Utf8Const
*name
);
649 bool _Jv_VerifyIdentifier (_Jv_Utf8Const
*);
650 bool _Jv_ClassNameSamePackage (_Jv_Utf8Const
*name1
, _Jv_Utf8Const
*name2
);
652 struct _Jv_core_chain
659 struct _Jv_core_chain
*next
;
662 // This is called when new core data is loaded.
663 extern void (*_Jv_RegisterCoreHook
) (_Jv_core_chain
*);
665 _Jv_core_chain
*_Jv_FindCore (_Jv_core_chain
*node
, jstring name
);
666 void _Jv_FreeCoreChain (_Jv_core_chain
*chain
);
672 extern void (*_Jv_JVMPI_Notify_OBJECT_ALLOC
) (JVMPI_Event
*event
);
673 extern void (*_Jv_JVMPI_Notify_THREAD_START
) (JVMPI_Event
*event
);
674 extern void (*_Jv_JVMPI_Notify_THREAD_END
) (JVMPI_Event
*event
);
677 /* FIXME: this should really be defined in some more generic place */
678 #define ROUND(V, A) (((((unsigned) (V))-1) | ((A)-1))+1)
680 extern void _Jv_RegisterBootstrapPackages ();
682 #define FLAG_BINARYCOMPAT_ABI (1<<31) /* Class is built with the BC-ABI. */
684 #define FLAG_BOOTSTRAP_LOADER (1<<30) /* Used when defining a class that
685 should be loaded by the bootstrap
688 // These are used to find ABI versions we recognize.
689 #define GCJ_CXX_ABI_VERSION (__GNUC__ * 100000 + __GNUC_MINOR__ * 1000)
691 // This is the old-style BC version ID used by GCJ 4.0.0.
692 #define OLD_GCJ_40_BC_ABI_VERSION (4 * 10000 + 0 * 10 + 5)
694 // New style version IDs used by GCJ 4.0.1 and later.
695 #define GCJ_40_BC_ABI_VERSION (4 * 100000 + 0 * 1000)
697 void _Jv_CheckABIVersion (unsigned long value
);
701 _Jv_ClassForBootstrapLoader (unsigned long value
)
703 return (value
& FLAG_BOOTSTRAP_LOADER
);
706 // It makes the source cleaner if we simply always define this
707 // function. If the interpreter is not built, it will never return
709 extern inline jboolean
710 _Jv_IsInterpretedClass (jclass c
)
712 return (c
->accflags
& java::lang::reflect::Modifier::INTERPRETED
) != 0;
715 // Return true if the class was compiled with the BC ABI.
716 extern inline jboolean
717 _Jv_IsBinaryCompatibilityABI (jclass c
)
719 // There isn't really a better test for the ABI type at this point,
720 // that will work once the class has been registered.
721 return c
->otable_syms
|| c
->atable_syms
|| c
->itable_syms
;
724 // Returns whether the given class does not really exists (ie. we have no
725 // bytecode) but still allows us to do some very conservative actions.
726 // E.g. throwing a NoClassDefFoundError with the name of the missing
728 extern inline jboolean
729 _Jv_IsPhantomClass (jclass c
)
731 return c
->state
== JV_STATE_PHANTOM
;
734 // A helper function defined in prims.cc.
735 char* _Jv_PrependVersionedLibdir (char* libpath
);
738 // An enum for use with JvSetThreadState. We use a C++ enum rather
739 // than the Java enum to avoid problems with class initialization
740 // during VM bootstrap.
751 // Temporarily set the thread's state.
752 class JvSetThreadState
755 ::java::lang::Thread
*thread
;
760 // Note that 'cthread' could be NULL -- during VM startup there may
761 // not be a Thread available.
762 JvSetThreadState(::java::lang::Thread
*cthread
, JvThreadState nstate
)
764 saved (cthread
? cthread
->state
: (jint
)JV_NEW
)
767 thread
->state
= nstate
;
773 thread
->state
= saved
;
777 // This structure is used to represent all the data the native side
778 // needs. An object of this type is assigned to the `data' member of
782 // A thread is either alive, dead, or being sent a signal; if it is
783 // being sent a signal, it is also alive. Thus, if you want to know
784 // if a thread is alive, it is sufficient to test alive_status !=
786 volatile obj_addr_t alive_flag
;
788 // These are used to interrupt sleep and join calls. We can share a
789 // condition variable here since it only ever gets notified when the thread
791 _Jv_Mutex_t join_mutex
;
792 _Jv_ConditionVariable_t join_cond
;
794 // These are used by Unsafe.park() and Unsafe.unpark().
795 ParkHelper park_helper
;
797 // This is private data for the thread system layer.
798 _Jv_Thread_t
*thread
;
800 // Each thread has its own JNI object.
804 #endif /* __JAVA_JVM_H__ */