harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gshiman...@apache.org
Subject svn commit: r544123 - in /harmony/enhanced/jdktools/trunk/modules/jpda: src/main/native/jdwp/common/agent/core/ test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/
Date Mon, 04 Jun 2007 11:25:05 GMT
Author: gshimansky
Date: Mon Jun  4 04:25:04 2007
New Revision: 544123

URL: http://svn.apache.org/viewvc?view=rev&rev=544123
Log:
Applied workaround from HARMONY-3314 [jdktools][jpda] DRLVM hangs on exit while detaching
thread


Modified:
    harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/EventDispatcher.cpp
    harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/EventDispatcher.h
    harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/PacketDispatcher.cpp
    harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/PacketDispatcher.h
    harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/ThreadManager.cpp
    harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/ThreadManager.h
    harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.cpp
    harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPUnitDebuggeeWrapper.java

Modified: harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/EventDispatcher.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/EventDispatcher.cpp?view=diff&rev=544123&r1=544122&r2=544123
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/EventDispatcher.cpp
(original)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/EventDispatcher.cpp
Mon Jun  4 04:25:04 2007
@@ -36,6 +36,7 @@
     m_waitMonitor = 0;
     m_invokeMonitor = 0;
     m_completeMonitor = 0;
+    m_threadObject = 0;
     m_stopFlag = true;
     m_holdFlag = false;
     m_resetFlag = false;
@@ -55,12 +56,14 @@
                 // get next event from queue
                 {
                     MonitorAutoLock lock(m_queueMonitor JDWP_FILE_LINE);
+
                     while (m_holdFlag || m_eventQueue.empty()) {
                         m_queueMonitor->Wait();
-                        if (m_stopFlag) {
-                            return;
-                        }
+                        if (m_stopFlag) break; // break event waiting loop
                     }
+
+                    if (m_stopFlag) break; // break events handling loop
+
                     ec = m_eventQueue.front();
                     m_eventQueue.pop();
                     m_queueMonitor->NotifyAll();
@@ -79,6 +82,10 @@
             JDWP_TRACE_PROG("Run: reset session after exception");
             GetPacketDispatcher().ResetAll(jni);
         }
+
+        // release completion monitor and wait forever until VM kills this thread
+        // TODO: remove this workaround to prevent from resource leak
+        m_completeMonitor->Wait(0);
     }
     catch (const AgentException& e)
     {
@@ -109,7 +116,7 @@
 void EventDispatcher::Start(JNIEnv *jni) throw(AgentException) {
     JDWP_TRACE_ENTRY("Start(" << jni << ')');
 
-    GetThreadManager().RunAgentThread(jni, StartFunction, this,
+    m_threadObject = GetThreadManager().RunAgentThread(jni, StartFunction, this,
         JVMTI_THREAD_MAX_PRIORITY, "_jdwp_EventDispatcher");
 }
 
@@ -164,6 +171,8 @@
         MonitorAutoLock lock(m_completeMonitor JDWP_FILE_LINE);
     } 
 
+    // wait for thread finished
+//    GetThreadManager().Join(jni, m_threadObject);
 }
 
 void EventDispatcher::Clean(JNIEnv *jni) throw(AgentException) {
@@ -201,10 +210,15 @@
         delete m_invokeMonitor;
         m_invokeMonitor = 0;
     }
+
+    // do not delete m_completeMonitor because thread is waiting on it
+    // TODO: remove this workaround to prevent from resource leak
+    /*
     if (m_completeMonitor != 0){
         delete m_completeMonitor;
         m_completeMonitor = 0;
     }
+    */
 
     // clean counter for packet id
 

Modified: harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/EventDispatcher.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/EventDispatcher.h?view=diff&rev=544123&r1=544122&r2=544123
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/EventDispatcher.h
(original)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/EventDispatcher.h
Mon Jun  4 04:25:04 2007
@@ -255,6 +255,12 @@
          * Flag to reset all data.
          */
         bool volatile m_resetFlag;
+
+        /**
+         * Associated thread object.
+         */
+        jthread m_threadObject;
+
     };
 
 }

