Exemplo n.º 1
0
        public IEnumerable <MethodWithGCInfo> EnumerateCompiledMethods(EcmaModule moduleToEnumerate, CompiledMethodCategory methodCategory)
        {
            foreach (IMethodNode methodNode in MetadataManager.GetCompiledMethods(moduleToEnumerate, methodCategory))
            {
                MethodDesc       method         = methodNode.Method;
                MethodWithGCInfo methodCodeNode = methodNode as MethodWithGCInfo;
#if DEBUG
                EcmaModule  module      = ((EcmaMethod)method.GetTypicalMethodDefinition()).Module;
                ModuleToken moduleToken = Resolver.GetModuleTokenForMethod(method, throwIfNotFound: true);

                IMethodNode      methodNodeDebug     = MethodEntrypoint(new MethodWithToken(method, moduleToken, constrainedType: null, unboxing: false, context: null), false, false, false);
                MethodWithGCInfo methodCodeNodeDebug = methodNodeDebug as MethodWithGCInfo;
                if (methodCodeNodeDebug == null && methodNodeDebug is DelayLoadMethodImport DelayLoadMethodImport)
                {
                    methodCodeNodeDebug = DelayLoadMethodImport.MethodCodeNode;
                }
                if (methodCodeNodeDebug == null && methodNodeDebug is PrecodeMethodImport precodeMethodImport)
                {
                    methodCodeNodeDebug = precodeMethodImport.MethodCodeNode;
                }
                Debug.Assert(methodCodeNodeDebug == methodCodeNode);
#endif

                if (methodCodeNode != null && !methodCodeNode.IsEmpty)
                {
                    yield return(methodCodeNode);
                }
            }
        }
Exemplo n.º 2
0
        public IEnumerable <IMethodNode> GetCompiledMethods(EcmaModule moduleToEnumerate, CompiledMethodCategory methodCategory)
        {
            lock (_methodsGenerated)
            {
                if (!_sortedMethods)
                {
                    TypeSystemComparer       comparer   = new TypeSystemComparer();
                    Comparison <IMethodNode> sortHelper = (x, y) => comparer.Compare(x.Method, y.Method);

                    List <PerModuleMethodsGenerated> perModuleDatas = new List <PerModuleMethodsGenerated>(_methodsGenerated.Values);
                    perModuleDatas.Sort((x, y) => x.Module.CompareTo(y.Module));

                    foreach (var perModuleData in perModuleDatas)
                    {
                        perModuleData.MethodsGenerated.Sort(sortHelper);
                        perModuleData.GenericMethodsGenerated.Sort(sortHelper);
                        _completeSortedMethods.AddRange(perModuleData.MethodsGenerated);
                        _completeSortedMethods.AddRange(perModuleData.GenericMethodsGenerated);
                        _completeSortedGenericMethods.AddRange(perModuleData.GenericMethodsGenerated);
                    }
                    _completeSortedMethods.Sort(sortHelper);
                    _completeSortedGenericMethods.Sort(sortHelper);
                    _sortedMethods = true;
                }
            }
            if (moduleToEnumerate == null)
            {
                if (methodCategory == CompiledMethodCategory.All)
                {
                    return(_completeSortedMethods);
                }
                else if (methodCategory == CompiledMethodCategory.Instantiated)
                {
                    return(_completeSortedGenericMethods);
                }
                else
                {
                    // This isn't expected to be needed, and thus isn't implemented
                    throw new ArgumentException();
                }
            }
            else if (_methodsGenerated.TryGetValue(moduleToEnumerate, out var perModuleData))
            {
                if (methodCategory == CompiledMethodCategory.All)
                {
                    return(GetCompiledMethodsAllMethodsInModuleHelper(moduleToEnumerate));
                }

                if (methodCategory == CompiledMethodCategory.Instantiated)
                {
                    return(perModuleData.GenericMethodsGenerated);
                }
                else
                {
                    Debug.Assert(methodCategory == CompiledMethodCategory.NonInstantiated);
                    return(perModuleData.MethodsGenerated);
                }
            }
            else
            {
                return(Array.Empty <IMethodNode>());
            }
        }
