harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gregory Shimansky <gshiman...@apache.org>
Subject Re: DestroyJavaVM, System.exit, etc
Date Sat, 09 Feb 2008 14:02:29 GMT
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.


View raw message