prims.cc (catch_fpe): Call to HANDLE_DIVIDE_OVERFLOW added.

1999-05-20  Andrew Haley  <aph@cygnus.com>
        * libjava/prims.cc (catch_fpe): Call to HANDLE_DIVIDE_OVERFLOW
        added.
        * include/i386-signal.h (HANDLE_DIVIDE_OVERFLOW): New macro.
        (INIT_FPE): Exception string made more informative.
        * include/sparc-signal.h (INIT_FPE): Exception string made more
        informative.
        * testsuite/libjava.lang/Divide_1.java: New file.
        * testsuite/libjava.lang/Divide_1.out: New file.

From-SVN: r27056
This commit is contained in:
Andrew Haley 1999-05-20 08:26:55 +00:00 committed by Andrew Haley
parent bf3118d04b
commit 554b61bb30
6 changed files with 211 additions and 8 deletions

View File

@ -1,3 +1,14 @@
1999-05-20 Andrew Haley <aph@cygnus.com>
* libjava/prims.cc (catch_fpe): Call to HANDLE_DIVIDE_OVERFLOW
added.
* include/i386-signal.h (HANDLE_DIVIDE_OVERFLOW): New macro.
(INIT_FPE): Exception string made more informative.
* include/sparc-signal.h (INIT_FPE): Exception string made more
informative.
* testsuite/libjava.lang/Divide_1.java: New file.
* testsuite/libjava.lang/Divide_1.out: New file.
1999-05-19 Tom Tromey <tromey@cygnus.com>
* aclocal.m4, configure: Rebuilt.

View File

