United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6851688 Hung up in applet application
JDK-6851688 : Hung up in applet application

Details
Type:
Bug
Submit Date:
2009-06-16
Status:
Resolved
Updated Date:
2011-01-19
Project Name:
JDK
Resolved Date:
2009-08-19
Component:
client-libs
OS:
windows_vista
Sub-Component:
java.awt
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
5.0u11
Fixed Versions:

Related Reports
Backport:
Backport:
Backport:
Backport:
Backport:
Backport:
Backport:

Sub Tasks

Description
The problem(abort/hung up) was found in customer's applet application.

JDK : 5.0u11
OS  : Windows Vista

After analyzing the dump, Fujitsu found the thread where the problem
occurred used JNIEnv* that belonged to another thread.

---
[j2se/src/windows/native/sun/windows/awt_Toolkit.cpp]
  ...
JNIEnv* AwtToolkit::m_env;
HANDLE AwtToolkit::m_thread;

void AwtToolkit::SetEnv(JNIEnv *env) {
    if (m_env != NULL) { // If already cashed (by means of embeddedInit() call).
        return;
    }
    m_thread = GetCurrentThread();
    m_env = env;
}

JNIEnv* AwtToolkit::GetEnv() {
    return (m_env == NULL || m_thread != GetCurrentThread()) ?
        (JNIEnv*)JNU_GetEnv(jvm, JNI_VERSION_1_2) : m_env;
}
---

The above snippet is where JNIEnv * was used that was set by another thread.
The code uses Windows API GetCurrentThread() that always returns a
constant according to the following page.

http://msdn.microsoft.com/en-us/library/ms683182.aspx
---
GetCurrentThread()
 Return Value
   The return value is a pseudo handle for the current thread.
 Remarks
   A pseudo handle is a special constant that is interpreted
                        ~~~~~~~~~~~~~~~~
   as the current thread handle. The calling thread can use this handle
   to specify itself whenever a thread handle is required.
   Pseudo handles are not inherited by child processes.
---

It is wrong that the AWT code uses the return value of
GetCurrentThread() as thread identity. GetCurrentThreadId() should be
used if Windows API is used.

Additionally, we found the some codes where call AwtToolkit::GetEnv()
and get returned JNIEnv* uses JNU_GetEnv(). These should to be fixed to
call JNU_GetEnv(jvm, JNI_VERSION_1_2).

                                    

Comments
EVALUATION

It is wrong that the AWT code uses the return value of
GetCurrentThread() as thread identity. GetCurrentThreadId() should be
used if Windows API is used.
                                     
2009-06-16
SUGGESTED FIX

--- old/src/windows/native/sun/windows/awt_Toolkit.cpp	Fri Jul 31 15:21:54 2009
+++ new/src/windows/native/sun/windows/awt_Toolkit.cpp	Fri Jul 31 15:21:53 2009
@@ -1596,18 +1596,18 @@
 }

 JNIEnv* AwtToolkit::m_env;
-HANDLE AwtToolkit::m_thread;
+DWORD AwtToolkit::m_threadId;

 void AwtToolkit::SetEnv(JNIEnv *env) {
     if (m_env != NULL) { // If already cashed (by means of embeddedInit() call).
         return;
     }
-    m_thread = GetCurrentThread();
+    m_threadId = GetCurrentThreadId();
     m_env = env;
 }

 JNIEnv* AwtToolkit::GetEnv() {
-    return (m_env == NULL || m_thread != GetCurrentThread()) ?
+    return (m_env == NULL || m_threadId != GetCurrentThreadId()) ?
         (JNIEnv*)JNU_GetEnv(jvm, JNI_VERSION_1_2) : m_env;
 }

--- old/src/windows/native/sun/windows/awt_Toolkit.h	Fri Jul 31 15:21:59 2009
+++ new/src/windows/native/sun/windows/awt_Toolkit.h	Fri Jul 31 15:21:57 2009
@@ -442,7 +442,7 @@

  private:
     static JNIEnv *m_env;
-    static HANDLE m_thread;
+    static DWORD m_threadId;
  public:
     static void SetEnv(JNIEnv *env);
     static JNIEnv* GetEnv();
                                     
2009-07-31



Hardware and Software, Engineered to Work Together