public MethodAnalyzer DeepCopy() { MethodAnalyzer deepcopyMethodAnalyzer = new MethodAnalyzer(this.methodName); foreach (var ele in this.InvokedMethods) { deepcopyMethodAnalyzer.InvokedMethods.Add(new Tuple <string, string, string, IOperation> (ele.Item1, ele.Item2, ele.Item3, ele.Item4)); } foreach (var ele in this.conflictUnit) { deepcopyMethodAnalyzer.conflictUnit.Add(new Tuple <Accesses, string, IOperation>(ele.Item1, ele.Item2, ele.Item3)); } foreach (var ele in this.awaitInvocRel) { deepcopyMethodAnalyzer.awaitInvocRel.Add(new Tuple <string, string>(ele.Item1, ele.Item2)); } foreach (var ele in this.methodInvocReturnRegs) { deepcopyMethodAnalyzer.methodInvocReturnRegs.Add(ele); } deepcopyMethodAnalyzer.isAsync = this.isAsync; deepcopyMethodAnalyzer.invocSuffix = this.invocSuffix; return(deepcopyMethodAnalyzer); }
public ConflictGraph DeepCopy() { ConflictGraph deepcopyConflictGraph = new ConflictGraph(); foreach (var ele in this.cgMethods) { MethodAnalyzer newEle = new MethodAnalyzer(ele.methodName); newEle = ele.DeepCopy(); deepcopyConflictGraph.cgMethods.Add(newEle); } deepcopyConflictGraph.systemMethod = new List <string>(this.systemMethod); deepcopyConflictGraph.systemMethodConflicts = new List <List <string> >(this.systemMethodConflicts); deepcopyConflictGraph.progMethods = new List <string>(this.progMethods); deepcopyConflictGraph.cgSharedFields = new List <string>(this.cgSharedFields); deepcopyConflictGraph.nbRepairedDR = this.nbRepairedDR; deepcopyConflictGraph.nbMovedAwait = this.nbMovedAwait; deepcopyConflictGraph.isAsync = this.isAsync; deepcopyConflictGraph.syntaxTree = this.syntaxTree; deepcopyConflictGraph.compilation = this.compilation; return(deepcopyConflictGraph); }
private void BuildGraph() { // get syntax nodes for methods var methodNodes = from methodDeclaration in syntaxTree.GetRoot().DescendantNodes() .Where(x => x is MethodDeclarationSyntax) select methodDeclaration; int cnt = methodNodes.Count(); // get syntax nodes for fields var fieldNodes = from FieldDeclaration in syntaxTree.GetRoot().DescendantNodes() .Where(x => x is FieldDeclarationSyntax) select FieldDeclaration; List <string> sharedFields = new List <string>(); foreach (FieldDeclarationSyntax field in fieldNodes) { if (field.Declaration.Variables.Count == 1) { sharedFields.Add(field.Declaration.Variables[0].Identifier.ToString()); } } cgSharedFields = new List <string>(sharedFields); foreach (MethodDeclarationSyntax node in methodNodes) { var model = compilation.GetSemanticModel(node.SyntaxTree); var methodName = node.Identifier.ToString(); progMethods.Add(methodName); //Console.Write(typeof(string).Assembly.ImageRuntimeVersion); var graph = ControlFlowGraph.Create(node, model); // CFG is here ImmutableArray <BasicBlock> bb = graph.Blocks; MethodAnalyzer methodAnalyzer = new MethodAnalyzer(methodName); methodAnalyzer.SetUp(bb, sharedFields); if (methodAnalyzer.isAsync && !this.isAsync) { this.isAsync = true; } cgMethods.Add(methodAnalyzer); } }
private int FindDependentInstruction(string returnReg, MethodAnalyzer meth, int index_await) { int j = 0; string invocArg0 = meth.FindInvokedArgument(returnReg); string invocMeth0 = meth.FindInvokedMethod(returnReg); foreach (Tuple <Accesses, string, IOperation> ele in meth.conflictUnit) { if (j > index_await) { if (ele.Item1 == Accesses.Read && ele.Item2 == returnReg) { return(j); } else if ((ele.Item1 == Accesses.Read || ele.Item1 == Accesses.Write) && ele.Item2 == invocArg0) { return(j); } else if (ele.Item1 == Accesses.Invocation && ele.Item2 != returnReg) { string invocArg1 = meth.FindInvokedArgument(ele.Item2); string invocMeth2 = meth.FindInvokedMethod(ele.Item2); if (progMethods.IndexOf(invocMeth0) == -1 && progMethods.IndexOf(invocMeth2) == -1) { if (invocArg1 == invocArg0 || invocArg1 == returnReg) { return(j); } } } } j = j + 1; } return(j); }
private int IsThereDataRace(MethodAnalyzer meth1, List <Tuple <Accesses, string, IOperation> > conflictUnit1, MethodAnalyzer meth2, List <Tuple <Accesses, string, IOperation> > conflictUnit2) { int j = 0; string meth2Name; int sysm2Index = -1; if (conflictUnit2.Count == 1 && conflictUnit2[0].Item1 == Accesses.Invocation) { meth2Name = meth2.FindInvokedMethod(conflictUnit2[0].Item2); if (systemMethod.IndexOf(meth2Name) != -1) { sysm2Index = systemMethod.IndexOf(meth2Name); } } foreach (var ele in conflictUnit1) { if (ele.Item1 == Accesses.Invocation) { string methName = meth1.FindInvokedMethod(ele.Item2); MethodAnalyzer newMeth = FindMethod(methName); if (newMeth != null) { var confUnit = newMeth.conflictUnit; var k = IsThereDataRace(newMeth, confUnit, meth2, conflictUnit2); if (k != -1) { return(j); } } else if (progMethods.IndexOf(methName) == -1 && sysm2Index != -1) { if (systemMethodConflicts[sysm2Index].IndexOf(methName) != -1) { string invocArg0 = meth2.FindInvokedArgument(conflictUnit2[0].Item2); string invocArg1 = meth1.FindInvokedArgument(ele.Item2); if (invocArg0 == invocArg1 && invocArg0 != null) { return(j); } } } else if (progMethods.IndexOf(methName) == -1 && sysm2Index == -1) { string invocArg1 = meth1.FindInvokedArgument(ele.Item2); foreach (var ele2 in conflictUnit2) { if (ele2.Item1 == Accesses.Invocation) { string methName2 = meth2.FindInvokedMethod(ele2.Item2); MethodAnalyzer newMeth2 = FindMethod(methName2); if (newMeth2 != null) { var confUnit2 = newMeth2.conflictUnit; var confUnit1 = new List <Tuple <Accesses, string, IOperation> >(); confUnit1.Add(ele); var k = IsThereDataRace(meth1, confUnit1, newMeth2, confUnit2); if (k != -1) { return(j); } } else if (systemMethod.IndexOf(methName2) != -1) { string invocArg0 = meth2.FindInvokedArgument(ele2.Item2); if (invocArg0 == invocArg1 && systemMethodConflicts[systemMethod.IndexOf(methName2)].IndexOf(methName) != -1) { return(j); } } } else if (ele2.Item1 == Accesses.Write && ele2.Item2 == invocArg1) { return(j); } else if (ele2.Item1 == Accesses.Read && ele2.Item2 == invocArg1) { return(j); } } } } else if (ele.Item1 == Accesses.Read) { if (sysm2Index == -1) { foreach (var ele2 in conflictUnit2) { if (ele2.Item1 == Accesses.Invocation) { string methName2 = meth2.FindInvokedMethod(ele2.Item2); MethodAnalyzer newMeth2 = FindMethod(methName2); if (newMeth2 != null) { var confUnit2 = newMeth2.conflictUnit; var confUnit1 = new List <Tuple <Accesses, string, IOperation> >(); confUnit1.Add(ele); var k = IsThereDataRace(meth1, confUnit1, newMeth2, confUnit2); if (k != -1) { return(j); } } // should this be any system method or only the ones with asynchronous counter parts else if (progMethods.IndexOf(methName2) == -1) { string invocArg0 = meth2.FindInvokedArgument(ele2.Item2); if (invocArg0 == ele.Item2) { return(j); } } } else if (ele2.Item1 == Accesses.Write && ele2.Item2 == ele.Item2) { return(j); } } } } else if (ele.Item1 == Accesses.Write) { if (sysm2Index == -1) { foreach (var ele2 in conflictUnit2) { if (ele2.Item1 == Accesses.Invocation) { string methName2 = meth2.FindInvokedMethod(ele2.Item2); MethodAnalyzer newMeth2 = FindMethod(methName2); if (newMeth2 != null) { var confUnit2 = newMeth2.conflictUnit; var confUnit1 = new List <Tuple <Accesses, string, IOperation> >(); confUnit1.Add(ele); var k = IsThereDataRace(meth1, confUnit1, newMeth2, confUnit2); if (k != -1) { return(j); } } else if (progMethods.IndexOf(methName2) == -1) { string invocArg0 = meth2.FindInvokedArgument(ele2.Item2); if (invocArg0 == ele.Item2) { return(j); } } } else if (ele2.Item1 == Accesses.Write && ele2.Item2 == ele.Item2) { return(j); } else if (ele2.Item1 == Accesses.Read && ele2.Item2 == ele.Item2) { return(j); } } } } j = j + 1; } return(-1); }
private void RepairMethod(int methIndex) { if (methIndex > -1 && methIndex < cgMethods.Count) { MethodAnalyzer cpMeth = cgMethods[methIndex]; //int j = 0; // int cnt = cpMeth.conflictUnit.Count; List <Tuple <Accesses, string, IOperation> > cp = new List <Tuple <Accesses, string, IOperation> >(cpMeth.conflictUnit); foreach (var ele in cp) { int dr = -1; if (ele.Item1 == Accesses.Invocation) { string methName = cpMeth.FindInvokedMethod(ele.Item2); MethodAnalyzer newMeth = FindMethod(methName); if (newMeth != null) { if (newMeth.isAsync) { int j = FindInstruction(ele.Item2, cpMeth.conflictUnit, cpMeth.awaitInvocRel, Accesses.Invocation); int cnt = FindInstruction(ele.Item2, cpMeth.conflictUnit, cpMeth.awaitInvocRel, Accesses.Await); // position of the associated await List <Tuple <Accesses, string, IOperation> > confUnit1 = new List <Tuple <Accesses, string, IOperation> >(cpMeth.conflictUnit.GetRange(j + 1, cnt - j - 1)); var confUnit = newMeth.conflictUnit; int i = 0; string reg = ""; foreach (var ele2 in confUnit) { if (ele2.Item1 == Accesses.Await) { reg = ele2.Item2; break; } i = i + 1; } int cnt2 = confUnit.Count; List <Tuple <Accesses, string, IOperation> > confUnit2 = new List <Tuple <Accesses, string, IOperation> >(confUnit.GetRange(i + 1, cnt2 - i - 1)); foreach (var ele2 in confUnit) { if (ele2.Item1 == Accesses.Invocation && systemMethod.IndexOf(newMeth.FindInvokedMethod(reg)) != -1) { confUnit2.Insert(0, ele2); break; } i = i + 1; } dr = IsThereDataRace(cpMeth, confUnit1, newMeth, confUnit2); if (dr != -1) { var temp1 = cpMeth.conflictUnit[cnt]; // await position //var temp2 = cpMeth.conflictUnit[j + 1 + dr]; // conflict position to repair cpMeth.conflictUnit.RemoveAt(cnt); cpMeth.conflictUnit.Insert(j + 1 + dr, temp1); //cpMeth.conflictUnit[j + 1 + dr] = temp1; //cpMeth.conflictUnit[cnt] = temp2; nbRepairedDR = nbRepairedDR + 1; // increment the count of nb repaired data races } } } else if (systemMethod.IndexOf(methName) != -1) { int j = FindInstruction(ele.Item2, cpMeth.conflictUnit, cpMeth.awaitInvocRel, Accesses.Invocation); int cnt = FindInstruction(ele.Item2, cpMeth.conflictUnit, cpMeth.awaitInvocRel, Accesses.Await); // position of the associated await List <Tuple <Accesses, string, IOperation> > confUnit1 = new List <Tuple <Accesses, string, IOperation> >(cpMeth.conflictUnit.GetRange(j + 1, cnt - j - 1)); //int index = systemMethod.IndexOf(methName); List <Tuple <Accesses, string, IOperation> > confUnit2 = new List <Tuple <Accesses, string, IOperation> > { ele }; dr = IsThereDataRace(cpMeth, confUnit1, cpMeth, confUnit2); if (dr != -1) { var temp1 = cpMeth.conflictUnit[cnt]; // await position //var temp2 = cpMeth.conflictUnit[j + 1 + dr]; // conflict position to repair cpMeth.conflictUnit.RemoveAt(cnt); cpMeth.conflictUnit.Insert(j + 1 + dr, temp1); //cpMeth.conflictUnit[j + 1 + dr] = temp1; //cpMeth.conflictUnit[cnt] = temp2; nbRepairedDR = nbRepairedDR + 1; // increment the count of nb repaired data races } } } //j = j + 1; } cgMethods[methIndex] = cpMeth; } }