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

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

[Dotgnu-pnet-commits] CVS: pnet/engine heap.c,1.18,1.19 engine.h,1.80,1


From: Thong Nguyen <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/engine heap.c,1.18,1.19 engine.h,1.80,1.81 process.c,1.50,1.51
Date: Tue, 08 Jul 2003 08:05:19 -0400

Update of /cvsroot/dotgnu-pnet/pnet/engine
In directory subversions:/tmp/cvs-serv7886/engine

Modified Files:
        heap.c engine.h process.c 
Log Message:
GC & finalizer improvements.  Support for thread cleanup handlers.
 


Index: heap.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/heap.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -r1.18 -r1.19
*** heap.c      30 Jun 2003 21:49:47 -0000      1.18
--- heap.c      8 Jul 2003 12:05:17 -0000       1.19
***************
*** 26,29 ****
--- 26,32 ----
  #endif
  
+ /* TODO: Design a better way to access the main executing process */
+ static ILExecProcess *mainProcess;
+ 
  /*
   * Initialize a class.
***************
*** 31,34 ****
--- 34,40 ----
  static int InitializeClass(ILExecThread *thread, ILClass *classInfo)
  {
+       /* Cache the main process needed by finalizers */
+       mainProcess = thread->process;
+ 
        /* Quick check to see if the class is already laid out,
           to avoid acquiring the metadata lock if possible */
***************
*** 62,65 ****
--- 68,80 ----
  }
  
+ /*
+  *    Cleanup handler that is attached to the finalizer thread so that it 
unregisters
+  * itself upon closing.
+  */
+ static void DeregisterFinalizerThreadForManagedExecution(ILThread *thread)
+ {
+       ILThreadUnregisterForManagedExecution(thread);
+ }
+ 
  void _ILFinalizeObject(void *block, void *data)
  {
***************
*** 68,71 ****
--- 83,87 ----
        ILMethod *method;
        ILType *signature;
+       ILExecThread *execThread;
        
        /* Skip the object header within the block */
***************
*** 75,89 ****
        classInfo = GetObjectClass(object);
  
!       if (ILExecThreadCurrent() == 0)
        {
!               /* The thread the finalizer is running on can't execute managed 
code */
  
!               fprintf
!                       (
!                               stderr, "GC: Finalizer thread [0x%x] can't 
execute managed code.\n",
!                               (int)ILThreadSelf()
!                       );
  
!               return;
        }
        
--- 91,126 ----
        classInfo = GetObjectClass(object);
  
!       execThread = ILExecThreadCurrent();
! 
!       if (execThread == 0)
        {
!               ILThread *thread;
! 
!               /* The thread the finalizer isn't registered for managed 
execution */
!               /* Register the thread to execute managed code */
! 
!               thread = ILThreadSelf();
! 
!               if (!mainProcess)
!               {
!                       /* Impossible state */
!                       /* Finalizer on an object called before an object was 
allocated */
! 
!                       return;
!               }
! 
!               if ((execThread = 
ILThreadRegisterForManagedExecution(mainProcess, thread)) == 0)
!               {
!                       /* Registering for managed execution failed */
! 
!                       return;
!               }
  
!               /* Register a cleanup handler that will deregister the thread 
from the engine
!                   when it finishes */
!               ILThreadRegisterCleanup(thread, 
DeregisterFinalizerThreadForManagedExecution);
  
!               /* Mark the thread as a finalizer thread */
!               execThread->isFinalizerThread = 1;
        }
        

Index: engine.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/engine.h,v
retrieving revision 1.80
retrieving revision 1.81
diff -C2 -r1.80 -r1.81
*** engine.h    6 Jul 2003 00:41:16 -0000       1.80
--- engine.h    8 Jul 2003 12:05:17 -0000       1.81
***************
*** 220,223 ****
--- 220,227 ----
        ILObject *clrThread;
  
+       /* Marks this thread as a finalizer thread */
+       /* Finalizer threads are destroyed last */
+       int isFinalizerThread;
+ 
        /* Free monitors list */
        ILExecMonitor *freeMonitor;

Index: process.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/process.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -C2 -r1.50 -r1.51
*** process.c   6 Jul 2003 00:41:16 -0000       1.50
--- process.c   8 Jul 2003 12:05:17 -0000       1.51
***************
*** 148,162 ****
  void ILExecProcessDestroy(ILExecProcess *process)
  {
!       /* Deinit should run the last garbage collector
!               and a finalizer pass */
  
!       /* Tell the GC we're history */
!       ILGCDeinit();
  
        /* Wait for all foreground threads to finish */
!       if (process->firstThread != 0)
        {
!               ILThreadWaitForForegroundThreads(-1);
        }
        
        /* Destroy the CVM coder instance */
--- 148,199 ----
  void ILExecProcessDestroy(ILExecProcess *process)
  {
!       ILExecThread *thread, *next;
!       ILExecThread *firstFinalizerThread;
  
!       /* Note: All non-finalizer threads have to be destroyed *before* 
GCDeinit
!           is called so the GC can reclaim & finalize everything on those 
threads'
!               stacks - Tum */
  
        /* Wait for all foreground threads to finish */
!       ILThreadWaitForForegroundThreads(-1);
!       
!       /* Delete all non-finalizer threads */
! 
!       firstFinalizerThread = 0;
!       thread = process->firstThread;
! 
!       while (thread)
        {
!               next = thread->nextThread;
! 
!               /* Add the thread to the finalizer threads list if it is a 
finalizer thread */
!               if (thread->isFinalizerThread)
!               {
!                       if (firstFinalizerThread)
!                       {
!                               firstFinalizerThread->nextThread = thread;
!                       }
!                       else
!                       {
!                               firstFinalizerThread = thread;
!                       }
!               }
!               else
!               {
!                       /* The thread isn't a finalizer thread so destroy it */
! 
!                       ILThreadDestroy(thread->supportThread);
!                       _ILExecThreadDestroy(thread);
!               }
! 
!               thread = next;
        }
+ 
+       /* The only threads left in the process are finalizer threads */
+       process->firstThread = firstFinalizerThread;
+ 
+       /* Tell the GC we're history */ 
+       /* This performs a final collect and finalizer run */
+       ILGCDeinit();
        
        /* Destroy the CVM coder instance */





reply via email to

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