Skip to main content

CVM_EMBEDDED_HOOK CVMhookVMShutdown and Runtime.addShutdownHook()

6 replies [Last post]
john_silver
Offline
Joined: 2006-11-13
Points: 0

Hello all, I have a simple question that might bring more complex ones further down the road, but let us start simple shall we !

Why are the hooks not implemented by default ?

In share/javavm/include/hook.h
/* NOTE: The implementation of the following functions is to be provided
by the user of the hook functionality if CVM_EMBEDDED_HOOK is defined.
The shared code will not provide any implementations.
*/

We just want to use Runtime.addShutdownHook(Thread). But our thread is never runned, Shutdown(.java).sequence() is never called.

Am I missing something or we should implement the methods specified in share/javavm/include/hook.h ourselves to notify accordingly the JVM by calling sequence() or ... ?

Thank you for your time.

John

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
john_silver
Offline
Joined: 2006-11-13
Points: 0

Thanks Dean for the hints.
Unfortunatly I did not get the approval to do it, the time required is to long :)
So I did a little java signal handler with some jni, took me a day and it works flawlessy.
Had to be carefull to notify signals only from the registered thread. Through a *Listerner* interface we call System.exit(...) or do some clean up in our main thread. Easy and speedy :)

I might look at it on my free time, if my robots allow me to :)

Thanks again

John

xyzzy
Offline
Joined: 2006-08-30
Points: 0

Glad to hear it.

Dean

john_silver
Offline
Joined: 2006-11-13
Points: 0

Thank you for the reply.

Is there a reason why it is not handled ?
Any hint as the placement of such code and general directions. Not concerning the signal handling itself, but more stuff to look out for inside the VM. I have to do it, so might as well do it right and nice so I can contribute it back to the project.

Thanks

John

xyzzy
Offline
Joined: 2006-08-30
Points: 0

> Thank you for the reply.
>
> Is there a reason why it is not handled ?
> Any hint as the placement of such code and general
> directions. Not concerning the signal handling
> itself, but more stuff to look out for inside the VM.
> I have to do it, so might as well do it right and
> nice so I can contribute it back to the project.
>
> Thanks
>
> John

As far as I know it is not required by any spec, and it could be tricky to make it work on all platforms. However, if you want to take a shot at it, I suggest you look at how Java SE does it with the Terminator class. Another question is, what happens if the app also wants to catch ^C? One thing to look out for is doing work in the asynchronous signal handler, which can lead to deadlocks. It is usually safer to signal a thread that is waiting.

Dean

john_silver
Offline
Joined: 2006-11-13
Points: 0

Ok, too much simplicity and info missing :)

The hooks we are interested are not the normal ones when System.exit() is called. We want the Ctrl^C | kill ones. I do not know if it is a SIGNAL handling problem. When my test program exit normaly, I do see that it goes all the way:

Shutdown.add IN new shutdown hook: Thread[Thread-0,5,main]
Shutdown.add OUT
Waiting 5 seconds for Ctrl^C or kill...
5 seconds later...
Shutdown.exit IN 1
Shutdown.sequence() IN
Shutdown.runHooks IN
Shutdown.runHooks started Thread[Thread-0,5,main]
Shutdown Hook Has Been Called!
Shutdown.runHooks OUT

But when actualy doing the Ctrl^C

Shutdown.add IN new shutdown hook: Thread[Thread-0,5,main]
Shutdown.add OUT
Waiting 5 seconds for Ctrl^C or kill...

and nothing after a Ctrl^C or kill.
So that changes a lot from the previous statement.

Could somebody help to find out why the hooks are not working on a SIGINT ?
Is it a known issue, or am I the only one not being able to use correctly the addShutdownHook with a SIGINT ?
I am running cdc on arm(strong,xscale),x86 and all are giving the same results.
I am running the latest release b34-04_oct_2007.

Thanks.

John

xyzzy
Offline
Joined: 2006-08-30
Points: 0

This JVM doesn't catch SIGINT like Java SE. If you want to catch a signal and then call exit(), then you can add native code to do this.

Dean