public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* libgcj/7532: shutdown hooks not run upon abnormal termination
@ 2002-08-07 16:16 jmr
0 siblings, 0 replies; 5+ messages in thread
From: jmr @ 2002-08-07 16:16 UTC (permalink / raw)
To: gcc-gnats
>Number: 7532
>Category: libgcj
>Synopsis: shutdown hooks not run upon abnormal termination
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Wed Aug 07 15:36:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Jesse Rosenstock
>Release: 3.3 20020806 (experimental)
>Organization:
>Environment:
System: Linux churchill 2.4.3-12 #1 Fri Jun 8 15:05:56 EDT 2001 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc/configure --prefix=/scratch/app/gcc --enable-threads=posix --enable-shared --enable-languages=c++,java
>Description:
Shutdown hooks added with Runtime.addShutdownHook() are not run
if the program terminates abnormally, ie due to Ctrl-C.
>How-To-Repeat:
W.java:
public class W {
public static void main(String[] args) throws Exception {
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
public void run() {
System.err.println("shutting down");
}
}));
final Object o = new Object();
synchronized (o) {
o.wait();
}
}
}
; gcj -C W.java
; gij W
<Ctrl-C>
<nothing is printed>
; java W
<Ctrl-C>
shutting down
>Fix:
Here's a patch that installs a signal handler to catch SIGHUP, SIGINT, and
SIGTERM. The handler calls System.exit() so the shutdown hooks run.
Installation of the signal handlers can be disabled with
--reduce-signal-usage.
Index: gij.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/gij.cc,v
retrieving revision 1.18
diff -c -r1.18 gij.cc
*** gij.cc 27 Feb 2002 05:32:13 -0000 1.18
--- gij.cc 7 Aug 2002 22:13:46 -0000
***************
*** 32,37 ****
--- 32,39 ----
printf (" --help print this help, then exit\n");
printf (" --ms=NUMBER set initial heap size\n");
printf (" --mx=NUMBER set maximum heap size\n");
+ printf (" --reduce-signal-usage\n");
+ printf (" reduce use of OS signals\n");
printf (" --version print version number, then exit\n");
printf ("\nSee http://gcc.gnu.org/java/ for information on reporting bugs\n");
exit (0);
***************
*** 115,120 ****
--- 117,124 ----
goto no_arg;
_Jv_SetMaximumHeapSize (argv[++i]);
}
+ else if (! strcmp (arg, "-reduce-signal-usage"))
+ _Jv_SetReduceSignalUsage (true);
else
{
fprintf (stderr, "gij: unrecognized option -- `%s'\n", argv[i]);
Index: posix.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/posix.cc,v
retrieving revision 1.7
diff -c -r1.7 posix.cc
*** posix.cc 7 Apr 2002 11:26:58 -0000 1.7
--- posix.cc 7 Aug 2002 22:13:46 -0000
***************
*** 17,22 ****
--- 17,23 ----
#include <signal.h>
#include <jvm.h>
+ #include <java/lang/System.h>
#include <java/lang/Thread.h>
#include <java/io/InterruptedIOException.h>
#include <java/util/Properties.h>
***************
*** 48,53 ****
--- 49,60 ----
#endif
}
+ static void
+ shutdown (int signum)
+ {
+ ::java::lang::System::exit (128 + signum);
+ }
+
// Platform-specific VM initialization.
void
_Jv_platform_initialize (void)
***************
*** 59,66 ****
--- 66,88 ----
sigemptyset (&act.sa_mask);
act.sa_flags = 0;
sigaction (SIGPIPE, &act, NULL);
+
+ if (! ::gcj::reduceSignalUsage)
+ {
+ act.sa_handler = &shutdown;
+ sigaction (SIGHUP, &act, NULL);
+ sigaction (SIGINT, &act, NULL);
+ sigaction (SIGTERM, &act, NULL);
+ }
#else
signal (SIGPIPE, SIG_IGN);
+
+ if (! ::gcj::reduceSignalUsage)
+ {
+ signal (SIGHUP, &shutdown);
+ signal (SIGINT, &shutdown);
+ signal (SIGTERM, &shutdown);
+ }
#endif
}
Index: prims.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/prims.cc,v
retrieving revision 1.72
diff -c -r1.72 prims.cc
*** prims.cc 10 Mar 2002 03:53:12 -0000 1.72
--- prims.cc 7 Aug 2002 22:13:46 -0000
***************
*** 874,879 ****
--- 874,880 ----
_Jv_Utf8Const *finit_name;
bool runtimeInitialized = false;
+ bool reduceSignalUsage = false;
}
jint
***************
*** 1051,1056 ****
--- 1052,1063 ----
{
size_t size = parse_heap_size (arg);
_Jv_GCSetMaximumHeapSize (size);
+ }
+
+ void
+ _Jv_SetReduceSignalUsage (bool reduce_signal_usage)
+ {
+ ::gcj::reduceSignalUsage = reduce_signal_usage;
}
\f
Index: include/jvm.h
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/include/jvm.h,v
retrieving revision 1.51
diff -c -r1.51 jvm.h
*** include/jvm.h 11 Apr 2002 15:57:56 -0000 1.51
--- include/jvm.h 7 Aug 2002 22:13:47 -0000
***************
*** 148,153 ****
--- 148,158 ----
/* Set to true by _Jv_CreateJavaVM. */
extern bool runtimeInitialized;
+
+ /* Controls whether or not the usage of signals by the runtime should
+ be reduced. If set to true, shutdown hooks registered with
+ Runtime.addShutdownHook() may not run upon abnormal termination. */
+ extern bool reduceSignalUsage;
};
/* Type of pointer used as finalizer. */
***************
*** 225,230 ****
--- 230,241 ----
number which can optionally have "k" or "m" appended and calls
_Jv_GCSetMaximumHeapSize. */
void _Jv_SetMaximumHeapSize (const char *arg);
+
+ /* External interface to controlling whether or not the usage of signals
+ by the runtime should be reduced. If set to true, shutdown hooks
+ registered with Runtime.addShutdownHook() may not run upon abnormal
+ termination. */
+ void _Jv_SetReduceSignalUsage (bool reduce_signal_usage);
extern "C" void JvRunMain (jclass klass, int argc, const char **argv);
void _Jv_RunMain (jclass klass, const char *name, int argc, const char **argv,
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: libgcj/7532: shutdown hooks not run upon abnormal termination
@ 2002-08-07 16:26 Andrew Pinski
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Pinski @ 2002-08-07 16:26 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR libgcj/7532; it has been noted by GNATS.
From: Andrew Pinski <pinskia@physics.uc.edu>
To: <jmr@fulcrummicro.com>
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: libgcj/7532: shutdown hooks not run upon abnormal termination
Date: Wed, 7 Aug 2002 19:09:25 -0400
I do not think you can abuse^wuse signals this way.
Thanks,
Andrew Pinski
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: libgcj/7532: shutdown hooks not run upon abnormal termination
@ 2002-08-07 16:36 Jesse Rosenstock
0 siblings, 0 replies; 5+ messages in thread
From: Jesse Rosenstock @ 2002-08-07 16:36 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR libgcj/7532; it has been noted by GNATS.
From: Jesse Rosenstock <jmr@fulcrummicro.com>
To: Andrew Pinski <pinskia@physics.uc.edu>
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: libgcj/7532: shutdown hooks not run upon abnormal termination
Date: Wed, 7 Aug 2002 16:20:56 -0700
On Wed, Aug 07, 2002 at 07:09:25PM -0400, Andrew Pinski wrote:
> I do not think you can abuse^wuse signals this way.
I wouldn't be surprised if this were an abuse, but could you be more specific?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: libgcj/7532: shutdown hooks not run upon abnormal termination
@ 2002-08-16 15:26 Tom Tromey
0 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2002-08-16 15:26 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR libgcj/7532; it has been noted by GNATS.
From: Tom Tromey <tromey@redhat.com>
To: <jmr@fulcrummicro.com>
Cc: gcc-gnats@gcc.gnu.org, Andrew Haley <aph@redhat.com>
Subject: Re: libgcj/7532: shutdown hooks not run upon abnormal termination
Date: 16 Aug 2002 16:02:16 -0600
jmr> Shutdown hooks added with Runtime.addShutdownHook() are not run
jmr> if the program terminates abnormally, ie due to Ctrl-C.
Yeah, definitely a bug.
jmr> Here's a patch that installs a signal handler to catch SIGHUP, SIGINT, and
jmr> SIGTERM. The handler calls System.exit() so the shutdown hooks run.
jmr> Installation of the signal handlers can be disabled with
jmr> --reduce-signal-usage.
I don't think we can do this stuff directly from the signal handler.
I'm not sure what a better approach is though. Maybe Andrew has an idea.
I also don't think we need a gij command-line argument to reduce
signal usage.
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: libgcj/7532: shutdown hooks not run upon abnormal termination
@ 2002-08-19 3:26 Andrew Haley
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Haley @ 2002-08-19 3:26 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR libgcj/7532; it has been noted by GNATS.
From: Andrew Haley <aph@cambridge.redhat.com>
To: tromey@redhat.com
Cc: <jmr@fulcrummicro.com>, gcc-gnats@gcc.gnu.org
Subject: Re: libgcj/7532: shutdown hooks not run upon abnormal termination
Date: Mon, 19 Aug 2002 10:08:29 +0100 (BST)
Tom Tromey writes:
> jmr> Shutdown hooks added with Runtime.addShutdownHook() are not run
> jmr> if the program terminates abnormally, ie due to Ctrl-C.
>
> Yeah, definitely a bug.
>
> jmr> Here's a patch that installs a signal handler to catch SIGHUP, SIGINT, and
> jmr> SIGTERM. The handler calls System.exit() so the shutdown hooks run.
> jmr> Installation of the signal handlers can be disabled with
> jmr> --reduce-signal-usage.
>
> I don't think we can do this stuff directly from the signal handler.
> I'm not sure what a better approach is though. Maybe Andrew has an idea.
I think it's legal to do this from a signal handler. However, we
might deadlock if a thread is inside a synchronized region at the time
the ctrl-C is caught. We could perhaps solve this by sending a
message to a dedicated shutdown thread instead of quitting immediately
but I don't know if the extra complexity can be justified.
However, we must ensure that if a second ctrl-C is received we
terminate immediately.
> I also don't think we need a gij command-line argument to reduce
> signal usage.
I agree.
Andrew.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2002-08-19 9:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-07 16:16 libgcj/7532: shutdown hooks not run upon abnormal termination jmr
2002-08-07 16:26 Andrew Pinski
2002-08-07 16:36 Jesse Rosenstock
2002-08-16 15:26 Tom Tromey
2002-08-19 3:26 Andrew Haley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).