Esempio n. 1
0
        private void ProcessMarkStack()
        {
            do
            {
                while (_markStack.Count > 0)
                {
                    // Pop the top node of the mark stack
                    DependencyNodeCore <DependencyContextType> currentNode = _markStack.Pop();

                    Debug.Assert(currentNode.Marked);

                    // Only some marked objects are interesting for dynamic dependencies
                    // store those in a seperate list to avoid excess scanning over non-interesting
                    // nodes during dynamic dependency discovery
                    if (currentNode.InterestingForDynamicDependencyAnalysis)
                    {
                        _dynamicDependencyInterestingList.Add(currentNode);
                        _newDynamicDependenciesMayHaveAppeared = true;
                    }

                    // Add all static dependencies to the mark stack
                    GetStaticDependencies(currentNode);

                    // If there are dynamic dependencies, note for later
                    if (currentNode.HasDynamicDependencies)
                    {
                        _newDynamicDependenciesMayHaveAppeared = true;
                        _markedNodesWithDynamicDependencies.Add(new DynamicDependencyNode(currentNode));
                    }

                    // If this new node satisfies any stored conditional dependencies,
                    // add them to the mark stack
                    HashSet <DependencyNodeCore <DependencyContextType> .CombinedDependencyListEntry> storedDependencySet = null;
                    if (_conditional_dependency_store.TryGetValue(currentNode, out storedDependencySet))
                    {
                        foreach (DependencyNodeCore <DependencyContextType> .CombinedDependencyListEntry newlySatisfiedDependency in storedDependencySet)
                        {
                            AddToMarkStack(newlySatisfiedDependency.Node, newlySatisfiedDependency.Reason, newlySatisfiedDependency.OtherReasonNode, currentNode);
                        }

                        _conditional_dependency_store.Remove(currentNode);
                    }
                }

                // Find new dependencies introduced by dynamic depedencies
                if (_newDynamicDependenciesMayHaveAppeared)
                {
                    _newDynamicDependenciesMayHaveAppeared = false;
                    for (int i = 0; i < _markedNodesWithDynamicDependencies.Count; i++)
                    {
                        DynamicDependencyNode dynamicNode = _markedNodesWithDynamicDependencies[i];
                        dynamicNode.MarkNewDynamicDependencies(this);

                        // Update the copy in the list
                        _markedNodesWithDynamicDependencies[i] = dynamicNode;
                    }
                }
            } while (_markStack.Count != 0);
        }
Esempio n. 2
0
 public CombinedDependencyListEntry(DependencyNodeCore <DependencyContextType> node,
                                    DependencyNodeCore <DependencyContextType> otherReasonNode,
                                    string reason)
 {
     Node            = node;
     OtherReasonNode = otherReasonNode;
     Reason          = reason;
 }
        bool IDependencyAnalysisMarkStrategy <DependencyContextType> .MarkNode(
            DependencyNodeCore <DependencyContextType> node,
            DependencyNodeCore <DependencyContextType> reasonNode,
            DependencyNodeCore <DependencyContextType> reasonNode2,
            string reason)
        {
            bool retVal = false;

            int nodeIndex;

            if (!node.Marked)
            {
                nodeIndex = Interlocked.Increment(ref ObjectIndex);
                node.SetMark(nodeIndex);

                if (GraphId == 0)
                {
                    lock (GraphEventSource.Log)
                    {
                        if (GraphId == 0)
                        {
                            GraphId = Interlocked.Increment(ref s_GraphIds);
                            GraphEventSource.Log.Graph(GraphId, "");
                            RootIndex = Interlocked.Increment(ref ObjectIndex);
                            GraphEventSource.Log.Node(GraphId, RootIndex, "roots");
                        }
                    }
                }

                retVal = true;

                GraphEventSource.Log.Node(GraphId, nodeIndex, node.GetNameInternal(_context));
            }
            else
            {
                nodeIndex = (int)node.GetMark();
            }

            if (reasonNode != null)
            {
                if (reasonNode2 != null)
                {
                    GraphEventSource.Log.ConditionalEdge(GraphId, (int)reasonNode.GetMark(), (int)reasonNode2.GetMark(), nodeIndex, reason);
                }
                else
                {
                    GraphEventSource.Log.Edge(GraphId, (int)reasonNode.GetMark(), nodeIndex, reason);
                }
            }
            else
            {
                GraphEventSource.Log.Edge(GraphId, RootIndex, nodeIndex, reason);
            }
            return(retVal);
        }
Esempio n. 4
0
 private void GetStaticDependencies(DependencyNodeCore<DependencyContextType> node)
 {
     if (node.StaticDependenciesAreComputed)
     {
         GetStaticDependenciesImpl(node);
     }
     else
     {
         _deferredStaticDependencies.Add(node);
     }
 }
Esempio n. 5
0
        bool IDependencyAnalysisMarkStrategy <DependencyContextType> .MarkNode(
            DependencyNodeCore <DependencyContextType> node,
            DependencyNodeCore <DependencyContextType> reasonNode,
            DependencyNodeCore <DependencyContextType> reasonNode2,
            string reason)
        {
            if (node.Marked)
            {
                return(false);
            }

            node.SetMark(s_singleton);
            return(true);
        }
