1 // prims.cc - Code for core of runtime environment.
3 /* Copyright (C) 1998, 1999, 2000 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>
41 #ifndef DISABLE_GETENV_PROPERTIES
43 #include <java-props.h>
44 #define PROCESS_GCJ_PROPERTIES process_gcj_properties()
46 #define PROCESS_GCJ_PROPERTIES
47 #endif // DISABLE_GETENV_PROPERTIES
49 #include <java/lang/Class.h>
50 #include <java/lang/ClassLoader.h>
51 #include <java/lang/Runtime.h>
52 #include <java/lang/String.h>
53 #include <java/lang/Thread.h>
54 #include <java/lang/ThreadGroup.h>
55 #include <gnu/gcj/runtime/FirstThread.h>
56 #include <java/lang/ArrayIndexOutOfBoundsException.h>
57 #include <java/lang/ArithmeticException.h>
58 #include <java/lang/ClassFormatError.h>
59 #include <java/lang/NegativeArraySizeException.h>
60 #include <java/lang/NullPointerException.h>
61 #include <java/lang/OutOfMemoryError.h>
62 #include <java/lang/System.h>
63 #include <java/lang/reflect/Modifier.h>
64 #include <java/io/PrintStream.h>
70 #define ObjectClass _CL_Q34java4lang6Object
71 extern java::lang::Class ObjectClass
;
73 // We allocate a single OutOfMemoryError exception which we keep
74 // around for use if we run out of memory.
75 static java::lang::OutOfMemoryError
*no_memory
;
77 // Largest representable size_t.
78 #define SIZE_T_MAX ((size_t) (~ (size_t) 0))
80 // Properties set at compile time.
81 const char **_Jv_Compiler_Properties
;
83 // The JAR file to add to the beginning of java.class.path.
84 const char *_Jv_Jar_Class_Path
;
86 #ifndef DISABLE_GETENV_PROPERTIES
87 // Property key/value pairs.
88 property_pair
*_Jv_Environment_Properties
;
91 // The name of this executable.
92 static char * _Jv_execName
;
95 // Pointer to JVMPI notification functions.
96 void (*_Jv_JVMPI_Notify_OBJECT_ALLOC
) (JVMPI_Event
*event
);
97 void (*_Jv_JVMPI_Notify_THREAD_START
) (JVMPI_Event
*event
);
98 void (*_Jv_JVMPI_Notify_THREAD_END
) (JVMPI_Event
*event
);
102 extern "C" void _Jv_ThrowSignal (void *) __attribute ((noreturn
));
104 // Just like _Jv_Throw, but fill in the stack trace first. Although
105 // this is declared extern in order that its name not be mangled, it
106 // is not intended to be used outside this file.
108 _Jv_ThrowSignal (void *e
)
110 java::lang::Throwable
*throwable
= (java::lang::Throwable
*)e
;
111 throwable
->fillInStackTrace ();
112 _Jv_Throw (throwable
);
116 static java::lang::NullPointerException
*nullp
;
118 SIGNAL_HANDLER (catch_segv
)
120 MAKE_THROW_FRAME (nullp
);
121 _Jv_ThrowSignal (nullp
);
125 static java::lang::ArithmeticException
*arithexception
;
128 SIGNAL_HANDLER (catch_fpe
)
130 #ifdef HANDLE_DIVIDE_OVERFLOW
131 HANDLE_DIVIDE_OVERFLOW
;
133 MAKE_THROW_FRAME (arithexception
);
135 _Jv_ThrowSignal (arithexception
);
142 _Jv_equalUtf8Consts (Utf8Const
* a
, Utf8Const
*b
)
145 _Jv_ushort
*aptr
, *bptr
;
148 if (a
->hash
!= b
->hash
)
151 if (b
->length
!= len
)
153 aptr
= (_Jv_ushort
*)a
->data
;
154 bptr
= (_Jv_ushort
*)b
->data
;
155 len
= (len
+ 1) >> 1;
157 if (*aptr
++ != *bptr
++)
162 /* True iff A is equal to STR.
163 HASH is STR->hashCode().
167 _Jv_equal (Utf8Const
* a
, jstring str
, jint hash
)
169 if (a
->hash
!= (_Jv_ushort
) hash
)
171 jint len
= str
->length();
173 jchar
*sptr
= _Jv_GetStringChars (str
);
174 unsigned char* ptr
= (unsigned char*) a
->data
;
175 unsigned char* limit
= ptr
+ a
->length
;
178 int ch
= UTF8_GET (ptr
, limit
);
187 /* Like _Jv_equal, but stop after N characters. */
189 _Jv_equaln (Utf8Const
*a
, jstring str
, jint n
)
191 jint len
= str
->length();
193 jchar
*sptr
= _Jv_GetStringChars (str
);
194 unsigned char* ptr
= (unsigned char*) a
->data
;
195 unsigned char* limit
= ptr
+ a
->length
;
196 for (; n
-- > 0; i
++, sptr
++)
198 int ch
= UTF8_GET (ptr
, limit
);
207 /* Count the number of Unicode chars encoded in a given Ut8 string. */
209 _Jv_strLengthUtf8(char* str
, int len
)
212 unsigned char* limit
;
215 ptr
= (unsigned char*) str
;
218 for (; ptr
< limit
; str_length
++) {
219 if (UTF8_GET (ptr
, limit
) < 0) {
226 /* Calculate a hash value for a string encoded in Utf8 format.
227 * This returns the same hash value as specified or java.lang.String.hashCode.
230 hashUtf8String (char* str
, int len
)
232 unsigned char* ptr
= (unsigned char*) str
;
233 unsigned char* limit
= ptr
+ len
;
238 int ch
= UTF8_GET (ptr
, limit
);
239 /* Updated specification from
240 http://www.javasoft.com/docs/books/jls/clarify.html. */
241 hash
= (31 * hash
) + ch
;
247 _Jv_makeUtf8Const (char* s
, int len
)
251 Utf8Const
* m
= (Utf8Const
*) _Jv_AllocBytes (sizeof(Utf8Const
) + len
+ 1);
254 memcpy (m
->data
, s
, len
);
257 m
->hash
= hashUtf8String (s
, len
) & 0xFFFF;
262 _Jv_makeUtf8Const (jstring string
)
264 jint hash
= string
->hashCode ();
265 jint len
= _Jv_GetStringUTFLength (string
);
267 Utf8Const
* m
= (Utf8Const
*)
268 _Jv_AllocBytesChecked (sizeof(Utf8Const
) + len
+ 1);
273 _Jv_GetStringUTFRegion (string
, 0, string
->length (), m
->data
);
283 _Jv_Abort (const char *function
, const char *file
, int line
,
287 _Jv_Abort (const char *, const char *, int, const char *message
)
292 "libgcj failure: %s\n in function %s, file %s, line %d\n",
293 message
, function
, file
, line
);
295 java::io::PrintStream
*err
= java::lang::System::err
;
296 err
->print(JvNewStringLatin1 ("libgcj failure: "));
297 err
->println(JvNewStringLatin1 (message
));
304 fail_on_finalization (jobject
)
306 JvFail ("object was finalized");
310 _Jv_GCWatch (jobject obj
)
312 _Jv_RegisterFinalizer (obj
, fail_on_finalization
);
316 _Jv_ThrowBadArrayIndex(jint bad_index
)
318 JvThrow (new java::lang::ArrayIndexOutOfBoundsException
319 (java::lang::String::valueOf(bad_index
)));
323 _Jv_ThrowNullPointerException ()
325 throw new java::lang::NullPointerException ();
328 // Allocate some unscanned memory and throw an exception if no memory.
330 _Jv_AllocBytesChecked (jsize size
)
332 void *r
= _Jv_AllocBytes (size
);
334 _Jv_Throw (no_memory
);
338 // Allocate a new object of class C. SIZE is the size of the object
339 // to allocate. You might think this is redundant, but it isn't; some
340 // classes, such as String, aren't of fixed size.
342 _Jv_AllocObject (jclass c
, jint size
)
346 jobject obj
= (jobject
) _Jv_AllocObj (size
);
347 if (__builtin_expect (! obj
, false))
349 *((_Jv_VTable
**) obj
) = c
->vtable
;
351 // If this class has inherited finalize from Object, then don't
352 // bother registering a finalizer. We know that finalize() is the
353 // very first method after the dummy entry. If this turns out to be
354 // unreliable, a more robust implementation can be written. Such an
355 // implementation would look for Object.finalize in Object's method
356 // table at startup, and then use that information to find the
357 // appropriate index in the method vector.
358 if (c
->vtable
->method
[1] != ObjectClass
.vtable
->method
[1])
359 _Jv_RegisterFinalizer (obj
, _Jv_FinalizeObject
);
362 // Service JVMPI request.
364 if (__builtin_expect (_Jv_JVMPI_Notify_OBJECT_ALLOC
!= 0, false))
368 event
.event_type
= JVMPI_EVENT_OBJECT_ALLOC
;
370 event
.u
.obj_alloc
.arena_id
= 0;
371 event
.u
.obj_alloc
.class_id
= (jobjectID
) c
;
372 event
.u
.obj_alloc
.is_array
= 0;
373 event
.u
.obj_alloc
.size
= size
;
374 event
.u
.obj_alloc
.obj_id
= (jobjectID
) obj
;
377 (*_Jv_JVMPI_Notify_OBJECT_ALLOC
) (&event
);
385 // Allocate a new array of Java objects. Each object is of type
386 // `elementClass'. `init' is used to initialize each slot in the
389 _Jv_NewObjectArray (jsize count
, jclass elementClass
, jobject init
)
391 if (__builtin_expect (count
< 0, false))
392 JvThrow (new java::lang::NegativeArraySizeException
);
394 JvAssert (! elementClass
->isPrimitive ());
396 jobjectArray obj
= NULL
;
397 size_t size
= (size_t) _Jv_GetArrayElementFromElementType (obj
,
400 // Check for overflow.
401 if (__builtin_expect ((size_t) count
>
402 (SIZE_T_MAX
- size
) / sizeof (jobject
), false))
405 size
+= count
* sizeof (jobject
);
407 // FIXME: second argument should be "current loader" //
408 jclass clas
= _Jv_FindArrayClass (elementClass
, 0);
410 obj
= (jobjectArray
) _Jv_AllocArray (size
);
411 if (__builtin_expect (! obj
, false))
414 jobject
* ptr
= elements(obj
);
415 // We know the allocator returns zeroed memory. So don't bother
422 // Set the vtbl last to avoid problems if the GC happens during the
423 // window in this function between the allocation and this
425 *((_Jv_VTable
**) obj
) = clas
->vtable
;
429 // Allocate a new array of primitives. ELTYPE is the type of the
430 // element, COUNT is the size of the array.
432 _Jv_NewPrimArray (jclass eltype
, jint count
)
434 int elsize
= eltype
->size();
435 if (__builtin_expect (count
< 0, false))
436 JvThrow (new java::lang::NegativeArraySizeException ());
438 JvAssert (eltype
->isPrimitive ());
439 jobject dummy
= NULL
;
440 size_t size
= (size_t) _Jv_GetArrayElementFromElementType (dummy
, eltype
);
442 // Check for overflow.
443 if (__builtin_expect ((size_t) count
>
444 (SIZE_T_MAX
- size
) / elsize
, false))
447 __JArray
*arr
= (__JArray
*) _Jv_AllocObj (size
+ elsize
* count
);
448 if (__builtin_expect (! arr
, false))
451 // Note that we assume we are given zeroed memory by the allocator.
453 jclass klass
= _Jv_FindArrayClass (eltype
, 0);
454 // Set the vtbl last to avoid problems if the GC happens during the
455 // window in this function between the allocation and this
457 *((_Jv_VTable
**) arr
) = klass
->vtable
;
462 _Jv_NewArray (jint type
, jint size
)
466 case 4: return JvNewBooleanArray (size
);
467 case 5: return JvNewCharArray (size
);
468 case 6: return JvNewFloatArray (size
);
469 case 7: return JvNewDoubleArray (size
);
470 case 8: return JvNewByteArray (size
);
471 case 9: return JvNewShortArray (size
);
472 case 10: return JvNewIntArray (size
);
473 case 11: return JvNewLongArray (size
);
475 JvFail ("newarray - bad type code");
476 return NULL
; // Placate compiler.
480 _Jv_NewMultiArray (jclass type
, jint dimensions
, jint
*sizes
)
482 JvAssert (type
->isArray());
483 jclass element_type
= type
->getComponentType();
485 if (element_type
->isPrimitive())
486 result
= _Jv_NewPrimArray (element_type
, sizes
[0]);
488 result
= _Jv_NewObjectArray (sizes
[0], element_type
, NULL
);
492 JvAssert (! element_type
->isPrimitive());
493 JvAssert (element_type
->isArray());
494 jobject
*contents
= elements ((jobjectArray
) result
);
495 for (int i
= 0; i
< sizes
[0]; ++i
)
496 contents
[i
] = _Jv_NewMultiArray (element_type
, dimensions
- 1,
504 _Jv_NewMultiArray (jclass array_type
, jint dimensions
, ...)
507 jint sizes
[dimensions
];
508 va_start (args
, dimensions
);
509 for (int i
= 0; i
< dimensions
; ++i
)
511 jint size
= va_arg (args
, jint
);
516 return _Jv_NewMultiArray (array_type
, dimensions
, sizes
);
521 class _Jv_PrimClass
: public java::lang::Class
524 // FIXME: calling convention is weird. If we use the natural types
525 // then the compiler will complain because they aren't Java types.
526 _Jv_PrimClass (jobject cname
, jbyte sig
, jint len
, jobject array_vtable
)
528 using namespace java::lang::reflect
;
530 // We must initialize every field of the class. We do this in
531 // the same order they are declared in Class.h.
533 name
= _Jv_makeUtf8Const ((char *) cname
, -1);
534 accflags
= Modifier::PUBLIC
| Modifier::FINAL
;
537 constants
.tags
= NULL
;
538 constants
.data
= NULL
;
541 vtable_method_count
= 0;
545 static_field_count
= 0;
546 vtable
= JV_PRIMITIVE_VTABLE
;
550 state
= JV_STATE_DONE
;
553 // Note that we have to set `methods' to NULL.
555 _Jv_FindArrayClass (this, NULL
, (_Jv_VTable
*) array_vtable
);
559 // We use this to define both primitive classes and the vtables for
560 // arrays of primitive classes. The latter are given names so that we
561 // can refer to them from the compiler, allowing us to construct
562 // arrays of primitives statically.
563 #define DECLARE_PRIM_TYPE(NAME, SIG, LEN) \
564 _Jv_ArrayVTable _Jv_##NAME##VTable; \
565 _Jv_PrimClass _Jv_##NAME##Class((jobject) #NAME, (jbyte) SIG, (jint) LEN, \
566 (jobject) &_Jv_##NAME##VTable)
568 DECLARE_PRIM_TYPE(byte
, 'B', 1);
569 DECLARE_PRIM_TYPE(short, 'S', 2);
570 DECLARE_PRIM_TYPE(int, 'I', 4);
571 DECLARE_PRIM_TYPE(long, 'J', 8);
572 DECLARE_PRIM_TYPE(boolean
, 'Z', 1);
573 DECLARE_PRIM_TYPE(char, 'C', 2);
574 DECLARE_PRIM_TYPE(float, 'F', 4);
575 DECLARE_PRIM_TYPE(double, 'D', 8);
576 DECLARE_PRIM_TYPE(void, 'V', 0);
579 _Jv_FindClassFromSignature (char *sig
, java::lang::ClassLoader
*loader
)
584 return JvPrimClass (byte
);
586 return JvPrimClass (short);
588 return JvPrimClass (int);
590 return JvPrimClass (long);
592 return JvPrimClass (boolean
);
594 return JvPrimClass (char);
596 return JvPrimClass (float);
598 return JvPrimClass (double);
600 return JvPrimClass (void);
604 for (i
= 1; sig
[i
] && sig
[i
] != ';'; ++i
)
606 _Jv_Utf8Const
*name
= _Jv_makeUtf8Const (&sig
[1], i
- 1);
607 return _Jv_FindClass (name
, loader
);
611 return _Jv_FindArrayClass (_Jv_FindClassFromSignature (&sig
[1], loader
),
614 JvFail ("couldn't understand class signature");
615 return NULL
; // Placate compiler.
621 JvConvertArgv (int argc
, const char **argv
)
625 jobjectArray ar
= JvNewObjectArray(argc
, &StringClass
, NULL
);
626 jobject
* ptr
= elements(ar
);
627 for (int i
= 0; i
< argc
; i
++)
629 const char *arg
= argv
[i
];
630 // FIXME - should probably use JvNewStringUTF.
631 *ptr
++ = JvNewStringLatin1(arg
, strlen(arg
));
633 return (JArray
<jstring
>*) ar
;
636 // FIXME: These variables are static so that they will be
637 // automatically scanned by the Boehm collector. This is needed
638 // because with qthreads the collector won't scan the initial stack --
639 // it will only scan the qthreads stacks.
641 // Command line arguments.
642 static jobject arg_vec
;
644 // The primary thread.
645 static java::lang::Thread
*main_thread
;
648 _Jv_ThisExecutable (void)
654 _Jv_ThisExecutable (const char *name
)
658 _Jv_execName
= new char[strlen (name
) + 1];
659 strcpy (_Jv_execName
, name
);
663 #ifdef USE_WIN32_SIGNALLING
665 extern "C" int* win32_get_restart_frame (void *);
668 win32_exception_handler (LPEXCEPTION_POINTERS e
)
671 if (e
->ExceptionRecord
->ExceptionCode
== EXCEPTION_ACCESS_VIOLATION
)
672 setjmp_buf
= win32_get_restart_frame (nullp
);
673 else if (e
->ExceptionRecord
->ExceptionCode
== EXCEPTION_INT_DIVIDE_BY_ZERO
)
674 setjmp_buf
= win32_get_restart_frame (arithexception
);
676 return EXCEPTION_CONTINUE_SEARCH
;
678 e
->ContextRecord
->Ebp
= setjmp_buf
[0];
679 // FIXME: Why does i386-signal.h increment the PC here, do we need to do it?
680 e
->ContextRecord
->Eip
= setjmp_buf
[1];
681 // FIXME: Is this the stack pointer? Do we need it?
682 e
->ContextRecord
->Esp
= setjmp_buf
[2];
684 return EXCEPTION_CONTINUE_EXECUTION
;
696 arithexception
= new java::lang::ArithmeticException
697 (JvNewStringLatin1 ("/ by zero"));
700 no_memory
= new java::lang::OutOfMemoryError
;
703 LTDL_SET_PRELOADED_SYMBOLS ();
707 // Initialise winsock for networking
709 if (WSAStartup (MAKEWORD (1, 1), &data
))
710 MessageBox (NULL
, "Error initialising winsock library.", "Error", MB_OK
| MB_ICONEXCLAMATION
);
711 #endif /* USE_WINSOCK */
713 #ifdef USE_WIN32_SIGNALLING
714 // Install exception handler
715 SetUnhandledExceptionFilter (win32_exception_handler
);
717 // We only want this on POSIX systems.
718 struct sigaction act
;
719 act
.sa_handler
= SIG_IGN
;
720 sigemptyset (&act
.sa_mask
);
722 sigaction (SIGPIPE
, &act
, NULL
);
723 #endif /* USE_WIN32_SIGNALLING */
728 #ifndef DISABLE_GETENV_PROPERTIES
731 next_property_key (char *s
, size_t *length
)
737 // Skip over whitespace
741 // If we've reached the end, return NULL. Also return NULL if for
742 // some reason we've come across a malformed property string.
748 // Determine the length of the property key.
766 next_property_value (char *s
, size_t *length
)
782 // If we've reached the end, return NULL.
786 // Determine the length of the property value.
805 process_gcj_properties ()
807 char *props
= getenv("GCJ_PROPERTIES");
810 size_t property_count
= 0;
815 // Whip through props quickly in order to count the number of
817 while (p
&& (p
= next_property_key (p
, &length
)))
819 // Skip to the end of the key
822 p
= next_property_value (p
, &length
);
829 // Allocate an array of property value/key pairs.
830 _Jv_Environment_Properties
=
831 (property_pair
*) malloc (sizeof(property_pair
)
832 * (property_count
+ 1));
834 // Go through the properties again, initializing _Jv_Properties
838 while (p
&& (p
= next_property_key (p
, &length
)))
840 _Jv_Environment_Properties
[property_count
].key
= p
;
841 _Jv_Environment_Properties
[property_count
].key_length
= length
;
843 // Skip to the end of the key
846 p
= next_property_value (p
, &length
);
848 _Jv_Environment_Properties
[property_count
].value
= p
;
849 _Jv_Environment_Properties
[property_count
].value_length
= length
;
856 memset ((void *) &_Jv_Environment_Properties
[property_count
],
857 0, sizeof (property_pair
));
861 // Null terminate the strings.
862 while (_Jv_Environment_Properties
[i
].key
)
864 _Jv_Environment_Properties
[i
].key
[_Jv_Environment_Properties
[i
].key_length
] = 0;
865 _Jv_Environment_Properties
[i
++].value
[_Jv_Environment_Properties
[i
].value_length
] = 0;
869 #endif // DISABLE_GETENV_PROPERTIES
872 JvRunMain (jclass klass
, int argc
, const char **argv
)
874 PROCESS_GCJ_PROPERTIES
;
877 #ifdef HAVE_PROC_SELF_EXE
879 sprintf (exec_name
, "/proc/%d/exe", getpid ());
880 _Jv_ThisExecutable (exec_name
);
882 _Jv_ThisExecutable (argv
[0]);
885 arg_vec
= JvConvertArgv (argc
- 1, argv
+ 1);
886 main_thread
= new gnu::gcj::runtime::FirstThread (klass
, arg_vec
);
888 main_thread
->start();
891 int status
= (int) java::lang::ThreadGroup::had_uncaught_exception
;
893 java::lang::Runtime::getRuntime ()->exit (status
);
897 _Jv_RunMain (const char *name
, int argc
, const char **argv
, bool is_jar
)
900 PROCESS_GCJ_PROPERTIES
;
904 #ifdef HAVE_PROC_SELF_EXE
906 sprintf (exec_name
, "/proc/%d/exe", getpid ());
907 _Jv_ThisExecutable (exec_name
);
912 // name specifies a jar file. We must now extract the
913 // Main-Class attribute from the jar's manifest file. This is
914 // done by gnu.gcj.runtime.FirstThread.main.
915 _Jv_Jar_Class_Path
= strdup (name
);
916 arg_vec
= JvConvertArgv (1, &_Jv_Jar_Class_Path
);
919 new gnu::gcj::runtime::FirstThread (&_CL_Q43gnu3gcj7runtime11FirstThread
,
921 main_thread
->start();
924 // FirstThread.main extracts the main class name and stores it
926 class_name
= gnu::gcj::runtime::FirstThread::jarMainClassName
;
928 // We need a new ClassLoader because the classpath must be the
929 // jar file only. The easiest way to do this is to lose our
930 // reference to the previous classloader.
931 java::lang::ClassLoader::system
= NULL
;
934 class_name
= JvNewStringLatin1 (name
);
936 arg_vec
= JvConvertArgv (argc
- 1, argv
+ 1);
940 main_thread
= new gnu::gcj::runtime::FirstThread (class_name
, arg_vec
);
941 main_thread
->start();
945 int status
= (int) java::lang::ThreadGroup::had_uncaught_exception
;
947 java::lang::Runtime::getRuntime ()->exit (status
);
952 // Parse a string and return a heap size.
954 parse_heap_size (const char *spec
)
957 unsigned long val
= strtoul (spec
, &end
, 10);
958 if (*end
== 'k' || *end
== 'K')
960 else if (*end
== 'm' || *end
== 'M')
965 // Set the initial heap size. This might be ignored by the GC layer.
966 // This must be called before _Jv_RunMain.
968 _Jv_SetInitialHeapSize (const char *arg
)
970 size_t size
= parse_heap_size (arg
);
971 _Jv_GCSetInitialHeapSize (size
);
974 // Set the maximum heap size. This might be ignored by the GC layer.
975 // This must be called before _Jv_RunMain.
977 _Jv_SetMaximumHeapSize (const char *arg
)
979 size_t size
= parse_heap_size (arg
);
980 _Jv_GCSetMaximumHeapSize (size
);
986 _Jv_Malloc (jsize size
)
988 if (__builtin_expect (size
== 0, false))
990 void *ptr
= malloc ((size_t) size
);
991 if (__builtin_expect (ptr
== NULL
, false))
997 _Jv_Realloc (void *ptr
, jsize size
)
999 if (__builtin_expect (size
== 0, false))
1001 ptr
= realloc (ptr
, (size_t) size
);
1002 if (__builtin_expect (ptr
== NULL
, false))
1003 JvThrow (no_memory
);
1008 _Jv_MallocUnchecked (jsize size
)
1010 if (__builtin_expect (size
== 0, false))
1012 return malloc ((size_t) size
);
1016 _Jv_Free (void* ptr
)
1023 // In theory, these routines can be #ifdef'd away on machines which
1024 // support divide overflow signals. However, we never know if some
1025 // code might have been compiled with "-fuse-divide-subroutine", so we
1026 // always include them in libgcj.
1029 _Jv_divI (jint dividend
, jint divisor
)
1031 if (__builtin_expect (divisor
== 0, false))
1032 _Jv_ThrowSignal (arithexception
);
1034 if (dividend
== (jint
) 0x80000000L
&& divisor
== -1)
1037 return dividend
/ divisor
;
1041 _Jv_remI (jint dividend
, jint divisor
)
1043 if (__builtin_expect (divisor
== 0, false))
1044 _Jv_ThrowSignal (arithexception
);
1046 if (dividend
== (jint
) 0x80000000L
&& divisor
== -1)
1049 return dividend
% divisor
;
1053 _Jv_divJ (jlong dividend
, jlong divisor
)
1055 if (__builtin_expect (divisor
== 0, false))
1056 _Jv_ThrowSignal (arithexception
);
1058 if (dividend
== (jlong
) 0x8000000000000000LL
&& divisor
== -1)
1061 return dividend
/ divisor
;
1065 _Jv_remJ (jlong dividend
, jlong divisor
)
1067 if (__builtin_expect (divisor
== 0, false))
1068 _Jv_ThrowSignal (arithexception
);
1070 if (dividend
== (jlong
) 0x8000000000000000LL
&& divisor
== -1)
1073 return dividend
% divisor
;