Modified: harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/PacketDispatcher.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/PacketDispatcher.cpp?view=diff&rev=544123&r1=544122&r2=544123
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/PacketDispatcher.cpp
(original)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/PacketDispatcher.cpp
Mon Jun  4 04:25:04 2007
@@ -37,9 +37,9 @@
     :AgentBase()
 {
     m_isProcessed = false;
-    m_isRunning = false;
     m_completionMonitor = 0;
     m_executionMonitor = 0;
+    m_threadObject = 0;
 }
 
 //-----------------------------------------------------------------------------
@@ -62,7 +62,7 @@
 
     try
     {
-        GetThreadManager().RunAgentThread(jni, StartFunction, this,
+        m_threadObject = GetThreadManager().RunAgentThread(jni, StartFunction, this,
             JVMTI_THREAD_MAX_PRIORITY, "_jdwp_PacketDispatcher");
     }
     catch (const AgentException& e)
@@ -83,8 +83,6 @@
     JDWP_TRACE_ENTRY("Run(" << jni << ")");
 
     try {
-        m_isRunning = true;
-        
         MonitorAutoLock lock(m_completionMonitor JDWP_FILE_LINE);
         TransportManager &transport = GetTransportManager();
         
@@ -208,7 +206,9 @@
                             << e.what() << " [" << e.ErrCode() <<
"]");
         }
 
