示例#1
0
 public InstantiatedMethodKey(MethodDesc methodDef, Instantiation instantiation)
 {
     _methodDef     = methodDef;
     _instantiation = instantiation;
     _hashcode      = TypeHashingAlgorithms.ComputeMethodHashCode(methodDef.OwningType.GetHashCode(),
                                                                  instantiation.ComputeGenericInstanceHashCode(TypeHashingAlgorithms.ComputeNameHashCode(methodDef.Name)));
 }
        /// <summary>
        /// Builds a native hashtable containing data about each manifest resource
        /// </summary>
        /// <returns></returns>
        private byte[] GenerateIndexBlob(NodeFactory factory)
        {
            NativeWriter    nativeWriter          = new NativeWriter();
            Section         indexHashtableSection = nativeWriter.NewSection();
            VertexHashtable indexHashtable        = new VertexHashtable();

            indexHashtableSection.Place(indexHashtable);

            // Build a table with a tuple of Assembly Full Name, Resource Name, Offset within the resource data blob, Length
            // for each resource.
            // This generates a hashtable for the convenience of managed code since there's
            // a reader for VertexHashtable, but not for VertexSequence.

            foreach (ResourceIndexData indexData in _resourceDataNode.GetOrCreateIndexData(factory))
            {
                Vertex asmName      = nativeWriter.GetStringConstant(indexData.AssemblyName);
                Vertex resourceName = nativeWriter.GetStringConstant(indexData.ResourceName);
                Vertex offsetVertex = nativeWriter.GetUnsignedConstant((uint)indexData.NativeOffset);
                Vertex lengthVertex = nativeWriter.GetUnsignedConstant((uint)indexData.Length);

                Vertex indexVertex = nativeWriter.GetTuple(asmName, resourceName);
                indexVertex = nativeWriter.GetTuple(indexVertex, offsetVertex);
                indexVertex = nativeWriter.GetTuple(indexVertex, lengthVertex);

                int hashCode = TypeHashingAlgorithms.ComputeNameHashCode(indexData.AssemblyName);
                indexHashtable.Append((uint)hashCode, indexHashtableSection.Place(indexVertex));
            }

            byte[] blob = nativeWriter.Save();
            _endSymbol.SetSymbolOffset(blob.Length);
            return(blob);
        }
示例#3
0
        public override int GetHashCode()
        {
            // TODO: Determine what a the right hash function should be. Use stable hashcode based on the type name?
            // For now, use the same hash as a SignatureVariable type.
            GenericParameter parameter = _module.MetadataReader.GetGenericParameter(_handle);

            return(TypeHashingAlgorithms.ComputeSignatureVariableHashCode(parameter.Index, parameter.Parent.Kind == HandleKind.MethodDefinition));
        }
示例#4
0
 public override int GetHashCode()
 {
     if (!_hashCode.HasValue)
     {
         _hashCode = _declaringTypeHandle.GetHashCode() ^ TypeHashingAlgorithms.ComputeGenericInstanceHashCode(TypeHashingAlgorithms.ComputeNameHashCode(_methodNameAndSignature.Name), _genericMethodArgumentHandles);
     }
     return(_hashCode.Value);
 }
示例#5
0
 public override int GetHashCode()
 {
     if (!_hashCode.HasValue)
     {
         _hashCode = TypeHashingAlgorithms.ComputeGenericInstanceHashCode(_genericTypeDefinitionHandle.GetHashCode(), _genericTypeArgumentHandles);
     }
     return(_hashCode.Value);
 }
            public RuntimeMethodKey(bool unboxingStub, DefType owningType, MethodNameAndSignature nameAndSignature)
            {
                _unboxingStub           = unboxingStub;
                _owningType             = owningType;
                _methodNameAndSignature = nameAndSignature;

                _hashCode = TypeHashingAlgorithms.ComputeMethodHashCode(owningType.GetHashCode(), TypeHashingAlgorithms.ComputeNameHashCode(nameAndSignature.Name));
            }
示例#7
0
        public override int GetHashCode()
        {
            if (_hashcode == 0)
            {
                _hashcode = TypeHashingAlgorithms.ComputeNameHashCode(FullName);
            }

            return(_hashcode);
        }
