dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[dotgnu-pnet-commits] [SCM] DotGNU Portable.NET engine, compilers and to


From: Klaus Treichel
Subject: [dotgnu-pnet-commits] [SCM] DotGNU Portable.NET engine, compilers and tools (pnet) branch, master, updated. fffcb315d040a6cc6792e2994f906570cea924ec
Date: Thu, 31 Dec 2009 20:37:53 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "DotGNU Portable.NET engine, compilers and tools (pnet)".

The branch, master has been updated
       via  fffcb315d040a6cc6792e2994f906570cea924ec (commit)
      from  46170787d2b3b5f4793df24e626096433d5d173b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/pnet.git/commit/?id=fffcb315d040a6cc6792e2994f906570cea924ec

commit fffcb315d040a6cc6792e2994f906570cea924ec
Author: Klaus Treichel <address@hidden>
Date:   Thu Dec 31 21:37:39 2009 +0100

    Fix collection of threads by gc.

diff --git a/ChangeLog b/ChangeLog
index 06048f8..4d40841 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,19 @@
 2009-12-31  Klaus Treichel  <address@hidden>
 
+       * engine/engine.h (_ILExecThreadClearExecutionState): Add prototype.
+
        * engine/heap.c (_ILFinalizeObject): Reclaim the monitor still attached
        to a finalized object.
 
+       * engine/thread.c (_ILExecThreadClearExecutionState): Add function to
+       clear the data not needed anymore after execution of the thread 
finished.
+
+       * engine/lib_thread.c (__PrivateStreadStart): Clear the execution state
+       of the thread after it finished execution to allow collection of the
+       clr thread by the gc.
+       (_IL_Thread_Start): Use the new monitor implementation instead of the
+       ILWaitMonitor to lock the thread.
+
        * include/il_thread.h: Move the threading error code definitions and
        monitor prototypes from thr_defs.h to here.
 
@@ -10,6 +21,8 @@
        monitor prototypes to il_thread.h.
 
        * support/thread.c: Add more debugging support.
+       Move running the thread's cleanup functions from _ILThreadRun to
+       _ILPrivateThraedDestroy.
 
 2009-12-30  Klaus Treichel  <address@hidden>
 
diff --git a/engine/engine.h b/engine/engine.h
index 8322cf7..191304e 100644
--- a/engine/engine.h
+++ b/engine/engine.h
@@ -615,6 +615,9 @@ void ILExecEngineDestroy(ILExecEngine *engine);
  */
 ILExecEngine *ILExecEngineCreate(void);
 