Exemplo n.º 3
0
        public IEnumerable <IMethodNode> GetCompiledMethods(EcmaModule moduleToEnumerate, CompiledMethodCategory methodCategory)
        {
            lock (_methodsGenerated)
            {
                if (!_sortedMethods)
                {
                    CompilerComparer comparer = CompilerComparer.Instance;
                    SortableDependencyNode.ObjectNodeComparer objectNodeComparer = new SortableDependencyNode.ObjectNodeComparer(comparer);
                    Comparison <IMethodNode> sortHelper = (x, y) =>
                    {
                        int nodeComparerResult = objectNodeComparer.Compare((SortableDependencyNode)x, (SortableDependencyNode)y);
#if DEBUG
                        int methodOnlyResult = comparer.Compare(x.Method, y.Method);

                        // Assert the two sorting techniques produce the same result unless there is a CustomSort applied
                        Debug.Assert((nodeComparerResult == methodOnlyResult) ||
                                     ((x is SortableDependencyNode sortableX && sortableX.CustomSort != Int32.MaxValue) ||
                                      (y is SortableDependencyNode sortableY && sortableY.CustomSort != Int32.MaxValue)));
#endif
                        return(nodeComparerResult);
                    };
                    Comparison <IMethodNode> sortHelperNoCustomSort = (x, y) => comparer.Compare(x, y);

                    List <PerModuleMethodsGenerated> perModuleDatas = new List <PerModuleMethodsGenerated>(_methodsGenerated.Values);
                    perModuleDatas.Sort((x, y) => x.Module.CompareTo(y.Module));

                    foreach (var perModuleData in perModuleDatas)
                    {
                        perModuleData.MethodsGenerated.MergeSort(sortHelperNoCustomSort);
                        perModuleData.GenericMethodsGenerated.MergeSort(sortHelperNoCustomSort);
                        _completeSortedMethods.AddRange(perModuleData.MethodsGenerated);
                        _completeSortedMethods.AddRange(perModuleData.GenericMethodsGenerated);
                        _completeSortedGenericMethods.AddRange(perModuleData.GenericMethodsGenerated);
                    }
                    _completeSortedMethods.MergeSort(sortHelper);
                    _completeSortedGenericMethods.MergeSort(sortHelper);
                    _sortedMethods = true;
                }
            }
            if (moduleToEnumerate == null)
            {
                if (methodCategory == CompiledMethodCategory.All)
                {
                    return(_completeSortedMethods);
                }
                else if (methodCategory == CompiledMethodCategory.Instantiated)
                {
                    return(_completeSortedGenericMethods);
                }
                else
                {
                    // This isn't expected to be needed, and thus isn't implemented
                    throw new ArgumentException();
                }
            }
            else if (_methodsGenerated.TryGetValue(moduleToEnumerate, out var perModuleData))
            {
                if (methodCategory == CompiledMethodCategory.All)
                {
                    return(GetCompiledMethodsAllMethodsInModuleHelper(moduleToEnumerate));
                }

                if (methodCategory == CompiledMethodCategory.Instantiated)
                {
                    return(perModuleData.GenericMethodsGenerated);
                }
                else
                {
                    Debug.Assert(methodCategory == CompiledMethodCategory.NonInstantiated);
                    return(perModuleData.MethodsGenerated);
                }
            }
            else
            {
                return(Array.Empty <IMethodNode>());
            }
        }
Exemplo n.º 4
0
        public IEnumerable <MethodWithGCInfo> EnumerateCompiledMethods(EcmaModule moduleToEnumerate, CompiledMethodCategory methodCategory)
        {
            foreach (IMethodNode methodNode in MetadataManager.GetCompiledMethods(moduleToEnumerate, methodCategory))
            {
                MethodDesc       method         = methodNode.Method;
                MethodWithGCInfo methodCodeNode = methodNode as MethodWithGCInfo;
#if DEBUG
                IMethodNode      methodNodeDebug     = MethodEntrypoint(method);
                MethodWithGCInfo methodCodeNodeDebug = methodNodeDebug as MethodWithGCInfo;
                if (methodCodeNodeDebug == null && methodNodeDebug is LocalMethodImport localMethodImport)
                {
                    methodCodeNodeDebug = localMethodImport.MethodCodeNode;
                }
                if (methodCodeNodeDebug == null && methodNodeDebug is PrecodeMethodImport precodeMethodImport)
                {
                    methodCodeNodeDebug = precodeMethodImport.MethodCodeNode;
                }
                Debug.Assert(methodCodeNodeDebug == methodCodeNode);
#endif

                if (methodCodeNode != null && !methodCodeNode.IsEmpty)
                {
                    yield return(methodCodeNode);
                }
            }
        }