示例#8
0
        public void TestSingleDimensionalArrays()
        {
            DefType systemArrayType = _context.GetWellKnownType(WellKnownType.Array);

            TypeDesc objectType = _context.GetWellKnownType(WellKnownType.Object);

            ArrayType objectArray = _context.GetArrayType(objectType);

            Assert.Equal(TypeHashingAlgorithms.ComputeArrayTypeHashCode(objectType.GetHashCode(), 1), objectArray.GetHashCode());
        }
            public RuntimeMethodHandleKey(RuntimeTypeHandle declaringType, string methodName, RuntimeSignature signature, RuntimeTypeHandle[] genericArgs)
            {
                Debug.Assert(genericArgs != null);

                _declaringType = declaringType;
                _methodName    = methodName;
                _signature     = signature;
                _genericArgs   = genericArgs;
                _hashcode      = TypeHashingAlgorithms.ComputeGenericInstanceHashCode(declaringType.GetHashCode(), genericArgs) ^ methodName.GetHashCode() ^ signature.GetHashCode();
            }
示例#10
0
        void TestGenericTypes()
        {
            MetadataType ilistType          = (MetadataType)_testModule.GetType("System.Collections.Generic", "IList`1");
            DefType      systemArrayType    = _context.GetWellKnownType(WellKnownType.Array);
            DefType      ilistOfSystemArray = ilistType.MakeInstantiatedType(systemArrayType);

            int expectedIListOfTHashcode    = TypeHashingAlgorithms.ComputeNameHashCode("System.Collections.Generic.IList`1");
            int expectedSystemArrayHashcode = TypeHashingAlgorithms.ComputeNameHashCode("System.Array");

            Assert.Equal(expectedIListOfTHashcode, ilistType.GetHashCode());
            Assert.Equal(TypeHashingAlgorithms.ComputeGenericInstanceHashCode(expectedIListOfTHashcode, new int[] { expectedSystemArrayHashcode }), ilistOfSystemArray.GetHashCode());
        }
示例#11
0
        public void TestNonGenericTypes()
        {
            DefType      systemArrayType = _context.GetWellKnownType(WellKnownType.Array);
            MetadataType nonNestedType   = (MetadataType)_testModule.GetType("Hashcode", "NonNestedType");
            TypeDesc     nestedType      = nonNestedType.GetNestedType("NestedType");

            int expectedNonNestedTypeHashcode  = TypeHashingAlgorithms.ComputeNameHashCode("Hashcode.NonNestedType");
            int expectedNestedTypeNameHashcode = TypeHashingAlgorithms.ComputeNameHashCode("NestedType");
            int expectedNestedTypeHashcode     = TypeHashingAlgorithms.ComputeNestedTypeHashCode(expectedNonNestedTypeHashcode, expectedNestedTypeNameHashcode);

            Assert.Equal(expectedNonNestedTypeHashcode, nonNestedType.GetHashCode());
            Assert.Equal(expectedNestedTypeHashcode, nestedType.GetHashCode());
        }
示例#12
0
        public void TestMultidimensionalArrays()
        {
            DefType  systemArrayType = _context.GetWellKnownType(WellKnownType.Array);
            TypeDesc objectType      = _context.GetWellKnownType(WellKnownType.Object);

            ArrayType objectMDArrayRank1 = _context.GetArrayType(objectType, 1);
            ArrayType objectMDArrayRank2 = _context.GetArrayType(objectType, 2);
            ArrayType objectMDArrayRank3 = _context.GetArrayType(objectType, 3);

            Assert.Equal(TypeHashingAlgorithms.ComputeArrayTypeHashCode(objectType.GetHashCode(), 1), objectMDArrayRank1.GetHashCode());
            Assert.Equal(TypeHashingAlgorithms.ComputeArrayTypeHashCode(objectType.GetHashCode(), 2), objectMDArrayRank2.GetHashCode());
            Assert.Equal(TypeHashingAlgorithms.ComputeArrayTypeHashCode(objectType.GetHashCode(), 3), objectMDArrayRank3.GetHashCode());
        }
