Index: modules/jpda/src/main/native/jdwp/common/agent/core/ThreadManager.cpp =================================================================== --- modules/jpda/src/main/native/jdwp/common/agent/core/ThreadManager.cpp (revision 540936) +++ modules/jpda/src/main/native/jdwp/common/agent/core/ThreadManager.cpp (working copy) @@ -654,6 +654,24 @@ //----------------------------------------------------------------------------- +void +ThreadManager::Join(JNIEnv *jni, jthread thread) +{ + JDWP_TRACE_ENTRY("Join(" << jni << ',' << thread << ')'); + + ClassManager &clsMgr = GetClassManager(); + + jclass klass = clsMgr.GetThreadClass(); + + jmethodID methodID = jni->GetMethodID(klass, "join", "()V"); + + jni->CallVoidMethod(thread, methodID); + + clsMgr.CheckOnException(jni); +} + +//----------------------------------------------------------------------------- + bool ThreadManager::IsAgentThread(JNIEnv *jni, jthread thread) { Index: modules/jpda/src/main/native/jdwp/common/agent/core/PacketDispatcher.cpp =================================================================== --- modules/jpda/src/main/native/jdwp/common/agent/core/PacketDispatcher.cpp (revision 540936) +++ modules/jpda/src/main/native/jdwp/common/agent/core/PacketDispatcher.cpp (working copy) @@ -40,6 +40,7 @@ m_isRunning = false; m_completionMonitor = 0; m_executionMonitor = 0; + myThread = NULL; } //----------------------------------------------------------------------------- @@ -62,7 +63,7 @@ try { - GetThreadManager().RunAgentThread(jni, StartFunction, this, + myThread = GetThreadManager().RunAgentThread(jni, StartFunction, this, JVMTI_THREAD_MAX_PRIORITY, "_jdwp_PacketDispatcher"); } catch (const AgentException& e) @@ -221,7 +222,7 @@ //----------------------------------------------------------------------------- void -PacketDispatcher::Stop() throw(AgentException) +PacketDispatcher::Stop(JNIEnv *jni) throw(AgentException) { JDWP_TRACE_ENTRY("Stop()"); @@ -230,13 +231,15 @@ // cause thread loop to break m_isProcessed = false; - // wait for thread finished + // wait for Run method finished { MonitorAutoLock lock(m_completionMonitor JDWP_FILE_LINE); } JDWP_ASSERT(!m_isRunning); // EventDispatcher is also stopped + + GetThreadManager().Join(jni, myThread); } void @@ -304,7 +307,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"); Index: modules/jpda/src/main/native/jdwp/common/agent/core/EventDispatcher.h =================================================================== --- modules/jpda/src/main/native/jdwp/common/agent/core/EventDispatcher.h (revision 540936) +++ modules/jpda/src/main/native/jdwp/common/agent/core/EventDispatcher.h (working copy) @@ -255,6 +255,12 @@ * Flag to reset all data. */ bool volatile m_resetFlag; + + /** + * Dispatcher's thread. + */ + jthread myThread; + }; } Index: modules/jpda/src/main/native/jdwp/common/agent/core/ThreadManager.h =================================================================== --- modules/jpda/src/main/native/jdwp/common/agent/core/ThreadManager.h (revision 540936) +++ modules/jpda/src/main/native/jdwp/common/agent/core/ThreadManager.h (working copy) @@ -232,6 +232,14 @@ throw(AgentException); /** + * Join the specified thread. + * + * @param jni - the JNI interface pointer + * @param thread - the thread to be joined + */ + void Join(JNIEnv *jni, jthread thread); + + /** * Checks if the specified thread is an agent thread. * * @param jni - the JNI interface pointer Index: modules/jpda/src/main/native/jdwp/common/agent/core/PacketDispatcher.h =================================================================== --- modules/jpda/src/main/native/jdwp/common/agent/core/PacketDispatcher.h (revision 540936) +++ modules/jpda/src/main/native/jdwp/common/agent/core/PacketDispatcher.h (working copy) @@ -88,9 +88,11 @@ /** * Stops the PacketDispatcher's thread. * + * @param jni - the JNI interface pointer + * * @exception If any error occurs, AgentException is thrown. */ - void Stop() throw(AgentException); + void Stop(JNIEnv *jni) throw(AgentException); /** * Resets the PacketDispatcher object. @@ -165,6 +167,7 @@ CommandDispatcher m_cmdDispatcher; AgentMonitor* m_completionMonitor; AgentMonitor* m_executionMonitor; + jthread myThread; };//class PacketDispatcher Index: modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.cpp =================================================================== --- modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.cpp (revision 540936) +++ modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.cpp (working copy) @@ -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,7 +264,7 @@ CheckReturnStatus(err); } JDWP_TRACE_PROG("Reset: connection closed"); -} // TransportManager::Close() +} // TransportManager::Reset() void @@ -339,4 +339,4 @@ << " cmdSet=" << (int)(packet->type.cmd.cmdSet) << " cmd=" << (int)(packet->type.cmd.cmd)); } -} // TracePacket() +} // TransportManager::TracePacket() Index: modules/jpda/src/main/native/jdwp/common/agent/core/EventDispatcher.cpp =================================================================== --- modules/jpda/src/main/native/jdwp/common/agent/core/EventDispatcher.cpp (revision 540936) +++ modules/jpda/src/main/native/jdwp/common/agent/core/EventDispatcher.cpp (working copy) @@ -109,7 +109,7 @@ void EventDispatcher::Start(JNIEnv *jni) throw(AgentException) { JDWP_TRACE_ENTRY("Start(" << jni << ')'); - GetThreadManager().RunAgentThread(jni, StartFunction, this, + myThread = GetThreadManager().RunAgentThread(jni, StartFunction, this, JVMTI_THREAD_MAX_PRIORITY, "_jdwp_EventDispatcher"); } @@ -164,6 +164,8 @@ MonitorAutoLock lock(m_completeMonitor JDWP_FILE_LINE); } + // wait for thread finishing + GetThreadManager().Join(jni, myThread); } void EventDispatcher::Clean(JNIEnv *jni) throw(AgentException) { Index: modules/jpda/make/exclude.windows.x86.drl =================================================================== --- modules/jpda/make/exclude.windows.x86.drl (revision 540936) +++ modules/jpda/make/exclude.windows.x86.drl (working copy) @@ -1,2 +0,0 @@ -#3377 (Windows only) -org/apache/harmony/jpda/tests/jdwp/MultiSession/ListenConnectorTest.java