harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Evgueni Brevnov" <evgueni.brev...@gmail.com>
Subject Re: [drlvm][shutdown] How to cleanup resources safely?
Date Tue, 21 Nov 2006 13:54:17 GMT
On 11/21/06, Gregory Shimansky <gshimansky@gmail.com> wrote:
> Evgueni Brevnov wrote:
> > On 11/21/06, Xiao-Feng Li <xiaofeng.li@gmail.com> wrote:
> >> On 11/20/06, Evgueni Brevnov <evgueni.brevnov@gmail.com> wrote:
> >> > Hi All,
> >> >
> >> > I'd like to share with you my findings regarding current DRLVM
> >> > shutdown procedure (not in too many details) and discuss further steps
> >> > to improve it.
> >> >
> >> > /* General words about shutdown */
> >> >
> >> > Here is a snip from the j.l.Runtime.addShutdownHook() spec:
> >> >
> >> > "The Java virtual machine shuts down in response to two kinds of
> >> events:
> >> > 1) The program exits normally, when the last non-daemon thread exits
> >> > or when the exit (equivalently, System.exit) method is invoked, or
> >> > 2) The virtual machine is terminated in response to a user interrupt,
> >> > such as typing ^C, or a system-wide event, such as user logoff or
> >> > system shutdown."
> >> >
> >> > Except these 2 events there is one more player on the scene. It is
> >> > DestroyJavaVM defined by invocation API.User calls DestroyJavaVM to
> >> > request reclamation of  all resources owned by the VM.
> >> >
> >> > As it was discussed earlier (and I think agreed) the System.exit()
> >> > should terminate entire process the VM is running in right after it
> >> > executed shutdown hooks and finalizes. At least RI does so. Thus I
> >> > would like to look closer at the case when the last non-daemon thread
> >> > exits and the VM is requested to cleanup resources through
> >> > DestroyJavaVM. When DestroyJavaVM is called it waits until current
> >> > thread is the last non-daemon thread before cleaning up all resources
> >> > owned by the VM. It is important to note it is still possible daemon
> >> > java and native threads are running inside the VM even if there is no
> >> > running non-daemon threads.  These running threads may still be using
> >> > VM-wide data (generally located in Global_Env). Thus before cleaning
> >> > resources up we need to stop these threads somehow. Unfortunately, we
> >> > can't just kill threads. We need to release all resources (system
> >> > locks, heap/stack memory, open files/connections, etc) owed by each
> >> > thread. So the problem I'd like to discuss and solve: How to stop
> >> > running threads in a safe manner?
> >>
> >> Evgueni, when the process is stopped, why do we need care about the
> >> system resource in details if they are released by the system
> >> automatically?
> >
> > Xiao-Feng, the process is not necessarily stopped. The invocation API
> > defines standard way to create/destroy VM instances. Thus VM
> > destroying doesn't mean process termination.
>
> I want to add my 2 cents. Resources cleanup is also useful for analyzing
> memory leaks. If VM and classlib don't release their resources on
> shutdown, any memory leak analyzers would complain a lot about memory
> which wasn't released.

Yes, exactly. I was thinking about looping VM creation/destroying
operations as a good test to detect resource leaking.

Evgueni
>
> --
> Gregory
>
>

Mime
View raw message