From fd851b9380a6ef9021c5bc4389334d3930f643ea Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 12 Oct 2007 21:40:01 +0000 Subject: [PATCH] Add DetachCurrentThread back in for directors. The problems occuring on Solaris look like they were jdk bugs (1.4.2 and older) git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9983 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/java/director_thread_runme.java | 5 +---- Lib/java/director.swg | 6 +++++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Examples/test-suite/java/director_thread_runme.java b/Examples/test-suite/java/director_thread_runme.java index 6752c778b..c67d4104f 100644 --- a/Examples/test-suite/java/director_thread_runme.java +++ b/Examples/test-suite/java/director_thread_runme.java @@ -14,16 +14,13 @@ public class director_thread_runme { } public static void main(String argv[]) { - /* + // This test used to hang the process. The solution is to call DetachCurrentThread in ~JNIEnvWrapper, however it causes seg faults in other JNI calls on older JDKs on Solaris. See SWIG_JAVA_NO_DETACH_CURRENT_THREAD in director.swg. director_thread_Derived d = new director_thread_Derived(); d.run(); if (d.getVal() >= 0) { throw new RuntimeException("Failed. Val: " + d.getVal()); } - */ - // Disabled as it hangs the process. The solution of calling DetachCurrentThread in ~JNIEnvWrapper causes seg faults in other JNI calls on some machines - System.err.println("Disabled runtest - it fails"); } } diff --git a/Lib/java/director.swg b/Lib/java/director.swg index e587b931d..09e7e915e 100644 --- a/Lib/java/director.swg +++ b/Lib/java/director.swg @@ -116,7 +116,11 @@ namespace Swig { director_->swig_jvm_->AttachCurrentThread((void **) &jenv_, NULL); } ~JNIEnvWrapper() { - //director_->swig_jvm_->DetachCurrentThread(); +// Some JVMs, eg JDK 1.4.2 and lower on Solaris have a bug and crash with the DetachCurrentThread call. +// However, without this call, the JVM hangs on exit when the thread was not created by the JVM and creates a memory leak. +#if !defined(SWIG_JAVA_NO_DETACH_CURRENT_THREAD) + director_->swig_jvm_->DetachCurrentThread(); +#endif } JNIEnv *getJNIEnv() const { return jenv_;