-        m_isRunning = false;
+        // release completion monitor and wait forever until VM kills this thread
+        // TODO: remove this workaround to prevent from resource leak
+        m_completionMonitor->Wait(0);
     }
     catch (const AgentException& e)
     {
@@ -221,22 +221,20 @@
 //-----------------------------------------------------------------------------
 
 void 
-PacketDispatcher::Stop() throw(AgentException)
+PacketDispatcher::Stop(JNIEnv *jni) throw(AgentException)
 {
     JDWP_TRACE_ENTRY("Stop()");
 
-    if (!m_isRunning) return;
-
     // cause thread loop to break
     m_isProcessed = false;
     
-    // wait for thread finished
+    // wait for loop finished and EventDispatcher is also stopped
     {
         MonitorAutoLock lock(m_completionMonitor JDWP_FILE_LINE);
     }
-    JDWP_ASSERT(!m_isRunning);
 
-    // EventDispatcher is also stopped
+    // wait for thread finished
+//    GetThreadManager().Join(jni, m_threadObject);
 }
 
 void 
@@ -246,10 +244,14 @@
 
     JDWP_TRACE_PROG("Clean: clean internal data");
 
+    // do not delete m_completionMonitor because thread is waiting on it
+    // TODO: remove this workaround to prevent from resource leak
+    /*
     if (m_completionMonitor != 0) {
         delete m_completionMonitor;
         m_completionMonitor = 0;
     }
+    */
 
     if (m_executionMonitor != 0) {
         delete m_executionMonitor;
@@ -304,7 +306,7 @@
 
         // stop PacketDispatcher and EventDispatcher threads, and reset all modules
         JDWP_TRACE_PROG("ShutdownAll: stop agent threads");
-        GetPacketDispatcher().Stop();
+        GetPacketDispatcher().Stop(jni);
 
         // clean all modules
         JDWP_TRACE_PROG("ShutdownAll: clean agent modules");

Modified: harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/PacketDispatcher.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/PacketDispatcher.h?view=diff&rev=544123&r1=544122&r2=544123
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/PacketDispatcher.h
(original)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/PacketDispatcher.h
Mon Jun  4 04:25:04 2007
@@ -88,9 +88,11 @@
         /**
          * Stops the <code>PacketDispatcher</code>'s thread.
          *
+         * @param jni - the JNI interface pointer
+         *
          * @exception If any error occurs, <code>AgentException</code> is thrown.
          */
-        void Stop() throw(AgentException);
+        void Stop(JNIEnv *jni) throw(AgentException);
 
         /**
          * Resets the <code>PacketDispatcher</code> object.
@@ -165,6 +167,7 @@
         CommandDispatcher   m_cmdDispatcher;
         AgentMonitor*       m_completionMonitor;
         AgentMonitor*       m_executionMonitor;
+        jthread             m_threadObject;
 
     };//class PacketDispatcher
 

Modified: harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/ThreadManager.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/ThreadManager.cpp?view=diff&rev=544123&r1=544122&r2=544123
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/ThreadManager.cpp
(original)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/ThreadManager.cpp
Mon Jun  4 04:25:04 2007
@@ -654,6 +654,24 @@
 
 //-----------------------------------------------------------------------------
 
+void
+ThreadManager::Join(JNIEnv *jni, jthread thread)
+{
+    JDWP_TRACE_ENTRY("Join(" << jni << ',' << thread << ')');
+
+    ClassManager &clsMgr = GetClassManager();
+    jclass threadClass = clsMgr.GetThreadClass();
+
+    jmethodID joinMethodID = jni->GetMethodID(threadClass, "join", "()V");
+    clsMgr.CheckOnException(jni);
+    JDWP_ASSERT(joinMethodID != NULL);
+
+    jni->CallVoidMethod(thread, joinMethodID);
+    clsMgr.CheckOnException(jni);
+}
+
+//-----------------------------------------------------------------------------
+
 bool
 ThreadManager::IsAgentThread(JNIEnv *jni, jthread thread)
 {

Modified: harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/ThreadManager.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/ThreadManager.h?view=diff&rev=544123&r1=544122&r2=544123
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/ThreadManager.h
(original)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/ThreadManager.h
Mon Jun  4 04:25:04 2007
@@ -232,6 +232,17 @@
             throw(AgentException);
         
         /**
+         * Join the specified thread.
+         * 
+         * @param jni       - the JNI interface pointer
+         * @param thread    - the thread to be joined
+         * 
+         * @exception AgentException is thrown in case an universal 
+         *            error, with the corresponded error code.
+         */
+        void Join(JNIEnv *jni, jthread thread);
+
+        /**
          * Checks if the specified thread is an agent thread.
          *
          * @param jni    - the JNI interface pointer

Modified: harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.cpp?view=diff&rev=544123&r1=544122&r2=544123
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.cpp
(original)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.cpp
Mon Jun  4 04:25:04 2007
@@ -223,7 +223,7 @@
         CheckReturnStatus(err);
     }
     JDWP_TRACE_PROG("Connect: connection established");
-} // TransportManager::Start()
+} // TransportManager::Connect()
 
 void 
 TransportManager::Launch(const char* command) throw(TransportException)
@@ -264,13 +264,12 @@
         CheckReturnStatus(err);
     }
     JDWP_TRACE_PROG("Reset: connection closed");
-} // TransportManager::Close()
+} // TransportManager::Reset()
 
 
 void 
 TransportManager::Clean() throw(TransportException)
 {
-    JDWP_ASSERT(m_ConnectionPrepared);
     JDWP_TRACE_PROG("Clean: close connection and stop listening");
     if (m_env != 0) {
         m_env->Close();
@@ -339,4 +338,4 @@
                 << " cmdSet=" << (int)(packet->type.cmd.cmdSet) 
                 << " cmd=" << (int)(packet->type.cmd.cmd)); 
     } 
-} // TracePacket()
+} // TransportManager::TracePacket()

Modified: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPUnitDebuggeeWrapper.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPUnitDebuggeeWrapper.java?view=diff&rev=544123&r1=544122&r2=544123
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPUnitDebuggeeWrapper.java
(original)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPUnitDebuggeeWrapper.java
Mon Jun  4 04:25:04 2007
@@ -208,7 +208,11 @@
             logWriter.println("Finished debuggee with exit code: " + exitCode);
         } catch (IllegalThreadStateException e) {
             logWriter.printError("Enforced debuggee termination");
+            process.destroy();
+            throw new TestErrorException("Debuggee process did not finish during timeout",
e);
         }
+
+        // dispose any resources of the process
         process.destroy();
     }
 



Mime
View raw message