示例#13
0
        public void TestByRefTypes()
        {
            DefType intType = _context.GetWellKnownType(WellKnownType.Int32);

            int expHashInt = TypeHashingAlgorithms.ComputeNameHashCode("System.Int32");

            Assert.Equal(expHashInt, intType.GetHashCode());

            int      expHashIntByRef = TypeHashingAlgorithms.ComputeByrefTypeHashCode(expHashInt);
            TypeDesc intByRefType    = _context.GetByRefType(intType);

            Assert.Equal(expHashIntByRef, intByRefType.GetHashCode());
        }
示例#14
0
        public string Lookup(string s)
        {
            int hashCode = TypeHashingAlgorithms.ComputeNameHashCode(s);

            string existing = Find(hashCode, s);

            if (existing != null)
            {
                return(existing);
            }

            return(Add(hashCode, s));
        }
示例#15
0
        public void TestFunctionPointerTypes()
        {
            DefType intType    = _context.GetWellKnownType(WellKnownType.Int32);
            DefType objectType = _context.GetWellKnownType(WellKnownType.Object);

            int expHashInt    = TypeHashingAlgorithms.ComputeNameHashCode("System.Int32");
            int expHashObject = TypeHashingAlgorithms.ComputeNameHashCode("System.Object");

            int expHashFnPtr = TypeHashingAlgorithms.ComputeMethodSignatureHashCode(expHashInt, new[] { expHashObject });

            MethodSignature fnPtrSig  = new MethodSignature(MethodSignatureFlags.None, 0, intType, new TypeDesc[] { objectType });
            var             fnPtrType = _context.GetFunctionPointerType(fnPtrSig);

            Assert.Equal(expHashFnPtr, fnPtrType.GetHashCode());
        }
示例#16
0
        public override unsafe string GetString(byte *bytes, int byteCount)
        {
            bool isAscii;
            int  hashCode = TypeHashingAlgorithms.ComputeASCIINameHashCode(bytes, byteCount, out isAscii);

            if (isAscii)
            {
                string existing = FindASCII(hashCode, bytes, byteCount);
                if (existing != null)
                {
                    return(existing);
                }
                return(Add(hashCode, Encoding.GetString(bytes, byteCount)));
            }
            return(Lookup(Encoding.GetString(bytes, byteCount)));
        }
示例#17
0
文件: EcmaType.cs 项目: rivy/corert
        public override int GetHashCode()
        {
            if (_hashcode != 0)
            {
                return(_hashcode);
            }
            int      nameHash       = TypeHashingAlgorithms.ComputeNameHashCode(this.GetFullName());
            TypeDesc containingType = ContainingType;

            if (containingType == null)
            {
                _hashcode = nameHash;
            }
            else
            {
                _hashcode = TypeHashingAlgorithms.ComputeNestedTypeHashCode(containingType.GetHashCode(), nameHash);
            }

            return(_hashcode);
        }
示例#18
0
        private int InitializeHashCode()
        {
            TypeDesc containingType = ContainingType;
            if (containingType == null)
            {
                string ns = Namespace;
                var hashCodeBuilder = new TypeHashingAlgorithms.HashCodeBuilder(ns);
                if (ns.Length > 0)
                    hashCodeBuilder.Append(".");
                hashCodeBuilder.Append(Name);
                _hashcode = hashCodeBuilder.ToHashCode();
            }
            else
            {
                _hashcode = TypeHashingAlgorithms.ComputeNestedTypeHashCode(
                    containingType.GetHashCode(), TypeHashingAlgorithms.ComputeNameHashCode(Name));
            }

            return _hashcode;
        }
        public override int GetHashCode()
        {
            if (!_hashCode.HasValue)
            {
                int hashCode = 79 + 971 * (int)_thunkKind + 83 * (_targetFunctionPointer.GetHashCode() >> 7) + 13 * (_instantiatingArg.GetHashCode() >> 3);
                switch (_registrationKind)
                {
                case CallConversionInfoRegistrationKind.UsesMethodSignatureAndGenericArgs:
                    hashCode ^= _methodSignature.GetHashCode();
                    hashCode  = _typeArgs == null ? hashCode : TypeHashingAlgorithms.ComputeGenericInstanceHashCode(hashCode, _typeArgs);
                    hashCode  = _methodArgs == null ? hashCode : TypeHashingAlgorithms.ComputeGenericInstanceHashCode(hashCode, _methodArgs);
                    break;

                case CallConversionInfoRegistrationKind.UsesArgIteratorData:
                    hashCode ^= _argIteratorData.GetHashCode();
                    break;
                }
                _hashCode = hashCode;
            }

            return(_hashCode.Value);
        }
