RFR(s): Support graceful application termination on Windows shutdown/logoff

David Holmes david.holmes at oracle.com
Fri Jul 24 03:01:56 UTC 2020


Hi Nikola,

I'm redirecting this to the core-libs team initially because this is an 
issue that has been raised and discussed considerably in the past 
(possibly with some misunderstanding relating to the WM_ENDSESSION 
event). The core-libs team need to confirm the intended semantics here 
and we (runtime) can then implement whatever is determined to be needed. 
Interaction with the client team for AWT interoperability may also be 
needed.

Thanks,
David

On 24/07/2020 11:47 am, Nikola Grcevski wrote:
> Hello hotspot-runtime-dev,
> 
> After some recent investigation into stale files remaining after Java process terminates
> on Windows shutdown, we noticed that there's missing support for detecting Windows
> shutdown/logoff events for interactive Java applications. Given that Java loads both
> GDI32.dll and USER32.dll, even for console applications, this means that almost all Java
> processes launched on Windows don't run any shutdown hooks at the moment on
> user logoff or system shutdown/restart.
> 
> Since Windows 7, all Windows applications that load (or transitively call) GDI32.dll or USER32.dll
> will not receive the CTRL_LOGOFF_EVENT and CTRL_SHUTDOWN_EVENT events, but
> instead they will be sent WM_ENDSESSION.
> 
> This is documented in MSDN under the following article:
> 
> https://docs.microsoft.com/en-us/windows/console/setconsolectrlhandler
> 
> It appears that this issue was logged in JSB at some point, but it was
> made duplicate of another issue:
> 
> https://bugs.openjdk.java.net/browse/JDK-8079631
> 
> The behaviour changed going from Windows Vista to Windows 7.
> 
> I've made a proposal patch to address this issue under the following webrev:
> 
> http://cr.openjdk.java.net/~adityam/nikola/wm_endsession_handling/
> 
> At the moment only AWT applications would terminate gracefully on
> shutdown/logoff, because they have support for listening on WM_ENDSESSION.
> There's a bug in the AWT code, it doesn't check for wparam upon receiving the
> event, but it will work in most cases. If this patch is accepted I can submit a
> follow-up patch for AWT to resolve the possible issues.
> 
> Finally, there are third set of events for service processes, for example
> java applications which are started with a Windows Service wrappers. These
> services work with SERVICE_ACCEPT_SHUTDOWN and SERVICE_CONTROL_SHUTDOWN.
> Once the most common case is resolved, I'd like to submit perhaps a follow-up patch
> to support graceful termination of Java as Windows service programs.
> 
> We are working to amend the MSDN documentation for SetConsoleCtrlHandler
> to specify that this behaviour change is also present on server OSs. The documentation only
> mentions the workstation OS flavours at the moment.
> 
> Thanks in advance for reviewing this.
> 
> Nikola Grcevski
> Microsoft
> 


More information about the core-libs-dev mailing list