Ejemplo n.º 1
0
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            if (_methods.Count == 0 || relocsOnly)
            {
                return(new ObjectData(
                           data: Array.Empty <byte>(),
                           relocs: Array.Empty <Relocation>(),
                           alignment: 1,
                           definedSymbols: new ISymbolDefinitionNode[] { this }));
            }

            GCRefMapBuilder builder = new GCRefMapBuilder(factory, relocsOnly);

            builder.Builder.RequireInitialAlignment(4);
            builder.Builder.AddSymbol(this);

            // First, emit the initial ref map offset and reserve the offset map entries
            int offsetCount = _methods.Count / GCREFMAP_LOOKUP_STRIDE;

            builder.Builder.EmitInt((offsetCount + 1) * sizeof(int));

            ObjectDataBuilder.Reservation[] offsets = new ObjectDataBuilder.Reservation[offsetCount];
            for (int offsetIndex = 0; offsetIndex < offsetCount; offsetIndex++)
            {
                offsets[offsetIndex] = builder.Builder.ReserveInt();
            }

            // Next, generate the actual method GC ref maps and update the offset map
            int nextOffsetIndex = 0;
            int nextMethodIndex = GCREFMAP_LOOKUP_STRIDE - 1;

            for (int methodIndex = 0; methodIndex < _methods.Count; methodIndex++)
            {
                if (methodIndex >= nextMethodIndex)
                {
                    builder.Builder.EmitInt(offsets[nextOffsetIndex], builder.Builder.CountBytes);
                    nextOffsetIndex++;
                    nextMethodIndex += GCREFMAP_LOOKUP_STRIDE;
                }
                MethodWithGCInfo methodNode = _methods[methodIndex];
                if (methodNode == null || methodNode.IsEmpty)
                {
                    // Flush an empty GC ref map block to prevent
                    // the indexed records from falling out of sync with methods
                    builder.Flush();
                }
                else
                {
                    builder.GetCallRefMap(methodNode.Method);
                }
            }
            Debug.Assert(nextOffsetIndex == offsets.Length);

            return(builder.Builder.ToObjectData());
        }
Ejemplo n.º 2
0
        public override int CompareToImpl(ISortableNode other, CompilerComparer comparer)
        {
            MethodWithGCInfo otherNode = (MethodWithGCInfo)other;
            int result = comparer.Compare(_method, otherNode._method);

            if (result != 0)
            {
                return(result);
            }

            return(SignatureContext.CompareTo(otherNode.SignatureContext, comparer));
        }
Ejemplo n.º 3
0
        public int GetIndex(MethodWithGCInfo method)
        {
#if DEBUG
            Debug.Assert(_nodeFactory.MarkingComplete);
            Debug.Assert(method.Marked);
#endif
            if (_methodNodes == null)
            {
                LayoutRuntimeFunctions();
            }

            return(_insertedMethodNodes[method]);
        }
Ejemplo n.º 4
0
 public PrecodeMethodImport(
     NodeFactory factory,
     ReadyToRunFixupKind fixupKind,
     MethodWithToken method,
     MethodWithGCInfo localMethod,
     bool isInstantiatingStub) :
     base(
         factory,
         factory.MethodSignature(
             fixupKind,
             method,
             isInstantiatingStub)
         )
 {
     _localMethod = localMethod;
     _method      = method;
 }
Ejemplo n.º 5
0
        private ArraySignatureBuilder BuildSignatureForMethod(MethodWithGCInfo method, NodeFactory factory)
        {
            // In composite R2R format, always enforce owning type to let us share generic instantiations among modules

            EcmaMethod  typicalMethod = (EcmaMethod)method.Method.GetTypicalMethodDefinition();
            ModuleToken moduleToken   = new ModuleToken(typicalMethod.Module, typicalMethod.Handle);

            ArraySignatureBuilder signatureBuilder = new ArraySignatureBuilder();

            signatureBuilder.EmitMethodSignature(
                new MethodWithToken(method.Method, moduleToken, constrainedType: null, unboxing: false, context: null),
                enforceDefEncoding: true,
                enforceOwningType: _factory.CompilationModuleGroup.EnforceOwningType(moduleToken.Module),
                factory.SignatureContext,
                isInstantiatingStub: false);

            return(signatureBuilder);
        }
Ejemplo n.º 6
0
 public DelayLoadMethodImport(
     NodeFactory factory,
     ReadyToRunFixupKind fixupKind,
     MethodWithToken method,
     MethodWithGCInfo localMethod,
     bool isInstantiatingStub)
     : base(
         factory,
         factory.MethodImports,
         ReadyToRunHelper.DelayLoad_MethodCall,
         factory.MethodSignature(
             fixupKind,
             method,
             isInstantiatingStub))
 {
     _localMethod = localMethod;
     _method      = method;
 }
Ejemplo n.º 7
0
 public PrecodeMethodImport(
     ReadyToRunCodegenNodeFactory factory,
     ReadyToRunFixupKind fixupKind,
     MethodWithToken method,
     MethodWithGCInfo localMethod,
     bool isUnboxingStub,
     bool isInstantiatingStub,
     SignatureContext signatureContext) :
     base(
         factory,
         factory.MethodSignature(
             fixupKind,
             method,
             isUnboxingStub,
             isInstantiatingStub,
             signatureContext)
         )
 {
     _localMethod = localMethod;
 }
Ejemplo n.º 8
0
 public LocalMethodImport(
     ReadyToRunCodegenNodeFactory factory,
     ReadyToRunFixupKind fixupKind,
     MethodWithToken method,
     MethodWithGCInfo localMethod,
     bool isUnboxingStub,
     bool isInstantiatingStub,
     SignatureContext signatureContext)
     : base(
         factory,
         factory.MethodImports,
         ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_MethodCall,
         factory.MethodSignature(
             fixupKind,
             method,
             isUnboxingStub,
             isInstantiatingStub,
             signatureContext))
 {
     _signatureContext = signatureContext;
     _localMethod      = localMethod;
 }