示例#20
0
            public RuntimeMethodHandleKey(RuntimeTypeHandle declaringType, string methodName, RuntimeSignature signature, RuntimeTypeHandle[] genericArgs)
            {
                // genericArgs will be null if this is a (typical or not) method definition
                // genericArgs are non-null only for instantiated generic methods.
                Debug.Assert(genericArgs == null || genericArgs.Length > 0);

                _declaringType = declaringType;
                _methodName    = methodName;
                _signature     = signature;
                _genericArgs   = genericArgs;
                int methodNameHashCode = methodName == null ? 0 : methodName.GetHashCode();

                _hashcode = methodNameHashCode ^ signature.GetHashCode();

                if (genericArgs != null)
                {
                    _hashcode ^= TypeHashingAlgorithms.ComputeGenericInstanceHashCode(declaringType.GetHashCode(), genericArgs);
                }
                else
                {
                    _hashcode ^= declaringType.GetHashCode();
                }
            }
示例#21
0
        public void TestInstantiatedMethods()
        {
            MetadataType nonNestedType = (MetadataType)_testModule.GetType("Hashcode", "NonNestedType");
            MetadataType genericType   = (MetadataType)_testModule.GetType("Hashcode", "GenericType`2");
            DefType      intType       = _context.GetWellKnownType(WellKnownType.Int32);
            DefType      stringType    = _context.GetWellKnownType(WellKnownType.String);

            MetadataType genericTypeOfIntString = genericType.MakeInstantiatedType(intType, stringType);
            MetadataType genericTypeOfStringInt = genericType.MakeInstantiatedType(stringType, intType);

            // build up expected hash codes for the above
            int expHashNonNestedType = TypeHashingAlgorithms.ComputeNameHashCode("Hashcode.NonNestedType");

            Assert.Equal(expHashNonNestedType, nonNestedType.GetHashCode());
            int expHashGenType = TypeHashingAlgorithms.ComputeNameHashCode("Hashcode.GenericType`2");

            Assert.Equal(expHashGenType, genericType.GetHashCode());
            int expHashInt = TypeHashingAlgorithms.ComputeNameHashCode("System.Int32");

            Assert.Equal(expHashInt, intType.GetHashCode());
            int expHashString = TypeHashingAlgorithms.ComputeNameHashCode("System.String");

            Assert.Equal(expHashString, stringType.GetHashCode());
            int expHashGenTypeOfIS = TypeHashingAlgorithms.ComputeGenericInstanceHashCode(expHashGenType, new int[] { expHashInt, expHashString });

            Assert.Equal(expHashGenTypeOfIS, genericTypeOfIntString.GetHashCode());
            int expHashGenTypeOfSI = TypeHashingAlgorithms.ComputeGenericInstanceHashCode(expHashGenType, new int[] { expHashString, expHashInt });

            Assert.Equal(expHashGenTypeOfSI, genericTypeOfStringInt.GetHashCode());

            // Test that instantiated method's have the right hashes

            int genMethodNameHash     = TypeHashingAlgorithms.ComputeNameHashCode("GenericMethod");
            int genMethodNameAndIHash = TypeHashingAlgorithms.ComputeGenericInstanceHashCode(genMethodNameHash, new int[] { expHashInt });
            int genMethodNameAndSHash = TypeHashingAlgorithms.ComputeGenericInstanceHashCode(genMethodNameHash, new int[] { expHashString });


            Action <MetadataType, int> testSequence = (MetadataType typeWithGenericMethod, int expectedTypeHash) =>
            {
                // Uninstantiated Generic method
                MethodDesc genMethod = typeWithGenericMethod.GetMethod("GenericMethod", null);
                Assert.Equal(TypeHashingAlgorithms.ComputeMethodHashCode(expectedTypeHash, genMethodNameHash), genMethod.GetHashCode());

                // Instantiated over int
                MethodDesc genMethodI = genMethod.MakeInstantiatedMethod(intType);
                Assert.Equal(TypeHashingAlgorithms.ComputeMethodHashCode(expectedTypeHash, genMethodNameAndIHash), genMethodI.GetHashCode());

                // Instantiated over string
                MethodDesc genMethodS = genMethod.MakeInstantiatedMethod(stringType);
                Assert.Equal(TypeHashingAlgorithms.ComputeMethodHashCode(expectedTypeHash, genMethodNameAndSHash), genMethodS.GetHashCode());

                // Assert they aren't the same as the other hashes
                Assert.NotEqual(genMethodI.GetHashCode(), genMethodS.GetHashCode());
                Assert.NotEqual(genMethodI.GetHashCode(), genMethod.GetHashCode());
                Assert.NotEqual(genMethodS.GetHashCode(), genMethod.GetHashCode());
            };

            // Test cases on non-generic type
            testSequence(nonNestedType, expHashNonNestedType);

            // Test cases on generic type
            testSequence(genericType, expHashGenType);

            // Test cases on instantiated generic type
            testSequence(genericTypeOfIntString, expHashGenTypeOfIS);
            testSequence(genericTypeOfStringInt, expHashGenTypeOfSI);
        }
