/// <summary> /// Create a mirror for a given executive /// </summary> /// <param name="exec"></param> public ExecutionMirror(ProtoCore.DSASM.Executive exec, ProtoCore.RuntimeCore coreObj) { Validity.Assert(exec != null, "Can't mirror a null executive"); runtimeCore = coreObj; MirrorTarget = exec; }
/// <summary> /// Create a mirror for a given executive /// </summary> /// <param name="exec"></param> public ExecutionMirror(ProtoCore.DSASM.Executive exec, ProtoCore.Core coreObj) { Validity.Assert(exec != null, "Can't mirror a null executive"); core = coreObj; MirrorTarget = exec; LoadPropertyFilters(); }
private void GCDisposeObject(StackValue svPtr, Executive exe) { int classIndex = svPtr.metaData.type; ClassNode cn = exe.exe.classTable.ClassNodes[classIndex]; ProcedureNode pn = cn.GetDisposeMethod(); while (pn == null) { if (cn.Bases != null && cn.Bases.Count != 0) { classIndex = cn.Bases[0]; cn = exe.exe.classTable.ClassNodes[classIndex]; pn = cn.GetDisposeMethod(); } else { break; } } if (pn != null) { // TODO Jun/Jiong: Use build pointer utilities exe.rmem.Push(StackValue.BuildArrayDimension(0)); exe.rmem.Push(StackValue.BuildPointer(svPtr.Pointer, svPtr.metaData)); exe.rmem.Push(StackValue.BuildInt(1)); ++exe.RuntimeCore.FunctionCallDepth; // TODO: Need to move IsExplicitCall to DebugProps and come up with a more elegant solution for this // fix for IDE-963 - pratapa bool explicitCall = exe.IsExplicitCall; bool tempFlag = explicitCall; exe.Callr(pn.RuntimeIndex, pn.ID, classIndex, ref explicitCall); exe.IsExplicitCall = tempFlag; --exe.RuntimeCore.FunctionCallDepth; } }
public static IEmployee GetEmployeeInstance(UserRole role, AccessBoundry access) { IEmployee employee = new Employee(access); switch (role) { case UserRole.Director: employee = new Director(access); break; case UserRole.Manager: employee = new Manager(access); break; case UserRole.Executive: employee = new Executive(access); break; case UserRole.SalesPerson: employee = new SalesPerson(access); break; case UserRole.Secretary: employee = new Secretary(access); break; case UserRole.Developer: employee = new Developer(access); break; case UserRole.Watchman: employee = new Watchman(access); break; case UserRole.General: employee = new Employee(access); break; } return(employee); }
/// <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.RawIntValue < heapElements.Count() && r.RawIntValue >= 0 && heapElements[(int)r.RawIntValue] != null); roots = new List<StackValue>(validPointers); executive = exe; StartCollection(); gcState = GCState.Propagate; return true; }
void UpdateCommand() { List <Character> OnBoard = Emp.GetCharactersAtLocation(this, OfficerRoles.Navy); if (OnBoard.Count > 0) { if (Captain != null && Captain != OnBoard [0]) { Captain.StepDownCaptain(this); AddHistory("Captain Stands Down", string.Format("\n{0}: {1} stands down as Captain.", StrategicClock.GetDate(), Captain.GetNameString())); } OnBoard [0].AppointCaptain(this); } if (OnBoard.Count > 1) { if (Executive != null && Executive != OnBoard [1]) { Executive.StepDownXO(this); AddHistory("Exec Stands Down", string.Format("\n{0}: {1} stands down as Exec.", StrategicClock.GetDate(), Executive.GetNameString())); } OnBoard [1].AppointXO(this); } }
/// <summary> /// Do a full GC cycle /// </summary> /// <param name="gcroots"></param> /// <param name="exe"></param> public void FullGC(IEnumerable <StackValue> gcroots, Executive exe) { if (gcroots == null) { throw new ArgumentNullException("gcroots"); } if (exe == null) { throw new ArgumentNullException("exe"); } while (gcState != GCState.WaitingForRoots) { SingleStep(true); } SetRoots(gcroots, exe); while (gcState != GCState.Pause) { SingleStep(true); } }
public RuntimeCore(Heap heap, Options options = null) { // The heap is initialized by the core and is used to allocate strings // Use the that heap for runtime Validity.Assert(heap != null); this.Heap = heap; RuntimeMemory = new RuntimeMemory(Heap); this.Options = options; InterpreterProps = new Stack<InterpreterProperties>(); ReplicationGuides = new List<List<ReplicationGuide>>(); RunningBlock = 0; ExecutionState = (int)ExecutionStateEventArgs.State.kInvalid; //not yet started FFIPropertyChangedMonitor = new FFIPropertyChangedMonitor(this); ContinuationStruct = new ContinuationStructure(); watchStack = new List<StackValue>(); watchFramePointer = Constants.kInvalidIndex; WatchSymbolList = new List<SymbolNode>(); FunctionCallDepth = 0; cancellationPending = false; watchClassScope = Constants.kInvalidIndex; ExecutionInstance = CurrentExecutive = new Executive(this); ExecutiveProvider = new ExecutiveProvider(); RuntimeStatus = new ProtoCore.RuntimeStatus(this); StartPC = Constants.kInvalidPC; RuntimeData = new ProtoCore.RuntimeData(); }
public Interpreter(RuntimeCore runtimeCore, bool isFEP = false) { runtime = runtimeCore.ExecutiveProvider.CreateExecutive(runtimeCore, isFEP); }
/*----< define how each message will be processed >------------*/ void initializeDispatcher() { Func <CommMessage, CommMessage> getTopFiles = (CommMessage msg) => { localFileMgr.currentPath = ""; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getTopFiles"; reply.arguments = localFileMgr.getFiles().ToList <string>(); return(reply); }; messageDispatcher["getTopFiles"] = getTopFiles; Func <CommMessage, CommMessage> getTopDirs = (CommMessage msg) => { localFileMgr.currentPath = ""; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getTopDirs"; reply.arguments = localFileMgr.getDirs().ToList <string>(); return(reply); }; messageDispatcher["getTopDirs"] = getTopDirs; Executive exe = new Executive(); Func <CommMessage, CommMessage> moveIntoFolderFiles = (CommMessage msg) => { if (msg.arguments.Count() == 1) { localFileMgr.currentPath = msg.arguments[0]; } CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "moveIntoFolderFiles"; reply.arguments = localFileMgr.getFiles().ToList <string>(); return(reply); }; messageDispatcher["moveIntoFolderFiles"] = moveIntoFolderFiles; Func <CommMessage, CommMessage> moveIntoFolderDirs = (CommMessage msg) => { if (msg.arguments.Count() == 1) { localFileMgr.currentPath = msg.arguments[0]; } CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "moveIntoFolderDirs"; reply.arguments = localFileMgr.getDirs().ToList <string>(); return(reply); }; messageDispatcher["moveIntoFolderDirs"] = moveIntoFolderDirs; Func <CommMessage, CommMessage> getTypeAnalysis = (CommMessage msg) => { localFileMgr.currentPath = ""; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getTypeAnalysis"; string Displaytokenfile = Path.GetFullPath(ServerEnvironment.displaypath + "SampleTypeAnalysis.txt"); exe.displaytypeanalysis(msg.arguments, Displaytokenfile); string[] displayfile = { Displaytokenfile }; reply.arguments = displayfile.ToList(); return(reply); }; messageDispatcher["getTypeAnalysis"] = getTypeAnalysis; Func <CommMessage, CommMessage> DependencyAnalysis = (CommMessage msg) => { localFileMgr.currentPath = ""; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getDependency"; string Displaytokenfile = Path.GetFullPath(ServerEnvironment.displaypath + "SampleDependency.txt"); exe.displaydependency(msg.arguments, Displaytokenfile); string[] displayfile = { Displaytokenfile }; reply.arguments = displayfile.ToList(); return(reply); }; messageDispatcher["getDependency"] = DependencyAnalysis; Func <CommMessage, CommMessage> StrongComponent = (CommMessage msg) => { localFileMgr.currentPath = ""; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getStrongComponent"; string Displaytokenfile = Path.GetFullPath(ServerEnvironment.displaypath + "SampleStrongComponent.txt"); exe.displaystrongcomponent(msg.arguments, Displaytokenfile); string[] displayfile = { Displaytokenfile }; reply.arguments = displayfile.ToList(); return(reply); }; messageDispatcher["getStrongComponent"] = StrongComponent; Func <CommMessage, CommMessage> Tokenizer = (CommMessage msg) => { localFileMgr.currentPath = ""; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getTokenizer"; string Displaytokenfile = Path.GetFullPath(ServerEnvironment.displaypath + "SampleToken.txt"); exe.displaytok(msg.arguments, Displaytokenfile); string[] displayfile = { Displaytokenfile }; reply.arguments = displayfile.ToList(); return(reply); }; messageDispatcher["getTokenizer"] = Tokenizer; Func <CommMessage, CommMessage> SemiExpression = (CommMessage msg) => { localFileMgr.currentPath = ""; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getSemiExp"; string Displaytokenfile = Path.GetFullPath(ServerEnvironment.displaypath + "SampleSemiExp.txt"); exe.displaysemi(msg.arguments, Displaytokenfile); string[] displayfile = { Displaytokenfile }; reply.arguments = displayfile.ToList(); return(reply); }; messageDispatcher["getSemiExp"] = SemiExpression; }
static void Main(string[] args) { try { XpoDefault.DataLayer = new SimpleDataLayer(new InMemoryDataStore()); #if TEST_OWN_TABLE using (var unitOfWork = new UnitOfWork()) { #region Person var dataPerson = new[] { new { Id = 1, Name = "Person" } }; foreach (var rec in dataPerson) { var entity = InMemoryDataStoreHelper.CreateSimpleEntity(typeof(Person), rec, unitOfWork); if (entity == null) { continue; } unitOfWork.Save(entity); } unitOfWork.CommitChanges(); InMemoryDataStoreHelper.ShowExistingData(typeof(Person), o => o is Person item ? $"{{Id:{item.Id}, Name:\"{item.Name}\"}}" : string.Empty); #endregion #region Employee var dataEmployee = new[] { new { Id = 2, Name = "Employee" } }; foreach (var rec in dataEmployee) { var entity = InMemoryDataStoreHelper.CreateSimpleEntity(typeof(Employee), rec, unitOfWork); if (entity == null) { continue; } unitOfWork.Save(entity); } unitOfWork.CommitChanges(); InMemoryDataStoreHelper.ShowExistingData(typeof(Person), o => o is Person item ? $"{{Id:{item.Id}, Name:\"{item.Name}\"}}" : string.Empty); InMemoryDataStoreHelper.ShowExistingData(typeof(Employee), o => o is Employee item ? $"{{Id:{item.Id}, Name:\"{item.Name}\", Salary:{item.Salary}}}" : string.Empty); #endregion #region Executive var executive = new Executive(unitOfWork); executive.Id = 3; executive.Name = "Executive"; executive.Salary = 456; executive.Bonus = 789; var person = unitOfWork.GetObjectByKey <Person>(3); var employee = unitOfWork.GetObjectByKey <Employee>(3); var executive2 = unitOfWork.GetObjectByKey <Executive>(3); unitOfWork.Save(executive); unitOfWork.CommitChanges(); #endregion } #endif #if TEST_MAPINHERITANCETYPE_PARENTTABLE using (var unitOfWork = new UnitOfWork()) { var entity1 = new Entity1(unitOfWork); entity1.Id = 1; entity1.Value = "Entity1"; entity1.Entity3Derived1.AddRange(new[] { new Entity3Derived1(unitOfWork), new Entity3Derived1(unitOfWork) }); for (var i = 0; i < entity1.Entity3Derived1.Count; ++i) { ((Entity3Derived1)entity1.Entity3Derived1[i]).Value = $"Entity3Derived1 #{i + 1} (\"{entity1.Value}\")"; } var entity2 = new Entity2(unitOfWork); entity2.Id = 2; entity2.Value = "Entity2"; entity2.Entity3Derived2.AddRange(new[] { new Entity3Derived2(unitOfWork), new Entity3Derived2(unitOfWork) }); for (var i = 0; i < entity2.Entity3Derived2.Count; ++i) { ((Entity3Derived2)entity2.Entity3Derived2[i]).Value = $"Entity3Derived2 #{i + 1} (\"{entity2.Value}\")"; } unitOfWork.CommitChanges(); foreach (var entity in new XPCollection <Entity3Base>(unitOfWork).OrderBy(item => item.Id)) { var entity3Derived1 = entity as Entity3Derived1; var entity3Derived2 = entity as Entity3Derived2; var elementId = entity3Derived1?.Element.Id ?? entity3Derived2?.Element.Id; var elementValue = entity3Derived1?.Element.Value ?? entity3Derived2?.Element.Value; Debug.WriteLine($"Id:{entity.Id}, Value:{entity.Value}, Element.Id:{elementId?.ToString() ?? "NULL"}, Element.Value:{elementValue ?? "NULL"}"); } } #endif Session session = new Session(), sessionII = new Session(), sessionIII = new Session(); XPClassInfo classInfoTestMaster = session.GetClassInfo(typeof(TestMaster)), classInfoTestDetail = session.GetClassInfo(typeof(TestDetail)); TestMaster testMaster; testMaster = new TestMaster(sessionII); testMaster.Val = "testMaster (sessionII)"; sessionII.Save(testMaster); testMaster = new TestMaster(sessionIII); testMaster.Val = "testMaster (sessionIII)"; sessionIII.Save(testMaster); var criteria = new BinaryOperator(new OperandProperty("Name"), new OperandValue("testMaster (sessionII)"), BinaryOperatorType.Equal); if ((testMaster = session.FindObject <TestMaster>(criteria)) != null) { Console.WriteLine("TestMaster: {{Id:{0}, Name:\"{1}\"}}", testMaster.Id, testMaster.Val); // oB! } if ((testMaster = sessionII.FindObject <TestMaster>(criteria)) != null) { Console.WriteLine("TestMaster: {{Id:{0}, Name:\"{1}\"}}", testMaster.Id, testMaster.Val); // oB! } if ((testMaster = sessionIII.FindObject <TestMaster>(criteria)) != null) { Console.WriteLine("TestMaster: {{Id:{0}, Name:\"{1}\"}}", testMaster.Id, testMaster.Val); // oB! } criteria = new BinaryOperator(new OperandProperty("Name"), new OperandValue("testMaster (sessionIII)"), BinaryOperatorType.Equal); if ((testMaster = session.FindObject <TestMaster>(criteria)) != null) { Console.WriteLine("TestMaster: {{Id:{0}, Name:\"{1}\"}}", testMaster.Id, testMaster.Val); // oB! } if ((testMaster = sessionII.FindObject <TestMaster>(criteria)) != null) { Console.WriteLine("TestMaster: {{Id:{0}, Name:\"{1}\"}}", testMaster.Id, testMaster.Val); // oB! } if ((testMaster = sessionIII.FindObject <TestMaster>(criteria)) != null) { Console.WriteLine("TestMaster: {{Id:{0}, Name:\"{1}\"}}", testMaster.Id, testMaster.Val); // oB! } UnitOfWork uow = new UnitOfWork(), uowII = new UnitOfWork(), uowIII = new UnitOfWork(); testMaster = new TestMaster(uowII); testMaster.Val = "testMaster (uowII)"; uowII.Save(testMaster); testMaster = new TestMaster(uowIII); testMaster.Val = "testMaster (uowIII)"; uowIII.Save(testMaster); var objToSave = uow.GetObjectsToSave(); // Count = 0 var objToSaveII = uowII.GetObjectsToSave(); // Count = 1 var objToSaveIII = uowIII.GetObjectsToSave(); // Count = 1 criteria = new BinaryOperator(new OperandProperty("Name"), new OperandValue("testMaster (uowII)"), BinaryOperatorType.Equal); if ((testMaster = uow.FindObject <TestMaster>(criteria)) != null) { Console.WriteLine("TestMaster: {{Id:{0}, Name:\"{1}\"}}", testMaster.Id, testMaster.Val); // null } if ((testMaster = uowII.FindObject <TestMaster>(criteria)) != null) { Console.WriteLine("TestMaster: {{Id:{0}, Name:\"{1}\"}}", testMaster.Id, testMaster.Val); // null } if ((testMaster = uowIII.FindObject <TestMaster>(criteria)) != null) { Console.WriteLine("TestMaster: {{Id:{0}, Name:\"{1}\"}}", testMaster.Id, testMaster.Val); // null } criteria = new BinaryOperator(new OperandProperty("Name"), new OperandValue("testMaster (uowIII)"), BinaryOperatorType.Equal); if ((testMaster = uow.FindObject <TestMaster>(criteria)) != null) { Console.WriteLine("TestMaster: {{Id:{0}, Name:\"{1}\"}}", testMaster.Id, testMaster.Val); // null } if ((testMaster = uowII.FindObject <TestMaster>(criteria)) != null) { Console.WriteLine("TestMaster: {{Id:{0}, Name:\"{1}\"}}", testMaster.Id, testMaster.Val); // null } if ((testMaster = uowIII.FindObject <TestMaster>(criteria)) != null) { Console.WriteLine("TestMaster: {{Id:{0}, Name:\"{1}\"}}", testMaster.Id, testMaster.Val); // nul } // https://documentation.devexpress.com/#CoreLibraries/CustomDocument2111 var collection = new XPCollection <TestMaster>(uow); Console.WriteLine(collection.Count); collection = new XPCollection <TestMaster>(uowII); Console.WriteLine(collection.Count); collection = new XPCollection <TestMaster>(uowIII); Console.WriteLine(collection.Count); collection = new XPCollection <TestMaster>(PersistentCriteriaEvaluationBehavior.InTransaction, uow, null); Console.WriteLine(collection.Count); collection = new XPCollection <TestMaster>(PersistentCriteriaEvaluationBehavior.InTransaction, uowII, null); Console.WriteLine(collection.Count); collection = new XPCollection <TestMaster>(PersistentCriteriaEvaluationBehavior.InTransaction, uowIII, null); Console.WriteLine(collection.Count); uowII.CommitChanges(); criteria = new BinaryOperator(new OperandProperty("Name"), new OperandValue("testMaster (uowII)"), BinaryOperatorType.Equal); if ((testMaster = uow.FindObject <TestMaster>(criteria)) != null) { Console.WriteLine("TestMaster: {{Id:{0}, Name:\"{1}\"}}", testMaster.Id, testMaster.Val); // oB! } if ((testMaster = uowII.FindObject <TestMaster>(criteria)) != null) { Console.WriteLine("TestMaster: {{Id:{0}, Name:\"{1}\"}}", testMaster.Id, testMaster.Val); // oB! } if ((testMaster = uowIII.FindObject <TestMaster>(criteria)) != null) { Console.WriteLine("TestMaster: {{Id:{0}, Name:\"{1}\"}}", testMaster.Id, testMaster.Val); // oB! } uowIII.CommitChanges(); criteria = new BinaryOperator(new OperandProperty("Name"), new OperandValue("testMaster (uowII)"), BinaryOperatorType.Equal); if ((testMaster = uow.FindObject <TestMaster>(criteria)) != null) { Console.WriteLine("TestMaster: {{Id:{0}, Name:\"{1}\"}}", testMaster.Id, testMaster.Val); // oB! } if ((testMaster = uowII.FindObject <TestMaster>(criteria)) != null) { Console.WriteLine("TestMaster: {{Id:{0}, Name:\"{1}\"}}", testMaster.Id, testMaster.Val); // oB! } if ((testMaster = uowIII.FindObject <TestMaster>(criteria)) != null) { Console.WriteLine("TestMaster: {{Id:{0}, Name:\"{1}\"}}", testMaster.Id, testMaster.Val); // oB! } objToSave = uow.GetObjectsToSave(); // Count = 0 objToSaveII = uowII.GetObjectsToSave(); // Count = 0 objToSaveIII = uowIII.GetObjectsToSave(); // Count = 0 uow.Dispose(); uowII.Dispose(); uowIII.Dispose(); for (var i = 0; i < 3; ++i) { testMaster = new TestMaster(session); testMaster.Val = i.ToString(); for (var j = 0; j < 3; ++j) { testMaster.Details.Add(new TestDetail(session)); testMaster.Details[j].Val = string.Format("{0}.{1}", i, j); } session.Save(testMaster); } if ( (testMaster = session.FindObject <TestMaster>(new BinaryOperator(new OperandProperty("Name"), new OperandValue("1"), BinaryOperatorType.Equal))) != null) { Console.WriteLine("TestMaster: {{Id:{0}, Name:\"{1}\"}}", testMaster.Id, testMaster.Val); foreach (var detail in testMaster.Details) { Console.WriteLine("TestDetail: {{Id:{0}, Master.Id:{1}, Name:\"{2}\"}}", detail.Id, detail.Master.Id, detail.Val); } } var resultOfSelectData = session.SelectData( classInfoTestMaster, new CriteriaOperatorCollection { new OperandProperty("Id") }, CriteriaOperator.Or( new BinaryOperator(new OperandProperty("Name"), new OperandValue("1"), BinaryOperatorType.Equal), new BinaryOperator(new OperandProperty("Name"), new OperandValue("2"), BinaryOperatorType.Equal) ), false, 0, null).ToArray(); var resultOfGetObjects = session.GetObjects( classInfoTestMaster, CriteriaOperator.Or( new BinaryOperator(new OperandProperty("Name"), new OperandValue("1"), BinaryOperatorType.Equal), new BinaryOperator(new OperandProperty("Name"), new OperandValue("2"), BinaryOperatorType.Equal) ), null, 0, false, true).OfType <TestMaster>().ToArray(); using (uow = new UnitOfWork()) { for (var i = 3; i < 6; ++i) { testMaster = new TestMaster(uow); testMaster.Val = i.ToString(); for (var j = 0; j < 3; ++j) { testMaster.Details.Add(new TestDetail(uow)); testMaster.Details[j].Val = string.Format("{0}.{1}", i, j); } uow.CommitChanges(); } } resultOfSelectData = session.SelectData( classInfoTestMaster, new CriteriaOperatorCollection { new OperandProperty("Id") }, CriteriaOperator.Or( new BinaryOperator(new OperandProperty("Name"), new OperandValue("4"), BinaryOperatorType.Equal), new BinaryOperator(new OperandProperty("Name"), new OperandValue("5"), BinaryOperatorType.Equal) ), false, 0, null).ToArray(); var res = (from _testMaster_ in new XPQuery <TestMaster>(session) join _testDetail_ in new XPQuery <TestDetail>(session) on _testMaster_.Id equals _testDetail_.Master.Id where _testDetail_.Val == "1.1" /*&& _testDetail_.PhysicalPerson.id == processedUser.id*/ && _testDetail_.Master.Id == 6 select new { TestMasterId = _testMaster_.Id, TestDetailId = _testDetail_.Id }).ToList(); } catch (Exception eException) { Console.WriteLine(eException.GetType().FullName + Environment.NewLine + "Message: " + eException.Message + Environment.NewLine + (eException.InnerException != null && !string.IsNullOrEmpty(eException.InnerException.Message) ? "InnerException.Message" + eException.InnerException.Message + Environment.NewLine : string.Empty) + "StackTrace:" + Environment.NewLine + eException.StackTrace); } }
public void GCMarkAndSweep(List<StackValue> rootPointers, Executive exe) { if (IsGCRunning) return; try { IsGCRunning = true; // Mark var count = heapElements.Count; var markBits = new BitArray(count); foreach (var index in fixedHeapElements) { markBits.Set(index, true); } var workingStack = new Stack<StackValue>(rootPointers); while (workingStack.Any()) { var pointer = workingStack.Pop(); var ptr = (int)pointer.RawIntValue; if (!pointer.IsReferenceType || markBits.Get(ptr)) { continue; } markBits.Set(ptr, true); var heapElement = heapElements[ptr]; IEnumerable<StackValue> subElements = Enumerable.Empty<StackValue>(); if (pointer.IsArray) { var array = ToHeapObject<DSArray>(pointer); var dict = array.ToDictionary(); subElements = subElements.Concat(dict.Keys).Concat(dict.Values); } else { subElements = heapElement.Values; } foreach (var subElement in subElements) { if (subElement.IsReferenceType && !markBits.Get((int)subElement.RawIntValue)) { workingStack.Push(subElement); } } } // Sweep for (int i = 0; i < count; ++i) { if (markBits.Get(i) || heapElements[i] == null) { continue; } var metaData = heapElements[i].MetaData; if (metaData.type == (int)PrimitiveType.kTypeString) { stringTable.TryRemoveString(i); } else if (metaData.type >= (int)PrimitiveType.kMaxPrimitives) { var objPointer = StackValue.BuildPointer(i, metaData); GCDisposeObject(objPointer, exe); } heapElements[i] = null; #if !HEAP_VERIFICATION freeList.Add(i); #endif } } finally { IsGCRunning = false; } }
public void GCRelease(StackValue[] ptrList, Executive exe) { for (int n = 0; n < ptrList.Length; ++n) { StackValue svPtr = ptrList[n]; if (!svPtr.IsPointer && !svPtr.IsArray) { continue; } int ptr = (int)svPtr.opdata; if (ptr < 0 || ptr >= heapElements.Count) { #if HEAP_VERIFICATION throw new Exception("Memory corrupted: Release invalid pointer (7364B8C2-FF34-4C67-8DFE-5DFA678BF50D)."); #else continue; #endif } HeapElement hs = heapElements[ptr]; if (!hs.Active) { #if HEAP_VERIFICATION throw new Exception("Memory corrupted: Release dead memory (7F70A6A1-FE99-476E-BE8B-CA7615EE1A3B)."); #else continue; #endif } // The reference count could be 0 if this heap object // is a temporary heap object that hasn't been assigned // to any variable yet, for example, Type.Coerce() may // allocate a new array and when this one is type converted // again, it will be released. if (hs.Refcount > 0) { hs.Refcount--; } // TODO Jun: If its a pointer to a primitive then dont decrease its refcount, just free it if (hs.Refcount == 0) { // if it is of class type, first call its destructor before clean its members if (svPtr.IsPointer) { GCDisposeObject(svPtr, exe); } if (svPtr.IsArray && hs.Dict != null) { foreach (var item in hs.Dict) { GCRelease(new StackValue[] { item.Key }, exe); GCRelease(new StackValue[] { item.Value }, exe); } } hs.Dict = null; hs.Active = false; GCRelease(hs.Stack, exe); #if !HEAP_VERIFICATION freeList.Add(ptr); #endif } } }
public void GCMarkAndSweep(List <StackValue> rootPointers, Executive exe) { if (isGarbageCollecting) { return; } try { isGarbageCollecting = true; // Mark var count = heapElements.Count; var markBits = new BitArray(count); var workingStack = new Stack <StackValue>(rootPointers); while (workingStack.Any()) { var pointer = workingStack.Pop(); var ptr = (int)pointer.RawIntValue; if (!pointer.IsReferenceType || markBits.Get(ptr)) { continue; } markBits.Set(ptr, true); var heapElement = heapElements[ptr]; var subElements = heapElement.VisibleItems; if (heapElement.Dict != null) { subElements = subElements.Concat(heapElement.Dict.Keys) .Concat(heapElement.Dict.Values); } foreach (var subElement in subElements) { if (subElement.IsReferenceType && !markBits.Get((int)subElement.RawIntValue)) { workingStack.Push(subElement); } } } // Sweep for (int i = 0; i < count; ++i) { if (markBits.Get(i) || heapElements[i] == null) { continue; } var metaData = heapElements[i].MetaData; if (metaData.type >= (int)PrimitiveType.kMaxPrimitives) { var objPointer = StackValue.BuildPointer(i, metaData); GCDisposeObject(objPointer, exe); } heapElements[i] = null; #if !HEAP_VERIFICATION freeList.Add(i); #endif } } finally { isGarbageCollecting = false; } }
// Duplicates the public FullGC method for testing purposes internal void FullGCTest(IEnumerable <StackValue> gcroots, Executive exe, Dictionary <GCState, (Action, Action)> testNotifications)
public Interpreter(Core core, bool isFEP = false) { runtime = core.ExecutiveProvider.CreateExecutive(core, isFEP); }
/// <summary> /// If dsValue is a pointer (object), expand the size of this object and /// add references to referencedObjects; if dsValue is an array, then /// traverse recursively. /// /// Exception: ProtoCore.Exception.RunOutOfMemoryException if the engine /// fails to expand the size of object. /// </summary> /// <param name="dsValue"></param> /// <param name="referencedObjects"></param> /// <param name="exec"></param> private void SetReferenceObjects(StackValue dsValue, List <StackValue> referencedObjects, Executive exec) { if (dsValue.IsPointer) { var dsObject = exec.rmem.Heap.ToHeapObject <DSObject>(dsValue); if (dsObject != null) { int startIndex = dsObject.Count; dsObject.ExpandBySize(referencedObjects.Count); Validity.Assert(dsObject.Count >= referencedObjects.Count); for (int i = 0; i < referencedObjects.Count; i++) { dsObject.SetValueAtIndex(startIndex + i, referencedObjects[i], exec.RuntimeCore); } } } else if (dsValue.IsArray) { var dsArray = exec.rmem.Heap.ToHeapObject <DSArray>(dsValue); if (dsArray != null) { foreach (var element in dsArray.Values) { SetReferenceObjects(element, referencedObjects, exec); } } } }
/*----< define how each message will be processed >------------*/ private void initializeDispatcher() { Func <CommMessage, CommMessage> getUpFiles = msg => { localFileMgr.currentPath = ""; var temp = string.Empty; var send_path = string.Empty; var count = 0; if (localFileMgr.pathStack.Count == 1 && localFileMgr.pathStack.Peek().Equals(ServerEnvironment.root)) { localFileMgr.currentPath = ""; if (localFileMgr.pathStack.Count != 0) { localFileMgr.pathStack.Clear(); localFileMgr.pathStack.Push(ServerEnvironment.root); } var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getUpFiles"; reply.arguments = localFileMgr.getFiles().ToList(); return(reply); } else { temp = localFileMgr.pathStack.Pop(); send_path = localFileMgr.pathStack.Peek(); var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getUpFiles"; reply.arguments = localFileMgr.getFiles(send_path).ToList(); return(reply); } }; messageDispatcher["getUpFiles"] = getUpFiles; Func <CommMessage, CommMessage> getUpDirs = msg => { localFileMgr.currentPath = ""; var send_path = string.Empty; var count = 0; if (localFileMgr.pathStack.Count == 1 && localFileMgr.pathStack.Peek().Equals(ServerEnvironment.root)) { localFileMgr.currentPath = ""; var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getUpDirs"; reply.arguments = localFileMgr.getDirs().ToList(); return(reply); } else { send_path = localFileMgr.pathStack.Peek(); var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getUpDirs"; reply.arguments = localFileMgr.getDirs(send_path).ToList(); return(reply); } }; messageDispatcher["getUpDirs"] = getUpDirs; Func <CommMessage, CommMessage> connect = msg => { localFileMgr.currentPath = ""; if (localFileMgr.pathStack.Count != 0) { localFileMgr.pathStack.Clear(); localFileMgr.pathStack.Push(ServerEnvironment.root); } var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "connect"; reply.arguments.Add("Connected"); return(reply); }; messageDispatcher["connect"] = connect; Func <CommMessage, CommMessage> getTopFiles = msg => { localFileMgr.currentPath = ""; if (localFileMgr.pathStack.Count != 0) { localFileMgr.pathStack.Clear(); localFileMgr.pathStack.Push(ServerEnvironment.root); } var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getTopFiles"; reply.arguments = localFileMgr.getFiles().ToList(); return(reply); }; messageDispatcher["getTopFiles"] = getTopFiles; Func <CommMessage, CommMessage> getTopDirs = msg => { localFileMgr.currentPath = ""; var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getTopDirs"; reply.arguments = localFileMgr.getDirs().ToList(); return(reply); }; messageDispatcher["getTopDirs"] = getTopDirs; Func <CommMessage, CommMessage> moveIntoFolderFiles = msg => { var temp = string.Empty; if (msg.arguments.Count() == 1) { //temp_path = localFileMgr.pathStack.Peek(); temp = localFileMgr.pathStack.Peek() + "/" + msg.arguments[0]; localFileMgr.pathStack.Push(temp); localFileMgr.currentPath = msg.arguments[0]; } //string temp = localFileMgr.pathStack.Peek(); var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "moveIntoFolderFiles"; reply.arguments = localFileMgr.getFiles(temp).ToList(); return(reply); }; messageDispatcher["moveIntoFolderFiles"] = moveIntoFolderFiles; Func <CommMessage, CommMessage> moveIntoFolderDirs = msg => { var temp = string.Empty; if (msg.arguments.Count() == 1) { temp = localFileMgr.pathStack.Peek(); } var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "moveIntoFolderDirs"; reply.arguments = localFileMgr.getDirs(temp).ToList(); return(reply); }; messageDispatcher["moveIntoFolderDirs"] = moveIntoFolderDirs; Func <CommMessage, CommMessage> Close = msg => { var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "Close"; reply.arguments.Add("Close"); return(reply); }; messageDispatcher["Close"] = Close; Func <CommMessage, CommMessage> DepAnalysis = msg => { localFileMgr.currentPath = ""; var temp = string.Empty; var send_path = string.Empty; var count = 0; try { var ex = new Executive(); FileStream ostrm; StreamWriter writer; var oldOut = Console.Out; var directory = Directory.GetParent(Directory.GetParent(ServerEnvironment.root).ToString()) .ToString(); var listOfSelectedFiles = msg.arguments; if (File.Exists(directory + "/Analysis.txt")) { File.Delete(directory + "/Analysis.txt"); } ostrm = new FileStream(directory + "/Analysis.txt", FileMode.Create, FileAccess.Write); writer = new StreamWriter(ostrm); writer.AutoFlush = true; Console.SetOut(writer); send_path = localFileMgr.pathStack.Peek(); var temp_list = new List <string> { "/Analysis.txt" }; var nav = new Navigate(); nav.Add("*.cs"); List <string> files; if (listOfSelectedFiles.Count > 0) { nav.go(send_path, listOfSelectedFiles); files = nav.allFiles; ex.getResult(files); } else { nav.go(send_path); files = nav.allFiles; ex.getResult(files); } Console.SetOut(oldOut); writer.Flush(); ostrm.Flush(); writer.Close(); ostrm.Close(); var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "DepAnalysis"; reply.arguments = temp_list; return(reply); } catch (Exception e) { var temp_list = new List <string> { "/Analysis.txt" }; Console.WriteLine(e); var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "DepAnalysis"; reply.arguments = temp_list; return(reply); } }; messageDispatcher["DepAnalysis"] = DepAnalysis; Func <CommMessage, CommMessage> OpenFile = msg => { var send_path = string.Empty; var count = 0; try { var FileToOpen = msg.arguments[0]; send_path = localFileMgr.pathStack.Peek(); comm.postFile(send_path, FileToOpen); var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "OpenFile"; reply.arguments.Add(FileToOpen); return(reply); } catch (Exception e) { var temp_list = new List <string> { "" }; Console.WriteLine(e); var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "OpenFile"; reply.arguments = temp_list; return(reply); } }; messageDispatcher["OpenFile"] = OpenFile; }
/*----< define how each message will be processed >------------*/ void initializeDispatcher() { Executive exex = new Executive(); Func <CommMessage, CommMessage> getTopFiles = (CommMessage msg) => { localFileMgr.currentPath = ""; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getTopFiles"; reply.arguments = localFileMgr.getFiles().ToList <string>(); return(reply); }; messageDispatcher["getTopFiles"] = getTopFiles; Func <CommMessage, CommMessage> getTopDirs = (CommMessage msg) => { localFileMgr.currentPath = ""; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getTopDirs"; reply.arguments = localFileMgr.getDirs().ToList <string>(); return(reply); }; messageDispatcher["getTopDirs"] = getTopDirs; Func <CommMessage, CommMessage> moveIntoFolderFiles = (CommMessage msg) => { if (msg.arguments.Count() == 1) { localFileMgr.currentPath = msg.arguments[0]; } CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "moveIntoFolderFiles"; reply.arguments = localFileMgr.getFiles().ToList <string>(); return(reply); }; messageDispatcher["moveIntoFolderFiles"] = moveIntoFolderFiles; Func <CommMessage, CommMessage> moveIntoFolderDirs = (CommMessage msg) => { if (msg.arguments.Count() == 1) { localFileMgr.currentPath = msg.arguments[0]; } CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "moveIntoFolderDirs"; reply.arguments = localFileMgr.getDirs().ToList <string>(); return(reply); }; messageDispatcher["moveIntoFolderDirs"] = moveIntoFolderDirs; Func <CommMessage, CommMessage> getTok = (CommMessage msg) => { localFileMgr.currentPath = ""; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getTok"; string tokresult = Path.GetFullPath(ServerEnvironment.result + "tokens.txt"); exex.TokResultFile(msg.arguments, tokresult); string[] tokresultfile = { tokresult }; reply.arguments = tokresultfile.ToList(); return(reply); }; messageDispatcher["getTok"] = getTok; Func <CommMessage, CommMessage> getSemi = (CommMessage msg) => { localFileMgr.currentPath = ""; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getSemi"; string semiresult = Path.GetFullPath(ServerEnvironment.result + "semi.txt"); exex.SemiResultFile(msg.arguments, semiresult); string[] tokresultfile = { semiresult }; reply.arguments = tokresultfile.ToList(); return(reply); }; messageDispatcher["getSemi"] = getSemi; Func <CommMessage, CommMessage> getTypeTable = (CommMessage msg) => { localFileMgr.currentPath = ""; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getTypeTable"; string typtableresult = Path.GetFullPath(ServerEnvironment.result + "typttable.txt"); exex.TyttableResultFile(msg.arguments, typtableresult); string[] tokresultfile = { typtableresult }; reply.arguments = tokresultfile.ToList(); return(reply); }; messageDispatcher["getTypeTable"] = getTypeTable; Func <CommMessage, CommMessage> getDependency = (CommMessage msg) => { localFileMgr.currentPath = ""; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getDependency"; string Dependencyresult = Path.GetFullPath(ServerEnvironment.result + "Dependency.txt"); exex.DependencyResultFile(msg.arguments, Dependencyresult); string[] tokresultfile = { Dependencyresult }; reply.arguments = tokresultfile.ToList(); return(reply); }; messageDispatcher["getDependency"] = getDependency; Func <CommMessage, CommMessage> getStrongComponent = (CommMessage msg) => { localFileMgr.currentPath = ""; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getStrongComponent"; string sscresult = Path.GetFullPath(ServerEnvironment.result + "ssc.txt"); exex.StrongComponentResultFile(msg.arguments, sscresult); string[] tokresultfile = { sscresult }; reply.arguments = tokresultfile.ToList(); return(reply); }; messageDispatcher["getStrongComponent"] = getStrongComponent; }
/*----< define how each message will be processed >------------*/ void initializeDispatcher() { Executive executive = new Executive(); Func <CommMessage, CommMessage> getTopFiles = (CommMessage msg) => { localFileMgr.currentPath = ""; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getTopFiles"; reply.arguments = localFileMgr.getFiles().ToList <string>(); return(reply); }; messageDispatcher["getTopFiles"] = getTopFiles; Func <CommMessage, CommMessage> getTopDirs = (CommMessage msg) => { localFileMgr.currentPath = ""; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getTopDirs"; reply.arguments = localFileMgr.getDirs().ToList <string>(); return(reply); }; messageDispatcher["getTopDirs"] = getTopDirs; Func <CommMessage, CommMessage> moveIntoFolderFiles = (CommMessage msg) => { if (msg.arguments.Count() == 1) { localFileMgr.currentPath = msg.arguments[0]; } CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "moveIntoFolderFiles"; reply.arguments = localFileMgr.getFiles().ToList <string>(); return(reply); }; messageDispatcher["moveIntoFolderFiles"] = moveIntoFolderFiles; Func <CommMessage, CommMessage> moveIntoFolderDirs = (CommMessage msg) => { if (msg.arguments.Count() == 1) { localFileMgr.currentPath = msg.arguments[0]; } CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "moveIntoFolderDirs"; reply.arguments = localFileMgr.getDirs().ToList <string>(); return(reply); }; messageDispatcher["moveIntoFolderDirs"] = moveIntoFolderDirs; Func <CommMessage, CommMessage> getTokens = (CommMessage msg) => { CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getTokens"; string tokenOutputfile = Path.GetFullPath(ServerEnvironment.OutputPath + "tokenFile.txt"); executive.showTokens(msg.arguments, tokenOutputfile); string[] outputFile = { tokenOutputfile }; reply.arguments = outputFile.ToList(); return(reply); }; messageDispatcher["getTokens"] = getTokens; Func <CommMessage, CommMessage> getSemiExpression = (CommMessage msg) => { CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getSemiExpression"; string semiOutputfile = Path.GetFullPath(ServerEnvironment.OutputPath + "semiFile.txt"); executive.showSemiExpression(msg.arguments, semiOutputfile); string[] outputFile = { semiOutputfile }; reply.arguments = outputFile.ToList(); return(reply); }; messageDispatcher["getSemiExpression"] = getSemiExpression; Func <CommMessage, CommMessage> getTypeTable = (CommMessage msg) => { CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getTypeTable"; string typeTableOutputfile = Path.GetFullPath(ServerEnvironment.OutputPath + "typeTableFile.txt"); executive.showTypeAnalysis(msg.arguments, typeTableOutputfile); string[] outputFile = { typeTableOutputfile }; reply.arguments = outputFile.ToList(); return(reply); }; messageDispatcher["getTypeTable"] = getTypeTable; Func <CommMessage, CommMessage> getDependencyTable = (CommMessage msg) => { CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getDependencyTable"; string dependencyOutputfile = Path.GetFullPath(ServerEnvironment.OutputPath + "dependencyFile.txt"); executive.showDependencyAnalysis(msg.arguments, dependencyOutputfile); string[] outputFile = { dependencyOutputfile }; reply.arguments = outputFile.ToList(); return(reply); }; messageDispatcher["getDependencyTable"] = getDependencyTable; Func <CommMessage, CommMessage> getGraph = (CommMessage msg) => { CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getGraph"; string graphOutputfile = Path.GetFullPath(ServerEnvironment.OutputPath + "graphFile.txt"); executive.showGraphAnalysis(msg.arguments, graphOutputfile); string[] outputFile = { graphOutputfile }; reply.arguments = outputFile.ToList(); return(reply); }; messageDispatcher["getGraph"] = getGraph; Func <CommMessage, CommMessage> getStrongComponents = (CommMessage msg) => { CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getStrongComponents"; string strongComponentsOutputfile = Path.GetFullPath(ServerEnvironment.OutputPath + "strongComponentsFile.txt"); executive.showStrongComponents(msg.arguments, strongComponentsOutputfile); string[] outputFile = { strongComponentsOutputfile }; reply.arguments = outputFile.ToList(); return(reply); }; messageDispatcher["getStrongComponents"] = getStrongComponents; }