public VirtualResolutionFixupSignature VirtualResolutionFixupSignature(ReadyToRunFixupKind fixupKind, MethodWithToken declMethod, TypeDesc implType, MethodWithToken implMethod) { return(_virtualResolutionSignatures.GetOrAdd(new VirtualResolutionFixupSignatureFixupKey(fixupKind, declMethod, implType, implMethod))); }
public IMethodNode MethodEntrypoint(MethodWithToken method, bool isInstantiatingStub, bool isPrecodeImportRequired) { TypeAndMethod key = new TypeAndMethod(method.ConstrainedType, method, isInstantiatingStub, isPrecodeImportRequired); return(_importMethods.GetOrAdd(key)); }
public ISymbolNode GetPInvokeTargetNode(MethodWithToken methodWithToken) { return(_pInvokeTargetNodes.GetOrAdd(new PInvokeTargetKey(methodWithToken, isIndirect: false))); }
private void EmitMethodSpecificationSignature(MethodWithToken method, uint flags, bool enforceDefEncoding, SignatureContext context) { ModuleToken methodToken = method.Token; if (method.Method.HasInstantiation) { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_MethodInstantiation; if (!method.Token.IsNull) { if (method.Token.TokenType == CorTokenType.mdtMethodSpec) { MethodSpecification methodSpecification = methodToken.MetadataReader.GetMethodSpecification((MethodSpecificationHandle)methodToken.Handle); methodToken = new ModuleToken(methodToken.Module, methodSpecification.Method); } } } if (methodToken.IsNull && !enforceDefEncoding) { methodToken = context.GetModuleTokenForMethod(method.Method, throwIfNotFound: false); } if (methodToken.IsNull) { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType; methodToken = context.GetModuleTokenForMethod(method.Method); } if (method.Method.OwningType.HasInstantiation) { // resolveToken currently resolves the token in the context of a given scope; // in such case, we receive a method on instantiated type along with the // generic definition token. flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType; } switch (methodToken.TokenType) { case CorTokenType.mdtMethodDef: break; case CorTokenType.mdtMemberRef: flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_MemberRefToken; break; default: throw new NotImplementedException(); } EmitUInt(flags); if ((flags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType) != 0) { EmitTypeSignature(method.Method.OwningType, context); } EmitTokenRid(methodToken.Token); if ((flags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_MethodInstantiation) != 0) { Instantiation instantiation = method.Method.Instantiation; EmitUInt((uint)instantiation.Length); SignatureContext outerContext = context.OuterContext; for (int typeParamIndex = 0; typeParamIndex < instantiation.Length; typeParamIndex++) { EmitTypeSignature(instantiation[typeParamIndex], outerContext); } } }
public ISymbolNode InterfaceDispatchCell(MethodWithToken method, MethodDesc callingMethod) { MethodAndCallSite cellKey = new MethodAndCallSite(method, null); return(_interfaceDispatchCells.GetOrAdd(cellKey)); }
public MethodAndCallSite(MethodWithToken method, MethodDesc callingMethod) { Method = method; CallingMethod = callingMethod; }
private void EmitMethodSpecificationSignature(MethodWithToken method, uint flags, bool enforceDefEncoding, bool enforceOwningType, SignatureContext context) { ModuleToken methodToken = method.Token; if (method.Method.HasInstantiation && !method.Method.IsGenericMethodDefinition) { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_MethodInstantiation; if (!method.Token.IsNull) { if (method.Token.TokenType == CorTokenType.mdtMethodSpec) { MethodSpecification methodSpecification = methodToken.MetadataReader.GetMethodSpecification((MethodSpecificationHandle)methodToken.Handle); methodToken = new ModuleToken(methodToken.Module, methodSpecification.Method); } } } Debug.Assert(!methodToken.IsNull); switch (methodToken.TokenType) { case CorTokenType.mdtMethodDef: break; case CorTokenType.mdtMemberRef: flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_MemberRefToken; break; default: throw new NotImplementedException(); } if ((method.Token.Module != context.LocalContext) && (!enforceOwningType || (enforceDefEncoding && methodToken.TokenType == CorTokenType.mdtMemberRef))) { // If enforeOwningType is set, this is an entry for the InstanceEntryPoint or InstrumentationDataTable nodes // which are not used in quite the same way, and for which the MethodDef is always matched to the module // which defines the type flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_UpdateContext; } EmitUInt(flags); if ((flags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_UpdateContext) != 0) { uint moduleIndex = (uint)context.Resolver.GetModuleIndex(method.Token.Module); EmitUInt(moduleIndex); context = context.InnerContext(method.Token.Module); } if ((flags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType) != 0) { // The type here should be the type referred to by the memberref (if this is one, not the type where the method was eventually found! EmitTypeSignature(method.OwningType, context); } EmitTokenRid(methodToken.Token); if ((flags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_MethodInstantiation) != 0) { Instantiation instantiation = method.Method.Instantiation; EmitUInt((uint)instantiation.Length); SignatureContext methodInstantiationsContext; if ((flags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_UpdateContext) != 0) { methodInstantiationsContext = context; } else { methodInstantiationsContext = context.OuterContext; } for (int typeParamIndex = 0; typeParamIndex < instantiation.Length; typeParamIndex++) { EmitTypeSignature(instantiation[typeParamIndex], methodInstantiationsContext); } } }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { if (relocsOnly) { // Method fixup signature doesn't contain any direct relocs return(new ObjectData(data: Array.Empty <byte>(), relocs: null, alignment: 0, definedSymbols: null)); } ObjectDataSignatureBuilder dataBuilder = new ObjectDataSignatureBuilder(); dataBuilder.AddSymbol(this); // Optimize some of the fixups into a more compact form ReadyToRunFixupKind fixupKind = _fixupKind; bool optimized = false; if (!_method.Unboxing && !_isInstantiatingStub && _method.ConstrainedType == null && fixupKind == ReadyToRunFixupKind.MethodEntry) { if (!_method.Method.HasInstantiation && !_method.Method.OwningType.HasInstantiation && !_method.Method.OwningType.IsArray) { if (_method.Token.TokenType == CorTokenType.mdtMethodDef) { fixupKind = ReadyToRunFixupKind.MethodEntry_DefToken; optimized = true; } else if (_method.Token.TokenType == CorTokenType.mdtMemberRef) { if (!_method.OwningTypeNotDerivedFromToken) { fixupKind = ReadyToRunFixupKind.MethodEntry_RefToken; optimized = true; } } } } MethodWithToken method = _method; if (factory.CompilationModuleGroup.VersionsWithMethodBody(method.Method)) { if (method.Token.TokenType == CorTokenType.mdtMethodSpec) { method = new MethodWithToken(method.Method, factory.SignatureContext.GetModuleTokenForMethod(method.Method, throwIfNotFound: false), method.ConstrainedType, unboxing: _method.Unboxing, null); } else if (!optimized && (method.Token.TokenType == CorTokenType.mdtMemberRef)) { if (method.Method.OwningType.GetTypeDefinition() is EcmaType) { method = new MethodWithToken(method.Method, factory.SignatureContext.GetModuleTokenForMethod(method.Method, throwIfNotFound: false), method.ConstrainedType, unboxing: _method.Unboxing, null); } } } SignatureContext innerContext = dataBuilder.EmitFixup(factory, fixupKind, method.Token.Module, factory.SignatureContext); if (optimized && method.Token.TokenType == CorTokenType.mdtMethodDef) { dataBuilder.EmitMethodDefToken(method.Token); } else if (optimized && method.Token.TokenType == CorTokenType.mdtMemberRef) { dataBuilder.EmitMethodRefToken(method.Token); } else { dataBuilder.EmitMethodSignature(method, enforceDefEncoding: false, enforceOwningType: false, innerContext, _isInstantiatingStub); } return(dataBuilder.ToObjectData()); }
public MethodAndCallSite(MethodWithToken method, string callSite) { CallSite = callSite; Method = method; }
public MethodAndCallSite(MethodWithToken method, bool isUnboxingStub, MethodDesc callingMethod) { IsUnboxingStub = isUnboxingStub; Method = method; CallingMethod = callingMethod; }
public ISymbolNode GetIndirectPInvokeTargetNode(MethodWithToken methodWithToken, SignatureContext signatureContext) { return(_indirectPInvokeTargetNodes.GetOrAdd(new IndirectPInvokeTargetKey(methodWithToken, signatureContext))); }
public IndirectPInvokeTargetKey(MethodWithToken methodWithToken, SignatureContext signatureContext) { MethodWithToken = methodWithToken; SignatureContext = signatureContext; }
public MethodAndCallSite(MethodWithToken method, bool isUnboxingStub, string callSite) { CallSite = callSite; IsUnboxingStub = isUnboxingStub; Method = method; }
public DynamicHelperCellKey(MethodWithToken method, bool isUnboxingStub, bool isInstantiatingStub) { Method = method; IsUnboxingStub = isUnboxingStub; IsInstantiatingStub = isInstantiatingStub; }
public ISymbolNode InterfaceDispatchCell(MethodWithToken method, SignatureContext signatureContext, bool isUnboxingStub, string callSite) { MethodAndCallSite cellKey = new MethodAndCallSite(method, isUnboxingStub, callSite, signatureContext); return(_interfaceDispatchCells.GetOrAdd(cellKey)); }
public VirtualResolutionFixupSignature(ReadyToRunFixupKind fixupKind, MethodWithToken declMethod, TypeDesc implType, MethodWithToken implMethod) { _fixupKind = fixupKind; _declMethod = declMethod; _implType = implType; _implMethod = implMethod; // Ensure types in signature are loadable and resolvable, otherwise we'll fail later while emitting the signature CompilerTypeSystemContext compilerContext = (CompilerTypeSystemContext)declMethod.Method.Context; compilerContext.EnsureLoadableMethod(declMethod.Method); compilerContext.EnsureLoadableType(implType); if (implMethod != null) { compilerContext.EnsureLoadableMethod(implMethod.Method); } }
public PInvokeTargetKey(MethodWithToken methodWithToken, SignatureContext signatureContext, bool isIndirect) { MethodWithToken = methodWithToken; SignatureContext = signatureContext; IsIndirect = isIndirect; }
public ISymbolNode DynamicHelperCell(MethodWithToken methodWithToken, bool isInstantiatingStub, SignatureContext signatureContext) { DynamicHelperCellKey key = new DynamicHelperCellKey(methodWithToken, isUnboxingStub: false, isInstantiatingStub, signatureContext); return(_dynamicHelperCellCache.GetOrAdd(key)); }
public ISymbolNode GetPInvokeTargetNode(MethodWithToken methodWithToken, SignatureContext signatureContext) { return(_pInvokeTargetNodes.GetOrAdd(new PInvokeTargetKey(methodWithToken, signatureContext, isIndirect: false))); }
public ISymbolNode CheckVirtualFunctionOverride(MethodWithToken declMethod, TypeDesc implType, MethodWithToken implMethod) { return(_virtualFunctionOverrideCache.GetOrAdd(_codegenNodeFactory.VirtualResolutionFixupSignature( _verifyTypeAndFieldLayout ? ReadyToRunFixupKind.Verify_VirtualFunctionOverride : ReadyToRunFixupKind.Check_VirtualFunctionOverride, declMethod, implType, implMethod))); }
private MethodWithGCInfo CreateMethodEntrypointNodeHelper(MethodWithToken targetMethod) { Debug.Assert(CompilationModuleGroup.ContainsMethodBody(targetMethod.Method, false)); return(_localMethodCache.GetOrAdd(targetMethod.Method)); }
public PInvokeTargetKey(MethodWithToken methodWithToken, bool isIndirect) { MethodWithToken = methodWithToken; IsIndirect = isIndirect; }
public GenericLookupKey(CORINFO_RUNTIME_LOOKUP_KIND lookupKind, ReadyToRunFixupKind fixupKind, TypeDesc typeArgument, MethodWithToken methodArgument, TypeDesc contextType) { LookupKind = lookupKind; FixupKind = fixupKind; TypeArgument = typeArgument; MethodArgument = methodArgument; ContextType = contextType; }
public void EmitMethodSignature( MethodWithToken method, bool enforceDefEncoding, bool enforceOwningType, SignatureContext context, bool isInstantiatingStub) { uint flags = 0; if (method.Unboxing) { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_UnboxingStub; } if (isInstantiatingStub) { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_InstantiatingStub; } if (method.ConstrainedType != null) { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_Constrained; } if (enforceOwningType) { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType; } if ((method.Method.HasInstantiation || method.Method.OwningType.HasInstantiation) && !method.Method.IsGenericMethodDefinition) { EmitMethodSpecificationSignature(method, flags, enforceDefEncoding, context); } else { switch (method.Token.TokenType) { case CorTokenType.mdtMethodDef: { EmitUInt(flags); if ((flags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType) != 0) { EmitTypeSignature(method.Method.OwningType, context); } EmitMethodDefToken(method.Token); } break; case CorTokenType.mdtMemberRef: { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_MemberRefToken; // Owner type is needed for type specs to instantiating stubs or generics with signature variables still present if (!method.Method.OwningType.IsDefType && ((flags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_InstantiatingStub) != 0 || method.Method.OwningType.ContainsSignatureVariables()) || method.Method.IsArrayAddressMethod()) { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType; } EmitUInt(flags); if ((flags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType) != 0) { EmitTypeSignature(method.Method.OwningType, context); } EmitMethodRefToken(method.Token); } break; default: throw new NotImplementedException(); } } if (method.ConstrainedType != null) { EmitTypeSignature(method.ConstrainedType, context); } }
public void EmitMethodSignature( MethodWithToken method, bool enforceDefEncoding, bool enforceOwningType, SignatureContext context, bool isUnboxingStub, bool isInstantiatingStub) { uint flags = 0; if (isUnboxingStub) { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_UnboxingStub; } if (isInstantiatingStub) { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_InstantiatingStub; } if (method.ConstrainedType != null) { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_Constrained; } if (enforceOwningType) { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType; } if ((method.Method.HasInstantiation || method.Method.OwningType.HasInstantiation) && !method.Method.IsGenericMethodDefinition) { EmitMethodSpecificationSignature(method, flags, enforceDefEncoding, context); } else { switch (method.Token.TokenType) { case CorTokenType.mdtMethodDef: { EmitUInt(flags); if ((flags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType) != 0) { EmitTypeSignature(method.Method.OwningType, context); } EmitMethodDefToken(method.Token); } break; case CorTokenType.mdtMemberRef: { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_MemberRefToken; MemberReference memberRef = method.Token.MetadataReader.GetMemberReference((MemberReferenceHandle)method.Token.Handle); if (method.Token.Module.GetObject(memberRef.Parent) != (object)method.Method.OwningType) { // We have a memberref token for a different type - encode owning type explicitly in the signature flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType; } EmitUInt(flags); if ((flags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType) != 0) { EmitTypeSignature(method.Method.OwningType, context); } EmitMethodRefToken(method.Token); } break; default: throw new NotImplementedException(); } } if (method.ConstrainedType != null) { EmitTypeSignature(method.ConstrainedType, context); } }
private bool getReadyToRunHelper(ref CORINFO_RESOLVED_TOKEN pResolvedToken, ref CORINFO_LOOKUP_KIND pGenericLookupKind, CorInfoHelpFunc id, ref CORINFO_CONST_LOOKUP pLookup) { switch (id) { case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_NEW: { var type = HandleToObject(pResolvedToken.hClass); Debug.Assert(type.IsDefType); if (type.IsCanonicalSubtype(CanonicalFormKind.Any)) { return(false); } pLookup = CreateConstLookupToSymbol(_compilation.SymbolNodeFactory.ReadyToRunHelper(ReadyToRunHelperId.NewHelper, type, _signatureContext)); } break; case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_NEWARR_1: { var type = HandleToObject(pResolvedToken.hClass); Debug.Assert(type.IsSzArray); if (type.IsCanonicalSubtype(CanonicalFormKind.Any)) { return(false); } pLookup = CreateConstLookupToSymbol(_compilation.SymbolNodeFactory.ReadyToRunHelper(ReadyToRunHelperId.NewArr1, type, _signatureContext)); } break; case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_ISINSTANCEOF: { var type = HandleToObject(pResolvedToken.hClass); if (type.IsCanonicalSubtype(CanonicalFormKind.Any)) { return(false); } // ECMA-335 III.4.3: If typeTok is a nullable type, Nullable<T>, it is interpreted as "boxed" T if (type.IsNullable) { type = type.Instantiation[0]; } pLookup = CreateConstLookupToSymbol(_compilation.SymbolNodeFactory.ReadyToRunHelper(ReadyToRunHelperId.IsInstanceOf, type, _signatureContext)); } break; case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_CHKCAST: { var type = HandleToObject(pResolvedToken.hClass); if (type.IsCanonicalSubtype(CanonicalFormKind.Any)) { return(false); } // ECMA-335 III.4.3: If typeTok is a nullable type, Nullable<T>, it is interpreted as "boxed" T if (type.IsNullable) { type = type.Instantiation[0]; } pLookup = CreateConstLookupToSymbol(_compilation.SymbolNodeFactory.ReadyToRunHelper(ReadyToRunHelperId.CastClass, type, _signatureContext)); } break; case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_STATIC_BASE: { var type = HandleToObject(pResolvedToken.hClass); if (type.IsCanonicalSubtype(CanonicalFormKind.Any)) { return(false); } pLookup = CreateConstLookupToSymbol(_compilation.SymbolNodeFactory.ReadyToRunHelper(ReadyToRunHelperId.CctorTrigger, type, _signatureContext)); } break; case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_GENERIC_HANDLE: { Debug.Assert(pGenericLookupKind.needsRuntimeLookup); ReadyToRunHelperId helperId = (ReadyToRunHelperId)pGenericLookupKind.runtimeLookupFlags; object helperArg = HandleToObject((IntPtr)pGenericLookupKind.runtimeLookupArgs); if (helperArg is MethodDesc methodArg) { helperArg = new MethodWithToken(methodArg, new ModuleToken(_tokenContext, pResolvedToken.token)); } GenericContext methodContext = new GenericContext(entityFromContext(pResolvedToken.tokenContext)); ISymbolNode helper = _compilation.SymbolNodeFactory.GenericLookupHelper( pGenericLookupKind.runtimeLookupKind, helperId, helperArg, methodContext, _signatureContext); pLookup = CreateConstLookupToSymbol(helper); } break; default: throw new NotImplementedException("ReadyToRun: " + id.ToString()); } return(true); }
public VirtualResolutionFixupSignatureFixupKey(ReadyToRunFixupKind fixupKind, MethodWithToken declMethod, TypeDesc implType, MethodWithToken implMethod) { FixupKind = fixupKind; DeclMethod = declMethod; ImplType = implType; ImplMethod = implMethod; }