+/* Clear the thread data needed only during execution */
+void _ILExecThreadClearExecutionState(ILExecThread *thread);
+
 #ifdef IL_CONFIG_APPDOMAINS
 /*
  * Let the thread return from an other ILExecProcess and restore the saved
diff --git a/engine/lib_thread.c b/engine/lib_thread.c
index dca1517..d941e01 100644
--- a/engine/lib_thread.c
+++ b/engine/lib_thread.c
@@ -200,6 +200,9 @@ static void __PrivateThreadStart(void *objectArg)
        }
 
        ILThreadClearStack(4096);
+
+       /* Clear the thread data needed only during execution */
+       _ILExecThreadClearExecutionState(thread);
 }
 
 /*
@@ -444,29 +447,37 @@ void _IL_Thread_InternalSleep(ILExecThread *thread, 
ILInt32 timeout)
  */
 void _IL_Thread_Start(ILExecThread *thread, ILObject *_this)
 {
-       ILWaitHandle *monitor;
        ILThread *supportThread;
        ILExecThread *execThread;
-
+       int result;
+       
        /* Get the support thread stored inside the first field of the 
        CLR thread by _IL_Thread_InitializeThread */
 
        supportThread = ((System_Thread *)_this)->privateData;
 
-       monitor = ILThreadGetMonitor(supportThread);
+       result = ILMonitorEnter((void **)GetObjectLockWordPtr(thread, _this));
+       if(result != IL_THREAD_OK)
+       {
+               _ILExecThreadHandleError(thread, result);
+               return;
+       }
 
-       ILWaitMonitorEnter(monitor);
-       
        if (supportThread == 0
                || (ILThreadGetState(supportThread) & IL_TS_UNSTARTED) == 0)
        {
                /* Thread has already been started or has ended. */
 
-               ILWaitMonitorLeave(monitor);
+               result = ILMonitorExit((void **)GetObjectLockWordPtr(thread, 
_this));
+               if(result != IL_THREAD_OK)
+               {
+                       _ILExecThreadHandleError(thread, result);
+                       return;
+               }
 
                ILExecThreadThrowSystem(thread, 
"System.Threading.ThreadStateException", 
                        "Exception_ThreadAlreadyStarted");
-               
+
                return;
        }
 
@@ -474,16 +485,21 @@ void _IL_Thread_Start(ILExecThread *thread, ILObject 
*_this)
 
        if ((execThread = ILThreadRegisterForManagedExecution(thread->process, 
supportThread)) == 0)
        {
-               ILWaitMonitorLeave(monitor);
+               result = ILMonitorExit((void **)GetObjectLockWordPtr(thread, 
_this));
+               if(result != IL_THREAD_OK)
+               {
+                       _ILExecThreadHandleError(thread, result);
+                       return;
+               }
 
                if ((thread->process->state & (_IL_PROCESS_STATE_UNLOADED | 
_IL_PROCESS_STATE_UNLOADING)) == 0)
                {
                        ILExecThreadThrowOutOfMemory(thread);
                }
-               
+
                return;
        }
-       
+
        /* Associate the CLR thread with the engine thread */
 
        execThread->clrThread = _this;
@@ -497,21 +513,24 @@ void _IL_Thread_Start(ILExecThread *thread, ILObject 
*_this)
                ILGCCollect();
                /* Wait a resonable amount of time (1 sec) for finalizers to 
run */
                ILGCInvokeFinalizers(1000);
-       
+
                if (ILThreadStart(supportThread) == 0)
                {
                        /* Start unsuccessful.  Destroy the engine thread */
                        /* The support thread will linger as long as the CLR 
thread does */
-
                        ILThreadUnregisterForManagedExecution(supportThread);
-                       
-                       /* Throw an OutOfMemoryException */
 
+                       /* Throw an OutOfMemoryException */
                        ILExecThreadThrowOutOfMemory(thread);
                }
        }
