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
;
313 static bool has_field_p (jclass
, _Jv_Utf8Const
*);
314 static void print_class_loaded (jclass
);
315 static void resolve_class_ref (jclass
, jclass
*);
316 static void wait_for_state(jclass
, int);
317 static _Jv_Method
*resolve_method_entry (jclass
, jclass
&,
320 static _Jv_word
resolve_pool_entry (jclass
, int, bool =false);
321 static void resolve_field (_Jv_Field
*, java::lang::ClassLoader
*);
322 static void verify_type_assertions (jclass
);
323 static _Jv_Method
*search_method_in_class (jclass
, jclass
,
326 bool check_perms
= true);
327 static void layout_vtable_methods(jclass
);
330 /* Type of pointer used as finalizer. */
331 typedef void _Jv_FinalizerFunc (jobject
);
333 /* Allocate space for a new Java object. */
334 void *_Jv_AllocObj (jsize size
, jclass cl
) __attribute__((__malloc__
));
335 /* Allocate space for a potentially uninitialized pointer-free object.
336 Interesting only with JV_HASH_SYNCHRONIZATION. */
337 void *_Jv_AllocPtrFreeObj (jsize size
, jclass cl
) __attribute__((__malloc__
));
338 /* Allocate space for an array of Java objects. */
339 void *_Jv_AllocArray (jsize size
, jclass cl
) __attribute__((__malloc__
));
340 /* Allocate space that is known to be pointer-free. */
341 void *_Jv_AllocBytes (jsize size
) __attribute__((__malloc__
));
342 /* Allocate space for a new non-Java object, which does not have the usual
343 Java object header but may contain pointers to other GC'ed objects. */
344 void *_Jv_AllocRawObj (jsize size
) __attribute__((__malloc__
));
345 /* Allocate a double-indirect pointer to a _Jv_ClosureList such that
346 the _Jv_ClosureList gets automatically finalized when it is no
347 longer reachable, not even by other finalizable objects. */
348 _Jv_ClosureList
**_Jv_ClosureListFinalizer (void) __attribute__((__malloc__
));
349 /* Explicitly throw an out-of-memory exception. */
350 void _Jv_ThrowNoMemory() __attribute__((__noreturn__
));
351 /* Allocate an object with a single pointer. The first word is reserved
352 for the GC, and the second word is the traced pointer. */
353 void *_Jv_AllocTraceOne (jsize size
/* incl. reserved slot */);
354 /* Ditto, but for two traced pointers. */
355 void *_Jv_AllocTraceTwo (jsize size
/* incl. reserved slot */);
356 /* Initialize the GC. */
357 void _Jv_InitGC (void);
358 /* Register a finalizer. */
359 void _Jv_RegisterFinalizer (void *object
, _Jv_FinalizerFunc
*method
);
360 /* Compute the GC descriptor for a class */
361 void * _Jv_BuildGCDescr(jclass
);
363 /* Allocate some unscanned, unmoveable memory. Return NULL if out of
365 void *_Jv_MallocUnchecked (jsize size
) __attribute__((__malloc__
));
367 /* Initialize finalizers. The argument is a function to be called
368 when a finalizer is ready to be run. */
369 void _Jv_GCInitializeFinalizers (void (*notifier
) (void));
370 /* Run finalizers for objects ready to be finalized.. */
371 void _Jv_RunFinalizers (void);
372 /* Run all finalizers. Should be called only before exit. */
373 void _Jv_RunAllFinalizers (void);
375 void _Jv_RunGC (void);
376 /* Disable and enable GC. */
377 void _Jv_DisableGC (void);
378 void _Jv_EnableGC (void);
379 /* Register a disappearing link. This is a field F which should be
380 cleared when *F is found to be inaccessible. This is used in the
381 implementation of java.lang.ref.Reference. */
382 void _Jv_GCRegisterDisappearingLink (jobject
*objp
);
383 /* Return true if OBJECT should be reclaimed. This is used to
384 implement soft references. */
385 jboolean
_Jv_GCCanReclaimSoftReference (jobject obj
);
387 /* Register a finalizer for a String object. This is only used by
388 the intern() implementation. */
389 void _Jv_RegisterStringFinalizer (jobject str
);
390 /* This is called to actually finalize a possibly-intern()d String. */
391 void _Jv_FinalizeString (jobject str
);
393 /* Return approximation of total size of heap. */
394 long _Jv_GCTotalMemory (void);
395 /* Return approximation of total free memory. */
396 long _Jv_GCFreeMemory (void);
398 /* Set initial heap size. If SIZE==0, ignore. Should be run before
399 _Jv_InitGC. Not required to have any actual effect. */
400 void _Jv_GCSetInitialHeapSize (size_t size
);
402 /* Set maximum heap size. If SIZE==0, unbounded. Should be run
403 before _Jv_InitGC. Not required to have any actual effect. */
404 void _Jv_GCSetMaximumHeapSize (size_t size
);
406 /* External interface to setting the heap size. Parses ARG (a number
407 which can optionally have "k" or "m" appended and calls
408 _Jv_GCSetInitialHeapSize. */
409 void _Jv_SetInitialHeapSize (const char *arg
);
411 /* External interface to setting the maximum heap size. Parses ARG (a
412 number which can optionally have "k" or "m" appended and calls
413 _Jv_GCSetMaximumHeapSize. */
414 void _Jv_SetMaximumHeapSize (const char *arg
);
416 /* External interface for setting the GC_free_space_divisor. Calls
417 GC_set_free_space_divisor and returns the old value. */
418 int _Jv_SetGCFreeSpaceDivisor (int div
);
420 /* Free the method cache, if one was allocated. This is only called
421 during thread deregistration. */
422 void _Jv_FreeMethodCache ();
424 /* Set the stack size for threads. Parses ARG, a number which can
425 optionally have "k" or "m" appended. */
426 void _Jv_SetStackSize (const char *arg
);
428 extern "C" void JvRunMain (jclass klass
, int argc
, const char **argv
);
429 extern "C" void JvRunMainName (const char *name
, int argc
, const char **argv
);
431 void _Jv_RunMain (jclass klass
, const char *name
, int argc
, const char **argv
,
434 void _Jv_RunMain (struct _Jv_VMInitArgs
*vm_args
, jclass klass
,
435 const char *name
, int argc
, const char **argv
, bool is_jar
);
437 // Delayed until after _Jv_AllocRawObj is declared.
439 _Jv_VTable::new_vtable (int count
)
441 size_t size
= sizeof(_Jv_VTable
) + (count
- 1) * vtable_elt_size ();
442 return (_Jv_VTable
*) _Jv_AllocRawObj (size
);
445 // Determine if METH gets an entry in a VTable.
446 static inline jboolean
_Jv_isVirtualMethod (_Jv_Method
*meth
)
448 using namespace java::lang::reflect
;
449 return (((meth
->accflags
& (Modifier::STATIC
| Modifier::PRIVATE
)) == 0)
450 && meth
->name
->first() != '<');
453 // This function is used to determine the hash code of an object.
455 _Jv_HashCode (jobject obj
)
457 // This was chosen to yield relatively well distributed results on
458 // both 32- and 64-bit architectures. Note 0x7fffffff is prime.
459 // FIXME: we assume sizeof(long) == sizeof(void *).
460 return (jint
) ((unsigned long) obj
% 0x7fffffff);
463 // Return a raw pointer to the elements of an array given the array
464 // and its element type. You might think we could just pick a single
465 // array type and use elements() on it, but we can't because we must
466 // account for alignment of the element type. When ARRAY is null, we
467 // obtain the number of bytes taken by the base part of the array.
469 _Jv_GetArrayElementFromElementType (jobject array
,
473 if (element_type
== JvPrimClass (byte
))
474 elts
= (char *) elements ((jbyteArray
) array
);
475 else if (element_type
== JvPrimClass (short))
476 elts
= (char *) elements ((jshortArray
) array
);
477 else if (element_type
== JvPrimClass (int))
478 elts
= (char *) elements ((jintArray
) array
);
479 else if (element_type
== JvPrimClass (long))
480 elts
= (char *) elements ((jlongArray
) array
);
481 else if (element_type
== JvPrimClass (boolean
))
482 elts
= (char *) elements ((jbooleanArray
) array
);
483 else if (element_type
== JvPrimClass (char))
484 elts
= (char *) elements ((jcharArray
) array
);
485 else if (element_type
== JvPrimClass (float))
486 elts
= (char *) elements ((jfloatArray
) array
);
487 else if (element_type
== JvPrimClass (double))
488 elts
= (char *) elements ((jdoubleArray
) array
);
490 elts
= (char *) elements ((jobjectArray
) array
);
494 extern "C" void _Jv_ThrowBadArrayIndex (jint bad_index
)
495 __attribute__((noreturn
));
496 extern "C" void _Jv_ThrowNullPointerException (void)
497 __attribute__((noreturn
));
498 extern "C" void _Jv_ThrowNoSuchMethodError (void)
499 __attribute__((noreturn
));
500 extern "C" void _Jv_ThrowNoSuchFieldError (int)
501 __attribute__((noreturn
));
502 extern "C" jobject
_Jv_NewArray (jint type
, jint size
)
503 __attribute__((__malloc__
));
504 extern "C" jobject
_Jv_NewMultiArray (jclass klass
, jint dims
, ...)
505 __attribute__((__malloc__
));
506 extern "C" void *_Jv_CheckCast (jclass klass
, jobject obj
);
507 extern "C" void *_Jv_LookupInterfaceMethod (jclass klass
, Utf8Const
*name
,
508 Utf8Const
*signature
);
509 extern "C" void *_Jv_LookupInterfaceMethodIdx (jclass klass
, jclass iface
,
511 extern "C" void _Jv_CheckArrayStore (jobject array
, jobject obj
);
512 extern "C" void _Jv_RegisterClass (jclass klass
);
513 extern "C" void _Jv_RegisterClasses (const jclass
*classes
);
514 extern "C" void _Jv_RegisterClasses_Counted (const jclass
*classes
,
516 extern "C" void _Jv_RegisterResource (void *vptr
);
517 extern void _Jv_UnregisterClass (_Jv_Utf8Const
*, java::lang::ClassLoader
*);
519 extern "C" jobject
_Jv_UnwrapJNIweakReference (jobject
);
521 extern jclass
_Jv_FindClass (_Jv_Utf8Const
*name
,
522 java::lang::ClassLoader
*loader
);
524 extern jclass
_Jv_FindClassNoException (_Jv_Utf8Const
*name
,
525 java::lang::ClassLoader
*loader
);
527 extern jclass
_Jv_FindClassFromSignature (char *,
528 java::lang::ClassLoader
*loader
,
531 extern jclass
_Jv_FindClassFromSignatureNoException (char *,
532 java::lang::ClassLoader
*loader
,
535 extern void _Jv_GetTypesFromSignature (jmethodID method
,
536 jclass declaringClass
,
537 JArray
<jclass
> **arg_types_out
,
538 jclass
*return_type_out
);
540 extern jboolean
_Jv_CheckAccess (jclass self_klass
, jclass other_klass
,
543 extern jobject
_Jv_CallAnyMethodA (jobject obj
, jclass return_type
,
544 jmethodID meth
, jboolean is_constructor
,
545 JArray
<jclass
> *parameter_types
,
547 jclass iface
= NULL
);
550 extern void _Jv_CallAnyMethodA (jobject obj
,
553 jboolean is_constructor
,
554 jboolean is_virtual_call
,
555 JArray
<jclass
> *parameter_types
,
558 jboolean is_jni_call
= true,
559 jclass iface
= NULL
);
561 extern void _Jv_CheckOrCreateLoadingConstraint (jclass
,
562 java::lang::ClassLoader
*);
564 extern jobject
_Jv_NewMultiArray (jclass
, jint ndims
, jint
* dims
)
565 __attribute__((__malloc__
));
567 extern "C" void _Jv_ThrowAbstractMethodError () __attribute__((__noreturn__
));
569 /* Checked divide subroutines. */
572 jint
_Jv_divI (jint
, jint
);
573 jint
_Jv_remI (jint
, jint
);
574 jlong
_Jv_divJ (jlong
, jlong
);
575 jlong
_Jv_remJ (jlong
, jlong
);
578 /* Get the number of arguments (cf. argc) or 0 if our argument
579 list was never initialized. */
580 extern int _Jv_GetNbArgs (void);
582 /* Get the specified argument (cf. argv[index]) or "" if either
583 our argument list was never initialized or the specified index
585 extern const char * _Jv_GetSafeArg (int index
);
587 /* Sets our argument list. Can be used by programs with non-standard
589 extern void _Jv_SetArgs (int argc
, const char **argv
);
591 /* Get the name of the running executable. */
592 extern const char *_Jv_ThisExecutable (void);
594 /* Return a pointer to a symbol in executable or loaded library. */
595 void *_Jv_FindSymbolInExecutable (const char *);
597 /* Initialize JNI. */
598 extern void _Jv_JNI_Init (void);
600 /* Get or set the per-thread JNIEnv used by the invocation API. */
601 _Jv_JNIEnv
*_Jv_GetCurrentJNIEnv ();
602 void _Jv_SetCurrentJNIEnv (_Jv_JNIEnv
*);
605 void _Jv_FreeJNIEnv (_Jv_JNIEnv
*);
607 extern "C" void _Jv_JNI_PopSystemFrame (_Jv_JNIEnv
*);
608 _Jv_JNIEnv
*_Jv_GetJNIEnvNewFrameWithLoader (::java::lang::ClassLoader
*);
611 _Jv_JavaVM
*_Jv_GetJavaVM ();
613 /* Get a JVMTI environment */
615 _Jv_JVMTIEnv
*_Jv_GetJVMTIEnv (void);
617 /* Initialize JVMTI */
618 extern void _Jv_JVMTI_Init (void);
620 // Some verification functions from defineclass.cc.
621 bool _Jv_VerifyFieldSignature (_Jv_Utf8Const
*sig
);
622 bool _Jv_VerifyMethodSignature (_Jv_Utf8Const
*sig
);
623 bool _Jv_VerifyClassName (unsigned char* ptr
, _Jv_ushort length
);
624 bool _Jv_VerifyClassName (_Jv_Utf8Const
*name
);
625 bool _Jv_VerifyIdentifier (_Jv_Utf8Const
*);
626 bool _Jv_ClassNameSamePackage (_Jv_Utf8Const
*name1
, _Jv_Utf8Const
*name2
);
628 struct _Jv_core_chain
635 struct _Jv_core_chain
*next
;
638 // This is called when new core data is loaded.
639 extern void (*_Jv_RegisterCoreHook
) (_Jv_core_chain
*);
641 _Jv_core_chain
*_Jv_FindCore (_Jv_core_chain
*node
, jstring name
);
642 void _Jv_FreeCoreChain (_Jv_core_chain
*chain
);
648 extern void (*_Jv_JVMPI_Notify_OBJECT_ALLOC
) (JVMPI_Event
*event
);
649 extern void (*_Jv_JVMPI_Notify_THREAD_START
) (JVMPI_Event
*event
);
650 extern void (*_Jv_JVMPI_Notify_THREAD_END
) (JVMPI_Event
*event
);
653 /* FIXME: this should really be defined in some more generic place */
654 #define ROUND(V, A) (((((unsigned) (V))-1) | ((A)-1))+1)
656 extern void _Jv_RegisterBootstrapPackages ();
658 #define FLAG_BINARYCOMPAT_ABI (1<<31) /* Class is built with the BC-ABI. */
660 #define FLAG_BOOTSTRAP_LOADER (1<<30) /* Used when defining a class that
661 should be loaded by the bootstrap
664 // These are used to find ABI versions we recognize.
665 #define GCJ_CXX_ABI_VERSION (__GNUC__ * 100000 + __GNUC_MINOR__ * 1000)
667 // This is the old-style BC version ID used by GCJ 4.0.0.
668 #define OLD_GCJ_40_BC_ABI_VERSION (4 * 10000 + 0 * 10 + 5)
670 // New style version IDs used by GCJ 4.0.1 and later.
671 #define GCJ_40_BC_ABI_VERSION (4 * 100000 + 0 * 1000)
673 void _Jv_CheckABIVersion (unsigned long value
);
677 _Jv_ClassForBootstrapLoader (unsigned long value
)
679 return (value
& FLAG_BOOTSTRAP_LOADER
);
682 // It makes the source cleaner if we simply always define this
683 // function. If the interpreter is not built, it will never return
685 extern inline jboolean
686 _Jv_IsInterpretedClass (jclass c
)
688 return (c
->accflags
& java::lang::reflect::Modifier::INTERPRETED
) != 0;
691 // Return true if the class was compiled with the BC ABI.
692 extern inline jboolean
693 _Jv_IsBinaryCompatibilityABI (jclass c
)
695 // There isn't really a better test for the ABI type at this point,
696 // that will work once the class has been registered.
697 return c
->otable_syms
|| c
->atable_syms
|| c
->itable_syms
;
700 // Returns whether the given class does not really exists (ie. we have no
701 // bytecode) but still allows us to do some very conservative actions.
702 // E.g. throwing a NoClassDefFoundError with the name of the missing
704 extern inline jboolean
705 _Jv_IsPhantomClass (jclass c
)
707 return c
->state
== JV_STATE_PHANTOM
;
710 // A helper function defined in prims.cc.
711 char* _Jv_PrependVersionedLibdir (char* libpath
);
714 // An enum for use with JvSetThreadState. We use a C++ enum rather
715 // than the Java enum to avoid problems with class initialization
716 // during VM bootstrap.
727 // Temporarily set the thread's state.
728 class JvSetThreadState
731 ::java::lang::Thread
*thread
;
736 // Note that 'cthread' could be NULL -- during VM startup there may
737 // not be a Thread available.
738 JvSetThreadState(::java::lang::Thread
*cthread
, JvThreadState nstate
)
740 saved (cthread
? cthread
->state
: (jint
)JV_NEW
)
743 thread
->state
= nstate
;
749 thread
->state
= saved
;
753 // This structure is used to represent all the data the native side
754 // needs. An object of this type is assigned to the `data' member of
758 // A thread is either alive, dead, or being sent a signal; if it is
759 // being sent a signal, it is also alive. Thus, if you want to know
760 // if a thread is alive, it is sufficient to test alive_status !=
762 volatile obj_addr_t alive_flag
;
764 // These are used to interrupt sleep and join calls. We can share a
765 // condition variable here since it only ever gets notified when the thread
767 _Jv_Mutex_t join_mutex
;
768 _Jv_ConditionVariable_t join_cond
;
770 // These are used by Unsafe.park() and Unsafe.unpark().
771 ParkHelper park_helper
;
773 // This is private data for the thread system layer.
774 _Jv_Thread_t
*thread
;
776 // Each thread has its own JNI object.
780 #endif /* __JAVA_JVM_H__ */