public IMethodNode ImportedMethodNode( MethodDesc targetMethod, TypeDesc constrainedType, ModuleToken methodToken, SignatureContext signatureContext, bool unboxingStub) { IMethodNode methodImport; TypeAndMethod key = new TypeAndMethod(constrainedType, targetMethod, methodToken, unboxingStub, isInstantiatingStub: false); if (!_importMethods.TryGetValue(key, out methodImport)) { // First time we see a given external method - emit indirection cell and the import entry ExternalMethodImport indirectionCell = new ExternalMethodImport( this, ReadyToRunFixupKind.READYTORUN_FIXUP_MethodEntry, targetMethod, constrainedType, methodToken, unboxingStub, signatureContext); _importMethods.Add(key, indirectionCell); methodImport = indirectionCell; } return(methodImport); }
public sealed override bool TryGetModuleTokenForExternalType(TypeDesc type, out ModuleToken token) { Debug.Assert(!VersionsWithType(type)); if (_typeRefsInCompilationModuleSet == null) { _typeRefsInCompilationModuleSet = new Dictionary <TypeDesc, ModuleToken>(); foreach (var module in _compilationModuleSet) { EcmaModule ecmaModule = (EcmaModule)module; foreach (var typeRefHandle in ecmaModule.MetadataReader.TypeReferences) { try { TypeDesc typeFromTypeRef = ecmaModule.GetType(typeRefHandle); if (!_typeRefsInCompilationModuleSet.ContainsKey(typeFromTypeRef)) { _typeRefsInCompilationModuleSet.Add(typeFromTypeRef, new ModuleToken(ecmaModule, typeRefHandle)); } } catch (TypeSystemException) { } } } } return(_typeRefsInCompilationModuleSet.TryGetValue(type, out token)); }
protected override IMethodNode CreateMethodEntrypointNode(MethodDesc method) { ModuleToken moduleToken = Resolver.GetModuleTokenForMethod(method, throwIfNotFound: true); return(MethodEntrypoint(method, constrainedType: null, originalMethod: null, methodToken: moduleToken, signatureContext: InputModuleContext, isUnboxingStub: false, isInstantiatingStub: false)); }
public MethodFixupSignature MethodSignature( ReadyToRunFixupKind fixupKind, MethodDesc methodDesc, TypeDesc constrainedType, ModuleToken methodToken, SignatureContext signatureContext, bool isUnboxingStub, bool isInstantiatingStub) { Dictionary <TypeAndMethod, MethodFixupSignature> perFixupKindMap; if (!_methodSignatures.TryGetValue(fixupKind, out perFixupKindMap)) { perFixupKindMap = new Dictionary <TypeAndMethod, MethodFixupSignature>(); _methodSignatures.Add(fixupKind, perFixupKindMap); } TypeAndMethod key = new TypeAndMethod(constrainedType, methodDesc, methodToken, isUnboxingStub, isInstantiatingStub); MethodFixupSignature signature; if (!perFixupKindMap.TryGetValue(key, out signature)) { signature = new MethodFixupSignature(fixupKind, methodDesc, constrainedType, methodToken, signatureContext, isUnboxingStub, isInstantiatingStub); perFixupKindMap.Add(key, signature); } return(signature); }
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); } } }
public TypeAndMethod(TypeDesc type, MethodDesc method, ModuleToken methodToken, bool isUnboxingStub, bool isInstantiatingStub) { Type = type; Method = method; MethodToken = methodToken; IsUnboxingStub = isUnboxingStub; IsInstantiatingStub = isInstantiatingStub; }
public ISymbolNode StringLiteral(ModuleToken token) { if (!_importStrings.TryGetValue(token, out ISymbolNode stringNode)) { stringNode = new StringImport(_codegenNodeFactory.StringImports, token); _importStrings.Add(token, stringNode); } return(stringNode); }
public IMethodNode MethodEntrypoint(MethodDesc method) { ModuleToken moduleToken = Resolver.GetModuleTokenForMethod(method, throwIfNotFound: true); return(MethodEntrypoint( new MethodWithToken(method, moduleToken, constrainedType: null), isUnboxingStub: false, isInstantiatingStub: false, isPrecodeImportRequired: false)); }
protected override IMethodNode CreateMethodEntrypointNode(MethodDesc method) { ModuleToken moduleToken = Resolver.GetModuleTokenForMethod(method, throwIfNotFound: true); return(MethodEntrypoint( new MethodWithToken(method, moduleToken, constrainedType: null), isUnboxingStub: false, isInstantiatingStub: false, isPrecodeImportRequired: false, signatureContext: InputModuleContext)); }
public IMethodNode MethodEntrypoint( MethodDesc targetMethod, TypeDesc constrainedType, MethodDesc originalMethod, ModuleToken methodToken, bool isUnboxingStub, bool isInstantiatingStub, SignatureContext signatureContext) { bool isLocalMethod = CompilationModuleGroup.ContainsMethodBody(targetMethod, false); if (targetMethod == originalMethod || isLocalMethod) { constrainedType = null; } IMethodNode methodImport; TypeAndMethod key = new TypeAndMethod(constrainedType, targetMethod, methodToken, isUnboxingStub, isInstantiatingStub); if (!_importMethods.TryGetValue(key, out methodImport)) { if (!isLocalMethod) { // First time we see a given external method - emit indirection cell and the import entry methodImport = new ExternalMethodImport( this, ReadyToRunFixupKind.READYTORUN_FIXUP_MethodEntry, targetMethod, constrainedType, methodToken, isUnboxingStub, isInstantiatingStub, signatureContext); } else { MethodWithToken methodWithToken = new MethodWithToken(targetMethod, methodToken); methodImport = new LocalMethodImport( this, ReadyToRunFixupKind.READYTORUN_FIXUP_MethodEntry, methodWithToken, CreateMethodEntrypointNode(methodWithToken, isUnboxingStub, isInstantiatingStub, signatureContext), isUnboxingStub, isInstantiatingStub, signatureContext); } _importMethods.Add(key, methodImport); } return(methodImport); }
public IMethodNode ShadowConcreteMethod(MethodDesc targetMethod, TypeDesc constrainedType, MethodDesc originalMethod, ModuleToken methodToken, SignatureContext signatureContext, bool isUnboxingStub = false) { IMethodNode result; TypeAndMethod key = new TypeAndMethod(constrainedType, constrainedType != null ? originalMethod : targetMethod, methodToken, isUnboxingStub, isInstantiatingStub: false); if (!_shadowConcreteMethods.TryGetValue(key, out result)) { result = MethodEntrypoint(targetMethod, constrainedType, originalMethod, methodToken, signatureContext, isUnboxingStub); _shadowConcreteMethods.Add(key, result); } return(result); }
private ModuleToken GetTypeToken(ModuleToken token) { if (token.IsNull) { return(token); } MetadataReader mdReader = token.MetadataReader; EntityHandle handle = (EntityHandle)MetadataTokens.Handle((int)token.Token); ModuleToken typeToken; switch (token.TokenType) { case CorTokenType.mdtTypeRef: case CorTokenType.mdtTypeDef: typeToken = token; break; case CorTokenType.mdtMemberRef: { MemberReferenceHandle memberRefHandle = (MemberReferenceHandle)handle; MemberReference memberRef = mdReader.GetMemberReference(memberRefHandle); typeToken = new ModuleToken(token.Module, (mdToken)MetadataTokens.GetToken(memberRef.Parent)); } break; case CorTokenType.mdtFieldDef: { FieldDefinitionHandle fieldDefHandle = (FieldDefinitionHandle)handle; FieldDefinition fieldDef = mdReader.GetFieldDefinition(fieldDefHandle); typeToken = new ModuleToken(token.Module, (mdToken)MetadataTokens.GetToken(fieldDef.GetDeclaringType())); } break; case CorTokenType.mdtMethodDef: { MethodDefinitionHandle methodDefHandle = (MethodDefinitionHandle)handle; MethodDefinition methodDef = mdReader.GetMethodDefinition(methodDefHandle); typeToken = new ModuleToken(token.Module, (mdToken)MetadataTokens.GetToken(methodDef.GetDeclaringType())); } break; default: throw new NotImplementedException(); } return(typeToken); }
public ISortableSymbolNode MethodGenericDictionary(MethodDesc method, ModuleToken methodToken, SignatureContext signatureContext) { if (!_genericDictionaryCache.TryGetValue(method, out ISortableSymbolNode genericDictionary)) { genericDictionary = new PrecodeHelperImport( _codegenNodeFactory, _codegenNodeFactory.MethodSignature( ReadyToRunFixupKind.READYTORUN_FIXUP_MethodDictionary, method, constrainedType: null, methodToken: methodToken, signatureContext: signatureContext, isUnboxingStub: false, isInstantiatingStub: true)); _genericDictionaryCache.Add(method, genericDictionary); } return(genericDictionary); }
public IMethodNode MethodEntrypoint( MethodDesc targetMethod, TypeDesc constrainedType, MethodDesc originalMethod, ModuleToken methodToken, bool isUnboxingStub, bool isInstantiatingStub, SignatureContext signatureContext) { if (!CompilationModuleGroup.ContainsMethodBody(targetMethod, false)) { return(ImportedMethodNode(targetMethod, constrainedType, originalMethod, methodToken, isUnboxingStub, isInstantiatingStub, signatureContext)); } return(_methodEntrypoints.GetOrAdd(targetMethod, (m) => { return CreateMethodEntrypointNode(new MethodWithToken(targetMethod, methodToken), isUnboxingStub, isInstantiatingStub, signatureContext); })); }
public ISymbolNode InterfaceDispatchCell(MethodDesc method, ModuleToken methodToken, SignatureContext signatureContext, bool isUnboxingStub, string callSite) { MethodAndCallSite cellKey = new MethodAndCallSite(method, callSite); if (!_interfaceDispatchCells.TryGetValue(cellKey, out ISymbolNode dispatchCell)) { dispatchCell = new DelayLoadHelperImport( _codegenNodeFactory, _codegenNodeFactory.DispatchImports, ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_MethodCall | ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_FLAG_VSD, _codegenNodeFactory.MethodSignature(ReadyToRunFixupKind.READYTORUN_FIXUP_VirtualEntry, method, null, methodToken, signatureContext, isUnboxingStub, isInstantiatingStub: false), callSite); _interfaceDispatchCells.Add(cellKey, dispatchCell); } return(dispatchCell); }
public override bool TryGetModuleTokenForExternalType(TypeDesc type, out ModuleToken token) { Debug.Assert(!VersionsWithType(type)); if (_typeRefsInCompilationModuleSet == null) { _typeRefsInCompilationModuleSet = new Dictionary <TypeDesc, ModuleToken>(); EcmaModule ecmaModule = ((EcmaMethod)_method.GetTypicalMethodDefinition()).Module; foreach (var typeRefHandle in ecmaModule.MetadataReader.TypeReferences) { try { TypeDesc typeFromTypeRef = ecmaModule.GetType(typeRefHandle); _typeRefsInCompilationModuleSet[typeFromTypeRef] = new ModuleToken(ecmaModule, typeRefHandle); } catch (TypeSystemException) { } } } return(_typeRefsInCompilationModuleSet.TryGetValue(type, out token)); }
public IMethodNode MethodEntrypoint( MethodDesc targetMethod, TypeDesc constrainedType, MethodDesc originalMethod, ModuleToken methodToken, SignatureContext signatureContext, bool isUnboxingStub = false) { if (targetMethod == originalMethod) { constrainedType = null; } if (!CompilationModuleGroup.ContainsMethodBody(targetMethod, false)) { return(ImportedMethodNode(constrainedType != null ? originalMethod : targetMethod, constrainedType, methodToken, signatureContext, isUnboxingStub)); } return(_methodEntrypoints.GetOrAdd(targetMethod, (m) => { return CreateMethodEntrypointNode(targetMethod, signatureContext, isUnboxingStub); })); }
public ISymbolNode StringLiteral(ModuleToken moduleToken) { return(_importStrings.GetOrAdd(moduleToken)); }
/// <summary> /// Retrieve the module-based token for a type that is not part of the version bubble of the current compilation. /// </summary> /// <param name="type">Type to get a module token for</param> /// <param name="token">Module-based token for the type</param> /// <returns>Returns true the type was referenced by any of the input modules in the current compliation</returns> public abstract bool TryGetModuleTokenForExternalType(TypeDesc type, out ModuleToken token);
public ModuleTokenAndSignatureContext(ModuleToken moduleToken, SignatureContext signatureContext) { ModuleToken = moduleToken; SignatureContext = signatureContext; }
public ISymbolNode StringLiteral(ModuleToken moduleToken, SignatureContext signatureContext) { return(_importStrings.GetOrAdd(new ModuleTokenAndSignatureContext(moduleToken, signatureContext))); }
public MethodWithToken(MethodDesc method, ModuleToken token) { Method = method; Token = token; }
public IMethodNode StringAllocator(MethodDesc constructor, ModuleToken methodToken, SignatureContext signatureContext) { return(MethodEntrypoint(constructor, constrainedType: null, originalMethod: null, methodToken: methodToken, signatureContext: signatureContext, isUnboxingStub: false)); }
public ISymbolNode DelegateCtor(TypeDesc delegateType, MethodDesc targetMethod, ModuleToken methodToken, SignatureContext signatureContext) { TypeAndMethod ctorKey = new TypeAndMethod(delegateType, targetMethod, methodToken: methodToken, isUnboxingStub: false, isInstantiatingStub: false); if (!_delegateCtors.TryGetValue(ctorKey, out ISymbolNode ctorNode)) { IMethodNode targetMethodNode = _codegenNodeFactory.MethodEntrypoint( targetMethod, constrainedType: null, originalMethod: null, methodToken: methodToken, signatureContext: signatureContext, isUnboxingStub: false); ctorNode = new DelayLoadHelperImport( _codegenNodeFactory, _codegenNodeFactory.HelperImports, ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_Helper, new DelegateCtorSignature(delegateType, targetMethodNode, methodToken, signatureContext)); _delegateCtors.Add(ctorKey, ctorNode); } return(ctorNode); }