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; } }