Ejemplo n.º 9
0
 public LocalMethodImport(
     ReadyToRunCodegenNodeFactory factory,
     ReadyToRunFixupKind fixupKind,
     MethodWithGCInfo localMethod,
     bool isUnboxingStub,
     SignatureContext signatureContext)
     : base(
         factory,
         factory.MethodImports,
         ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_MethodCall,
         factory.MethodSignature(
             fixupKind,
             localMethod.Method,
             constrainedType: null,
             methodToken: default(ModuleToken),
             signatureContext,
             isUnboxingStub,
             isInstantiatingStub: false))
 {
     _signatureContext = signatureContext;
     _localMethod      = localMethod;
 }
Ejemplo n.º 10
0
        private byte[] CreateBoundsBlobForMethod(MethodWithGCInfo method)
        {
            if (method.DebugLocInfos == null || method.DebugLocInfos.Length == 0)
            {
                return(null);
            }

            NibbleWriter writer = new NibbleWriter();

            writer.WriteUInt((uint)method.DebugLocInfos.Length);

            uint previousNativeOffset = 0;

            foreach (var locInfo in method.DebugLocInfos)
            {
                writer.WriteUInt(locInfo.nativeOffset - previousNativeOffset);
                writer.WriteUInt(locInfo.ilOffset + 3); // Count of items in Internal.JitInterface.MappingTypes to adjust the IL offset by
                writer.WriteUInt((uint)locInfo.source);

                previousNativeOffset = locInfo.nativeOffset;
            }

            return(writer.ToArray());
        }
Ejemplo n.º 11
0
 public EntryPoint(int methodIndex, MethodWithGCInfo method)
 {
     MethodIndex = methodIndex;
     Method      = method;
 }
Ejemplo n.º 12
0
 public ProfileDataNode(MethodWithGCInfo methodNode, TargetDetails targetDetails)
 {
     _methodNode    = methodNode;
     _targetDetails = targetDetails;
 }
Ejemplo n.º 13
0
 public MethodGCInfoNode(MethodWithGCInfo methodNode)
 {
     _methodNode = methodNode;
 }
Ejemplo n.º 14
0
        public override int CompareToImpl(ISortableNode other, CompilerComparer comparer)
        {
            MethodWithGCInfo otherNode = (MethodWithGCInfo)other;

            return(comparer.Compare(_method, otherNode._method));
        }
Ejemplo n.º 15
0
        private byte[] CreateVarBlobForMethod(MethodWithGCInfo method)
        {
            if (method.DebugVarInfos == null || method.DebugVarInfos.Length == 0)
            {
                return(null);
            }

            NibbleWriter writer = new NibbleWriter();

            writer.WriteUInt((uint)method.DebugVarInfos.Length);

            foreach (var nativeVarInfo in method.DebugVarInfos)
            {
                writer.WriteUInt(nativeVarInfo.startOffset);
                writer.WriteUInt(nativeVarInfo.endOffset - nativeVarInfo.startOffset);
                writer.WriteUInt((uint)(nativeVarInfo.varNumber - (int)ILNum.MAX_ILNUM));

                VarLocType varLocType = nativeVarInfo.varLoc.LocationType;

                writer.WriteUInt((uint)varLocType);

                switch (varLocType)
                {
                case VarLocType.VLT_REG:
                case VarLocType.VLT_REG_FP:
                case VarLocType.VLT_REG_BYREF:
                    writer.WriteUInt((uint)nativeVarInfo.varLoc.B);
                    break;

                case VarLocType.VLT_STK:
                case VarLocType.VLT_STK_BYREF:
                    writer.WriteUInt((uint)nativeVarInfo.varLoc.B);
                    writer.WriteInt(nativeVarInfo.varLoc.C);
                    break;

                case VarLocType.VLT_REG_REG:
                    writer.WriteUInt((uint)nativeVarInfo.varLoc.B);
                    writer.WriteUInt((uint)nativeVarInfo.varLoc.C);
                    break;

                case VarLocType.VLT_REG_STK:
                    writer.WriteUInt((uint)nativeVarInfo.varLoc.B);
                    writer.WriteUInt((uint)nativeVarInfo.varLoc.C);
                    writer.WriteInt(nativeVarInfo.varLoc.D);
                    break;

                case VarLocType.VLT_STK_REG:
                    writer.WriteInt(nativeVarInfo.varLoc.B);
                    writer.WriteUInt((uint)nativeVarInfo.varLoc.C);
                    writer.WriteUInt((uint)nativeVarInfo.varLoc.D);
                    break;

                case VarLocType.VLT_STK2:
                    writer.WriteUInt((uint)nativeVarInfo.varLoc.B);
                    writer.WriteInt(nativeVarInfo.varLoc.C);
                    break;

                case VarLocType.VLT_FPSTK:
                    writer.WriteUInt((uint)nativeVarInfo.varLoc.B);
                    break;

                case VarLocType.VLT_FIXED_VA:
                    writer.WriteUInt((uint)nativeVarInfo.varLoc.B);
                    break;

                default:
                    throw new BadImageFormatException("Unexpected var loc type");
                }
            }

            return(writer.ToArray());
        }
Ejemplo n.º 16
0
 private byte[] BuildSignatureForMethod(MethodWithGCInfo method, NodeFactory factory)
 {
     return(BuildSignatureForMethodDefinedInModule(method.Method, factory));
 }