1 // prims.cc - Code for core of runtime environment.
3 /* Copyright (C) 1998, 1999, 2000, 2001, 2002 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
26 #include <java-signal.h>
27 #include <java-threads.h>
31 #include <java/lang/ThreadGroup.h>
34 #ifndef DISABLE_GETENV_PROPERTIES
36 #include <java-props.h>
37 #define PROCESS_GCJ_PROPERTIES process_gcj_properties()
39 #define PROCESS_GCJ_PROPERTIES
40 #endif // DISABLE_GETENV_PROPERTIES
42 #include <java/lang/Class.h>
43 #include <java/lang/ClassLoader.h>
44 #include <java/lang/Runtime.h>
45 #include <java/lang/String.h>
46 #include <java/lang/Thread.h>
47 #include <java/lang/ThreadGroup.h>
48 #include <java/lang/ArrayIndexOutOfBoundsException.h>
49 #include <java/lang/ArithmeticException.h>
50 #include <java/lang/ClassFormatError.h>
51 #include <java/lang/InternalError.h>
52 #include <java/lang/NegativeArraySizeException.h>
53 #include <java/lang/NullPointerException.h>
54 #include <java/lang/OutOfMemoryError.h>
55 #include <java/lang/System.h>
56 #include <java/lang/VMThrowable.h>
57 #include <java/lang/reflect/Modifier.h>
58 #include <java/io/PrintStream.h>
59 #include <java/lang/UnsatisfiedLinkError.h>
60 #include <java/lang/VirtualMachineError.h>
61 #include <gnu/gcj/runtime/VMClassLoader.h>
62 #include <gnu/gcj/runtime/FinalizerThread.h>
63 #include <gnu/gcj/runtime/FirstThread.h>
69 // We allocate a single OutOfMemoryError exception which we keep
70 // around for use if we run out of memory.
71 static java::lang::OutOfMemoryError *no_memory;
73 // Largest representable size_t.
74 #define SIZE_T_MAX ((size_t) (~ (size_t) 0))
76 static const char *no_properties[] = { NULL };
78 // Properties set at compile time.
79 const char **_Jv_Compiler_Properties = no_properties;
81 // The JAR file to add to the beginning of java.class.path.
82 const char *_Jv_Jar_Class_Path;
84 #ifndef DISABLE_GETENV_PROPERTIES
85 // Property key/value pairs.
86 property_pair *_Jv_Environment_Properties;
89 // Stash the argv pointer to benefit native libraries that need it.
90 const char **_Jv_argv;
97 // _Jv_argc is 0 if not explicitly initialized.
102 _Jv_GetSafeArg (int index)
104 if (index >=0 && index < _Jv_GetNbArgs ())
105 return _Jv_argv[index];
111 _Jv_SetArgs (int argc, const char **argv)
118 // Pointer to JVMPI notification functions.
119 void (*_Jv_JVMPI_Notify_OBJECT_ALLOC) (JVMPI_Event *event);
120 void (*_Jv_JVMPI_Notify_THREAD_START) (JVMPI_Event *event);
121 void (*_Jv_JVMPI_Notify_THREAD_END) (JVMPI_Event *event);
125 extern "C" void _Jv_ThrowSignal (jthrowable) __attribute ((noreturn));
127 // Just like _Jv_Throw, but fill in the stack trace first. Although
128 // this is declared extern in order that its name not be mangled, it
129 // is not intended to be used outside this file.
131 _Jv_ThrowSignal (jthrowable throwable)
133 throwable->fillInStackTrace ();
138 static java::lang::NullPointerException *nullp;
140 SIGNAL_HANDLER (catch_segv)
142 MAKE_THROW_FRAME (nullp);
143 _Jv_ThrowSignal (nullp);
147 static java::lang::ArithmeticException *arithexception;
150 SIGNAL_HANDLER (catch_fpe)
152 #ifdef HANDLE_DIVIDE_OVERFLOW
153 HANDLE_DIVIDE_OVERFLOW;
155 MAKE_THROW_FRAME (arithexception);
157 _Jv_ThrowSignal (arithexception);
164 _Jv_equalUtf8Consts (Utf8Const* a, Utf8Const *b)
167 _Jv_ushort *aptr, *bptr;
170 if (a->hash != b->hash)
173 if (b->length != len)
175 aptr = (_Jv_ushort *)a->data;
176 bptr = (_Jv_ushort *)b->data;
177 len = (len + 1) >> 1;
179 if (*aptr++ != *bptr++)
184 /* True iff A is equal to STR.
185 HASH is STR->hashCode().
189 _Jv_equal (Utf8Const* a, jstring str, jint hash)
191 if (a->hash != (_Jv_ushort) hash)
193 jint len = str->length();
195 jchar *sptr = _Jv_GetStringChars (str);
196 unsigned char* ptr = (unsigned char*) a->data;
197 unsigned char* limit = ptr + a->length;
200 int ch = UTF8_GET (ptr, limit);
209 /* Like _Jv_equal, but stop after N characters. */
211 _Jv_equaln (Utf8Const *a, jstring str, jint n)
213 jint len = str->length();
215 jchar *sptr = _Jv_GetStringChars (str);
216 unsigned char* ptr = (unsigned char*) a->data;
217 unsigned char* limit = ptr + a->length;
218 for (; n-- > 0; i++, sptr++)
220 int ch = UTF8_GET (ptr, limit);
229 /* Count the number of Unicode chars encoded in a given Ut8 string. */
231 _Jv_strLengthUtf8(char* str, int len)
234 unsigned char* limit;
237 ptr = (unsigned char*) str;
240 for (; ptr < limit; str_length++)
242 if (UTF8_GET (ptr, limit) < 0)
248 /* Calculate a hash value for a string encoded in Utf8 format.
249 * This returns the same hash value as specified or java.lang.String.hashCode.
252 hashUtf8String (char* str, int len)
254 unsigned char* ptr = (unsigned char*) str;
255 unsigned char* limit = ptr + len;
260 int ch = UTF8_GET (ptr, limit);
261 /* Updated specification from
262 http://www.javasoft.com/docs/books/jls/clarify.html. */
263 hash = (31 * hash) + ch;
269 _Jv_makeUtf8Const (char* s, int len)
273 Utf8Const* m = (Utf8Const*) _Jv_AllocBytes (sizeof(Utf8Const) + len + 1);
274 memcpy (m->data, s, len);
277 m->hash = hashUtf8String (s, len) & 0xFFFF;
282 _Jv_makeUtf8Const (jstring string)
284 jint hash = string->hashCode ();
285 jint len = _Jv_GetStringUTFLength (string);
287 Utf8Const* m = (Utf8Const*)
288 _Jv_AllocBytes (sizeof(Utf8Const) + len + 1);
293 _Jv_GetStringUTFRegion (string, 0, string->length (), m->data);
303 _Jv_Abort (const char *function, const char *file, int line,
307 _Jv_Abort (const char *, const char *, int, const char *message)
312 "libgcj failure: %s\n in function %s, file %s, line %d\n",
313 message, function, file, line);
315 fprintf (stderr, "libgcj failure: %s\n", message);
321 fail_on_finalization (jobject)
323 JvFail ("object was finalized");
327 _Jv_GCWatch (jobject obj)
329 _Jv_RegisterFinalizer (obj, fail_on_finalization);
333 _Jv_ThrowBadArrayIndex(jint bad_index)
335 throw new java::lang::ArrayIndexOutOfBoundsException
336 (java::lang::String::valueOf (bad_index));
340 _Jv_ThrowNullPointerException ()
342 throw new java::lang::NullPointerException;
345 // Explicitly throw a no memory exception.
346 // The collector calls this when it encounters an out-of-memory condition.
347 void _Jv_ThrowNoMemory()
354 jvmpi_notify_alloc(jclass klass, jint size, jobject obj)
356 // Service JVMPI allocation request.
357 if (__builtin_expect (_Jv_JVMPI_Notify_OBJECT_ALLOC != 0, false))
361 event.event_type = JVMPI_EVENT_OBJECT_ALLOC;
363 event.u.obj_alloc.arena_id = 0;
364 event.u.obj_alloc.class_id = (jobjectID) klass;
365 event.u.obj_alloc.is_array = 0;
366 event.u.obj_alloc.size = size;
367 event.u.obj_alloc.obj_id = (jobjectID) obj;
369 // FIXME: This doesn't look right for the Boehm GC. A GC may
370 // already be in progress. _Jv_DisableGC () doesn't wait for it.
371 // More importantly, I don't see the need for disabling GC, since we
372 // blatantly have a pointer to obj on our stack, ensuring that the
373 // object can't be collected. Even for a nonconservative collector,
374 // it appears to me that this must be true, since we are about to
375 // return obj. Isn't this whole approach way too intrusive for
376 // a useful profiling interface? - HB
378 (*_Jv_JVMPI_Notify_OBJECT_ALLOC) (&event);
382 #else /* !ENABLE_JVMPI */
383 # define jvmpi_notify_alloc(klass,size,obj) /* do nothing */
386 // Allocate a new object of class KLASS. SIZE is the size of the object
387 // to allocate. You might think this is redundant, but it isn't; some
388 // classes, such as String, aren't of fixed size.
389 // First a version that assumes that we have no finalizer, and that
390 // the class is already initialized.
391 // If we know that JVMPI is disabled, this can be replaced by a direct call
392 // to the allocator for the appropriate GC.
394 _Jv_AllocObjectNoInitNoFinalizer (jclass klass, jint size)
396 jobject obj = (jobject) _Jv_AllocObj (size, klass);
397 jvmpi_notify_alloc (klass, size, obj);
401 // And now a version that initializes if necessary.
403 _Jv_AllocObjectNoFinalizer (jclass klass, jint size)
405 _Jv_InitClass (klass);
406 jobject obj = (jobject) _Jv_AllocObj (size, klass);
407 jvmpi_notify_alloc (klass, size, obj);
411 // And now the general version that registers a finalizer if necessary.
413 _Jv_AllocObject (jclass klass, jint size)
415 jobject obj = _Jv_AllocObjectNoFinalizer (klass, size);
417 // We assume that the compiler only generates calls to this routine
418 // if there really is an interesting finalizer.
419 // Unfortunately, we still have to the dynamic test, since there may
420 // be cni calls to this routine.
421 // Note that on IA64 get_finalizer() returns the starting address of the
422 // function, not a function pointer. Thus this still works.
423 if (klass->vtable->get_finalizer ()
424 != java::lang::Object::class$.vtable->get_finalizer ())
425 _Jv_RegisterFinalizer (obj, _Jv_FinalizeObject);
429 // A version of the above that assumes the object contains no pointers,
430 // and requires no finalization. This can't happen if we need pointers
432 #ifdef JV_HASH_SYNCHRONIZATION
434 _Jv_AllocPtrFreeObject (jclass klass, jint size)
436 _Jv_InitClass (klass);
438 jobject obj = (jobject) _Jv_AllocPtrFreeObj (size, klass);
441 // Service JVMPI request.
443 if (__builtin_expect (_Jv_JVMPI_Notify_OBJECT_ALLOC != 0, false))
447 event.event_type = JVMPI_EVENT_OBJECT_ALLOC;
449 event.u.obj_alloc.arena_id = 0;
450 event.u.obj_alloc.class_id = (jobjectID) klass;
451 event.u.obj_alloc.is_array = 0;
452 event.u.obj_alloc.size = size;
453 event.u.obj_alloc.obj_id = (jobjectID) obj;
456 (*_Jv_JVMPI_Notify_OBJECT_ALLOC) (&event);
463 #endif /* JV_HASH_SYNCHRONIZATION */
466 // Allocate a new array of Java objects. Each object is of type
467 // `elementClass'. `init' is used to initialize each slot in the
470 _Jv_NewObjectArray (jsize count, jclass elementClass, jobject init)
472 if (__builtin_expect (count < 0, false))
473 throw new java::lang::NegativeArraySizeException;
475 JvAssert (! elementClass->isPrimitive ());
477 // Ensure that elements pointer is properly aligned.
478 jobjectArray obj = NULL;
479 size_t size = (size_t) elements (obj);
480 size += count * sizeof (jobject);
482 jclass klass = _Jv_GetArrayClass (elementClass,
483 elementClass->getClassLoaderInternal());
485 obj = (jobjectArray) _Jv_AllocArray (size, klass);
487 jsize *lp = const_cast<jsize *> (&obj->length);
489 // We know the allocator returns zeroed memory. So don't bother
493 jobject *ptr = elements(obj);
500 // Allocate a new array of primitives. ELTYPE is the type of the
501 // element, COUNT is the size of the array.
503 _Jv_NewPrimArray (jclass eltype, jint count)
505 int elsize = eltype->size();
506 if (__builtin_expect (count < 0, false))
507 throw new java::lang::NegativeArraySizeException;
509 JvAssert (eltype->isPrimitive ());
510 jobject dummy = NULL;
511 size_t size = (size_t) _Jv_GetArrayElementFromElementType (dummy, eltype);
513 // Check for overflow.
514 if (__builtin_expect ((size_t) count >
515 (SIZE_T_MAX - size) / elsize, false))
518 jclass klass = _Jv_GetArrayClass (eltype, 0);
520 # ifdef JV_HASH_SYNCHRONIZATION
521 // Since the vtable is always statically allocated,
522 // these are completely pointerfree! Make sure the GC doesn't touch them.
524 (__JArray*) _Jv_AllocPtrFreeObj (size + elsize * count, klass);
525 memset((char *)arr + size, 0, elsize * count);
527 __JArray *arr = (__JArray*) _Jv_AllocObj (size + elsize * count, klass);
528 // Note that we assume we are given zeroed memory by the allocator.
531 jsize *lp = const_cast<jsize *> (&arr->length);
538 _Jv_NewArray (jint type, jint size)
542 case 4: return JvNewBooleanArray (size);
543 case 5: return JvNewCharArray (size);
544 case 6: return JvNewFloatArray (size);
545 case 7: return JvNewDoubleArray (size);
546 case 8: return JvNewByteArray (size);
547 case 9: return JvNewShortArray (size);
548 case 10: return JvNewIntArray (size);
549 case 11: return JvNewLongArray (size);
551 throw new java::lang::InternalError
552 (JvNewStringLatin1 ("invalid type code in _Jv_NewArray"));
555 // Allocate a possibly multi-dimensional array but don't check that
556 // any array length is <0.
558 _Jv_NewMultiArrayUnchecked (jclass type, jint dimensions, jint *sizes)
560 JvAssert (type->isArray());
561 jclass element_type = type->getComponentType();
563 if (element_type->isPrimitive())
564 result = _Jv_NewPrimArray (element_type, sizes[0]);
566 result = _Jv_NewObjectArray (sizes[0], element_type, NULL);
570 JvAssert (! element_type->isPrimitive());
571 JvAssert (element_type->isArray());
572 jobject *contents = elements ((jobjectArray) result);
573 for (int i = 0; i < sizes[0]; ++i)
574 contents[i] = _Jv_NewMultiArrayUnchecked (element_type, dimensions - 1,
582 _Jv_NewMultiArray (jclass type, jint dimensions, jint *sizes)
584 for (int i = 0; i < dimensions; ++i)
586 throw new java::lang::NegativeArraySizeException;
588 return _Jv_NewMultiArrayUnchecked (type, dimensions, sizes);
592 _Jv_NewMultiArray (jclass array_type, jint dimensions, ...)
595 jint sizes[dimensions];
596 va_start (args, dimensions);
597 for (int i = 0; i < dimensions; ++i)
599 jint size = va_arg (args, jint);
601 throw new java::lang::NegativeArraySizeException;
606 return _Jv_NewMultiArrayUnchecked (array_type, dimensions, sizes);
611 // Ensure 8-byte alignment, for hash synchronization.
612 #define DECLARE_PRIM_TYPE(NAME) \
613 _Jv_ArrayVTable _Jv_##NAME##VTable; \
614 java::lang::Class _Jv_##NAME##Class __attribute__ ((aligned (8)));
616 DECLARE_PRIM_TYPE(byte)
617 DECLARE_PRIM_TYPE(short)
618 DECLARE_PRIM_TYPE(int)
619 DECLARE_PRIM_TYPE(long)
620 DECLARE_PRIM_TYPE(boolean)
621 DECLARE_PRIM_TYPE(char)
622 DECLARE_PRIM_TYPE(float)
623 DECLARE_PRIM_TYPE(double)
624 DECLARE_PRIM_TYPE(void)
627 _Jv_InitPrimClass (jclass cl, char *cname, char sig, int len,
628 _Jv_ArrayVTable *array_vtable)
630 using namespace java::lang::reflect;
632 _Jv_InitNewClassFields (cl);
634 // We must set the vtable for the class; the Java constructor
636 (*(_Jv_VTable **) cl) = java::lang::Class::class$.vtable;
638 // Initialize the fields we care about. We do this in the same
639 // order they are declared in Class.h.
640 cl->name = _Jv_makeUtf8Const ((char *) cname, -1);
641 cl->accflags = Modifier::PUBLIC | Modifier::FINAL | Modifier::ABSTRACT;
642 cl->method_count = sig;
643 cl->size_in_bytes = len;
644 cl->vtable = JV_PRIMITIVE_VTABLE;
645 cl->state = JV_STATE_DONE;
648 _Jv_NewArrayClass (cl, NULL, (_Jv_VTable *) array_vtable);
652 _Jv_FindClassFromSignature (char *sig, java::lang::ClassLoader *loader)
657 return JvPrimClass (byte);
659 return JvPrimClass (short);
661 return JvPrimClass (int);
663 return JvPrimClass (long);
665 return JvPrimClass (boolean);
667 return JvPrimClass (char);
669 return JvPrimClass (float);
671 return JvPrimClass (double);
673 return JvPrimClass (void);
677 for (i = 1; sig[i] && sig[i] != ';'; ++i)
679 _Jv_Utf8Const *name = _Jv_makeUtf8Const (&sig[1], i - 1);
680 return _Jv_FindClass (name, loader);
684 jclass klass = _Jv_FindClassFromSignature (&sig[1], loader);
687 return _Jv_GetArrayClass (klass, loader);
691 return NULL; // Placate compiler.
697 JvConvertArgv (int argc, const char **argv)
701 jobjectArray ar = JvNewObjectArray(argc, &StringClass, NULL);
702 jobject *ptr = elements(ar);
703 jbyteArray bytes = NULL;
704 for (int i = 0; i < argc; i++)
706 const char *arg = argv[i];
707 int len = strlen (arg);
708 if (bytes == NULL || bytes->length < len)
709 bytes = JvNewByteArray (len);
710 jbyte *bytePtr = elements (bytes);
711 // We assume jbyte == char.
712 memcpy (bytePtr, arg, len);
714 // Now convert using the default encoding.
715 *ptr++ = new java::lang::String (bytes, 0, len);
717 return (JArray<jstring>*) ar;
720 // FIXME: These variables are static so that they will be
721 // automatically scanned by the Boehm collector. This is needed
722 // because with qthreads the collector won't scan the initial stack --
723 // it will only scan the qthreads stacks.
725 // Command line arguments.
726 static JArray<jstring> *arg_vec;
728 // The primary thread.
729 static java::lang::Thread *main_thread;
731 #ifndef DISABLE_GETENV_PROPERTIES
734 next_property_key (char *s, size_t *length)
740 // Skip over whitespace
744 // If we've reached the end, return NULL. Also return NULL if for
745 // some reason we've come across a malformed property string.
751 // Determine the length of the property key.
769 next_property_value (char *s, size_t *length)
785 // If we've reached the end, return NULL.
789 // Determine the length of the property value.
808 process_gcj_properties ()
810 char *props = getenv("GCJ_PROPERTIES");
813 size_t property_count = 0;
818 // Whip through props quickly in order to count the number of
820 while (p && (p = next_property_key (p, &length)))
822 // Skip to the end of the key
825 p = next_property_value (p, &length);
832 // Allocate an array of property value/key pairs.
833 _Jv_Environment_Properties =
834 (property_pair *) malloc (sizeof(property_pair)
835 * (property_count + 1));
837 // Go through the properties again, initializing _Jv_Properties
841 while (p && (p = next_property_key (p, &length)))
843 _Jv_Environment_Properties[property_count].key = p;
844 _Jv_Environment_Properties[property_count].key_length = length;
846 // Skip to the end of the key
849 p = next_property_value (p, &length);
851 _Jv_Environment_Properties[property_count].value = p;
852 _Jv_Environment_Properties[property_count].value_length = length;
859 memset ((void *) &_Jv_Environment_Properties[property_count],
860 0, sizeof (property_pair));
864 // Null terminate the strings.
865 while (_Jv_Environment_Properties[i].key)
867 _Jv_Environment_Properties[i].key[_Jv_Environment_Properties[i].key_length] = 0;
868 _Jv_Environment_Properties[i++].value[_Jv_Environment_Properties[i].value_length] = 0;
872 #endif // DISABLE_GETENV_PROPERTIES
876 _Jv_Utf8Const *void_signature;
877 _Jv_Utf8Const *clinit_name;
878 _Jv_Utf8Const *init_name;
879 _Jv_Utf8Const *finit_name;
881 bool runtimeInitialized = false;
885 _Jv_CreateJavaVM (void* /*vm_args*/)
889 if (runtimeInitialized)
892 runtimeInitialized = true;
894 PROCESS_GCJ_PROPERTIES;
898 _Jv_InitializeSyncMutex ();
900 /* Initialize Utf8 constants declared in jvm.h. */
901 void_signature = _Jv_makeUtf8Const ("()V", 3);
902 clinit_name = _Jv_makeUtf8Const ("<clinit>", 8);
903 init_name = _Jv_makeUtf8Const ("<init>", 6);
904 finit_name = _Jv_makeUtf8Const ("finit$", 6);
906 /* Initialize built-in classes to represent primitive TYPEs. */
907 _Jv_InitPrimClass (&_Jv_byteClass, "byte", 'B', 1, &_Jv_byteVTable);
908 _Jv_InitPrimClass (&_Jv_shortClass, "short", 'S', 2, &_Jv_shortVTable);
909 _Jv_InitPrimClass (&_Jv_intClass, "int", 'I', 4, &_Jv_intVTable);
910 _Jv_InitPrimClass (&_Jv_longClass, "long", 'J', 8, &_Jv_longVTable);
911 _Jv_InitPrimClass (&_Jv_booleanClass, "boolean", 'Z', 1, &_Jv_booleanVTable);
912 _Jv_InitPrimClass (&_Jv_charClass, "char", 'C', 2, &_Jv_charVTable);
913 _Jv_InitPrimClass (&_Jv_floatClass, "float", 'F', 4, &_Jv_floatVTable);
914 _Jv_InitPrimClass (&_Jv_doubleClass, "double", 'D', 8, &_Jv_doubleVTable);
915 _Jv_InitPrimClass (&_Jv_voidClass, "void", 'V', 0, &_Jv_voidVTable);
917 // Turn stack trace generation off while creating exception objects.
918 _Jv_InitClass (&java::lang::VMThrowable::class$);
919 java::lang::VMThrowable::trace_enabled = 0;
925 arithexception = new java::lang::ArithmeticException
926 (JvNewStringLatin1 ("/ by zero"));
929 no_memory = new java::lang::OutOfMemoryError;
931 java::lang::VMThrowable::trace_enabled = 1;
934 LTDL_SET_PRELOADED_SYMBOLS ();
937 _Jv_platform_initialize ();
941 _Jv_GCInitializeFinalizers (&::gnu::gcj::runtime::FinalizerThread::finalizerReady);
943 // Start the GC finalizer thread. A VirtualMachineError can be
944 // thrown by the runtime if, say, threads aren't available. In this
945 // case finalizers simply won't run.
948 using namespace gnu::gcj::runtime;
949 FinalizerThread *ft = new FinalizerThread ();
952 catch (java::lang::VirtualMachineError *ignore)
960 _Jv_RunMain (jclass klass, const char *name, int argc, const char **argv,
963 _Jv_SetArgs (argc, argv);
965 java::lang::Runtime *runtime = NULL;
969 // Set this very early so that it is seen when java.lang.System
972 _Jv_Jar_Class_Path = strdup (name);
973 _Jv_CreateJavaVM (NULL);
975 // Get the Runtime here. We want to initialize it before searching
976 // for `main'; that way it will be set up if `main' is a JNI method.
977 runtime = java::lang::Runtime::getRuntime ();
979 #ifdef DISABLE_MAIN_ARGS
980 arg_vec = JvConvertArgv (0, 0);
982 arg_vec = JvConvertArgv (argc - 1, argv + 1);
985 using namespace gnu::gcj::runtime;
987 main_thread = new FirstThread (klass, arg_vec);
989 main_thread = new FirstThread (JvNewStringLatin1 (name),
992 catch (java::lang::Throwable *t)
994 java::lang::System::err->println (JvNewStringLatin1
995 ("Exception during runtime initialization"));
996 t->printStackTrace();
1000 _Jv_AttachCurrentThread (main_thread);
1001 _Jv_ThreadRun (main_thread);
1004 int status = (int) java::lang::ThreadGroup::had_uncaught_exception;
1005 runtime->exit (status);
1009 JvRunMain (jclass klass, int argc, const char **argv)
1011 _Jv_RunMain (klass, NULL, argc, argv, false);
1016 // Parse a string and return a heap size.
1018 parse_heap_size (const char *spec)
1021 unsigned long val = strtoul (spec, &end, 10);
1022 if (*end == 'k' || *end == 'K')
1024 else if (*end == 'm' || *end == 'M')
1026 return (size_t) val;
1029 // Set the initial heap size. This might be ignored by the GC layer.
1030 // This must be called before _Jv_RunMain.
1032 _Jv_SetInitialHeapSize (const char *arg)
1034 size_t size = parse_heap_size (arg);
1035 _Jv_GCSetInitialHeapSize (size);
1038 // Set the maximum heap size. This might be ignored by the GC layer.
1039 // This must be called before _Jv_RunMain.
1041 _Jv_SetMaximumHeapSize (const char *arg)
1043 size_t size = parse_heap_size (arg);
1044 _Jv_GCSetMaximumHeapSize (size);
1050 _Jv_Malloc (jsize size)
1052 if (__builtin_expect (size == 0, false))
1054 void *ptr = malloc ((size_t) size);
1055 if (__builtin_expect (ptr == NULL, false))
1061 _Jv_Realloc (void *ptr, jsize size)
1063 if (__builtin_expect (size == 0, false))
1065 ptr = realloc (ptr, (size_t) size);
1066 if (__builtin_expect (ptr == NULL, false))
1072 _Jv_MallocUnchecked (jsize size)
1074 if (__builtin_expect (size == 0, false))
1076 return malloc ((size_t) size);
1080 _Jv_Free (void* ptr)
1087 // In theory, these routines can be #ifdef'd away on machines which
1088 // support divide overflow signals. However, we never know if some
1089 // code might have been compiled with "-fuse-divide-subroutine", so we
1090 // always include them in libgcj.
1093 _Jv_divI (jint dividend, jint divisor)
1095 if (__builtin_expect (divisor == 0, false))
1096 _Jv_ThrowSignal (arithexception);
1098 if (dividend == (jint) 0x80000000L && divisor == -1)
1101 return dividend / divisor;
1105 _Jv_remI (jint dividend, jint divisor)
1107 if (__builtin_expect (divisor == 0, false))
1108 _Jv_ThrowSignal (arithexception);
1110 if (dividend == (jint) 0x80000000L && divisor == -1)
1113 return dividend % divisor;
1117 _Jv_divJ (jlong dividend, jlong divisor)
1119 if (__builtin_expect (divisor == 0, false))
1120 _Jv_ThrowSignal (arithexception);
1122 if (dividend == (jlong) 0x8000000000000000LL && divisor == -1)
1125 return dividend / divisor;
1129 _Jv_remJ (jlong dividend, jlong divisor)
1131 if (__builtin_expect (divisor == 0, false))
1132 _Jv_ThrowSignal (arithexception);
1134 if (dividend == (jlong) 0x8000000000000000LL && divisor == -1)
1137 return dividend % divisor;