示例#22
0
 public MethodForInstantiatedTypeKey(MethodDesc typicalMethodDef, InstantiatedType instantiatedType)
 {
     _typicalMethodDef = typicalMethodDef;
     _instantiatedType = instantiatedType;
     _hashcode         = TypeHashingAlgorithms.ComputeMethodHashCode(instantiatedType.GetHashCode(), TypeHashingAlgorithms.ComputeNameHashCode(typicalMethodDef.Name));
 }
示例#23
0
 internal override int LookupHashCode()
 {
     return(_typeToLookup != null?_typeToLookup.GetHashCode() : TypeHashingAlgorithms.ComputeGenericInstanceHashCode(_genericTypeDefinitionHandle.GetHashCode(), _genericTypeArgumentHandles));
 }
示例#24
0
 protected override int GetValueHashCode(ArrayType value)
 {
     return(TypeHashingAlgorithms.ComputeArrayTypeHashCode(value.ElementType, value.IsSzArray ? -1 : value.Rank));
 }
示例#25
0
 protected override int GetKeyHashCode(ArrayTypeKey key)
 {
     return(TypeHashingAlgorithms.ComputeArrayTypeHashCode(key._elementType, key._rank));
 }
示例#26
0
 /// <summary>
 /// Compute HashCode. Should only be overriden by a MethodDesc that represents an instantiated method.
 /// </summary>
 protected virtual int ComputeHashCode()
 {
     return(TypeHashingAlgorithms.ComputeMethodHashCode(OwningType.GetHashCode(), TypeHashingAlgorithms.ComputeNameHashCode(Name)));
 }
示例#27
0
 public override int GetHashCode()
 {
     return(TypeHashingAlgorithms.ComputeMethodSignatureHashCode(_returnType.GetHashCode(), _parameters));
 }
示例#28
0
 internal override int LookupHashCode()
 {
     // Todo: Signatures in the hash code.
     return(_methodToLookup != null?_methodToLookup.GetHashCode() : (_declaringType.GetHashCode() ^ TypeHashingAlgorithms.ComputeGenericInstanceHashCode(TypeHashingAlgorithms.ComputeNameHashCode(_nameAndSignature.Name), _genericMethodArgumentHandles)));
 }
示例#29
0
 protected override int ComputeHashCode()
 {
     return(TypeHashingAlgorithms.ComputeMethodHashCode(OwningType.GetHashCode(), Instantiation.ComputeGenericInstanceHashCode(TypeHashingAlgorithms.ComputeNameHashCode(Name))));
 }
示例#30
0
 public override int GetHashCode()
 {
     return(TypeHashingAlgorithms.ComputeSignatureVariableHashCode(Index, true));
 }