1 // prims.cc - Code for core of runtime environment.
3 /* Copyright (C) 1998, 1999, 2000, 2001 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
13 #ifdef USE_WIN32_SIGNALLING
15 #endif /* USE_WIN32_SIGNALLING */
18 #undef __INSIDE_CYGWIN__
20 #endif /* USE_WINSOCK */
34 #include <java-signal.h>
35 #include <java-threads.h>
39 #include <java/lang/ThreadGroup.h>
42 #ifndef DISABLE_GETENV_PROPERTIES
44 #include <java-props.h>
45 #define PROCESS_GCJ_PROPERTIES process_gcj_properties()
47 #define PROCESS_GCJ_PROPERTIES
48 #endif // DISABLE_GETENV_PROPERTIES
50 #include <java/lang/Class.h>
51 #include <java/lang/ClassLoader.h>
52 #include <java/lang/Runtime.h>
53 #include <java/lang/String.h>
54 #include <java/lang/Thread.h>
55 #include <java/lang/ThreadGroup.h>
56 #include <gnu/gcj/runtime/FirstThread.h>
57 #include <java/lang/ArrayIndexOutOfBoundsException.h>
58 #include <java/lang/ArithmeticException.h>
59 #include <java/lang/ClassFormatError.h>
60 #include <java/lang/NegativeArraySizeException.h>
61 #include <java/lang/NullPointerException.h>
62 #include <java/lang/OutOfMemoryError.h>
63 #include <java/lang/System.h>
64 #include <java/lang/reflect/Modifier.h>
65 #include <java/io/PrintStream.h>
66 #include <java/lang/UnsatisfiedLinkError.h>
72 // We allocate a single OutOfMemoryError exception which we keep
73 // around for use if we run out of memory.
74 static java::lang::OutOfMemoryError
*no_memory
;
76 // Largest representable size_t.
77 #define SIZE_T_MAX ((size_t) (~ (size_t) 0))
79 static const char *no_properties
[] = { NULL
};
81 // Properties set at compile time.
82 const char **_Jv_Compiler_Properties
= no_properties
;
84 // The JAR file to add to the beginning of java.class.path.
85 const char *_Jv_Jar_Class_Path
;
87 #ifndef DISABLE_GETENV_PROPERTIES
88 // Property key/value pairs.
89 property_pair
*_Jv_Environment_Properties
;
92 // The name of this executable.
93 static char *_Jv_execName
;
95 // Stash the argv pointer to benefit native libraries that need it.
96 const char **_Jv_argv
;
100 // Pointer to JVMPI notification functions.
101 void (*_Jv_JVMPI_Notify_OBJECT_ALLOC
) (JVMPI_Event
*event
);
102 void (*_Jv_JVMPI_Notify_THREAD_START
) (JVMPI_Event
*event
);
103 void (*_Jv_JVMPI_Notify_THREAD_END
) (JVMPI_Event
*event
);
107 extern "C" void _Jv_ThrowSignal (jthrowable
) __attribute ((noreturn
));
109 // Just like _Jv_Throw, but fill in the stack trace first. Although
110 // this is declared extern in order that its name not be mangled, it
111 // is not intended to be used outside this file.
113 _Jv_ThrowSignal (jthrowable throwable
)
115 throwable
->fillInStackTrace ();
120 static java::lang::NullPointerException
*nullp
;
122 SIGNAL_HANDLER (catch_segv
)
124 MAKE_THROW_FRAME (nullp
);
125 _Jv_ThrowSignal (nullp
);
129 static java::lang::ArithmeticException
*arithexception
;
132 SIGNAL_HANDLER (catch_fpe
)
134 #ifdef HANDLE_DIVIDE_OVERFLOW
135 HANDLE_DIVIDE_OVERFLOW
;
137 MAKE_THROW_FRAME (arithexception
);
139 _Jv_ThrowSignal (arithexception
);
146 _Jv_equalUtf8Consts (Utf8Const
* a
, Utf8Const
*b
)
149 _Jv_ushort
*aptr
, *bptr
;
152 if (a
->hash
!= b
->hash
)
155 if (b
->length
!= len
)
157 aptr
= (_Jv_ushort
*)a
->data
;
158 bptr
= (_Jv_ushort
*)b
->data
;
159 len
= (len
+ 1) >> 1;
161 if (*aptr
++ != *bptr
++)
166 /* True iff A is equal to STR.
167 HASH is STR->hashCode().
171 _Jv_equal (Utf8Const
* a
, jstring str
, jint hash
)
173 if (a
->hash
!= (_Jv_ushort
) hash
)
175 jint len
= str
->length();
177 jchar
*sptr
= _Jv_GetStringChars (str
);
178 unsigned char* ptr
= (unsigned char*) a
->data
;
179 unsigned char* limit
= ptr
+ a
->length
;
182 int ch
= UTF8_GET (ptr
, limit
);
191 /* Like _Jv_equal, but stop after N characters. */
193 _Jv_equaln (Utf8Const
*a
, jstring str
, jint n
)
195 jint len
= str
->length();
197 jchar
*sptr
= _Jv_GetStringChars (str
);
198 unsigned char* ptr
= (unsigned char*) a
->data
;
199 unsigned char* limit
= ptr
+ a
->length
;
200 for (; n
-- > 0; i
++, sptr
++)
202 int ch
= UTF8_GET (ptr
, limit
);
211 /* Count the number of Unicode chars encoded in a given Ut8 string. */
213 _Jv_strLengthUtf8(char* str
, int len
)
216 unsigned char* limit
;
219 ptr
= (unsigned char*) str
;
222 for (; ptr
< limit
; str_length
++)
224 if (UTF8_GET (ptr
, limit
) < 0)
230 /* Calculate a hash value for a string encoded in Utf8 format.
231 * This returns the same hash value as specified or java.lang.String.hashCode.
234 hashUtf8String (char* str
, int len
)
236 unsigned char* ptr
= (unsigned char*) str
;
237 unsigned char* limit
= ptr
+ len
;
242 int ch
= UTF8_GET (ptr
, limit
);
243 /* Updated specification from
244 http://www.javasoft.com/docs/books/jls/clarify.html. */
245 hash
= (31 * hash
) + ch
;
251 _Jv_makeUtf8Const (char* s
, int len
)
255 Utf8Const
* m
= (Utf8Const
*) _Jv_AllocBytes (sizeof(Utf8Const
) + len
+ 1);
258 memcpy (m
->data
, s
, len
);
261 m
->hash
= hashUtf8String (s
, len
) & 0xFFFF;
266 _Jv_makeUtf8Const (jstring string
)
268 jint hash
= string
->hashCode ();
269 jint len
= _Jv_GetStringUTFLength (string
);
271 Utf8Const
* m
= (Utf8Const
*)
272 _Jv_AllocBytes (sizeof(Utf8Const
) + len
+ 1);
277 _Jv_GetStringUTFRegion (string
, 0, string
->length (), m
->data
);
287 _Jv_Abort (const char *function
, const char *file
, int line
,
291 _Jv_Abort (const char *, const char *, int, const char *message
)
296 "libgcj failure: %s\n in function %s, file %s, line %d\n",
297 message
, function
, file
, line
);
299 java::io::PrintStream
*err
= java::lang::System::err
;
300 err
->print(JvNewStringLatin1 ("libgcj failure: "));
301 err
->println(JvNewStringLatin1 (message
));
308 fail_on_finalization (jobject
)
310 JvFail ("object was finalized");
314 _Jv_GCWatch (jobject obj
)
316 _Jv_RegisterFinalizer (obj
, fail_on_finalization
);
320 _Jv_ThrowBadArrayIndex(jint bad_index
)
322 throw new java::lang::ArrayIndexOutOfBoundsException
323 (java::lang::String::valueOf (bad_index
));
327 _Jv_ThrowNullPointerException ()
329 throw new java::lang::NullPointerException
;
332 // Explicitly throw a no memory exception.
333 // The collector calls this when it encounters an out-of-memory condition.
334 void _Jv_ThrowNoMemory()
336 _Jv_Throw (no_memory
);
339 // Allocate a new object of class KLASS. SIZE is the size of the object
340 // to allocate. You might think this is redundant, but it isn't; some
341 // classes, such as String, aren't of fixed size.
343 _Jv_AllocObject (jclass klass
, jint size
)
345 _Jv_InitClass (klass
);
347 jobject obj
= (jobject
) _Jv_AllocObj (size
, klass
);
349 // If this class has inherited finalize from Object, then don't
350 // bother registering a finalizer. We know that finalize() is the
351 // very first method after the dummy entry. If this turns out to be
352 // unreliable, a more robust implementation can be written. Such an
353 // implementation would look for Object.finalize in Object's method
354 // table at startup, and then use that information to find the
355 // appropriate index in the method vector.
356 if (klass
->vtable
->get_finalizer()
357 != java::lang::Object::class$
.vtable
->get_finalizer())
358 _Jv_RegisterFinalizer (obj
, _Jv_FinalizeObject
);
361 // Service JVMPI request.
363 if (__builtin_expect (_Jv_JVMPI_Notify_OBJECT_ALLOC
!= 0, false))
367 event
.event_type
= JVMPI_EVENT_OBJECT_ALLOC
;
369 event
.u
.obj_alloc
.arena_id
= 0;
370 event
.u
.obj_alloc
.class_id
= (jobjectID
) klass
;
371 event
.u
.obj_alloc
.is_array
= 0;
372 event
.u
.obj_alloc
.size
= size
;
373 event
.u
.obj_alloc
.obj_id
= (jobjectID
) obj
;
375 // FIXME: This doesn't look right for the Boehm GC. A GC may
376 // already be in progress. _Jv_DisableGC () doesn't wait for it.
377 // More importantly, I don't see the need for disabling GC, since we
378 // blatantly have a pointer to obj on our stack, ensuring that the
379 // object can't be collected. Even for a nonconservative collector,
380 // it appears to me that this must be true, since we are about to
381 // return obj. Isn't this whole approach way too intrusive for
382 // a useful profiling interface? - HB
384 (*_Jv_JVMPI_Notify_OBJECT_ALLOC
) (&event
);
392 // A version of the above that assumes the object contains no pointers,
393 // and requires no finalization. This can't happen if we need pointers
395 #ifdef JV_HASH_SYNCHRONIZATION
397 _Jv_AllocPtrFreeObject (jclass klass
, jint size
)
399 _Jv_InitClass (klass
);
401 jobject obj
= (jobject
) _Jv_AllocPtrFreeObj (size
, klass
);
404 // Service JVMPI request.
406 if (__builtin_expect (_Jv_JVMPI_Notify_OBJECT_ALLOC
!= 0, false))
410 event
.event_type
= JVMPI_EVENT_OBJECT_ALLOC
;
412 event
.u
.obj_alloc
.arena_id
= 0;
413 event
.u
.obj_alloc
.class_id
= (jobjectID
) klass
;
414 event
.u
.obj_alloc
.is_array
= 0;
415 event
.u
.obj_alloc
.size
= size
;
416 event
.u
.obj_alloc
.obj_id
= (jobjectID
) obj
;
419 (*_Jv_JVMPI_Notify_OBJECT_ALLOC
) (&event
);
426 #endif /* JV_HASH_SYNCHRONIZATION */
429 // Allocate a new array of Java objects. Each object is of type
430 // `elementClass'. `init' is used to initialize each slot in the
433 _Jv_NewObjectArray (jsize count
, jclass elementClass
, jobject init
)
435 if (__builtin_expect (count
< 0, false))
436 throw new java::lang::NegativeArraySizeException
;
438 JvAssert (! elementClass
->isPrimitive ());
440 // Ensure that elements pointer is properly aligned.
441 jobjectArray obj
= NULL
;
442 size_t size
= (size_t) elements (obj
);
443 size
+= count
* sizeof (jobject
);
445 // FIXME: second argument should be "current loader"
446 jclass klass
= _Jv_GetArrayClass (elementClass
, 0);
448 obj
= (jobjectArray
) _Jv_AllocArray (size
, klass
);
450 jsize
*lp
= const_cast<jsize
*> (&obj
->length
);
452 // We know the allocator returns zeroed memory. So don't bother
456 jobject
*ptr
= elements(obj
);
463 // Allocate a new array of primitives. ELTYPE is the type of the
464 // element, COUNT is the size of the array.
466 _Jv_NewPrimArray (jclass eltype
, jint count
)
468 int elsize
= eltype
->size();
469 if (__builtin_expect (count
< 0, false))
470 throw new java::lang::NegativeArraySizeException
;
472 JvAssert (eltype
->isPrimitive ());
473 jobject dummy
= NULL
;
474 size_t size
= (size_t) _Jv_GetArrayElementFromElementType (dummy
, eltype
);
476 // Check for overflow.
477 if (__builtin_expect ((size_t) count
>
478 (SIZE_T_MAX
- size
) / elsize
, false))
481 jclass klass
= _Jv_GetArrayClass (eltype
, 0);
483 # ifdef JV_HASH_SYNCHRONIZATION
484 // Since the vtable is always statically allocated,
485 // these are completely pointerfree! Make sure the GC doesn't touch them.
487 (__JArray
*) _Jv_AllocPtrFreeObj (size
+ elsize
* count
, klass
);
488 memset((char *)arr
+ size
, 0, elsize
* count
);
490 __JArray
*arr
= (__JArray
*) _Jv_AllocObj (size
+ elsize
* count
, klass
);
491 // Note that we assume we are given zeroed memory by the allocator.
494 jsize
*lp
= const_cast<jsize
*> (&arr
->length
);
501 _Jv_NewArray (jint type
, jint size
)
505 case 4: return JvNewBooleanArray (size
);
506 case 5: return JvNewCharArray (size
);
507 case 6: return JvNewFloatArray (size
);
508 case 7: return JvNewDoubleArray (size
);
509 case 8: return JvNewByteArray (size
);
510 case 9: return JvNewShortArray (size
);
511 case 10: return JvNewIntArray (size
);
512 case 11: return JvNewLongArray (size
);
514 JvFail ("newarray - bad type code");
515 return NULL
; // Placate compiler.
519 _Jv_NewMultiArray (jclass type
, jint dimensions
, jint
*sizes
)
521 JvAssert (type
->isArray());
522 jclass element_type
= type
->getComponentType();
524 if (element_type
->isPrimitive())
525 result
= _Jv_NewPrimArray (element_type
, sizes
[0]);
527 result
= _Jv_NewObjectArray (sizes
[0], element_type
, NULL
);
531 JvAssert (! element_type
->isPrimitive());
532 JvAssert (element_type
->isArray());
533 jobject
*contents
= elements ((jobjectArray
) result
);
534 for (int i
= 0; i
< sizes
[0]; ++i
)
535 contents
[i
] = _Jv_NewMultiArray (element_type
, dimensions
- 1,
543 _Jv_NewMultiArray (jclass array_type
, jint dimensions
, ...)
546 jint sizes
[dimensions
];
547 va_start (args
, dimensions
);
548 for (int i
= 0; i
< dimensions
; ++i
)
550 jint size
= va_arg (args
, jint
);
555 return _Jv_NewMultiArray (array_type
, dimensions
, sizes
);
560 #define DECLARE_PRIM_TYPE(NAME, SIG, LEN) \
561 _Jv_ArrayVTable _Jv_##NAME##VTable; \
562 java::lang::Class _Jv_##NAME##Class ((jobject) #NAME, \
563 (jbyte) SIG, (jint) LEN, \
564 (jobject) &_Jv_##NAME##VTable);
566 DECLARE_PRIM_TYPE(byte
, 'B', 1);
567 DECLARE_PRIM_TYPE(short, 'S', 2);
568 DECLARE_PRIM_TYPE(int, 'I', 4);
569 DECLARE_PRIM_TYPE(long, 'J', 8);
570 DECLARE_PRIM_TYPE(boolean
, 'Z', 1);
571 DECLARE_PRIM_TYPE(char, 'C', 2);
572 DECLARE_PRIM_TYPE(float, 'F', 4);
573 DECLARE_PRIM_TYPE(double, 'D', 8);
574 DECLARE_PRIM_TYPE(void, 'V', 0);
577 _Jv_FindClassFromSignature (char *sig
, java::lang::ClassLoader
*loader
)
582 return JvPrimClass (byte
);
584 return JvPrimClass (short);
586 return JvPrimClass (int);
588 return JvPrimClass (long);
590 return JvPrimClass (boolean
);
592 return JvPrimClass (char);
594 return JvPrimClass (float);
596 return JvPrimClass (double);
598 return JvPrimClass (void);
602 for (i
= 1; sig
[i
] && sig
[i
] != ';'; ++i
)
604 _Jv_Utf8Const
*name
= _Jv_makeUtf8Const (&sig
[1], i
- 1);
605 return _Jv_FindClass (name
, loader
);
610 jclass klass
= _Jv_FindClassFromSignature (&sig
[1], loader
);
613 return _Jv_GetArrayClass (klass
, loader
);
617 return NULL
; // Placate compiler.
623 JvConvertArgv (int argc
, const char **argv
)
627 jobjectArray ar
= JvNewObjectArray(argc
, &StringClass
, NULL
);
628 jobject
* ptr
= elements(ar
);
629 for (int i
= 0; i
< argc
; i
++)
631 const char *arg
= argv
[i
];
632 // FIXME - should probably use JvNewStringUTF.
633 *ptr
++ = JvNewStringLatin1(arg
, strlen(arg
));
635 return (JArray
<jstring
>*) ar
;
638 // FIXME: These variables are static so that they will be
639 // automatically scanned by the Boehm collector. This is needed
640 // because with qthreads the collector won't scan the initial stack --
641 // it will only scan the qthreads stacks.
643 // Command line arguments.
644 static JArray
<jstring
> *arg_vec
;
646 // The primary thread.
647 static java::lang::Thread
*main_thread
;
650 _Jv_ThisExecutable (void)
656 _Jv_ThisExecutable (const char *name
)
660 _Jv_execName
= (char *) _Jv_Malloc (strlen (name
) + 1);
661 strcpy (_Jv_execName
, name
);
665 #ifdef USE_WIN32_SIGNALLING
667 extern "C" int* win32_get_restart_frame (void *);
670 win32_exception_handler (LPEXCEPTION_POINTERS e
)
673 if (e
->ExceptionRecord
->ExceptionCode
== EXCEPTION_ACCESS_VIOLATION
)
674 setjmp_buf
= win32_get_restart_frame (nullp
);
675 else if (e
->ExceptionRecord
->ExceptionCode
== EXCEPTION_INT_DIVIDE_BY_ZERO
)
676 setjmp_buf
= win32_get_restart_frame (arithexception
);
678 return EXCEPTION_CONTINUE_SEARCH
;
680 e
->ContextRecord
->Ebp
= setjmp_buf
[0];
681 // FIXME: Why does i386-signal.h increment the PC here, do we need to do it?
682 e
->ContextRecord
->Eip
= setjmp_buf
[1];
683 // FIXME: Is this the stack pointer? Do we need it?
684 e
->ContextRecord
->Esp
= setjmp_buf
[2];
686 return EXCEPTION_CONTINUE_EXECUTION
;
691 #ifndef DISABLE_GETENV_PROPERTIES
694 next_property_key (char *s
, size_t *length
)
700 // Skip over whitespace
704 // If we've reached the end, return NULL. Also return NULL if for
705 // some reason we've come across a malformed property string.
711 // Determine the length of the property key.
729 next_property_value (char *s
, size_t *length
)
745 // If we've reached the end, return NULL.
749 // Determine the length of the property value.
768 process_gcj_properties ()
770 char *props
= getenv("GCJ_PROPERTIES");
773 size_t property_count
= 0;
778 // Whip through props quickly in order to count the number of
780 while (p
&& (p
= next_property_key (p
, &length
)))
782 // Skip to the end of the key
785 p
= next_property_value (p
, &length
);
792 // Allocate an array of property value/key pairs.
793 _Jv_Environment_Properties
=
794 (property_pair
*) malloc (sizeof(property_pair
)
795 * (property_count
+ 1));
797 // Go through the properties again, initializing _Jv_Properties
801 while (p
&& (p
= next_property_key (p
, &length
)))
803 _Jv_Environment_Properties
[property_count
].key
= p
;
804 _Jv_Environment_Properties
[property_count
].key_length
= length
;
806 // Skip to the end of the key
809 p
= next_property_value (p
, &length
);
811 _Jv_Environment_Properties
[property_count
].value
= p
;
812 _Jv_Environment_Properties
[property_count
].value_length
= length
;
819 memset ((void *) &_Jv_Environment_Properties
[property_count
],
820 0, sizeof (property_pair
));
824 // Null terminate the strings.
825 while (_Jv_Environment_Properties
[i
].key
)
827 _Jv_Environment_Properties
[i
].key
[_Jv_Environment_Properties
[i
].key_length
] = 0;
828 _Jv_Environment_Properties
[i
++].value
[_Jv_Environment_Properties
[i
].value_length
] = 0;
832 #endif // DISABLE_GETENV_PROPERTIES
835 _Jv_CreateJavaVM (void* /*vm_args*/)
837 PROCESS_GCJ_PROPERTIES
;
839 // Turn stack trace generation off while creating exception objects.
840 _Jv_InitClass (&java::lang::Throwable::class$
);
841 java::lang::Throwable::trace_enabled
= 0;
847 arithexception
= new java::lang::ArithmeticException
848 (JvNewStringLatin1 ("/ by zero"));
851 no_memory
= new java::lang::OutOfMemoryError
;
853 java::lang::Throwable::trace_enabled
= 1;
856 LTDL_SET_PRELOADED_SYMBOLS ();
860 // Initialise winsock for networking
862 if (WSAStartup (MAKEWORD (1, 1), &data
))
863 MessageBox (NULL
, "Error initialising winsock library.", "Error", MB_OK
| MB_ICONEXCLAMATION
);
864 #endif /* USE_WINSOCK */
866 #ifdef USE_WIN32_SIGNALLING
867 // Install exception handler
868 SetUnhandledExceptionFilter (win32_exception_handler
);
869 #elif defined(HAVE_SIGACTION)
870 // We only want this on POSIX systems.
871 struct sigaction act
;
872 act
.sa_handler
= SIG_IGN
;
873 sigemptyset (&act
.sa_mask
);
875 sigaction (SIGPIPE
, &act
, NULL
);
877 signal (SIGPIPE
, SIG_IGN
);
886 _Jv_RunMain (jclass klass
, const char *name
, int argc
, const char **argv
,
892 java::lang::Runtime
*runtime
= NULL
;
894 #ifdef HAVE_PROC_SELF_EXE
896 sprintf (exec_name
, "/proc/%d/exe", getpid ());
897 _Jv_ThisExecutable (exec_name
);
899 _Jv_ThisExecutable (argv
[0]);
904 _Jv_CreateJavaVM (NULL
);
906 // Get the Runtime here. We want to initialize it before searching
907 // for `main'; that way it will be set up if `main' is a JNI method.
908 runtime
= java::lang::Runtime::getRuntime ();
910 arg_vec
= JvConvertArgv (argc
- 1, argv
+ 1);
913 main_thread
= new gnu::gcj::runtime::FirstThread (klass
, arg_vec
);
915 main_thread
= new gnu::gcj::runtime::FirstThread
916 (JvNewStringLatin1 (name
), arg_vec
, is_jar
);
920 // We need a new ClassLoader because the classpath must be the
921 // jar file only. The easiest way to do this is to lose our
922 // reference to the previous classloader.
923 _Jv_Jar_Class_Path
= strdup (name
);
924 java::lang::ClassLoader::system
= NULL
;
927 catch (java::lang::Throwable
*t
)
929 java::lang::System::err
->println (JvNewStringLatin1
930 ("Exception during runtime initialization"));
931 t
->printStackTrace();
935 _Jv_AttachCurrentThread (main_thread
);
936 _Jv_ThreadRun (main_thread
);
939 int status
= (int) java::lang::ThreadGroup::had_uncaught_exception
;
940 runtime
->exit (status
);
944 JvRunMain (jclass klass
, int argc
, const char **argv
)
946 _Jv_RunMain (klass
, NULL
, argc
, argv
, false);
951 // Parse a string and return a heap size.
953 parse_heap_size (const char *spec
)
956 unsigned long val
= strtoul (spec
, &end
, 10);
957 if (*end
== 'k' || *end
== 'K')
959 else if (*end
== 'm' || *end
== 'M')
964 // Set the initial heap size. This might be ignored by the GC layer.
965 // This must be called before _Jv_RunMain.
967 _Jv_SetInitialHeapSize (const char *arg
)
969 size_t size
= parse_heap_size (arg
);
970 _Jv_GCSetInitialHeapSize (size
);
973 // Set the maximum heap size. This might be ignored by the GC layer.
974 // This must be called before _Jv_RunMain.
976 _Jv_SetMaximumHeapSize (const char *arg
)
978 size_t size
= parse_heap_size (arg
);
979 _Jv_GCSetMaximumHeapSize (size
);
985 _Jv_Malloc (jsize size
)
987 if (__builtin_expect (size
== 0, false))
989 void *ptr
= malloc ((size_t) size
);
990 if (__builtin_expect (ptr
== NULL
, false))
996 _Jv_Realloc (void *ptr
, jsize size
)
998 if (__builtin_expect (size
== 0, false))
1000 ptr
= realloc (ptr
, (size_t) size
);
1001 if (__builtin_expect (ptr
== NULL
, false))
1007 _Jv_MallocUnchecked (jsize size
)
1009 if (__builtin_expect (size
== 0, false))
1011 return malloc ((size_t) size
);
1015 _Jv_Free (void* ptr
)
1022 // In theory, these routines can be #ifdef'd away on machines which
1023 // support divide overflow signals. However, we never know if some
1024 // code might have been compiled with "-fuse-divide-subroutine", so we
1025 // always include them in libgcj.
1028 _Jv_divI (jint dividend
, jint divisor
)
1030 if (__builtin_expect (divisor
== 0, false))
1031 _Jv_ThrowSignal (arithexception
);
1033 if (dividend
== (jint
) 0x80000000L
&& divisor
== -1)
1036 return dividend
/ divisor
;
1040 _Jv_remI (jint dividend
, jint divisor
)
1042 if (__builtin_expect (divisor
== 0, false))
1043 _Jv_ThrowSignal (arithexception
);
1045 if (dividend
== (jint
) 0x80000000L
&& divisor
== -1)
1048 return dividend
% divisor
;
1052 _Jv_divJ (jlong dividend
, jlong divisor
)
1054 if (__builtin_expect (divisor
== 0, false))
1055 _Jv_ThrowSignal (arithexception
);
1057 if (dividend
== (jlong
) 0x8000000000000000LL
&& divisor
== -1)
1060 return dividend
/ divisor
;
1064 _Jv_remJ (jlong dividend
, jlong divisor
)
1066 if (__builtin_expect (divisor
== 0, false))
1067 _Jv_ThrowSignal (arithexception
);
1069 if (dividend
== (jlong
) 0x8000000000000000LL
&& divisor
== -1)
1072 return dividend
% divisor
;