-       
-       ILWaitMonitorLeave(monitor);
+
+       result = ILMonitorExit((void **)GetObjectLockWordPtr(thread, _this));
+       if(result != IL_THREAD_OK)
+       {
+               _ILExecThreadHandleError(thread, result);
+               return;
+       }
 }
 
 /*
diff --git a/engine/thread.c b/engine/thread.c
index 1dccca9..1b2b89b 100644
--- a/engine/thread.c
+++ b/engine/thread.c
@@ -186,7 +186,7 @@ void _ILThreadRestoreExecContext(ILThread *thread, 
ILThreadExecContext *context)
        if (context->execThread)
        {
                context->execThread->supportThread = thread;
-       
+
                #if defined(IL_USE_INTERRUPT_BASED_X)
                        ILThreadRegisterInterruptHandler(thread, 
_ILInterruptHandler);
                #endif
@@ -229,7 +229,7 @@ static void ILExecThreadCleanup(ILThread *thread)
  * Registers a thread for managed execution
  */
 ILExecThread *ILThreadRegisterForManagedExecution(ILExecProcess *process, 
ILThread *thread)
-{      
+{
        ILExecThread *execThread;
        ILThreadExecContext context;
 
@@ -386,7 +386,7 @@ void _ILExecThreadSuspendThread(ILExecThread *thread, 
ILThread *supportThread)
        int result;
        ILWaitHandle *monitor;
        ILExecThread *execThread;
-       
+
        monitor = ILThreadGetMonitor(supportThread);
 
        /* If the thread being suspended is the current thread then suspend now 
*/
@@ -394,7 +394,7 @@ void _ILExecThreadSuspendThread(ILExecThread *thread, 
ILThread *supportThread)
        {
                /* Suspend the current thread */
                result = ILThreadSuspend(supportThread);
-       
+
                if (result == 0)
                {
                        ILExecThreadThrowSystem
@@ -409,7 +409,7 @@ void _ILExecThreadSuspendThread(ILExecThread *thread, 
ILThread *supportThread)
                else if (result < 0)
                {
                        if (_ILExecThreadHandleWaitResult(thread, result) != 0)
-                       {                               
+                       {
                                return;
                        }
                }
@@ -742,7 +742,7 @@ ILExecThread *_ILExecThreadCreate(ILExecProcess *process, 
int ignoreProcessState
 }
 
 void _ILExecThreadDestroy(ILExecThread *thread)
-{      
+{
        ILExecProcess *process = _ILExecThreadProcess(thread);
 
        if(process)
@@ -766,7 +766,7 @@ void _ILExecThreadDestroy(ILExecThread *thread)
        /* Remove associations between ILExecThread and ILThread if they
           haven't already been removed */
        if (thread->supportThread)
-       {               
+       {
                _ILThreadClearExecContext(thread->supportThread);
        }
 
@@ -796,6 +796,37 @@ void _ILExecThreadDestroy(ILExecThread *thread)
        ILGCFreePersistent(thread);
 }
 
+/* Clear the thread data needed only during execution */
+void _ILExecThreadClearExecutionState(ILExecThread *thread)
+{
+       /*
+        * Clear the clrThread so that it can be collected if it's no longer
+        * referenced from managed code.
+        */
+       thread->clrThread = 0;
+       
+#ifdef IL_USE_CVM
+       /*
+        * Clear the members in the thread that are no longer needed after
+        * execution finished.
+        */
+       /* Destroy the operand stack */
+       if(thread->stackBase)
+       {
+               ILGCFreePersistent(thread->stackBase);
+               thread->stackBase = 0;
+       }
+       /* Destroy the call frame stack */
+       if(thread->frameStack)
+       {
+               ILGCFreePersistent(thread->frameStack);
+               thread->frameStack = 0;
+       }
+       thread->frame = 0;
+       thread->stackTop = 0;
+#endif
+}
+
 ILExecProcess *ILExecThreadGetProcess(ILExecThread *thread)
 {
        return _ILExecThreadProcess(thread);
@@ -865,7 +896,7 @@ ILLocalWatch *_ILAllocLocalWatch(ILExecThread *thread)
        if((watches = (ILLocalWatch *)ILGCAllocPersistent
                                (sizeof(ILLocalWatch) * newsize)) == 0)
        {
-           thread->thrownException = thread->process->outOfMemoryObject;
+               thread->thrownException = thread->process->outOfMemoryObject;
                return 0;
        }
 
diff --git a/support/thread.c b/support/thread.c
old mode 100755
new mode 100644
index 3db7743..4324299
--- a/support/thread.c
+++ b/support/thread.c
@@ -238,7 +238,8 @@ static void _ILPrivateThreadDestroy(ILThread *thread)
        
        /* Get the complete threadstate */
        threadState.comb = ILInterlockedLoadU4(&(thread->state.comb));
-       
+
+
        /* Don't destroy the thread if it's started and not yet stopped */
        if(((threadState.split.priv & IL_TS_STOPPED) == 0) &&
           ((threadState.split.pub & IL_TS_UNSTARTED) == 0))
@@ -252,6 +253,9 @@ static void _ILPrivateThreadDestroy(ILThread *thread)
                _ILCriticalSectionLeave(&(thread->lock));
        }
 
+       /* Run and free the cleanup handlers */
+       _ILThreadRunAndFreeCleanups(thread);
+
        /* Only destroy the system thread if one was created */
        if((threadState.split.pub & IL_TS_UNSTARTED) == 0)
        {
@@ -361,9 +365,6 @@ void _ILThreadRun(ILThread *thread)
 
        thread->startArg = 0;
        
-       /* Run and free the cleanup handlers */
-       _ILThreadRunAndFreeCleanups(thread);
-       
        /* Mark the thread as stopped */
        threadState.comb = ILInterlockedLoadU4(&(thread->state.comb));
        threadState.split.priv |= IL_TS_STOPPED;

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog           |   13 +++++++++++++
 engine/engine.h     |    3 +++
 engine/lib_thread.c |   51 +++++++++++++++++++++++++++++++++++----------------
 engine/thread.c     |   47 +++++++++++++++++++++++++++++++++++++++--------
 support/thread.c    |    9 +++++----
 5 files changed, 95 insertions(+), 28 deletions(-)
 mode change 100755 => 100644 support/thread.c


hooks/post-receive
-- 
DotGNU Portable.NET engine, compilers and tools (pnet)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]