hg: code-tools/jmh: 7901244: Forceful shutdown of forked VM when there are uncontrollable user threads

Aleksey Shipilev aleksey.shipilev at oracle.com
Tue Jan 13 12:03:06 UTC 2015


Hi Dawid,

On 01/13/2015 12:50 PM, Dawid Weiss wrote:
> Two notes about forceful exit in this commit:
> 
>> System.exit(0);
> 
> When there is user code involved my experience is that a forceful-exit
> is better done by Runtime.halt(), which doesn't try to run any
> shutdown hooks or finalizers. I've had user code that simply hung in
> those, effectively preventing the forceful exit...

Yes, but we need our own shutdown hook executed to gracefully detach
ourselves from the host VM. At the cost of some code munging, we may do
the same in the ShutdownTimeoutThread itself:
  https://bugs.openjdk.java.net/browse/CODETOOLS-7901245
  http://hg.openjdk.java.net/code-tools/jmh/rev/734a9b2a1965

I have tested both Behrooz's scenario, and HelloWorld with "stuck"
shutdown hook, and it seems to work nicely now.

> A funnier hack might be to tell the JVM to exit itself after a given
> deadline... it's my favorite JVM switch ever, after all (and yeah, I
> know it's not portable and undocumented, but who cares):
> 
>   product(intx, SelfDestructTimer, 0,                                       \
>           "Will cause VM to terminate after a given time (in minutes) "     \
>           "(0 means off)")                                                  \
> 
> Dawid

Ouch. I'll let users use that on their own. :)

Thanks,
-Aleksey



More information about the jmh-dev mailing list