harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexei Fedotov" <alexei.fedo...@gmail.com>
Subject Re: DestroyJavaVM, System.exit, etc
Date Sun, 10 Feb 2008 12:21:23 GMT

Thanks for your answers! I have created a patch which modifies
shutdown sequence slightly unifying DestroyJavaVM, System.exit() and
Ctrl+C shutdown paths [1]. Could you please look at it?

The question on thread detachment is actually provoked by confusing
comment in our launcher:

  /* Updated in the 6.0 spec, we can now detach the main thread before
calling DestroyJavaVM,
     and we must if we wish main thread uncaught exception handlers to
be called. */
  (*jvm)->DestroyJavaVM (jvm);

It seems that the thread is detached second time from inside of
DestroyJavaVM function, see vm_destroy():
    // Detach current main thread.
    status = jthread_detach(java_thread);

Fortunately, the java code from execShutdownSequence from
vm/vmcore/src/kernel_classes/javasrc/java/lang/Runtime.java launches
shutdown hooks in separate threads, so the early detach does not cause
any problems for the hooks. May be we should attach the thread back in
vm_destroy to execute java code of execShutdownSequence.

Thanks again.

[1] http://issues.apache.org/jira/browse/HARMONY-5481

On Feb 9, 2008 5:02 PM, Gregory Shimansky <gshimansky@apache.org> wrote:
> Alexei Fedotov said the following on 09.02.2008 16:34:
> > Hello, folks,
> > I have some problems trying to understand the current Harmony VM
> > shutdown mechanism. I would appreciate any help from you.
> >
> >    * What is a correct place to put my own C shutdown code?
> It depends on how the application shuts down. It if finishes all
> non-daemon threads, then vm_destroy is a good place. Keep in mind that
> shutdown sequence is very fragile and it is easy to break it. If
> application exits with System.exit, then the only place is before
> _exit() in Java_java_lang_VMExecutionEngine_exit.
> >    * Why does VM detach the main thread from both the launcher and
> > vm_destroy function?
> I didn't get the question. Do you mean that main thread is attached in
> the DestroyJavaVM function? It is done because at shutdown VM has to
> execute shutdown hooks, and therefore it has to execute Java on an
> attached thread.
> >    * What is the reason for the global monitor locks and unlocks in
> > the following function? What means the comment about jobjectArray?
> > JNIEXPORT void JNICALL Java_java_lang_VMExecutionEngine_exit
> >   (JNIEnv * jni_env, jclass, jint status, jboolean needFinalization,
> > jobjectArray)
> > {
> >     // ToDo: process jobjectArray
> >     hythread_global_lock();
> >     _exit(status);
> >     hythread_global_unlock();
> > }
> It was done to fix the bug HARMONY-5167. Somehow threads could be
> created even when _exit() function is executed, so final heap check
> could produce an error on windows in debug mode.
> >    * Where are VM resources reclaimed on shutdown? I found the only
> > apr_pool_destroy(java_vm->pool) in DestroyJavaVM(). Are there any
> > other places?
> The main place is Global_Env::~Global_Env() in Environment.cpp. This
> destructor is called only in case VM exits normally. For System.exit
> destructors are not executed.
> --
> Gregory

With best regards,

View raw message