From neil.richards at ngmr.net Thu Aug 16 08:32:32 2012 From: neil.richards at ngmr.net (Neil Richards) Date: Thu, 16 Aug 2012 16:32:32 +0100 Subject: Improve registering signal handlers in java.lang.Terminator.setup() In-Reply-To: <50237AA8.1040801@oracle.com> References: <501B8049.2020705@linux.vnet.ibm.com> <501F231C.9050300@oracle.com> <501F86FD.9040801@linux.vnet.ibm.com> <501FA5C3.6040706@oracle.com> <5020857A.30509@linux.vnet.ibm.com> <50208D13.2090006@oracle.com> <5020DCB8.4010609@oracle.com> <1344348131.28663.42.camel@chalkhill> <502149D9.6060304@oracle.com> <1344362827.27351.22.camel@chalkhill> <50225B8B.4040307@oracle.com> <1344442209.23350.232.camel@chalkhill> <50237AA8.1040801@oracle.com> Message-ID: <1345131152.2980.302.camel@chalkhill> On Thu, 2012-08-09 at 09:54 +0100, Alan Bateman wrote: > On 08/08/2012 17:10, Neil Richards wrote: > > : > > Hi Alan, > > Apologies, I confused myself about the Hotspot behaviour. > > (I was testing with 'nohup', but not checking the contents of > > 'nohup.out' for the output from my registered shutdown hook - doh!). > > > > You're correct, when running with Hotspot with 'nohup', no exception is > > thrown when trying to register a handler for SIGHUP. > > > > When running with J9 with 'nohup', the VM notices that a handler > > registered for SIGHUP is never going to get triggered, so throws the > > exception to notify the caller (of Signal.handle( )) about this. > > > > Regards, > > Neil > This probably comes back to documenting the interface between the VM and > the libraries that you and Steve are working on. In this case, > JVM_RegisterSignal is expected to return 1 when the action is SIG_IGN > where it sounds like J9 is returning -1. > > -Alan. Hi Alan, Thanks for your response. First, I think the discussion on the particular VM implementation behaviour is a slight diversion from Frank's suggested change, which I believe is all about making the Java code more robust / agnostic to the VM implementation behaviour. >From the perspective of the code in Terminator.setup(), I think the pertinent question is: Should the code try to register shutdown hook handlers for other signals if the attempt to register for one signal fails with an exception? Or, to put it another way: Should the registration of the shutdown hook handler for each signal be independent of each other? Frank's suggested change, and my argument, is that these registrations should be independent - i.e. that Terminator.setup() should register shutdown hook handlers for all (shutdown) signals that the system (VM) allows it to. It is self-evident from the Signal.handle() method that it may throw an exception on failure to register a handler - that's declared in its signature, after all - so Terminator.setup() should be coded to robustly handle that condition. Discussions on particular VM implementations' behaviours below Signal.handle() just serves to reinforce the rationale and efficacy of the suggested change, I feel. --- Having said that, and separate from the specifics of Frank's changes, I think it's interesting to consider what is the best behaviour of Signal.handle() (and JVM_RegisterSignal that underpins it). Let's consider the form of sun.misc.Signal.handle() (ignoring access modifiers for simplicity: SignalHandler handle(Signal sig, SignalHandler newHandler) throws IllegalArgumentException; So, it can return a SignalHandler object, or throw an IllegalArgumentException (IAG). If an exception is thrown, it is clear that the SignalHandler given to handle() has not been successfully registered. If, instead, a SignalHandler is returned, the returned value is generally that for the previously registered signal handler - i.e. the one that has just been replaced with the new handler. In J9's case, this is precisely the behaviour it provides: if the new handler is registered, the old handler is returned; if the new handler is not registered, an exception is thrown. However, in Hotspot's case, if the current handler is SIG_IGN, the new handler is not registered, no exception is thrown, and SIG_IGN is returned. So, on the surface, the call seems to have "succeeded", but actually, the new handler has not been registered. This behaviour forces a caller (who's interested in understanding if their new handler is actually getting registered) to understand this extra complexity in behaviour, and to do extra checking around the call to handle() in case it returns SIG_IGN to account for it. That doesn't seem to me like well-designed behaviour for the interface. I don't see any advantage gained in having this extra semantic complexity. Currently, both VMs decide not to replace SIG_IGN with any other handler, even if the SIG_IGN has been set up via a previous call to Signal.handle(). Thus setting a signal to be ignored is a one-way street to a dead end (in a vehicle with no reverse). But note that this behaviour is a choice of the VM (implementer). It isn't inherently the case that signal set to SIG_IGN can't be replaced with another action (at the C level), only that the JVM chooses never to do so. Perhaps in the future, Java might wish to allow the overriding of SIG_IGN signal handlers set up via a previous call to Signal.handle(), whilst respecting the setting if it has genuinely come from the OS / environment. (Also note this isn't only an issue for the HUP signal, either - using "trap '' SIGNUM" can set up (almost) any signal to be ignored.) So I'd submit J9's behaviour for JVM_RegisterSignal would be the better on which to standardize. --- However, I still consider that VM modification would be logically orthogonal to Frank's suggested change, and suggest that his change could continue to be approved for contribution at this point, regardless of the separate VM-related discussion in this area. Please get back to me with your thoughts and comments on any of the above. (If you agree to the separation of concerns I suggest, perhaps the discussion of the VM-related behaviour should be split to a separate thread ?) Regards, Neil -- Unless stated above: IBM email: neil_richards at uk.ibm.com IBM United Kingdom Limited - Registered in England and Wales with number 741598. Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU From dingxmin at linux.vnet.ibm.com Tue Aug 21 19:11:54 2012 From: dingxmin at linux.vnet.ibm.com (Frank Ding) Date: Wed, 22 Aug 2012 10:11:54 +0800 Subject: Improve registering signal handlers in java.lang.Terminator.setup() In-Reply-To: <502E079F.1080706@oracle.com> References: <501B8049.2020705@linux.vnet.ibm.com> <501F231C.9050300@oracle.com> <501F86FD.9040801@linux.vnet.ibm.com> <501FA5C3.6040706@oracle.com> <5020857A.30509@linux.vnet.ibm.com> <50208D13.2090006@oracle.com> <5020DCB8.4010609@oracle.com> <1344348131.28663.42.camel@chalkhill> <502149D9.6060304@oracle.com> <1344362827.27351.22.camel@chalkhill> <50225B8B.4040307@oracle.com> <1344442209.23350.232.camel@chalkhill> <50237AA8.1040801@oracle.com> <1345131152.2980.302.camel@chalkhill> <502E079F.1080706@oracle.com> Message-ID: <50343FEA.4060700@linux.vnet.ibm.com> Hi Alan and David, So is it OK to commit the patch in Terminator class? I think Neil will continue proposing the change in cvmi mailing list. Many thanks to all. Best regards, Frank On 8/17/2012 4:58 PM, Alan Bateman wrote: > On 16/08/2012 16:32, Neil Richards wrote: >> : >> >> However, I still consider that VM modification would be logically >> orthogonal to Frank's suggested change, and suggest that his change >> could continue to be approved for contribution at this point, regardless >> of the separate VM-related discussion in this area. >> > Both David and I have already reviewed Frank's change and okay with it. > > I'll leave it to you whether you want to propose a change to > JVM_RegisterSignal. > > -Alan > From david.holmes at oracle.com Tue Aug 21 19:13:38 2012 From: david.holmes at oracle.com (David Holmes) Date: Wed, 22 Aug 2012 12:13:38 +1000 Subject: Improve registering signal handlers in java.lang.Terminator.setup() In-Reply-To: <50343FEA.4060700@linux.vnet.ibm.com> References: <501B8049.2020705@linux.vnet.ibm.com> <501F231C.9050300@oracle.com> <501F86FD.9040801@linux.vnet.ibm.com> <501FA5C3.6040706@oracle.com> <5020857A.30509@linux.vnet.ibm.com> <50208D13.2090006@oracle.com> <5020DCB8.4010609@oracle.com> <1344348131.28663.42.camel@chalkhill> <502149D9.6060304@oracle.com> <1344362827.27351.22.camel@chalkhill> <50225B8B.4040307@oracle.com> <1344442209.23350.232.camel@chalkhill> <50237AA8.1040801@oracle.com> <1345131152.2980.302.camel@chalkhill> <502E079F.1080706@oracle.com> <50343FEA.4060700@linux.vnet.ibm.com> Message-ID: <50344052.1040200@oracle.com> On 22/08/2012 12:11 PM, Frank Ding wrote: > Hi Alan and David, > So is it OK to commit the patch in Terminator class? I think Neil will > continue proposing the change in cvmi mailing list. As Alan already said: "Both David and I have already reviewed Frank's change and okay with it." Cheers, David > Many thanks to all. > > Best regards, > Frank > > On 8/17/2012 4:58 PM, Alan Bateman wrote: >> On 16/08/2012 16:32, Neil Richards wrote: >>> : >>> >>> However, I still consider that VM modification would be logically >>> orthogonal to Frank's suggested change, and suggest that his change >>> could continue to be approved for contribution at this point, regardless >>> of the separate VM-related discussion in this area. >>> >> Both David and I have already reviewed Frank's change and okay with it. >> >> I'll leave it to you whether you want to propose a change to >> JVM_RegisterSignal. >> >> -Alan >> > From dingxmin at linux.vnet.ibm.com Thu Aug 23 01:05:13 2012 From: dingxmin at linux.vnet.ibm.com (Frank Ding) Date: Thu, 23 Aug 2012 16:05:13 +0800 Subject: Improve registering signal handlers in java.lang.Terminator.setup() In-Reply-To: <50344052.1040200@oracle.com> References: <501B8049.2020705@linux.vnet.ibm.com> <501F231C.9050300@oracle.com> <501F86FD.9040801@linux.vnet.ibm.com> <501FA5C3.6040706@oracle.com> <5020857A.30509@linux.vnet.ibm.com> <50208D13.2090006@oracle.com> <5020DCB8.4010609@oracle.com> <1344348131.28663.42.camel@chalkhill> <502149D9.6060304@oracle.com> <1344362827.27351.22.camel@chalkhill> <50225B8B.4040307@oracle.com> <1344442209.23350.232.camel@chalkhill> <50237AA8.1040801@oracle.com> <1345131152.2980.302.camel@chalkhill> <502E079F.1080706@oracle.com> <50343FEA.4060700@linux.vnet.ibm.com> <50344052.1040200@oracle.com> Message-ID: <5035E439.50402@linux.vnet.ibm.com> Thanks all. I created sun bug 7193463 to track the code change. Best regards, Frank On 8/22/2012 10:13 AM, David Holmes wrote: > On 22/08/2012 12:11 PM, Frank Ding wrote: >> Hi Alan and David, >> So is it OK to commit the patch in Terminator class? I think Neil will >> continue proposing the change in cvmi mailing list. > > As Alan already said: > > "Both David and I have already reviewed Frank's change and okay with it." > > Cheers, > David > >> Many thanks to all. >> >> Best regards, >> Frank >> >> On 8/17/2012 4:58 PM, Alan Bateman wrote: >>> On 16/08/2012 16:32, Neil Richards wrote: >>>> : >>>> >>>> However, I still consider that VM modification would be logically >>>> orthogonal to Frank's suggested change, and suggest that his change >>>> could continue to be approved for contribution at this point, >>>> regardless >>>> of the separate VM-related discussion in this area. >>>> >>> Both David and I have already reviewed Frank's change and okay with it. >>> >>> I'll leave it to you whether you want to propose a change to >>> JVM_RegisterSignal. >>> >>> -Alan >>> >> > From david.holmes at oracle.com Thu Aug 23 01:27:58 2012 From: david.holmes at oracle.com (David Holmes) Date: Thu, 23 Aug 2012 18:27:58 +1000 Subject: Improve registering signal handlers in java.lang.Terminator.setup() In-Reply-To: <5035E439.50402@linux.vnet.ibm.com> References: <501B8049.2020705@linux.vnet.ibm.com> <501F231C.9050300@oracle.com> <501F86FD.9040801@linux.vnet.ibm.com> <501FA5C3.6040706@oracle.com> <5020857A.30509@linux.vnet.ibm.com> <50208D13.2090006@oracle.com> <5020DCB8.4010609@oracle.com> <1344348131.28663.42.camel@chalkhill> <502149D9.6060304@oracle.com> <1344362827.27351.22.camel@chalkhill> <50225B8B.4040307@oracle.com> <1344442209.23350.232.camel@chalkhill> <50237AA8.1040801@oracle.com> <1345131152.2980.302.camel@chalkhill> <502E079F.1080706@oracle.com> <50343FEA.4060700@linux.vnet.ibm.com> <50344052.1040200@oracle.com> <5035E439.50402@linux.vnet.ibm.com> Message-ID: <5035E98E.1050303@oracle.com> On 23/08/2012 6:05 PM, Frank Ding wrote: > Thanks all. I created sun bug 7193463 to track the code change. We already have 7189865 for this. David > Best regards, > Frank > > On 8/22/2012 10:13 AM, David Holmes wrote: >> On 22/08/2012 12:11 PM, Frank Ding wrote: >>> Hi Alan and David, >>> So is it OK to commit the patch in Terminator class? I think Neil will >>> continue proposing the change in cvmi mailing list. >> >> As Alan already said: >> >> "Both David and I have already reviewed Frank's change and okay with it." >> >> Cheers, >> David >> >>> Many thanks to all. >>> >>> Best regards, >>> Frank >>> >>> On 8/17/2012 4:58 PM, Alan Bateman wrote: >>>> On 16/08/2012 16:32, Neil Richards wrote: >>>>> : >>>>> >>>>> However, I still consider that VM modification would be logically >>>>> orthogonal to Frank's suggested change, and suggest that his change >>>>> could continue to be approved for contribution at this point, >>>>> regardless >>>>> of the separate VM-related discussion in this area. >>>>> >>>> Both David and I have already reviewed Frank's change and okay with it. >>>> >>>> I'll leave it to you whether you want to propose a change to >>>> JVM_RegisterSignal. >>>> >>>> -Alan >>>> >>> >> > From dingxmin at linux.vnet.ibm.com Thu Aug 23 01:37:32 2012 From: dingxmin at linux.vnet.ibm.com (Frank Ding) Date: Thu, 23 Aug 2012 16:37:32 +0800 Subject: Improve registering signal handlers in java.lang.Terminator.setup() In-Reply-To: <5035E98E.1050303@oracle.com> References: <501B8049.2020705@linux.vnet.ibm.com> <501F231C.9050300@oracle.com> <501F86FD.9040801@linux.vnet.ibm.com> <501FA5C3.6040706@oracle.com> <5020857A.30509@linux.vnet.ibm.com> <50208D13.2090006@oracle.com> <5020DCB8.4010609@oracle.com> <1344348131.28663.42.camel@chalkhill> <502149D9.6060304@oracle.com> <1344362827.27351.22.camel@chalkhill> <50225B8B.4040307@oracle.com> <1344442209.23350.232.camel@chalkhill> <50237AA8.1040801@oracle.com> <1345131152.2980.302.camel@chalkhill> <502E079F.1080706@oracle.com> <50343FEA.4060700@linux.vnet.ibm.com> <50344052.1040200@oracle.com> <5035E439.50402@linux.vnet.ibm.com> <5035E98E.1050303@oracle.com> Message-ID: <5035EBCC.7060502@linux.vnet.ibm.com> Hi David, Sorry that Jonathan has already committed the code with bug id 7193463. Could you please dup the 2 bugs? Best regards, Frank On 8/23/2012 4:27 PM, David Holmes wrote: > On 23/08/2012 6:05 PM, Frank Ding wrote: >> Thanks all. I created sun bug 7193463 to track the code change. > > We already have 7189865 for this. > > David > >> Best regards, >> Frank >> >> On 8/22/2012 10:13 AM, David Holmes wrote: >>> On 22/08/2012 12:11 PM, Frank Ding wrote: >>>> Hi Alan and David, >>>> So is it OK to commit the patch in Terminator class? I think Neil will >>>> continue proposing the change in cvmi mailing list. >>> >>> As Alan already said: >>> >>> "Both David and I have already reviewed Frank's change and okay with >>> it." >>> >>> Cheers, >>> David >>> >>>> Many thanks to all. >>>> >>>> Best regards, >>>> Frank >>>> >>>> On 8/17/2012 4:58 PM, Alan Bateman wrote: >>>>> On 16/08/2012 16:32, Neil Richards wrote: >>>>>> : >>>>>> >>>>>> However, I still consider that VM modification would be logically >>>>>> orthogonal to Frank's suggested change, and suggest that his change >>>>>> could continue to be approved for contribution at this point, >>>>>> regardless >>>>>> of the separate VM-related discussion in this area. >>>>>> >>>>> Both David and I have already reviewed Frank's change and okay >>>>> with it. >>>>> >>>>> I'll leave it to you whether you want to propose a change to >>>>> JVM_RegisterSignal. >>>>> >>>>> -Alan >>>>> >>>> >>> >> > From david.holmes at oracle.com Thu Aug 23 03:38:46 2012 From: david.holmes at oracle.com (David Holmes) Date: Thu, 23 Aug 2012 20:38:46 +1000 Subject: Improve registering signal handlers in java.lang.Terminator.setup() In-Reply-To: <5035EBCC.7060502@linux.vnet.ibm.com> References: <501B8049.2020705@linux.vnet.ibm.com> <501F231C.9050300@oracle.com> <501F86FD.9040801@linux.vnet.ibm.com> <501FA5C3.6040706@oracle.com> <5020857A.30509@linux.vnet.ibm.com> <50208D13.2090006@oracle.com> <5020DCB8.4010609@oracle.com> <1344348131.28663.42.camel@chalkhill> <502149D9.6060304@oracle.com> <1344362827.27351.22.camel@chalkhill> <50225B8B.4040307@oracle.com> <1344442209.23350.232.camel@chalkhill> <50237AA8.1040801@oracle.com> <1345131152.2980.302.camel@chalkhill> <502E079F.1080706@oracle.com> <50343FEA.4060700@linux.vnet.ibm.com> <50344052.1040200@oracle.com> <5035E439.50402@linux.vnet.ibm.com> <5035E98E.1050303@oracle.com> <5035EBCC.7060502@linux.vnet.ibm.com> Message-ID: <50360835.5010106@oracle.com> On 23/08/2012 6:37 PM, Frank Ding wrote: > Hi David, > Sorry that Jonathan has already committed the code with bug id 7193463. > Could you please dup the 2 bugs? Alan has already taken care of it. David > Best regards, > Frank > > On 8/23/2012 4:27 PM, David Holmes wrote: >> On 23/08/2012 6:05 PM, Frank Ding wrote: >>> Thanks all. I created sun bug 7193463 to track the code change. >> >> We already have 7189865 for this. >> >> David >> >>> Best regards, >>> Frank >>> >>> On 8/22/2012 10:13 AM, David Holmes wrote: >>>> On 22/08/2012 12:11 PM, Frank Ding wrote: >>>>> Hi Alan and David, >>>>> So is it OK to commit the patch in Terminator class? I think Neil will >>>>> continue proposing the change in cvmi mailing list. >>>> >>>> As Alan already said: >>>> >>>> "Both David and I have already reviewed Frank's change and okay with >>>> it." >>>> >>>> Cheers, >>>> David >>>> >>>>> Many thanks to all. >>>>> >>>>> Best regards, >>>>> Frank >>>>> >>>>> On 8/17/2012 4:58 PM, Alan Bateman wrote: >>>>>> On 16/08/2012 16:32, Neil Richards wrote: >>>>>>> : >>>>>>> >>>>>>> However, I still consider that VM modification would be logically >>>>>>> orthogonal to Frank's suggested change, and suggest that his change >>>>>>> could continue to be approved for contribution at this point, >>>>>>> regardless >>>>>>> of the separate VM-related discussion in this area. >>>>>>> >>>>>> Both David and I have already reviewed Frank's change and okay >>>>>> with it. >>>>>> >>>>>> I'll leave it to you whether you want to propose a change to >>>>>> JVM_RegisterSignal. >>>>>> >>>>>> -Alan >>>>>> >>>>> >>>> >>> >> >