This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Remove shared exceptions
- From: Andrew Haley <aph at redhat dot com>
- To: java-patches at gcc dot gnu dot org
- Date: Thu, 12 Jun 2003 18:16:53 +0100
- Subject: Remove shared exceptions
This fixes a long-standing bug in libgcj where NullPointerException
and ArithmeticException objects are shared between threads.
Andrew.
2003-06-12 Andrew Haley <aph@redhat.com>
* prims.cc (catch_segv): Create exception in handler.
(catch_fpe): Likewise.
(_Jv_divI, _Jv_remI, _Jv_divJ, _Jv_remJ): Likewise.
(_Jv_ThrowSignal): Remove.
* include/x86_64-signal.h (INIT_SEGV): Delete reference to nullp.
* include/default-signal.h (INIT_SEGV, INIT_FPE): Delete reference
to nullp and arithexception.
* include/dwarf2-signal.h (INIT_SEGV, INIT_FPE): Likewise.
* include/i386-signal.h (INIT_SEGV, INIT_FPE): Likewise.
* include/s390-signal.h (INIT_SEGV, INIT_FPE): Likewise.
* include/sparc-signal.h (INIT_SEGV, INIT_FPE): Likewise.
* include/win32-signal.h (INIT_SEGV, INIT_FPE): Likewise.
Index: prims.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/prims.cc,v
retrieving revision 1.79
diff -u -r1.79 prims.cc
--- prims.cc 25 Apr 2003 16:48:12 -0000 1.79
+++ prims.cc 12 Jun 2003 16:14:20 -0000
@@ -135,20 +135,20 @@
}
#ifdef HANDLE_SEGV
-static java::lang::NullPointerException *nullp;
-
SIGNAL_HANDLER (catch_segv)
{
+ java::lang::NullPointerException *nullp
+ = new java::lang::NullPointerException;
MAKE_THROW_FRAME (nullp);
_Jv_ThrowSignal (nullp);
}
#endif
-static java::lang::ArithmeticException *arithexception;
-
#ifdef HANDLE_FPE
SIGNAL_HANDLER (catch_fpe)
{
+ java::lang::ArithmeticException *arithexception
+ = new java::lang::ArithmeticException (JvNewStringLatin1 ("/ by zero"));
#ifdef HANDLE_DIVIDE_OVERFLOW
HANDLE_DIVIDE_OVERFLOW;
#else
@@ -921,9 +921,6 @@
INIT_SEGV;
#ifdef HANDLE_FPE
INIT_FPE;
-#else
- arithexception = new java::lang::ArithmeticException
- (JvNewStringLatin1 ("/ by zero"));
#endif
no_memory = new java::lang::OutOfMemoryError;
@@ -1093,7 +1090,11 @@
_Jv_divI (jint dividend, jint divisor)
{
if (__builtin_expect (divisor == 0, false))
- _Jv_ThrowSignal (arithexception);
+ {
+ java::lang::ArithmeticException *arithexception
+ = new java::lang::ArithmeticException (JvNewStringLatin1 ("/ by zero"));
+ _Jv_ThrowSignal (arithexception);
+ }
if (dividend == (jint) 0x80000000L && divisor == -1)
return dividend;
@@ -1105,11 +1106,15 @@
_Jv_remI (jint dividend, jint divisor)
{
if (__builtin_expect (divisor == 0, false))
- _Jv_ThrowSignal (arithexception);
+ {
+ java::lang::ArithmeticException *arithexception
+ = new java::lang::ArithmeticException (JvNewStringLatin1 ("/ by zero"));
+ _Jv_ThrowSignal (arithexception);
+ }
if (dividend == (jint) 0x80000000L && divisor == -1)
return 0;
-
+
return dividend % divisor;
}
@@ -1117,8 +1122,12 @@
_Jv_divJ (jlong dividend, jlong divisor)
{
if (__builtin_expect (divisor == 0, false))
- _Jv_ThrowSignal (arithexception);
-
+ {
+ java::lang::ArithmeticException *arithexception
+ = new java::lang::ArithmeticException (JvNewStringLatin1 ("/ by zero"));
+ _Jv_ThrowSignal (arithexception);
+ }
+
if (dividend == (jlong) 0x8000000000000000LL && divisor == -1)
return dividend;
@@ -1129,10 +1138,16 @@
_Jv_remJ (jlong dividend, jlong divisor)
{
if (__builtin_expect (divisor == 0, false))
- _Jv_ThrowSignal (arithexception);
-
+ {
+ java::lang::ArithmeticException *arithexception
+ = new java::lang::ArithmeticException (JvNewStringLatin1 ("/ by zero"));
+ _Jv_ThrowSignal (arithexception);
+ }
+
if (dividend == (jlong) 0x8000000000000000LL && divisor == -1)
return 0;
return dividend % divisor;
}
+
+
Index: include/default-signal.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/default-signal.h,v
retrieving revision 1.7
diff -u -r1.7 default-signal.h
--- include/default-signal.h 19 May 2000 17:55:30 -0000 1.7
+++ include/default-signal.h 12 Jun 2003 16:14:20 -0000
@@ -24,7 +24,6 @@
#define INIT_SEGV \
do \
{ \
- nullp = new java::lang::NullPointerException (); \
signal (SIGSEGV, catch_segv); \
} \
while (0)
@@ -32,8 +31,6 @@
#define INIT_FPE \
do \
{ \
- arithexception = new java::lang::ArithmeticException \
- (JvNewStringLatin1 ("/ by zero")); \
signal (SIGFPE, catch_fpe); \
} \
while (0)
Index: include/dwarf2-signal.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/dwarf2-signal.h,v
retrieving revision 1.13
diff -u -r1.13 dwarf2-signal.h
--- include/dwarf2-signal.h 14 Jan 2003 14:02:13 -0000 1.13
+++ include/dwarf2-signal.h 12 Jun 2003 16:14:20 -0000
@@ -143,7 +143,6 @@
#define INIT_SEGV \
do \
{ \
- nullp = new java::lang::NullPointerException (); \
struct kernel_sigaction act; \
unsigned long stub = ((unsigned long)&__rt_sigreturn_stub); \
act.k_sa_sigaction = _Jv_catch_segv; \
@@ -197,8 +196,6 @@
#define INIT_FPE \
do \
{ \
- arithexception = new java::lang::ArithmeticException \
- (JvNewStringLatin1 ("/ by zero")); \
struct kernel_sigaction act; \
act.k_sa_sigaction = _Jv_catch_fpe; \
act.k_sa_mask = 0; \
@@ -212,7 +209,6 @@
#define INIT_SEGV \
do \
{ \
- nullp = new java::lang::NullPointerException (); \
struct sigaction act; \
act.sa_sigaction = _Jv_catch_segv; \
sigemptyset (&act.sa_mask); \
@@ -224,8 +220,6 @@
#define INIT_FPE \
do \
{ \
- arithexception = new java::lang::ArithmeticException \
- (JvNewStringLatin1 ("/ by zero")); \
struct sigaction act; \
act.sa_sigaction = _Jv_catch_fpe; \
sigemptyset (&act.sa_mask); \
@@ -250,7 +244,6 @@
#define INIT_SEGV \
do \
{ \
- nullp = new java::lang::NullPointerException (); \
struct sigaction act; \
act.sa_sigaction = _Jv_catch_segv; \
sigemptyset (&act.sa_mask); \
@@ -262,8 +255,6 @@
#define INIT_FPE \
do \
{ \
- arithexception = new java::lang::ArithmeticException \
- (JvNewStringLatin1 ("/ by zero")); \
struct sigaction act; \
act.sa_sigaction = _Jv_catch_fpe; \
sigemptyset (&act.sa_mask); \
Index: include/i386-signal.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/i386-signal.h,v
retrieving revision 1.14
diff -u -r1.14 i386-signal.h
--- include/i386-signal.h 18 Mar 2002 17:11:43 -0000 1.14
+++ include/i386-signal.h 12 Jun 2003 16:14:20 -0000
@@ -111,7 +111,6 @@
#define INIT_SEGV \
do \
{ \
- nullp = new java::lang::NullPointerException (); \
struct old_i386_kernel_sigaction kact; \
kact.k_sa_handler = catch_segv; \
kact.k_sa_mask = 0; \
@@ -123,8 +122,6 @@
#define INIT_FPE \
do \
{ \
- arithexception = new java::lang::ArithmeticException \
- (JvNewStringLatin1 ("/ by zero")); \
struct old_i386_kernel_sigaction kact; \
kact.k_sa_handler = catch_fpe; \
kact.k_sa_mask = 0; \
Index: include/s390-signal.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/s390-signal.h,v
retrieving revision 1.1
diff -u -r1.1 s390-signal.h
--- include/s390-signal.h 29 May 2002 18:36:50 -0000 1.1
+++ include/s390-signal.h 12 Jun 2003 16:14:20 -0000
@@ -52,7 +52,6 @@
#define INIT_SEGV \
do \
{ \
- nullp = new java::lang::NullPointerException (); \
struct old_s390_kernel_sigaction kact; \
kact.k_sa_handler = catch_segv; \
kact.k_sa_mask = 0; \
@@ -64,8 +63,6 @@
#define INIT_FPE \
do \
{ \
- arithexception = new java::lang::ArithmeticException \
- (JvNewStringLatin1 ("/ by zero")); \
struct old_s390_kernel_sigaction kact; \
kact.k_sa_handler = catch_fpe; \
kact.k_sa_mask = 0; \
Index: include/sparc-signal.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/sparc-signal.h,v
retrieving revision 1.8
diff -u -r1.8 sparc-signal.h
--- include/sparc-signal.h 21 Apr 2002 09:37:49 -0000 1.8
+++ include/sparc-signal.h 12 Jun 2003 16:14:20 -0000
@@ -45,7 +45,6 @@
#define INIT_SEGV \
do \
{ \
- nullp = new java::lang::NullPointerException (); \
struct sigaction act; \
act.sa_sigaction = catch_segv; \
act.sa_flags = SA_SIGINFO | SA_NODEFER; \
@@ -57,8 +56,6 @@
#define INIT_FPE \
do \
{ \
- arithexception = new java::lang::ArithmeticException \
- (JvNewStringLatin1 ("/ by zero")); \
struct sigaction act; \
act.sa_flags = SA_SIGINFO | SA_NODEFER; \
act.sa_sigaction = catch_fpe; \
Index: include/win32-signal.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/win32-signal.h,v
retrieving revision 1.2
diff -u -r1.2 win32-signal.h
--- include/win32-signal.h 16 Jun 2000 15:52:24 -0000 1.2
+++ include/win32-signal.h 12 Jun 2003 16:14:20 -0000
@@ -26,7 +26,6 @@
#define INIT_SEGV \
do \
{ \
- nullp = new java::lang::NullPointerException (); \
} \
while (0)
@@ -34,8 +33,6 @@
#define INIT_FPE \
do \
{ \
- arithexception = new java::lang::ArithmeticException \
- (JvNewStringLatin1 ("/ by zero")); \
} \
while (0)
Index: include/x86_64-signal.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/x86_64-signal.h,v
retrieving revision 1.2
diff -u -r1.2 x86_64-signal.h
--- include/x86_64-signal.h 22 Jan 2003 17:47:04 -0000 1.2
+++ include/x86_64-signal.h 12 Jun 2003 16:14:20 -0000
@@ -64,7 +64,6 @@
#define INIT_SEGV \
do \
{ \
- nullp = new java::lang::NullPointerException (); \
struct kernel_sigaction act; \
act.k_sa_sigaction = _Jv_catch_segv; \
sigemptyset (&act.k_sa_mask); \
Index: prims.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/prims.cc,v
retrieving revision 1.79
diff -u -r1.79 prims.cc
--- prims.cc 25 Apr 2003 16:48:12 -0000 1.79
+++ prims.cc 12 Jun 2003 17:04:42 -0000
@@ -122,39 +122,27 @@
#endif
-extern "C" void _Jv_ThrowSignal (jthrowable) __attribute ((noreturn));
-
-// Just like _Jv_Throw, but fill in the stack trace first. Although
-// this is declared extern in order that its name not be mangled, it
-// is not intended to be used outside this file.
-void
-_Jv_ThrowSignal (jthrowable throwable)
-{
- throwable->fillInStackTrace ();
- throw throwable;
-}
-
#ifdef HANDLE_SEGV
-static java::lang::NullPointerException *nullp;
-
SIGNAL_HANDLER (catch_segv)
{
+ java::lang::NullPointerException *nullp
+ = new java::lang::NullPointerException;
MAKE_THROW_FRAME (nullp);
- _Jv_ThrowSignal (nullp);
+ throw nullp;
}
#endif
-static java::lang::ArithmeticException *arithexception;
-
#ifdef HANDLE_FPE
SIGNAL_HANDLER (catch_fpe)
{
+ java::lang::ArithmeticException *arithexception
+ = new java::lang::ArithmeticException (JvNewStringLatin1 ("/ by zero"));
#ifdef HANDLE_DIVIDE_OVERFLOW
HANDLE_DIVIDE_OVERFLOW;
#else
MAKE_THROW_FRAME (arithexception);
#endif
- _Jv_ThrowSignal (arithexception);
+ throw arithexception;
}
#endif
@@ -921,9 +909,6 @@
INIT_SEGV;
#ifdef HANDLE_FPE
INIT_FPE;
-#else
- arithexception = new java::lang::ArithmeticException
- (JvNewStringLatin1 ("/ by zero"));
#endif
no_memory = new java::lang::OutOfMemoryError;
@@ -1093,7 +1078,11 @@
_Jv_divI (jint dividend, jint divisor)
{
if (__builtin_expect (divisor == 0, false))
- _Jv_ThrowSignal (arithexception);
+ {
+ java::lang::ArithmeticException *arithexception
+ = new java::lang::ArithmeticException (JvNewStringLatin1 ("/ by zero"));
+ throw arithexception;
+ }
if (dividend == (jint) 0x80000000L && divisor == -1)
return dividend;
@@ -1105,11 +1094,15 @@
_Jv_remI (jint dividend, jint divisor)
{
if (__builtin_expect (divisor == 0, false))
- _Jv_ThrowSignal (arithexception);
+ {
+ java::lang::ArithmeticException *arithexception
+ = new java::lang::ArithmeticException (JvNewStringLatin1 ("/ by zero"));
+ throw arithexception;
+ }
if (dividend == (jint) 0x80000000L && divisor == -1)
return 0;
-
+
return dividend % divisor;
}
@@ -1117,8 +1110,12 @@
_Jv_divJ (jlong dividend, jlong divisor)
{
if (__builtin_expect (divisor == 0, false))
- _Jv_ThrowSignal (arithexception);
-
+ {
+ java::lang::ArithmeticException *arithexception
+ = new java::lang::ArithmeticException (JvNewStringLatin1 ("/ by zero"));
+ throw arithexception;
+ }
+
if (dividend == (jlong) 0x8000000000000000LL && divisor == -1)
return dividend;
@@ -1129,10 +1126,16 @@
_Jv_remJ (jlong dividend, jlong divisor)
{
if (__builtin_expect (divisor == 0, false))
- _Jv_ThrowSignal (arithexception);
-
+ {
+ java::lang::ArithmeticException *arithexception
+ = new java::lang::ArithmeticException (JvNewStringLatin1 ("/ by zero"));
+ throw arithexception;
+ }
+
if (dividend == (jlong) 0x8000000000000000LL && divisor == -1)
return 0;
return dividend % divisor;
}
+
+
Index: include/default-signal.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/default-signal.h,v
retrieving revision 1.7
diff -u -r1.7 default-signal.h
--- include/default-signal.h 19 May 2000 17:55:30 -0000 1.7
+++ include/default-signal.h 12 Jun 2003 17:04:42 -0000
@@ -24,7 +24,6 @@
#define INIT_SEGV \
do \
{ \
- nullp = new java::lang::NullPointerException (); \
signal (SIGSEGV, catch_segv); \
} \
while (0)
@@ -32,8 +31,6 @@
#define INIT_FPE \
do \
{ \
- arithexception = new java::lang::ArithmeticException \
- (JvNewStringLatin1 ("/ by zero")); \
signal (SIGFPE, catch_fpe); \
} \
while (0)
Index: include/dwarf2-signal.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/dwarf2-signal.h,v
retrieving revision 1.13
diff -u -r1.13 dwarf2-signal.h
--- include/dwarf2-signal.h 14 Jan 2003 14:02:13 -0000 1.13
+++ include/dwarf2-signal.h 12 Jun 2003 17:04:42 -0000
@@ -143,7 +143,6 @@
#define INIT_SEGV \
do \
{ \
- nullp = new java::lang::NullPointerException (); \
struct kernel_sigaction act; \
unsigned long stub = ((unsigned long)&__rt_sigreturn_stub); \
act.k_sa_sigaction = _Jv_catch_segv; \
@@ -158,8 +157,6 @@
#define INIT_FPE \
do \
{ \
- arithexception = new java::lang::ArithmeticException \
- (JvNewStringLatin1 ("/ by zero")); \
struct kernel_sigaction act; \
unsigned long stub = ((unsigned long)&__rt_sigreturn_stub); \
act.k_sa_sigaction = _Jv_catch_fpe; \
@@ -185,7 +182,6 @@
do \
{ \
struct kernel_sigaction act; \
- nullp = new java::lang::NullPointerException (); \
act.k_sa_sigaction = _Jv_catch_segv; \
act.k_sa_mask = 0; \
act.k_sa_flags = SA_SIGINFO; \
@@ -197,8 +193,6 @@
#define INIT_FPE \
do \
{ \
- arithexception = new java::lang::ArithmeticException \
- (JvNewStringLatin1 ("/ by zero")); \
struct kernel_sigaction act; \
act.k_sa_sigaction = _Jv_catch_fpe; \
act.k_sa_mask = 0; \
@@ -212,7 +206,6 @@
#define INIT_SEGV \
do \
{ \
- nullp = new java::lang::NullPointerException (); \
struct sigaction act; \
act.sa_sigaction = _Jv_catch_segv; \
sigemptyset (&act.sa_mask); \
@@ -224,8 +217,6 @@
#define INIT_FPE \
do \
{ \
- arithexception = new java::lang::ArithmeticException \
- (JvNewStringLatin1 ("/ by zero")); \
struct sigaction act; \
act.sa_sigaction = _Jv_catch_fpe; \
sigemptyset (&act.sa_mask); \
@@ -250,7 +241,6 @@
#define INIT_SEGV \
do \
{ \
- nullp = new java::lang::NullPointerException (); \
struct sigaction act; \
act.sa_sigaction = _Jv_catch_segv; \
sigemptyset (&act.sa_mask); \
@@ -262,8 +252,6 @@
#define INIT_FPE \
do \
{ \
- arithexception = new java::lang::ArithmeticException \
- (JvNewStringLatin1 ("/ by zero")); \
struct sigaction act; \
act.sa_sigaction = _Jv_catch_fpe; \
sigemptyset (&act.sa_mask); \
Index: include/i386-signal.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/i386-signal.h,v
retrieving revision 1.14
diff -u -r1.14 i386-signal.h
--- include/i386-signal.h 18 Mar 2002 17:11:43 -0000 1.14
+++ include/i386-signal.h 12 Jun 2003 17:04:43 -0000
@@ -111,7 +111,6 @@
#define INIT_SEGV \
do \
{ \
- nullp = new java::lang::NullPointerException (); \
struct old_i386_kernel_sigaction kact; \
kact.k_sa_handler = catch_segv; \
kact.k_sa_mask = 0; \
@@ -123,8 +122,6 @@
#define INIT_FPE \
do \
{ \
- arithexception = new java::lang::ArithmeticException \
- (JvNewStringLatin1 ("/ by zero")); \
struct old_i386_kernel_sigaction kact; \
kact.k_sa_handler = catch_fpe; \
kact.k_sa_mask = 0; \
Index: include/s390-signal.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/s390-signal.h,v
retrieving revision 1.1
diff -u -r1.1 s390-signal.h
--- include/s390-signal.h 29 May 2002 18:36:50 -0000 1.1
+++ include/s390-signal.h 12 Jun 2003 17:04:43 -0000
@@ -52,7 +52,6 @@
#define INIT_SEGV \
do \
{ \
- nullp = new java::lang::NullPointerException (); \
struct old_s390_kernel_sigaction kact; \
kact.k_sa_handler = catch_segv; \
kact.k_sa_mask = 0; \
@@ -64,8 +63,6 @@
#define INIT_FPE \
do \
{ \
- arithexception = new java::lang::ArithmeticException \
- (JvNewStringLatin1 ("/ by zero")); \
struct old_s390_kernel_sigaction kact; \
kact.k_sa_handler = catch_fpe; \
kact.k_sa_mask = 0; \
Index: include/sparc-signal.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/sparc-signal.h,v
retrieving revision 1.8
diff -u -r1.8 sparc-signal.h
--- include/sparc-signal.h 21 Apr 2002 09:37:49 -0000 1.8
+++ include/sparc-signal.h 12 Jun 2003 17:04:43 -0000
@@ -45,7 +45,6 @@
#define INIT_SEGV \
do \
{ \
- nullp = new java::lang::NullPointerException (); \
struct sigaction act; \
act.sa_sigaction = catch_segv; \
act.sa_flags = SA_SIGINFO | SA_NODEFER; \
@@ -57,8 +56,6 @@
#define INIT_FPE \
do \
{ \
- arithexception = new java::lang::ArithmeticException \
- (JvNewStringLatin1 ("/ by zero")); \
struct sigaction act; \
act.sa_flags = SA_SIGINFO | SA_NODEFER; \
act.sa_sigaction = catch_fpe; \
Index: include/win32-signal.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/win32-signal.h,v
retrieving revision 1.2
diff -u -r1.2 win32-signal.h
--- include/win32-signal.h 16 Jun 2000 15:52:24 -0000 1.2
+++ include/win32-signal.h 12 Jun 2003 17:04:43 -0000
@@ -26,7 +26,6 @@
#define INIT_SEGV \
do \
{ \
- nullp = new java::lang::NullPointerException (); \
} \
while (0)
@@ -34,8 +33,6 @@
#define INIT_FPE \
do \
{ \
- arithexception = new java::lang::ArithmeticException \
- (JvNewStringLatin1 ("/ by zero")); \
} \
while (0)
Index: include/x86_64-signal.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/x86_64-signal.h,v
retrieving revision 1.3
diff -u -r1.3 x86_64-signal.h
--- include/x86_64-signal.h 3 Jun 2003 16:13:22 -0000 1.3
+++ include/x86_64-signal.h 12 Jun 2003 17:04:43 -0000
@@ -64,7 +64,6 @@
#define INIT_SEGV \
do \
{ \
- nullp = new java::lang::NullPointerException (); \
struct kernel_sigaction act; \
act.k_sa_sigaction = _Jv_catch_segv; \
sigemptyset (&act.k_sa_mask); \