超人高校免费观看:Jserv's blog: JNI_OnLoad 的非預期現象
来源:百度文库 编辑:九乡新闻网 时间:2024/04/20 03:47:29
JNI_OnLoad 的非預期現象
Alan Burlison 在 blog [JNI_OnUnload(): mostly useless] 提到 JNI_Unload 這個 JNI call 搭配 JNIInvokeInterface 的 AttachCurrentThread call 造成非預期的現象。在 kaffe/include/jni.h 中,相關的定義如下:/* These functions might be defined in librariesAlan Burlison 指出問題的癥結:
which we load; the JNI implementation calls
them at the appropriate times. */
extern JNIEXPORT jint JNICALL JNI_OnLoad (JavaVM *, void *);
extern JNIEXPORT void JNICALL JNI_OnUnload (JavaVM *, void *);
/*
* Invocation API.
*/
struct JNIInvokeInterface
{
void *reserved0;
void *reserved1;
void *reserved2;
jint (JNICALL *DestroyJavaVM) (JavaVM *);
jint (JNICALL *AttachCurrentThread) (JavaVM *, void **, void *);
jint (JNICALL *DetachCurrentThread) (JavaVM *);
jint (JNICALL *GetEnv) (JavaVM *, void **, jint);
jint (JNICALL *AttachCurrentThreadAsDaemon) (JavaVM *, void **, void *);
};
- what was puzzling me was that although JNI_OnLoad() was being called OK, JNI_OnUnload() was never being called, and because the thread was attached to the JVM via a call to AttachCurrentThread(), the JVM would never exit as it still had an active thread. A simple workaround was to attach the thread to the JVM as a daemon thread using AttachCurrentThreadAsDaemon as daemon threads don't keep the JVM alive, but that still meant the DLL wasn't being cleaned up properly.
- In light of this it appears that although JNI_OnLoad() is useful, JNI_OnUnload() is less than useful. There is a workaround, which is to register a native exit callback using Runtime.addShutdownHook() and do the cleanup that way, but it's kind of broken that JNI_OnUnload() doesn't actually do what it is supposed to, and even more odd that the JNI documentation is completely silent as to why it doesn't actually work.
Jserv's blog: JNI_OnLoad 的非預期現象
我的博客(戒定慧空'S Blog)
Xp's Blog-良好的思维方法
佛往今来(liuyq502'S Blog)
Oliver Yang's blog
Alex yu's Blog
一个学佛者真实的传奇经历(云中老鸟'S Blog)
管理能力的定义? - 蔡炎军’S BLOG - 世界经理人网站
WebLeOn's Blog: AppsGeyser:制作你自己的Android应用!
sinopharmalxq's blog - 里程碑式的肌松拮抗剂Sugammadex |...
Xp's Blog-良好的思维方法5
日志:五十条经典的爱情观 - 3w\'s Blog
麻将的必胜法 - 磨剑庐(thw‘s BLOG)
我的修行之路(云意'S Blog)
男人着装的20条“铁律” - EaSy‘s Blog
Eclipse RCP与Spring的整合 - guangnian0412‘s BLOG ...
爱因斯坦: 《我的世界观》(全文)--Fu Peishan's Blog
男人着装的20条 “铁律” - EaSy‘s Blog
电阻或电容值的选配标准 -- anxingedu‘s Blog
总结Content Provider的使用 | Marshal's Blog
男人着装的20条“铁律” - EaSy‘s Blog
更改Android设备的键盘映射 | 企鹅君's Blog
一定要记住的修行常识 (君合'S Blog)
VB变量名后跟的符号解释 ? LorDong's Blog