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
;
94 // Stash the argv pointer to benefit native libraries that need it.
95 const char **_Jv_argv
;
99 // Pointer to JVMPI notification functions.
100 void (*_Jv_JVMPI_Notify_OBJECT_ALLOC
) (JVMPI_Event
*event
);
101 void (*_Jv_JVMPI_Notify_THREAD_START
) (JVMPI_Event
*event
);
102 void (*_Jv_JVMPI_Notify_THREAD_END
) (JVMPI_Event
*event
);
106 extern "C" void _Jv_ThrowSignal (void *) __attribute ((noreturn
));
108 // Just like _Jv_Throw, but fill in the stack trace first. Although
109 // this is declared extern in order that its name not be mangled, it
110 // is not intended to be used outside this file.
112 _Jv_ThrowSignal (void *e
)
114 java::lang::Throwable
*throwable
= (java::lang::Throwable
*)e
;
115 throwable
->fillInStackTrace ();
116 _Jv_Throw (throwable
);
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
++) {
223 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_AllocBytesChecked (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 JvThrow (new java::lang::ArrayIndexOutOfBoundsException
323 (java::lang::String::valueOf(bad_index
)));
327 _Jv_ThrowNullPointerException ()
329 throw new java::lang::NullPointerException ();
332 // Allocate some unscanned memory and throw an exception if no memory.
334 _Jv_AllocBytesChecked (jsize size
)
336 void *r
= _Jv_AllocBytes (size
);
338 _Jv_Throw (no_memory
);
342 // Allocate a new object of class KLASS. SIZE is the size of the object
343 // to allocate. You might think this is redundant, but it isn't; some
344 // classes, such as String, aren't of fixed size.
346 _Jv_AllocObject (jclass klass
, jint size
)
348 _Jv_InitClass (klass
);
350 jobject obj
= (jobject
) _Jv_AllocObj (size
, klass
);
351 if (__builtin_expect (! obj
, false))
354 // If this class has inherited finalize from Object, then don't
355 // bother registering a finalizer. We know that finalize() is the
356 // very first method after the dummy entry. If this turns out to be
357 // unreliable, a more robust implementation can be written. Such an
358 // implementation would look for Object.finalize in Object's method
359 // table at startup, and then use that information to find the
360 // appropriate index in the method vector.
361 if (klass
->vtable
->get_finalizer() != ObjectClass
.vtable
->get_finalizer())
362 _Jv_RegisterFinalizer (obj
, _Jv_FinalizeObject
);
365 // Service JVMPI request.
367 if (__builtin_expect (_Jv_JVMPI_Notify_OBJECT_ALLOC
!= 0, false))
371 event
.event_type
= JVMPI_EVENT_OBJECT_ALLOC
;
373 event
.u
.obj_alloc
.arena_id
= 0;
374 event
.u
.obj_alloc
.class_id
= (jobjectID
) klass
;
375 event
.u
.obj_alloc
.is_array
= 0;
376 event
.u
.obj_alloc
.size
= size
;
377 event
.u
.obj_alloc
.obj_id
= (jobjectID
) obj
;
380 (*_Jv_JVMPI_Notify_OBJECT_ALLOC
) (&event
);
388 // Allocate a new array of Java objects. Each object is of type
389 // `elementClass'. `init' is used to initialize each slot in the
392 _Jv_NewObjectArray (jsize count
, jclass elementClass
, jobject init
)
394 if (__builtin_expect (count
< 0, false))
395 JvThrow (new java::lang::NegativeArraySizeException
);
397 JvAssert (! elementClass
->isPrimitive ());
399 jobjectArray obj
= NULL
;
400 size_t size
= (size_t) _Jv_GetArrayElementFromElementType (obj
,
403 // Check for overflow.
404 if (__builtin_expect ((size_t) count
>
405 (SIZE_T_MAX
- size
) / sizeof (jobject
), false))
408 size
+= count
* sizeof (jobject
);
410 // FIXME: second argument should be "current loader" //
411 jclass klass
= _Jv_FindArrayClass (elementClass
, 0);
413 obj
= (jobjectArray
) _Jv_AllocArray (size
, klass
);
414 if (__builtin_expect (! obj
, false))
417 jobject
* ptr
= elements(obj
);
418 // We know the allocator returns zeroed memory. So don't bother
428 // Allocate a new array of primitives. ELTYPE is the type of the
429 // element, COUNT is the size of the array.
431 _Jv_NewPrimArray (jclass eltype
, jint count
)
433 int elsize
= eltype
->size();
434 if (__builtin_expect (count
< 0, false))
435 JvThrow (new java::lang::NegativeArraySizeException ());
437 JvAssert (eltype
->isPrimitive ());
438 jobject dummy
= NULL
;
439 size_t size
= (size_t) _Jv_GetArrayElementFromElementType (dummy
, eltype
);
441 // Check for overflow.
442 if (__builtin_expect ((size_t) count
>
443 (SIZE_T_MAX
- size
) / elsize
, false))
446 jclass klass
= _Jv_FindArrayClass (eltype
, 0);
448 __JArray
*arr
= (__JArray
*) _Jv_AllocObj (size
+ elsize
* count
, klass
);
449 if (__builtin_expect (! arr
, false))
452 // Note that we assume we are given zeroed memory by the allocator.
458 _Jv_NewArray (jint type
, jint size
)
462 case 4: return JvNewBooleanArray (size
);
463 case 5: return JvNewCharArray (size
);
464 case 6: return JvNewFloatArray (size
);
465 case 7: return JvNewDoubleArray (size
);
466 case 8: return JvNewByteArray (size
);
467 case 9: return JvNewShortArray (size
);
468 case 10: return JvNewIntArray (size
);
469 case 11: return JvNewLongArray (size
);
471 JvFail ("newarray - bad type code");
472 return NULL
; // Placate compiler.
476 _Jv_NewMultiArray (jclass type
, jint dimensions
, jint
*sizes
)
478 JvAssert (type
->isArray());
479 jclass element_type
= type
->getComponentType();
481 if (element_type
->isPrimitive())
482 result
= _Jv_NewPrimArray (element_type
, sizes
[0]);
484 result
= _Jv_NewObjectArray (sizes
[0], element_type
, NULL
);
488 JvAssert (! element_type
->isPrimitive());
489 JvAssert (element_type
->isArray());
490 jobject
*contents
= elements ((jobjectArray
) result
);
491 for (int i
= 0; i
< sizes
[0]; ++i
)
492 contents
[i
] = _Jv_NewMultiArray (element_type
, dimensions
- 1,
500 _Jv_NewMultiArray (jclass array_type
, jint dimensions
, ...)
503 jint sizes
[dimensions
];
504 va_start (args
, dimensions
);
505 for (int i
= 0; i
< dimensions
; ++i
)
507 jint size
= va_arg (args
, jint
);
512 return _Jv_NewMultiArray (array_type
, dimensions
, sizes
);
517 class _Jv_PrimClass
: public java::lang::Class
520 // FIXME: calling convention is weird. If we use the natural types
521 // then the compiler will complain because they aren't Java types.
522 _Jv_PrimClass (jobject cname
, jbyte sig
, jint len
, jobject array_vtable
)
524 using namespace java::lang::reflect
;
526 // We must initialize every field of the class. We do this in
527 // the same order they are declared in Class.h.
529 name
= _Jv_makeUtf8Const ((char *) cname
, -1);
530 accflags
= Modifier::PUBLIC
| Modifier::FINAL
;
533 constants
.tags
= NULL
;
534 constants
.data
= NULL
;
537 vtable_method_count
= 0;
541 static_field_count
= 0;
542 vtable
= JV_PRIMITIVE_VTABLE
;
546 state
= JV_STATE_DONE
;
549 // Note that we have to set `methods' to NULL.
551 _Jv_FindArrayClass (this, NULL
, (_Jv_VTable
*) array_vtable
);
555 // We use this to define both primitive classes and the vtables for
556 // arrays of primitive classes. The latter are given names so that we
557 // can refer to them from the compiler, allowing us to construct
558 // arrays of primitives statically.
559 #define DECLARE_PRIM_TYPE(NAME, SIG, LEN) \
560 _Jv_ArrayVTable _Jv_##NAME##VTable; \
561 _Jv_PrimClass _Jv_##NAME##Class((jobject) #NAME, (jbyte) SIG, (jint) LEN, \
562 (jobject) &_Jv_##NAME##VTable)
564 DECLARE_PRIM_TYPE(byte
, 'B', 1);
565 DECLARE_PRIM_TYPE(short, 'S', 2);
566 DECLARE_PRIM_TYPE(int, 'I', 4);
567 DECLARE_PRIM_TYPE(long, 'J', 8);
568 DECLARE_PRIM_TYPE(boolean
, 'Z', 1);
569 DECLARE_PRIM_TYPE(char, 'C', 2);
570 DECLARE_PRIM_TYPE(float, 'F', 4);
571 DECLARE_PRIM_TYPE(double, 'D', 8);
572 DECLARE_PRIM_TYPE(void, 'V', 0);
575 _Jv_FindClassFromSignature (char *sig
, java::lang::ClassLoader
*loader
)
580 return JvPrimClass (byte
);
582 return JvPrimClass (short);
584 return JvPrimClass (int);
586 return JvPrimClass (long);
588 return JvPrimClass (boolean
);
590 return JvPrimClass (char);
592 return JvPrimClass (float);
594 return JvPrimClass (double);
596 return JvPrimClass (void);
600 for (i
= 1; sig
[i
] && sig
[i
] != ';'; ++i
)
602 _Jv_Utf8Const
*name
= _Jv_makeUtf8Const (&sig
[1], i
- 1);
603 return _Jv_FindClass (name
, loader
);
607 return _Jv_FindArrayClass (_Jv_FindClassFromSignature (&sig
[1], loader
),
610 JvFail ("couldn't understand class signature");
611 return NULL
; // Placate compiler.
617 JvConvertArgv (int argc
, const char **argv
)
621 jobjectArray ar
= JvNewObjectArray(argc
, &StringClass
, NULL
);
622 jobject
* ptr
= elements(ar
);
623 for (int i
= 0; i
< argc
; i
++)
625 const char *arg
= argv
[i
];
626 // FIXME - should probably use JvNewStringUTF.
627 *ptr
++ = JvNewStringLatin1(arg
, strlen(arg
));
629 return (JArray
<jstring
>*) ar
;
632 // FIXME: These variables are static so that they will be
633 // automatically scanned by the Boehm collector. This is needed
634 // because with qthreads the collector won't scan the initial stack --
635 // it will only scan the qthreads stacks.
637 // Command line arguments.
638 static jobject arg_vec
;
640 // The primary thread.
641 static java::lang::Thread
*main_thread
;
644 _Jv_ThisExecutable (void)
650 _Jv_ThisExecutable (const char *name
)
654 _Jv_execName
= new char[strlen (name
) + 1];
655 strcpy (_Jv_execName
, name
);
659 #ifdef USE_WIN32_SIGNALLING
661 extern "C" int* win32_get_restart_frame (void *);
664 win32_exception_handler (LPEXCEPTION_POINTERS e
)
667 if (e
->ExceptionRecord
->ExceptionCode
== EXCEPTION_ACCESS_VIOLATION
)
668 setjmp_buf
= win32_get_restart_frame (nullp
);
669 else if (e
->ExceptionRecord
->ExceptionCode
== EXCEPTION_INT_DIVIDE_BY_ZERO
)
670 setjmp_buf
= win32_get_restart_frame (arithexception
);
672 return EXCEPTION_CONTINUE_SEARCH
;
674 e
->ContextRecord
->Ebp
= setjmp_buf
[0];
675 // FIXME: Why does i386-signal.h increment the PC here, do we need to do it?
676 e
->ContextRecord
->Eip
= setjmp_buf
[1];
677 // FIXME: Is this the stack pointer? Do we need it?
678 e
->ContextRecord
->Esp
= setjmp_buf
[2];
680 return EXCEPTION_CONTINUE_EXECUTION
;
692 arithexception
= new java::lang::ArithmeticException
693 (JvNewStringLatin1 ("/ by zero"));
696 no_memory
= new java::lang::OutOfMemoryError
;
699 LTDL_SET_PRELOADED_SYMBOLS ();
703 // Initialise winsock for networking
705 if (WSAStartup (MAKEWORD (1, 1), &data
))
706 MessageBox (NULL
, "Error initialising winsock library.", "Error", MB_OK
| MB_ICONEXCLAMATION
);
707 #endif /* USE_WINSOCK */
709 #ifdef USE_WIN32_SIGNALLING
710 // Install exception handler
711 SetUnhandledExceptionFilter (win32_exception_handler
);
713 // We only want this on POSIX systems.
714 struct sigaction act
;
715 act
.sa_handler
= SIG_IGN
;
716 sigemptyset (&act
.sa_mask
);
718 sigaction (SIGPIPE
, &act
, NULL
);
719 #endif /* USE_WIN32_SIGNALLING */
724 #ifndef DISABLE_GETENV_PROPERTIES
727 next_property_key (char *s
, size_t *length
)
733 // Skip over whitespace
737 // If we've reached the end, return NULL. Also return NULL if for
738 // some reason we've come across a malformed property string.
744 // Determine the length of the property key.
762 next_property_value (char *s
, size_t *length
)
778 // If we've reached the end, return NULL.
782 // Determine the length of the property value.
801 process_gcj_properties ()
803 char *props
= getenv("GCJ_PROPERTIES");
806 size_t property_count
= 0;
811 // Whip through props quickly in order to count the number of
813 while (p
&& (p
= next_property_key (p
, &length
)))
815 // Skip to the end of the key
818 p
= next_property_value (p
, &length
);
825 // Allocate an array of property value/key pairs.
826 _Jv_Environment_Properties
=
827 (property_pair
*) malloc (sizeof(property_pair
)
828 * (property_count
+ 1));
830 // Go through the properties again, initializing _Jv_Properties
834 while (p
&& (p
= next_property_key (p
, &length
)))
836 _Jv_Environment_Properties
[property_count
].key
= p
;
837 _Jv_Environment_Properties
[property_count
].key_length
= length
;
839 // Skip to the end of the key
842 p
= next_property_value (p
, &length
);
844 _Jv_Environment_Properties
[property_count
].value
= p
;
845 _Jv_Environment_Properties
[property_count
].value_length
= length
;
852 memset ((void *) &_Jv_Environment_Properties
[property_count
],
853 0, sizeof (property_pair
));
857 // Null terminate the strings.
858 while (_Jv_Environment_Properties
[i
].key
)
860 _Jv_Environment_Properties
[i
].key
[_Jv_Environment_Properties
[i
].key_length
] = 0;
861 _Jv_Environment_Properties
[i
++].value
[_Jv_Environment_Properties
[i
].value_length
] = 0;
865 #endif // DISABLE_GETENV_PROPERTIES
868 JvRunMain (jclass klass
, int argc
, const char **argv
)
870 PROCESS_GCJ_PROPERTIES
;
876 #ifdef HAVE_PROC_SELF_EXE
878 sprintf (exec_name
, "/proc/%d/exe", getpid ());
879 _Jv_ThisExecutable (exec_name
);
881 _Jv_ThisExecutable (argv
[0]);
884 arg_vec
= JvConvertArgv (argc
- 1, argv
+ 1);
885 main_thread
= new gnu::gcj::runtime::FirstThread (klass
, arg_vec
);
887 main_thread
->start();
890 int status
= (int) java::lang::ThreadGroup::had_uncaught_exception
;
892 java::lang::Runtime::getRuntime ()->exit (status
);
896 _Jv_RunMain (const char *name
, int argc
, const char **argv
, bool is_jar
)
899 PROCESS_GCJ_PROPERTIES
;
903 #ifdef HAVE_PROC_SELF_EXE
905 sprintf (exec_name
, "/proc/%d/exe", getpid ());
906 _Jv_ThisExecutable (exec_name
);
911 // name specifies a jar file. We must now extract the
912 // Main-Class attribute from the jar's manifest file. This is
913 // done by gnu.gcj.runtime.FirstThread.main.
914 _Jv_Jar_Class_Path
= strdup (name
);
915 arg_vec
= JvConvertArgv (1, &_Jv_Jar_Class_Path
);
918 new gnu::gcj::runtime::FirstThread (&_CL_Q43gnu3gcj7runtime11FirstThread
,
920 main_thread
->start();
923 // FirstThread.main extracts the main class name and stores it
925 class_name
= gnu::gcj::runtime::FirstThread::jarMainClassName
;
927 // We need a new ClassLoader because the classpath must be the
928 // jar file only. The easiest way to do this is to lose our
929 // reference to the previous classloader.
930 java::lang::ClassLoader::system
= NULL
;
933 class_name
= JvNewStringLatin1 (name
);
935 arg_vec
= JvConvertArgv (argc
- 1, argv
+ 1);
939 main_thread
= new gnu::gcj::runtime::FirstThread (class_name
, arg_vec
);
940 main_thread
->start();
944 int status
= (int) java::lang::ThreadGroup::had_uncaught_exception
;
946 java::lang::Runtime::getRuntime ()->exit (status
);
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))
1002 JvThrow (no_memory
);
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
;