/// <summary> /// Move gc a step forward. /// </summary> private void SingleStep(bool forceGC) { switch (gcState) { case GCState.Pause: if (gcDebt <= 0 || forceGC) { gcState = GCState.WaitingForRoots; } break; case GCState.WaitingForRoots: break; case GCState.Propagate: if (grayList.Any()) { totalTraversed += RecursiveMark(grayList.First()); grayList.RemoveFirst(); } else { gcState = GCState.Sweep; } break; case GCState.Sweep: Sweep(); MarkAllWhite(); gcState = GCState.Pause; IsGCRunning = false; break; } }
/// <summary> /// Notify the heap that gc roots are ready so that gc could move /// forward. The executive is passed for dispoing objects. /// </summary> /// <param name="gcroots"></param> /// <param name="exe"></param> /// <returns></returns> public bool SetRoots(IEnumerable <StackValue> gcroots, Executive exe) { if (gcroots == null) { throw new ArgumentNullException("gcroots"); } if (exe == null) { throw new ArgumentNullException("exe"); } if (!IsWaitingForRoots) { return(false); } var validPointers = gcroots.Where(r => r.IsReferenceType && r.RawData < heapElements.Count() && r.RawData >= 0 && heapElements[(int)r.RawData] != null); roots = new List <StackValue>(validPointers); executive = exe; StartCollection(); gcState = GCState.Propagate; return(true); }
public void SetState(GCState state) { switch (state) { case GCState.LEVEL_ENTRY_STATE_ENTER: { m_doorRightIsOpen = false; m_levelComplete = false; string level_str = string.Format("level_{0:00}", m_levelNumber); m_levelEntities.LevelStop(); m_levelEntities.LevelLoad(level_str); string[] entities_1 = { "ball_mesh", "paddle_entry_mesh" }; m_levelEnvironment.EnableEntities(entities_1); m_levelNumber++; UpdatePaddleNumber(m_paddleSpare); } break; case GCState.LEVEL_ENTRY_STATE_EXIT: { string[] entities = { "ball_mesh", "paddle_entry_mesh" }; m_levelEnvironment.DisableEntities(entities); } break; case GCState.LEVEL_START_STATE_ENTER: { m_levelEntities.LevelStart(); } break; case GCState.LEVEL_CLEARED_STATE_ENTER: break; case GCState.LEVEL_CLEARED_STATE_EXIT: { } break; case GCState.LEVEL_PADDLE_LOST_STATE_ENTER: { SaveConfig(); m_levelEnvironment.EnableSparePaddleMesh(); break; } case GCState.LEVEL_PADDLE_LOST_STATE_EXIT: { m_levelEnvironment.DisableSparePaddleMesh(); } break; default: break; } }