@ -25,16 +25,86 @@ details. */
static void _name (int _dummy)
#define MAKE_THROW_FRAME \
do \
{ \
void **_p = (void **)&_dummy; \
struct sigcontext_struct *_regs = (struct sigcontext_struct *)++_p; \
\
register unsigned long _ebp = _regs->ebp; \
register unsigned long _eip = _regs->eip; \
\
register unsigned char *_eip = (unsigned char *)_regs->eip; \
\
asm volatile ("mov %0, (%%ebp); mov %1, 4(%%ebp)" \
: : "r"(_ebp), "r"(_eip)); \
}
} \
while (0)
#define HANDLE_DIVIDE_OVERFLOW \
do \
{ \
void **_p = (void **)&_dummy; \
struct sigcontext_struct *_regs = (struct sigcontext_struct *)++_p; \
\
register unsigned long *_ebp = (unsigned long *)_regs->ebp; \
register unsigned char *_eip = (unsigned char *)_regs->eip; \
\
/* According to the JVM spec, "if the dividend is the negative \
* integer of the smallest magnitude and the divisor is -1, then \
* overflow occurs and the result is equal to the dividend. Despite \
* the overflow, no exception occurs". \
\
* We handle this by inspecting the instruction which generated the \
* signal and advancing eip to point to the following instruction. \
* As the instructions are variable length it is necessary to do a \
* little calculation to figure out where the following instruction \
* actually is. \
\
*/ \
\
if (_eip[0] == 0xf7) \
{ \
unsigned char _modrm = _eip[1]; \
\
if (_regs->eax == 0x80000000 \
&& ((_modrm >> 3) & 7) == 7) /* Signed divide */ \
{ \
_regs->edx = 0; /* the remainder is zero */ \
switch (_modrm >> 6) \
{ \
case 0: \
if ((_modrm & 7) == 5) \
_eip += 4; \
break; \
case 1: \
_eip += 1; \
break; \
case 2: \
_eip += 4; \
break; \
case 3: \
break; \
} \
_eip += 2; \
_regs->eip = (unsigned long)_eip; \
return; \
} \
else if (((_modrm >> 3) & 7) == 6) /* Unsigned divide */ \
{ \
/* We assume that unsigned divisions are in library code, so \
* we throw one level down the stack, which was hopefully \
* the place that called the library routine. This will \
* break if the library is ever compiled with \
* -fomit-frame-pointer, but at least this way we've got a \
* good chance of finding the exception handler. */ \
\
_eip = (unsigned char *)_ebp[1]; \
_ebp = (unsigned long *)_ebp[0]; \
} \
} \
\
asm volatile ("mov %0, (%%ebp); mov %1, 4(%%ebp)" \
: : "r"(_ebp), "r"(_eip)); \
} \
while (0)
#define INIT_SEGV \
do \
@ -48,10 +118,11 @@ do \
} \
while (0)
#define INIT_FPE \
#define INIT_FPE \
do \
{ \
arithexception = new java::lang::ArithmeticException (); \
{ \
arithexception = new java::lang::ArithmeticException \
(JvNewStringLatin1 ("/ by zero")); \
struct sigaction act; \
act.sa_handler = catch_fpe; \
sigemptyset (&act.sa_mask); \

View File

@ -51,7 +51,8 @@ while (0)
#define INIT_FPE \
do \
{ \
arithexception = new java::lang::ArithmeticException (); \
arithexception = new java::lang::ArithmeticException \
(JvNewStringLatin1 ("/ by zero")); \
struct sigaction act; \
act.sa_flags = SA_SIGINFO; \
act.sa_sigaction = catch_fpe; \

View File

@ -68,7 +68,11 @@ SIGNAL_HANDLER (catch_segv)
static java::lang::ArithmeticException *arithexception;
SIGNAL_HANDLER (catch_fpe)
{
#ifdef HANDLE_DIVIDE_OVERFLOW
HANDLE_DIVIDE_OVERFLOW;
#else
MAKE_THROW_FRAME;
#endif
_Jv_Throw (arithexception);
}
#endif
@ -97,7 +101,7 @@ _Jv_equalUtf8Consts (Utf8Const* a, Utf8Const *b)
}
/* True iff A is equal to STR.
HASH is STR->hashCode().
HASH is STR->hashCode().
*/
jboolean

View File

@ -0,0 +1,105 @@
public class Divide_1
{
static int b = Integer.parseInt ("-1");
int b1 = Integer.parseInt ("-1");
static int zero = Integer.parseInt ("0");
void probe ()
{
try {
int a = Integer.parseInt ("-80000000", 16);
int c = a/b;
System.out.println (c);
} catch (Exception _) {
System.out.println (_);
}
try {
int a = Integer.parseInt ("-80000000", 16);
int c = a/-1;
System.out.println (c);
} catch (Exception _) {
System.out.println (_);
}
try {
int a = Integer.parseInt ("-80000000", 16);
int c = a%b;
System.out.println (c);
} catch (Exception _) {
System.out.println (_);
}
try {
int a = Integer.parseInt ("-80000000", 16);
int c = a%b1;
System.out.println (c);
} catch (Exception _) {
System.out.println (_);
}
try {
int a = Integer.parseInt ("-80000000", 16);
int c = a%-1;
System.out.println (c);
} catch (Exception _) {
System.out.println (_);
}
try {
int a = Integer.parseInt ("8000", 16);
int b = Integer.parseInt ("0", 16);
int c = a/b;
System.out.println (c);
} catch (Exception _) {
System.out.println (_);
}
try {
int a = Integer.parseInt ("8000", 16);
int b = Integer.parseInt ("0", 16);
int c = a%b;
System.out.println (c);
} catch (Exception _) {
System.out.println (_);
}
try {
long a = Long.parseLong ("-8000000000000000", 16);
long c = a/b;
System.out.println (c);
} catch (Exception _) {
System.out.println (_);
}
try {
long a = Long.parseLong ("-8000000000000000", 16);
long c = a%b;
System.out.println (c);
} catch (Exception _) {
System.out.println (_);
}
try {
long a = Long.parseLong ("8000", 16);
long b = Long.parseLong ("0", 16);
long c = a/b;
System.out.println (c);
} catch (Exception _) {
System.out.println (_);
}
try {
long a = Long.parseLong ("8000", 16);
long b = Long.parseLong ("0", 16);
long c = a%b;
System.out.println (c);
} catch (Exception _) {
System.out.println (_);
}
}
public static void main (String[] args) {
new Divide_1 ().probe ();
}
}

View File

@ -0,0 +1,11 @@
-2147483648
-2147483648
0
0
0
java.lang.ArithmeticException: / by zero
java.lang.ArithmeticException: / by zero
-9223372036854775808
0
java.lang.ArithmeticException: / by zero
java.lang.ArithmeticException: / by zero