Esempio n. 6
0
        private bool AddToMarkStack(DependencyNodeCore <DependencyContextType> node, string reason, DependencyNodeCore <DependencyContextType> reason1, DependencyNodeCore <DependencyContextType> reason2)
        {
            if (_marker.MarkNode(node, reason1, reason2, reason))
            {
                if (PerfEventSource.Log.IsEnabled())
                {
                    PerfEventSource.Log.AddedNodeToMarkStack();
                }

                // Pop the top node of the mark stack
                if (_stackPopRandomizer == null)
                {
                    _markStack.Push(node);
                }
                else
                {
                    //
                    // Expose output file determinism bugs in our system by randomizing the order nodes are pushed
                    // on to the mark stack.
                    //
                    int randomNodeIndex = _stackPopRandomizer.Next(_markStack.Count);
                    var tempStack       = new Stack <DependencyNodeCore <DependencyContextType> >();

                    for (int i = 0; i < randomNodeIndex; i++)
                    {
                        tempStack.Push(_markStack.Pop());
                    }

                    _markStack.Push(node);

                    while (tempStack.Count > 0)
                    {
                        _markStack.Push(tempStack.Pop());
                    }
                }

                _markedNodes.Add(node);

                node.CallOnMarked(_dependencyContext);

                if (NewMarkedNode != null)
                {
                    NewMarkedNode(node);
                }

                return(true);
            }

            return(false);
        }
Esempio n. 7
0
 private void GetStaticDependencies(DependencyNodeCore <DependencyContextType> node)
 {
     if (node.StaticDependenciesAreComputed)
     {
         GetStaticDependenciesImpl(node);
     }
     else
     {
         int dependencyPhase = Math.Max(node.DependencyPhaseForDeferredStaticComputation, _currentDependencyPhase);
         if (!_deferredStaticDependencies.TryGetValue(dependencyPhase, out var deferredPerPhaseDependencies))
         {
             deferredPerPhaseDependencies = new List <DependencyNodeCore <DependencyContextType> >();
             _deferredStaticDependencies.Add(dependencyPhase, deferredPerPhaseDependencies);
         }
         deferredPerPhaseDependencies.Add(node);
     }
 }
Esempio n. 8
0
        private bool AddToMarkStack(DependencyNodeCore <DependencyContextType> node, string reason, DependencyNodeCore <DependencyContextType> reason1, DependencyNodeCore <DependencyContextType> reason2)
        {
            if (_marker.MarkNode(node, reason1, reason2, reason))
            {
                _markStack.Push(node);
                _markedNodes.Add(node);

                node.CallOnMarked(_dependencyContext);

                if (NewMarkedNode != null)
                {
                    NewMarkedNode(node);
                }

                return(true);
            }

            return(false);
        }
Esempio n. 9
0
        // Internal details
        private void GetStaticDependenciesImpl(DependencyNodeCore <DependencyContextType> node)
        {
            IEnumerable <DependencyNodeCore <DependencyContextType> .DependencyListEntry> staticDependencies = node.GetStaticDependencies(_dependencyContext);

            if (staticDependencies != null)
            {
                foreach (DependencyNodeCore <DependencyContextType> .DependencyListEntry dependency in staticDependencies)
                {
                    AddToMarkStack(dependency.Node, dependency.Reason, node, null);
                }
            }

            if (node.HasConditionalStaticDependencies)
            {
                foreach (DependencyNodeCore <DependencyContextType> .CombinedDependencyListEntry dependency in node.GetConditionalStaticDependencies(_dependencyContext))
                {
                    if (dependency.OtherReasonNode.Marked)
                    {
                        AddToMarkStack(dependency.Node, dependency.Reason, node, dependency.OtherReasonNode);
                    }
                    else
                    {
                        HashSet <DependencyNodeCore <DependencyContextType> .CombinedDependencyListEntry> storedDependencySet = null;
                        if (!_conditional_dependency_store.TryGetValue(dependency.OtherReasonNode, out storedDependencySet))
                        {
                            storedDependencySet = new HashSet <DependencyNodeCore <DependencyContextType> .CombinedDependencyListEntry>();
                            _conditional_dependency_store.Add(dependency.OtherReasonNode, storedDependencySet);
                        }
                        // Swap out other reason node as we're storing that as the dictionary key
                        DependencyNodeCore <DependencyContextType> .CombinedDependencyListEntry conditionalDependencyStoreEntry = new DependencyNodeCore <DependencyContextType> .CombinedDependencyListEntry();

                        conditionalDependencyStoreEntry.Node            = dependency.Node;
                        conditionalDependencyStoreEntry.Reason          = dependency.Reason;
                        conditionalDependencyStoreEntry.OtherReasonNode = node;

                        storedDependencySet.Add(conditionalDependencyStoreEntry);
                    }
                }
            }
        }
Esempio n. 10
0
 public DynamicDependencyNode(DependencyNodeCore<DependencyContextType> node)
 {
     _node = node;
     _next = 0;
 }
Esempio n. 11
0
 public MarkData(string reason, DependencyNodeCore <DependencyContextType> reason1, DependencyNodeCore <DependencyContextType> reason2)
 {
     Reason  = reason;
     Reason1 = reason1;
     Reason2 = reason2;
 }
Esempio n. 12
0
 public void Add(DependencyNodeCore <DependencyContextType> node,
                 string reason)
 {
     this.Add(new DependencyListEntry(node, reason));
 }
Esempio n. 13
0
 public DependencyListEntry(DependencyNodeCore <DependencyContextType> node,
                            string reason)
 {
     Node   = node;
     Reason = reason;
 }
 /// <summary>
 /// Add a root node
 /// </summary>
 public abstract void AddRoot(DependencyNodeCore <DependencyContextType> rootNode, string reason);