Browse Source

Add stack GC write barriers

Greg 14 years ago
parent
commit
7963ca453b
3 changed files with 40 additions and 7 deletions
  1. 3 0
      gmsrc/doc/ChangeLog.txt
  2. 3 3
      gmsrc/doc/ToDoList.txt
  3. 34 4
      gmsrc/src/gm/gmThread.cpp

+ 3 - 0
gmsrc/doc/ChangeLog.txt

@@ -391,3 +391,6 @@ o Fixed GC root scan to ignore persistent objects.
 
 
 4/10/11
 4/10/11
 o Fixed GC tricolor invariance wasn't preserved with local object transfer of ownership.
 o Fixed GC tricolor invariance wasn't preserved with local object transfer of ownership.
+
+7/10/11
+o Fixed GC (Another attempt)

+ 3 - 3
gmsrc/doc/ToDoList.txt

@@ -5,11 +5,10 @@ In no particular order unless otherwise specified.  No time
 frame for changes or features, so effectively a wish list.
 frame for changes or features, so effectively a wish list.
 -----------------------------------------------------------
 -----------------------------------------------------------
 
 
-o Add 64bit MSVC GME build configs for testing and use
 o Fix issue where reported error line is not exact.  Occurs due to instruction pointer increment before exception handling.
 o Fix issue where reported error line is not exact.  Occurs due to instruction pointer increment before exception handling.
 o Fix empty / commented out script from producing parse error. Work around: Add a ';' semicolon to end of source, or ignore known empty scripts.
 o Fix empty / commented out script from producing parse error. Work around: Add a ';' semicolon to end of source, or ignore known empty scripts.
 o Change overide 'this' syntax from this:func() to func<this>() to support member chains eg. a.b.c<t>()
 o Change overide 'this' syntax from this:func() to func<this>() to support member chains eg. a.b.c<t>()
-o Put ++, -- operators back, but don't let them be used in conditions for consistency.
+o Put ++, -- operators back, but perhaps don't let them be used in conditions for consistency.
 
 
 o Make string hash table resize for efficiency in string intensive applications.
 o Make string hash table resize for efficiency in string intensive applications.
 o Make compiler thread safe.  Probably by moving to Lemon parser and Flex++.
 o Make compiler thread safe.  Probably by moving to Lemon parser and Flex++.
@@ -28,4 +27,5 @@ o Possibly store the 'color' bit and 'persistent' bit flags for GCObjects in the
 o Possibly change the double linked list to a single XOR encoded link.  This CPU for memory trade may not be worthwhile.
 o Possibly change the double linked list to a single XOR encoded link.  This CPU for memory trade may not be worthwhile.
 
 
 Done
 Done
-o Make 64bit compatible.
+o Make 64bit compatible.
+o Add 64bit MSVC GME build configs for testing and use

+ 34 - 4
gmsrc/src/gm/gmThread.cpp

@@ -901,6 +901,17 @@ gmThread::State gmThread::Sys_Execute(gmVariable * a_return)
       case BC_SETLOCAL :
       case BC_SETLOCAL :
       {
       {
         gmuint32 offset = OPCODE_INT(instruction);
         gmuint32 offset = OPCODE_INT(instruction);
+
+        // Write barrier old local objects
+        {
+          gmGarbageCollector* gc = m_machine->GetGC();
+          if( !gc->IsOff() && base[offset].IsReference() )
+          {
+            gmObject * object = GM_MOBJECT(m_machine, base[offset].m_value.m_ref);
+            gc->WriteBarrier(object);
+          }
+        }
+
         base[offset] = *(--top);
         base[offset] = *(--top);
         break;
         break;
       }
       }
@@ -1061,6 +1072,22 @@ gmThread::State gmThread::PushStackFrame(int a_numParameters, const gmuint8 ** a
 
 
     int result = fn->m_cFunction(this);
     int result = fn->m_cFunction(this);
 
 
+    // Write barrier old local objects at native pop time
+    {
+      gmGarbageCollector* gc = m_machine->GetGC();
+      if( !gc->IsOff() )
+      {
+        for(int index = m_base; index < m_top; ++index)
+        {
+          if(m_stack[index].IsReference())
+          {
+            gmObject * object = GM_MOBJECT(m_machine, m_stack[index].m_value.m_ref);
+            gc->WriteBarrier(object);
+          }
+        }
+      }
+    }
+
     // handle state
     // handle state
     if(result == GM_SYS_STATE)
     if(result == GM_SYS_STATE)
     {
     {
@@ -1184,12 +1211,15 @@ gmThread::State gmThread::Sys_PopStackFrame(const gmuint8 * &a_ip, const gmuint8
   // Write barrier old local objects
   // Write barrier old local objects
   {
   {
     gmGarbageCollector* gc = m_machine->GetGC();
     gmGarbageCollector* gc = m_machine->GetGC();
-    for(int index = m_base; index < m_top; ++index) // NOTE: Should this be from m_base - 2 ?
+    if( !gc->IsOff() )
     {
     {
-      if(m_stack[index].IsReference())
+      for(int index = m_base-2; index < m_top; ++index)
       {
       {
-        gmObject * object = GM_MOBJECT(m_machine, m_stack[index].m_value.m_ref);
-        gc->WriteBarrier(object);
+        if(m_stack[index].IsReference())
+        {
+          gmObject * object = GM_MOBJECT(m_machine, m_stack[index].m_value.m_ref);
+          gc->WriteBarrier(object);
+        }
       }
       }
     }
     }
   }
   }