コード例 #1
0
        /// <summary>
        /// Updates the tasks.
        /// </summary>
        /// <param name="machineTrace">MachineActionTrace</param>
        void UpdateTasks(MachineActionTrace machineTrace)
        {
            int currentMachineVC = 0;

            foreach (MachineActionInfo info in machineTrace)
            {
                if (info.Type == MachineActionType.TaskMachineCreation)
                {
                    //ThreadTrace matching = null;
                    var matching = this.AllThreadTraces.Where(item => item.IsTask && item.TaskId == info.TaskId);
                    if (matching.Count() == 0)
                    {
                        continue;
                    }

                    Node cn = new CActBegin(info.TaskMachineId.GetHashCode(), info.TaskId);
                    ((CActBegin)cn).IsStart = true;
                    cn.VectorClock          = new int[this.VcCount];
                    currentMachineVC++;
                    try
                    {
                        cn.VectorClock[info.TaskMachineId.GetHashCode()] = currentMachineVC;
                    }
                    catch (Exception ex)
                    {
                        IO.PrintLine("failed: " + this.VcCount + " " + info.TaskMachineId);
                        IO.PrintLine(ex.ToString());
                        Environment.Exit(Environment.ExitCode);
                    }
                    this.CGraph.AddVertex(cn);

                    foreach (var m in matching)
                    {
                        if (m.Accesses.Count > 0)
                        {
                            foreach (ActionInstr ins in m.Accesses)
                            {
                                ((CActBegin)cn).Addresses.Add(new MemAccess(ins.IsWrite, ins.Location, ins.ObjHandle, ins.Offset,
                                                                            ins.SrcLocation, info.TaskMachineId.GetHashCode()));
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        void DetectRacesFast()
        {
            IO.PrintLine("\nDETECTING RACES");

            if (this.CGraph.VertexCount == 0)
            {
                return;
            }

            List <Tuple <CActBegin, CActBegin> > checkRaces = new List <Tuple <CActBegin, CActBegin> >();

            foreach (Node n1 in this.CGraph.Vertices)
            {
                if (n1.GetType().ToString().Contains("CActBegin"))
                {
                    CActBegin v1 = (CActBegin)n1;
                    foreach (Node n2 in this.CGraph.Vertices)
                    {
                        if (n2.GetType().ToString().Contains("CActBegin"))
                        {
                            if (n1.Equals(n2))
                            {
                                continue;
                            }

                            CActBegin v2 = (CActBegin)n2;

                            if (v1.MachineId == v2.MachineId)
                            {
                                continue;
                            }

                            bool ordered = true;
                            for (int i = 0; i < this.VcCount; i++)
                            {
                                if (v1.VectorClock[i] > v2.VectorClock[i])
                                {
                                    ordered = false;
                                    break;
                                }
                            }

                            if (ordered == true)
                            {
                                continue;
                            }

                            bool orderedR = true;
                            for (int i = 0; i < this.VcCount; i++)
                            {
                                if (v2.VectorClock[i] > v1.VectorClock[i])
                                {
                                    orderedR = false;
                                    break;
                                }
                            }

                            if (orderedR == true)
                            {
                                continue;
                            }

                            checkRaces.Add(new Tuple <CActBegin, CActBegin>(v1, v2));
                        }
                    }
                }
            }

            List <Tuple <string, string> > reportedRaces = new List <Tuple <string, string> >();

            foreach (Tuple <CActBegin, CActBegin> checking in checkRaces)
            {
                List <MemAccess> addressList1 = checking.Item1.Addresses;
                List <MemAccess> addressList2 = checking.Item2.Addresses;

                foreach (MemAccess m in addressList1)
                {
                    foreach (MemAccess n in addressList2)
                    {
                        if (!(m.IsWrite || n.IsWrite))
                        {
                            continue;
                        }

                        if (m.ObjHandle == UIntPtr.Zero && m.Offset == UIntPtr.Zero &&
                            n.ObjHandle == UIntPtr.Zero && n.Offset == UIntPtr.Zero)
                        {
                            continue;
                        }

                        if (reportedRaces.Where(item
                                                => item.Item1.Equals(m.SrcLocation + ";" + m.IsWrite) &&
                                                item.Item2.Equals(n.SrcLocation + ";" + n.IsWrite)).Any() ||
                            reportedRaces.Where(item => item.Item1.Equals(n.SrcLocation + ";" + n.IsWrite) &&
                                                item.Item2.Equals(m.SrcLocation + ";" + m.IsWrite)).Any())
                        {
                            continue;
                        }

                        if (m.ObjHandle == n.ObjHandle && m.Offset == n.Offset)
                        {
                            IO.PrintLine("RACE: " + m.SrcLocation + ";" + m.IsWrite + " AND " +
                                         n.SrcLocation + ";" + n.IsWrite);
                            reportedRaces.Add(new Tuple <string, string>(m.SrcLocation + ";" + m.IsWrite,
                                                                         n.SrcLocation + ";" + n.IsWrite));
                        }
                    }
                }
            }
        }
コード例 #3
0
        void DetectRacesAgain()
        {
            IO.PrintLine("\nDETECTING RACES");

            List <Tuple <CActBegin, CActBegin> > checkRaces = new List <Tuple <CActBegin, CActBegin> >();

            foreach (Node n1 in this.CGraph.Vertices)
            {
                if (n1.GetType().ToString().Contains("CActBegin"))
                {
                    CActBegin v1 = (CActBegin)n1;
                    foreach (Node n2 in this.CGraph.Vertices)
                    {
                        if (n2.GetType().ToString().Contains("CActBegin"))
                        {
                            if (n1.Equals(n2))
                            {
                                continue;
                            }

                            CActBegin v2 = (CActBegin)n2;
                            if (v1.MachineId == v2.MachineId)
                            {
                                continue;
                            }

                            bool found = false;
                            foreach (MemAccess ma in v1.Addresses)
                            {
                                var list = v2.Addresses.Where(item
                                                              => item.ObjHandle == ma.ObjHandle &&
                                                              item.Offset == ma.Offset);
                                if (list.Count() > 0)

                                {
                                    found = true;
                                    break;
                                }
                            }

                            if (found == false)
                            {
                                continue;
                            }

                            if (!(cExistsPath(v1, v2) || cExistsPath(v2, v1)))
                            {
                                checkRaces.Add(new Tuple <CActBegin, CActBegin>(v1, v2));
                            }
                        }
                    }
                }
            }

            List <Tuple <string, string> > reportedRaces = new List <Tuple <string, string> >();

            foreach (Tuple <CActBegin, CActBegin> checking in checkRaces)
            {
                List <MemAccess> addressList1 = checking.Item1.Addresses;
                List <MemAccess> addressList2 = checking.Item2.Addresses;

                foreach (MemAccess m in addressList1)
                {
                    foreach (MemAccess n in addressList2)
                    {
                        if (!(m.IsWrite || n.IsWrite))
                        {
                            continue;
                        }

                        if (m.ObjHandle == UIntPtr.Zero && m.Offset == UIntPtr.Zero &&
                            n.ObjHandle == UIntPtr.Zero && n.Offset == UIntPtr.Zero)
                        {
                            continue;
                        }

                        if (reportedRaces.Where(item
                                                => item.Item1.Equals(m.SrcLocation + ";" + m.IsWrite) &&
                                                item.Item2.Equals(n.SrcLocation + ";" + n.IsWrite)).Any() ||
                            reportedRaces.Where(item => item.Item1.Equals(n.SrcLocation + ";" + n.IsWrite) &&
                                                item.Item2.Equals(m.SrcLocation + ";" + m.IsWrite)).Any())
                        {
                            continue;
                        }

                        if (m.ObjHandle == n.ObjHandle && m.Offset == n.Offset)
                        {
                            IO.PrintLine("RACE: " + m.SrcLocation + ";" + m.IsWrite + " AND " +
                                         n.SrcLocation + ";" + n.IsWrite);
                            reportedRaces.Add(new Tuple <string, string>(m.SrcLocation + ";" +
                                                                         m.IsWrite, n.SrcLocation + ";" + n.IsWrite));
                        }
                    }
                }
            }
        }
コード例 #4
0
 /// <summary>
 /// Updates the graph cross edges.
 /// </summary>
 void UpdateGraphCrossEdges()
 {
     foreach (Node n in this.CGraph.Vertices)
     {
         if (n.GetType().ToString().Contains("SendEvent"))
         {
             IEnumerable <Node> actBegins = this.CGraph.Vertices.Where(item
                                                                       => item.GetType().ToString().Contains("CActBegin"));
             foreach (Node n1 in actBegins)
             {
                 SendEvent sendNode  = (SendEvent)n;
                 CActBegin beginNode = (CActBegin)n1;
                 if (sendNode.ToMachine == beginNode.MachineId &&
                     sendNode.SendEventId == beginNode.EventId)
                 {
                     this.CGraph.AddEdge(new Edge(sendNode, beginNode));
                     for (int i = 0; i < this.VcCount; i++)
                     {
                         beginNode.VectorClock[i] = Math.Max(beginNode.VectorClock[i],
                                                             sendNode.VectorClock[i]);
                     }
                 }
             }
         }
         else if (n.GetType().ToString().Contains("CreateMachine"))
         {
             IEnumerable <Node> actBegins = this.CGraph.Vertices.Where(item
                                                                       => item.GetType().ToString().Contains("CActBegin"));
             foreach (Node n1 in actBegins)
             {
                 CreateMachine createNode = (CreateMachine)n;
                 CActBegin     beginNode  = (CActBegin)n1;
                 if (createNode.CreateMachineId == beginNode.MachineId && beginNode.ActionId == 1)
                 {
                     this.CGraph.AddEdge(new Edge(createNode, beginNode));
                     for (int i = 0; i < this.VcCount; i++)
                     {
                         beginNode.VectorClock[i] = Math.Max(beginNode.VectorClock[i],
                                                             createNode.VectorClock[i]);
                     }
                 }
             }
         }
         else if (n.GetType().ToString().Contains("CreateTask"))
         {
             IEnumerable <Node> actBegins = this.CGraph.Vertices.Where(item
                                                                       => item.GetType().ToString().Contains("CActBegin"));
             foreach (Node n1 in actBegins)
             {
                 CreateTask createNode = (CreateTask)n;
                 CActBegin  beginNode  = (CActBegin)n1;
                 if (createNode.TaskId == beginNode.TaskId)
                 {
                     this.CGraph.AddEdge(new Edge(createNode, beginNode));
                     for (int i = 0; i < this.VcCount; i++)
                     {
                         beginNode.VectorClock[i] = Math.Max(beginNode.VectorClock[i],
                                                             createNode.VectorClock[i]);
                     }
                 }
             }
         }
     }
 }
コード例 #5
0
        /// <summary>
        /// Prunes the graph.
        /// </summary>
        void PruneGraph()
        {
            List <Node> remove = new List <Node>();

            foreach (Node u in this.CGraph.Vertices)
            {
                if (u.GetType().ToString().Contains("CActBegin"))
                {
                    CActBegin m = (CActBegin)u;
                    if (m.Addresses.Count == 0)
                    {
                        remove.Add(u);
                        continue;
                    }

                    bool found = false;
                    foreach (Node v in this.CGraph.Vertices)
                    {
                        if (v.GetType().ToString().Contains("CActBegin"))
                        {
                            CActBegin n = (CActBegin)v;

                            if (m.Equals(n) || m.MachineId == n.MachineId)
                            {
                                continue;
                            }

                            foreach (MemAccess ma in m.Addresses)
                            {
                                var list = n.Addresses.Where(item
                                                             => item.ObjHandle == ma.ObjHandle &&
                                                             item.Offset == ma.Offset);
                                if (list.Count() > 0)
                                {
                                    found = true;
                                    break;
                                }
                            }
                        }
                        if (found == true)
                        {
                            break;
                        }
                    }

                    if (found == false)
                    {
                        remove.Add(u);
                    }
                }
            }

            foreach (Node u in remove)
            {
                if (this.CGraph.InDegree(u) == 0 || this.CGraph.OutDegree(u) == 0)
                {
                    this.CGraph.RemoveVertex(u);
                }
                else
                {
                    IEnumerable <Edge> fromEdges = this.CGraph.InEdges(u);
                    IEnumerable <Edge> toEdges   = this.CGraph.OutEdges(u);
                    foreach (Edge fromEdge in fromEdges)
                    {
                        Node from = fromEdge.Source;
                        foreach (Edge toEdge in toEdges)
                        {
                            Node to = toEdge.Target;
                            this.CGraph.AddEdge(new Edge(from, to));
                        }

                        this.CGraph.RemoveVertex(u);
                    }
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Updates the graph.
        /// </summary>
        /// <param name="machineTrace">MachineActionTrace</param>
        void UpdateGraph(MachineActionTrace machineTrace)
        {
            int currentMachineVC = 0;

            Node cLatestAction = null;

            foreach (MachineActionInfo info in machineTrace)
            {
                if (info.Type != MachineActionType.SendAction && (info.ActionId != 0) && !(info.Type == MachineActionType.TaskMachineCreation))
                {
                    ThreadTrace matching = null;

                    try
                    {
                        matching = this.AllThreadTraces.Where(item => item.MachineId == info.MachineId &&
                                                              item.ActionId == info.ActionId).Single();
                    }
                    catch (Exception)
                    {
                        //TODO: check correctness
                        //In case entry and exit functions not defined.
                        //IO.PrintLine("Skipping entry/exit actions: " + mt.MachineId + " " + mt.ActionId + " " + mt.ActionName);
                        continue;
                    }

                    Node cn = new CActBegin(matching.MachineId, matching.ActionName,
                                            matching.ActionId, info.EventName, info.EventId);
                    if (matching.ActionId == 1)
                    {
                        ((CActBegin)cn).IsStart = true;
                    }

                    cn.VectorClock = new int[this.VcCount];
                    currentMachineVC++;

                    try
                    {
                        cn.VectorClock[info.MachineId] = currentMachineVC;
                    }
                    catch (Exception ex)
                    {
                        IO.PrintLine("failed: " + this.VcCount + " " + info.MachineId);
                        IO.PrintLine(ex.ToString());
                        Environment.Exit(Environment.ExitCode);
                    }

                    this.CGraph.AddVertex(cn);

                    if (cLatestAction != null)
                    {
                        this.CGraph.AddEdge(new Edge(cLatestAction, cn));
                    }

                    Node cLatest = cn;
                    cLatestAction = cn;


                    bool createNew = false;

                    foreach (ActionInstr ins in matching.Accesses)
                    {
                        // User trace send event.
                        Node cn1;

                        if (createNew)
                        {
                            Node cnn = new CActBegin(matching.MachineId, matching.ActionName,
                                                     matching.ActionId, info.EventName, info.EventId);
                            cnn.VectorClock = new int[this.VcCount];
                            currentMachineVC++;

                            try
                            {
                                cnn.VectorClock[info.MachineId] = currentMachineVC;
                            }
                            catch (Exception ex)
                            {
                                IO.PrintLine("failed: " + this.VcCount + " " + info.MachineId);
                                IO.PrintLine(ex.ToString());
                                Environment.Exit(Environment.ExitCode);
                            }

                            this.CGraph.AddVertex(cnn);

                            cn = cnn;
                            this.CGraph.AddEdge(new Edge(cLatest, cn));
                            createNew = false;
                            cLatest   = cn;
                        }

                        if (ins.IsSend)
                        {
                            MachineActionInfo machineSend = machineTrace.Where(
                                item => item.MachineId == matching.MachineId &&
                                item.SendId == ins.SendId).Single();

                            cn1 = new SendEvent(machineSend.MachineId, machineSend.SendId,
                                                machineSend.TargetMachineId, machineSend.SendEventName, machineSend.EventId);
                            cn1.VectorClock = new int[this.VcCount];
                            currentMachineVC++;

                            try
                            {
                                cn1.VectorClock[info.MachineId] = currentMachineVC;
                            }
                            catch (Exception ex)
                            {
                                IO.PrintLine("failed: " + this.VcCount + " " + info.MachineId);
                                IO.PrintLine(ex.ToString());
                                Environment.Exit(Environment.ExitCode);
                            }

                            this.CGraph.AddVertex(cn1);
                            this.CGraph.AddEdge(new Edge(cLatest, cn1));

                            createNew = true;
                        }
                        // User trace create machine.
                        else if (ins.IsCreate)
                        {
                            cn1             = new CreateMachine(ins.CreateMachineId);
                            cn1.VectorClock = new int[this.VcCount];
                            currentMachineVC++;

                            try
                            {
                                cn1.VectorClock[info.MachineId] = currentMachineVC;
                            }
                            catch (Exception ex)
                            {
                                IO.PrintLine("failed: " + this.VcCount + " " + info.MachineId);
                                IO.PrintLine(ex.ToString());
                                Environment.Exit(Environment.ExitCode);
                            }

                            this.CGraph.AddVertex(cn1);
                            this.CGraph.AddEdge(new Edge(cLatest, cn1));

                            createNew = true;
                        }
                        // User trace task creation.
                        else if (ins.IsTask)
                        {
                            cn1             = new CreateTask(ins.TaskId);
                            cn1.VectorClock = new int[this.VcCount];
                            currentMachineVC++;

                            try
                            {
                                cn1.VectorClock[info.MachineId] = currentMachineVC;
                            }
                            catch (Exception ex)
                            {
                                IO.PrintLine("failed: " + this.VcCount + " " + info.MachineId);
                                IO.PrintLine(ex.ToString());
                                Environment.Exit(Environment.ExitCode);
                            }

                            this.CGraph.AddVertex(cn1);
                            this.CGraph.AddEdge(new Edge(cLatest, cn1));


                            createNew = true;
                        }
                        // User trace reads/writes.
                        else
                        {
                            ((CActBegin)cn).Addresses.Add(new MemAccess(ins.IsWrite, ins.Location,
                                                                        ins.ObjHandle, ins.Offset, ins.SrcLocation, info.MachineId));
                            cn1 = cn;
                        }

                        cLatest       = cn1;
                        cLatestAction = cn1;
                    }
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// Updates the graph.
        /// </summary>
        /// <param name="machineTrace">MachineActionTrace</param>
        void UpdateGraph(MachineActionTrace machineTrace)
        {
            int currentMachineVC = 0;

            Node cLatestAction = null;
            foreach (MachineActionInfo info in machineTrace)
            {
                if (info.Type != MachineActionType.SendAction && (info.ActionId != 0)/* && !info.isTaskMachine*/)
                {
                    ThreadTrace matching = null;

                    try
                    {
                        matching = this.AllThreadTraces.Where(item => item.MachineId == info.MachineId &&
                            item.ActionId == info.ActionId).Single();
                    }
                    catch (Exception)
                    {
                        //TODO: check correctness
                        //In case entry and exit functions not defined.
                        //IO.PrintLine("Skipping entry/exit actions: " + mt.MachineId + " " + mt.ActionId + " " + mt.ActionName);
                        continue;
                    }

                    Node cn = new CActBegin(matching.MachineId, matching.ActionName,
                        matching.ActionId, info.EventName, info.EventId);
                    if(matching.ActionId == 1)
                    {
                        ((CActBegin)cn).IsStart = true;
                    }

                    cn.VectorClock = new int[this.VcCount];
                    currentMachineVC++;

                    try
                    {
                        cn.VectorClock[info.MachineId] = currentMachineVC;
                    }
                    catch (Exception ex)
                    {
                        IO.PrintLine("failed: " + this.VcCount + " " + info.MachineId);
                        IO.PrintLine(ex.ToString());
                        Environment.Exit(Environment.ExitCode);
                    }

                    this.CGraph.AddVertex(cn);

                    if(cLatestAction != null)
                    {
                        this.CGraph.AddEdge(new Edge(cLatestAction, cn));
                    }

                    Node cLatest = cn;
                    cLatestAction = cn;

                    bool createNew = false;

                    foreach (ActionInstr ins in matching.Accesses)
                    {
                        // User trace send event.
                        Node cn1;

                        if (createNew)
                        {
                            Node cnn = new CActBegin(matching.MachineId, matching.ActionName,
                                matching.ActionId, info.EventName, info.EventId);
                            cnn.VectorClock = new int[this.VcCount];
                            currentMachineVC++;

                            try
                            {
                                cnn.VectorClock[info.MachineId] = currentMachineVC;
                            }
                            catch (Exception ex)
                            {
                                IO.PrintLine("failed: " + this.VcCount + " " + info.MachineId);
                                IO.PrintLine(ex.ToString());
                                Environment.Exit(Environment.ExitCode);
                            }

                            this.CGraph.AddVertex(cnn);

                            cn = cnn;
                            this.CGraph.AddEdge(new Edge(cLatest, cn));
                            createNew = false;
                            cLatest = cn;
                        }

                        if (ins.IsSend)
                        {
                            MachineActionInfo machineSend = machineTrace.Where(
                                item => item.MachineId == matching.MachineId &&
                                item.SendId == ins.SendId).Single();

                            cn1 = new SendEvent(machineSend.MachineId, machineSend.SendId,
                                machineSend.TargetMachineId, machineSend.EventName, machineSend.EventId);
                            cn1.VectorClock = new int[this.VcCount];
                            currentMachineVC++;

                            try
                            {
                                cn1.VectorClock[info.MachineId] = currentMachineVC;
                            }
                            catch (Exception ex)
                            {
                                IO.PrintLine("failed: " + this.VcCount + " " + info.MachineId);
                                IO.PrintLine(ex.ToString());
                                Environment.Exit(Environment.ExitCode);
                            }

                            this.CGraph.AddVertex(cn1);
                            this.CGraph.AddEdge(new Edge(cLatest, cn1));

                            createNew = true;
                        }
                        // User trace create machine.
                        else if (ins.IsCreate)
                        {
                            cn1 = new CreateMachine(ins.CreateMachineId);
                            cn1.VectorClock = new int[this.VcCount];
                            currentMachineVC++;

                            try
                            {
                                cn1.VectorClock[info.MachineId] = currentMachineVC;
                            }
                            catch (Exception ex)
                            {
                                IO.PrintLine("failed: " + this.VcCount + " " + info.MachineId);
                                IO.PrintLine(ex.ToString());
                                Environment.Exit(Environment.ExitCode);
                            }

                            this.CGraph.AddVertex(cn1);
                            this.CGraph.AddEdge(new Edge(cLatest, cn1));

                            createNew = true;
                        }
                        // User trace task creation.
                        else if (ins.IsTask)
                        {
                            cn1 = new CreateTask(ins.TaskId);
                            cn1.VectorClock = new int[this.VcCount];
                            currentMachineVC++;

                            try
                            {
                                cn1.VectorClock[info.MachineId] = currentMachineVC;
                            }
                            catch (Exception ex)
                            {
                                IO.PrintLine("failed: " + this.VcCount + " " + info.MachineId);
                                IO.PrintLine(ex.ToString());
                                Environment.Exit(Environment.ExitCode);
                            }

                            this.CGraph.AddVertex(cn1);
                            this.CGraph.AddEdge(new Edge(cLatest, cn1));

                            createNew = true;
                        }
                        // User trace reads/writes.
                        else
                        {
                            ((CActBegin)cn).Addresses.Add(new MemAccess(ins.IsWrite, ins.Location,
                                ins.ObjHandle, ins.Offset, ins.SrcLocation, info.MachineId));
                            cn1 = cn;

                        }

                        cLatest = cn1;
                        cLatestAction = cn1;
                    }
                }
            }
        }