private bool CanFetch(HeaderNode node) { bool isAvailable = _status.BestKnownHeader?.IsInSameChain(node) == true; bool canServe = (!IsWitnessEnabled(node.Previous) || PeerContext.CanServeWitness); return(isAvailable && canServe); }
public uint GetNextWorkRequired(HeaderNode previousHeaderNode, BlockHeader header) { if (previousHeaderNode == null) { ThrowHelper.ThrowArgumentNullException(nameof(previousHeaderNode)); } if (!_blockHeaderRepository.TryGet(previousHeaderNode.Hash, out BlockHeader? previousHeader)) { //this should never happens, if it happens means we have consistency problem (we lost an header) ThrowHelper.ThrowArgumentNullException(nameof(previousHeaderNode)); } uint proofOfWorkLimit = _consensusParameters.PowLimit.ToCompact(); int difficultyAdjustmentInterval = (int)GetDifficultyAdjustmentInterval(); // Only change once per difficulty adjustment interval if ((previousHeaderNode.Height + 1) % difficultyAdjustmentInterval != 0) { if (_consensusParameters.PowAllowMinDifficultyBlocks) { /// Special difficulty rule for test networks: /// if the new block's timestamp is more than 2 times the PoWTargetSpacing then allow mining of a min-difficulty block. if (header.TimeStamp > (previousHeader.TimeStamp + (_consensusParameters.PowTargetSpacing * 2))) { return(proofOfWorkLimit); } else { // Return the last non-special-min-difficulty-rules-block. HeaderNode currentHeaderNode = previousHeaderNode; BlockHeader currentHeader = previousHeader; while (currentHeaderNode.Previous != null && (currentHeaderNode.Height % difficultyAdjustmentInterval) != 0 && _blockHeaderRepository.TryGet(currentHeaderNode.Hash, out currentHeader !) && currentHeader.Bits == proofOfWorkLimit ) { currentHeaderNode = currentHeaderNode.Previous; } return(currentHeader.Bits); } } return(previousHeader.Bits); } // Go back by what we want to be 14 days worth of blocks int heightReference = previousHeaderNode.Height - (difficultyAdjustmentInterval - 1); HeaderNode?headerNodeReference = previousHeaderNode.GetAncestor(heightReference); BlockHeader?headerReference = null; if (headerNodeReference == null || !_blockHeaderRepository.TryGet(headerNodeReference.Hash, out headerReference)) { ThrowHelper.ThrowNotSupportedException("Header ancestor not found, PoW required work computation requires a full chain."); } return(CalculateNextWorkRequired(previousHeader, headerReference.TimeStamp)); }
public NodeFactory( CompilerTypeSystemContext context, CompilationModuleGroup compilationModuleGroup, NameMangler nameMangler, ModuleTokenResolver moduleTokenResolver, SignatureContext signatureContext, CopiedCorHeaderNode corHeaderNode, DebugDirectoryNode debugDirectoryNode, ResourceData win32Resources, AttributePresenceFilterNode attributePresenceFilterNode, HeaderNode headerNode) { TypeSystemContext = context; CompilationModuleGroup = compilationModuleGroup; Target = context.Target; NameMangler = nameMangler; MetadataManager = new ReadyToRunTableManager(context); Resolver = moduleTokenResolver; InputModuleContext = signatureContext; CopiedCorHeaderNode = corHeaderNode; DebugDirectoryNode = debugDirectoryNode; AttributePresenceFilter = attributePresenceFilterNode; Header = headerNode; if (!win32Resources.IsEmpty) { Win32ResourcesNode = new Win32ResourcesNode(win32Resources); } CreateNodeCaches(); }
} //* Unique Y value indentifing the location of each node /// <summary> /// Node constructor /// </summary> /// <param name="pX">Unique X value to indentify the node</param> /// <param name="pY">Unique Y value to indentify the node</param> /// <param name="pHeader">The header node for the column this node is contained in</param> public Node(int pX, int pY, HeaderNode pHeader) { Left = this; Right = this; Up = this; Down = this; X = pX; Y = pY; Header = pHeader; }
/// <summary> /// Initializes a new instance of the <see cref="BlockHeaderValidationSucceeded" /> class. /// </summary> /// <param name="validatedHeaders">The number of headers validated in the batch.</param> /// <param name="lastValidatedBlockHeader">The last validated block header.</param> /// <param name="lastValidatedHeaderNode">The last validated header node.</param> /// <param name="newHeadersFoundCount">The number of new headers found during this validation batch.</param> /// <param name="peerContext">The peer context.</param> public BlockHeaderValidationSucceeded(int validatedHeaders, BlockHeader lastValidatedBlockHeader, HeaderNode lastValidatedHeaderNode, int newHeadersFoundCount, IPeerContext?peerContext) { ValidatedHeadersCount = validatedHeaders; LastValidatedBlockHeader = lastValidatedBlockHeader; LastValidatedHeaderNode = lastValidatedHeaderNode; NewHeadersFoundCount = newHeadersFoundCount; PeerContext = peerContext; }
public async Task <bool> TryFetchAsync(HeaderNode blockToDownload, uint minimumScore) { uint blockScore = GetFetchBlockScore(blockToDownload); if (blockScore < minimumScore || blockScore == 0) { logger.LogDebug("Cannot download the block, score {BlockScore} doesn't satisfy requirement {MinimumScore}", blockScore, minimumScore); return(false); } await FetchBlockAsync(blockToDownload).ConfigureAwait(false); return(true); }
//Create the framework for the Dancing Links data structure protected void BuildFrame(int NumRows, int NumColumns) { StartNode = new HeaderNode(); StartNode.Name = "Start Node"; ColumnHeaders = new HeaderNode[NumColumns]; for (int i = 0; i < ColumnHeaders.Length; i++) { HeaderNode NewNode = new HeaderNode(); NewNode.Name = string.Format("Column {0}", i); ColumnHeaders[i] = NewNode; InsertLeft(StartNode, NewNode); } RowHeaders = new Node[NumRows]; }
private void PromoteEntireTreeToNewLevel(int itemsBeforeNewNodeBelow, TValue value, Node newNodeBelow) { if (newNodeBelow != null && _currentLevel < _maxLevel && ShouldPromoteToNextLevel()) { var newTopLeftNode = new HeaderNode(); TopLeft.Above = newTopLeftNode; newTopLeftNode.Below = TopLeft; newTopLeftNode.ItemsInNode = TotalItems; SplitNode(newTopLeftNode, itemsBeforeNewNodeBelow, value, newNodeBelow); TopLeft = newTopLeftNode; _currentLevel++; } }
public static string DumpKnownTree(HeaderNode tip) { var stringBuilder = new StringBuilder(); var nodes = new List <HeaderNode>(tip.Height + 1); HeaderNode?current = tip; do { nodes.Add(current); current = current.Previous; } while (current != null); nodes.Reverse(); for (int i = 0; i < nodes.Count - 1; i++) { PrintNode(stringBuilder, nodes[i], indent: "", isLast: false); } PrintNode(stringBuilder, nodes[^ 1], indent: "", isLast: true);
/// <summary> /// DancingLinks construtor /// </summary> /// <param name="pMap">Binary map to intialize the links. Any spot with non-zero in the map will be initialized with a node.</param> public DancingLinks(int[,] pMap) { _width = pMap.GetLength(0); _height = pMap.GetLength(1); //Initialize our matrix with an extra column for the header nodes Node[,] matrix = new Node[_width, _height + 1]; //Cycle through the matrix for (int X = 0; X < _width; X++) { HeaderNode header = new HeaderNode(X, 0); matrix[X, 0] = header; for (int Y = 0; Y < _height; Y++) { //If the map has a 1 if (pMap[X, Y] != 0) { //Initialize a node in the position matrix[X, Y + 1] = new Node(X, Y, header); //Mark the count of nodes for this column header.Count++; } } } //Create the links between each node LinkNodes(matrix); //Insert noot node Root = new HeaderNode(-1, -1); //Link root node Root.Left = matrix[0, 0].Left; Root.Right = matrix[0, 0]; Root.Left.Right = Root; matrix[0, 0].Left = Root; }
protected void UncoverColumn(HeaderNode TargetNode) { for (Node i = TargetNode.Up; i != TargetNode; i = i.Up) { for (Node j = i.Left; j != i; j = j.Left) { RestoreUpDown(j); j.Header.Size++; } } RestoreLeftRight(TargetNode); }
public override void AttachToDependencyGraph(DependencyAnalyzerBase <NodeFactory> graph) { Header = new HeaderNode(Target); var compilerIdentifierNode = new CompilerIdentifierNode(Target); Header.Add(Internal.Runtime.ReadyToRunSectionType.CompilerIdentifier, compilerIdentifierNode, compilerIdentifierNode); RuntimeFunctionsTable = new RuntimeFunctionsTableNode(this); Header.Add(Internal.Runtime.ReadyToRunSectionType.RuntimeFunctions, RuntimeFunctionsTable, RuntimeFunctionsTable); RuntimeFunctionsGCInfo = new RuntimeFunctionsGCInfoNode(); graph.AddRoot(RuntimeFunctionsGCInfo, "GC info is always generated"); ExceptionInfoLookupTableNode exceptionInfoLookupTableNode = new ExceptionInfoLookupTableNode(this); Header.Add(Internal.Runtime.ReadyToRunSectionType.ExceptionInfo, exceptionInfoLookupTableNode, exceptionInfoLookupTableNode); graph.AddRoot(exceptionInfoLookupTableNode, "ExceptionInfoLookupTable is always generated"); MethodEntryPointTable = new MethodEntryPointTableNode(Target); Header.Add(Internal.Runtime.ReadyToRunSectionType.MethodDefEntryPoints, MethodEntryPointTable, MethodEntryPointTable); InstanceEntryPointTable = new InstanceEntryPointTableNode(Target); Header.Add(Internal.Runtime.ReadyToRunSectionType.InstanceMethodEntryPoints, InstanceEntryPointTable, InstanceEntryPointTable); TypesTable = new TypesTableNode(Target); Header.Add(Internal.Runtime.ReadyToRunSectionType.AvailableTypes, TypesTable, TypesTable); ImportSectionsTable = new ImportSectionsTableNode(Target); Header.Add(Internal.Runtime.ReadyToRunSectionType.ImportSections, ImportSectionsTable, ImportSectionsTable.StartSymbol); DebugInfoTable = new DebugInfoTableNode(Target); Header.Add(Internal.Runtime.ReadyToRunSectionType.DebugInfo, DebugInfoTable, DebugInfoTable); EagerImports = new ImportSectionNode( "EagerImports", CorCompileImportType.CORCOMPILE_IMPORT_TYPE_UNKNOWN, CorCompileImportFlags.CORCOMPILE_IMPORT_FLAGS_EAGER, (byte)Target.PointerSize, emitPrecode: false, emitGCRefMap: false); ImportSectionsTable.AddEmbeddedObject(EagerImports); // All ready-to-run images have a module import helper which gets patched by the runtime on image load ModuleImport = new Import(EagerImports, new ReadyToRunHelperSignature( ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Module)); graph.AddRoot(ModuleImport, "Module import is required by the R2R format spec"); if (Target.Architecture != TargetArchitecture.X86) { Import personalityRoutineImport = new Import(EagerImports, new ReadyToRunHelperSignature( ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_PersonalityRoutine)); PersonalityRoutine = new ImportThunk( ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_PersonalityRoutine, this, personalityRoutineImport); graph.AddRoot(PersonalityRoutine, "Personality routine is faster to root early rather than referencing it from each unwind info"); Import filterFuncletPersonalityRoutineImport = new Import(EagerImports, new ReadyToRunHelperSignature( ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_PersonalityRoutineFilterFunclet)); FilterFuncletPersonalityRoutine = new ImportThunk( ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_PersonalityRoutineFilterFunclet, this, filterFuncletPersonalityRoutineImport); graph.AddRoot(FilterFuncletPersonalityRoutine, "Filter funclet personality routine is faster to root early rather than referencing it from each unwind info"); } MethodImports = new ImportSectionNode( "MethodImports", CorCompileImportType.CORCOMPILE_IMPORT_TYPE_STUB_DISPATCH, CorCompileImportFlags.CORCOMPILE_IMPORT_FLAGS_PCODE, (byte)Target.PointerSize, emitPrecode: false, emitGCRefMap: true); ImportSectionsTable.AddEmbeddedObject(MethodImports); DispatchImports = new ImportSectionNode( "DispatchImports", CorCompileImportType.CORCOMPILE_IMPORT_TYPE_STUB_DISPATCH, CorCompileImportFlags.CORCOMPILE_IMPORT_FLAGS_PCODE, (byte)Target.PointerSize, emitPrecode: false, emitGCRefMap: true); ImportSectionsTable.AddEmbeddedObject(DispatchImports); HelperImports = new ImportSectionNode( "HelperImports", CorCompileImportType.CORCOMPILE_IMPORT_TYPE_UNKNOWN, CorCompileImportFlags.CORCOMPILE_IMPORT_FLAGS_PCODE, (byte)Target.PointerSize, emitPrecode: false, emitGCRefMap: false); ImportSectionsTable.AddEmbeddedObject(HelperImports); PrecodeImports = new ImportSectionNode( "PrecodeImports", CorCompileImportType.CORCOMPILE_IMPORT_TYPE_UNKNOWN, CorCompileImportFlags.CORCOMPILE_IMPORT_FLAGS_PCODE, (byte)Target.PointerSize, emitPrecode: true, emitGCRefMap: false); ImportSectionsTable.AddEmbeddedObject(PrecodeImports); StringImports = new ImportSectionNode( "StringImports", CorCompileImportType.CORCOMPILE_IMPORT_TYPE_STRING_HANDLE, CorCompileImportFlags.CORCOMPILE_IMPORT_FLAGS_UNKNOWN, (byte)Target.PointerSize, emitPrecode: true, emitGCRefMap: false); ImportSectionsTable.AddEmbeddedObject(StringImports); graph.AddRoot(ImportSectionsTable, "Import sections table is always generated"); graph.AddRoot(ModuleImport, "Module import is always generated"); graph.AddRoot(EagerImports, "Eager imports are always generated"); graph.AddRoot(MethodImports, "Method imports are always generated"); graph.AddRoot(DispatchImports, "Dispatch imports are always generated"); graph.AddRoot(HelperImports, "Helper imports are always generated"); graph.AddRoot(PrecodeImports, "Precode imports are always generated"); graph.AddRoot(StringImports, "String imports are always generated"); graph.AddRoot(Header, "ReadyToRunHeader is always generated"); MetadataManager.AttachToDependencyGraph(graph); }
public PendingDownload(HeaderNode blockInDownload, IBlockFetcher blockFetcher, long startingTime) { BlockInDownload = blockInDownload; BlockFetcher = blockFetcher; StartingTime = startingTime; }
public uint GetFetchBlockScore(HeaderNode blockToBeEvaluated) { return(CanFetch(blockToBeEvaluated) ? GetScore() + 100 : 0); }
public override ICompilation ToCompilation() { ModuleTokenResolver moduleTokenResolver = new ModuleTokenResolver(_compilationGroup, _context); SignatureContext signatureContext = new SignatureContext(_inputModule, moduleTokenResolver); CopiedCorHeaderNode corHeaderNode = new CopiedCorHeaderNode(_inputModule); AttributePresenceFilterNode attributePresenceFilterNode = null; DebugDirectoryNode debugDirectoryNode = new DebugDirectoryNode(_inputModule); // Core library attributes are checked FAR more often than other dlls // attributes, so produce a highly efficient table for determining if they are // present. Other assemblies *MAY* benefit from this feature, but it doesn't show // as useful at this time. if (_inputModule == _inputModule.Context.SystemModule) { attributePresenceFilterNode = new AttributePresenceFilterNode(_inputModule); } // Produce a ResourceData where the IBC PROFILE_DATA entry has been filtered out ResourceData win32Resources = new ResourceData(_inputModule, (object type, object name, ushort language) => { if (!(type is string) || !(name is string)) { return(true); } if (language != 0) { return(true); } string typeString = (string)type; string nameString = (string)name; if ((typeString == "IBC") && (nameString == "PROFILE_DATA")) { return(false); } return(true); }); ReadyToRunFlags flags = ReadyToRunFlags.READYTORUN_FLAG_NonSharedPInvokeStubs; if (_inputModule.IsPlatformNeutral) { flags |= ReadyToRunFlags.READYTORUN_FLAG_PlatformNeutralSource; } flags |= _compilationGroup.GetReadyToRunFlags(); var header = new HeaderNode(_context.Target, flags); NodeFactory factory = new NodeFactory( _context, _compilationGroup, _nameMangler, moduleTokenResolver, signatureContext, corHeaderNode, debugDirectoryNode, win32Resources, attributePresenceFilterNode, header); IComparer <DependencyNodeCore <NodeFactory> > comparer = new SortableDependencyNode.ObjectNodeComparer(new CompilerComparer()); DependencyAnalyzerBase <NodeFactory> graph = CreateDependencyGraph(factory, comparer); List <CorJitFlag> corJitFlags = new List <CorJitFlag> { CorJitFlag.CORJIT_FLAG_DEBUG_INFO }; switch (_optimizationMode) { case OptimizationMode.None: corJitFlags.Add(CorJitFlag.CORJIT_FLAG_DEBUG_CODE); break; case OptimizationMode.PreferSize: corJitFlags.Add(CorJitFlag.CORJIT_FLAG_SIZE_OPT); break; case OptimizationMode.PreferSpeed: corJitFlags.Add(CorJitFlag.CORJIT_FLAG_SPEED_OPT); break; default: // Not setting a flag results in BLENDED_CODE. break; } if (_ibcTuning) { corJitFlags.Add(CorJitFlag.CORJIT_FLAG_BBINSTR); } corJitFlags.Add(CorJitFlag.CORJIT_FLAG_FEATURE_SIMD); JitConfigProvider.Initialize(corJitFlags, _ryujitOptions, _jitPath); return(new ReadyToRunCodegenCompilation( graph, factory, _compilationRoots, _ilProvider, _logger, new DependencyAnalysis.ReadyToRun.DevirtualizationManager(_compilationGroup), _inputFilePath, new ModuleDesc[] { _inputModule }, _resilient, _generateMapFile, _parallelism)); }
public override void AttachToDependencyGraph(DependencyAnalyzerBase <NodeFactory> graph) { Header = new HeaderNode(Target); var compilerIdentifierNode = new CompilerIdentifierNode(Target); Header.Add(Internal.Runtime.ReadyToRunSectionType.CompilerIdentifier, compilerIdentifierNode, compilerIdentifierNode); RuntimeFunctionsTable = new RuntimeFunctionsTableNode(this); Header.Add(Internal.Runtime.ReadyToRunSectionType.RuntimeFunctions, RuntimeFunctionsTable, RuntimeFunctionsTable); RuntimeFunctionsGCInfo = new RuntimeFunctionsGCInfoNode(); graph.AddRoot(RuntimeFunctionsGCInfo, "GC info is always generated"); ProfileDataSection = new ProfileDataSectionNode(); Header.Add(Internal.Runtime.ReadyToRunSectionType.ProfileDataInfo, ProfileDataSection, ProfileDataSection.StartSymbol); ExceptionInfoLookupTableNode exceptionInfoLookupTableNode = new ExceptionInfoLookupTableNode(this); Header.Add(Internal.Runtime.ReadyToRunSectionType.ExceptionInfo, exceptionInfoLookupTableNode, exceptionInfoLookupTableNode); graph.AddRoot(exceptionInfoLookupTableNode, "ExceptionInfoLookupTable is always generated"); MethodEntryPointTable = new MethodEntryPointTableNode(Target); Header.Add(Internal.Runtime.ReadyToRunSectionType.MethodDefEntryPoints, MethodEntryPointTable, MethodEntryPointTable); ManifestMetadataTable = new ManifestMetadataTableNode(InputModuleContext.GlobalContext); Header.Add(Internal.Runtime.ReadyToRunSectionType.ManifestMetadata, ManifestMetadataTable, ManifestMetadataTable); Resolver.SetModuleIndexLookup(ManifestMetadataTable.ModuleToIndex); InstanceEntryPointTable = new InstanceEntryPointTableNode(Target); Header.Add(Internal.Runtime.ReadyToRunSectionType.InstanceMethodEntryPoints, InstanceEntryPointTable, InstanceEntryPointTable); TypesTable = new TypesTableNode(Target); Header.Add(Internal.Runtime.ReadyToRunSectionType.AvailableTypes, TypesTable, TypesTable); ImportSectionsTable = new ImportSectionsTableNode(this); Header.Add(Internal.Runtime.ReadyToRunSectionType.ImportSections, ImportSectionsTable, ImportSectionsTable.StartSymbol); DebugInfoTable = new DebugInfoTableNode(Target); Header.Add(Internal.Runtime.ReadyToRunSectionType.DebugInfo, DebugInfoTable, DebugInfoTable); // Core library attributes are checked FAR more often than other dlls // attributes, so produce a highly efficient table for determining if they are // present. Other assemblies *MAY* benefit from this feature, but it doesn't show // as useful at this time. if (this.AttributePresenceFilter != null) { Header.Add(Internal.Runtime.ReadyToRunSectionType.AttributePresence, AttributePresenceFilter, AttributePresenceFilter); } EagerImports = new ImportSectionNode( "EagerImports", CorCompileImportType.CORCOMPILE_IMPORT_TYPE_UNKNOWN, CorCompileImportFlags.CORCOMPILE_IMPORT_FLAGS_EAGER, (byte)Target.PointerSize, emitPrecode: false, emitGCRefMap: false); ImportSectionsTable.AddEmbeddedObject(EagerImports); // All ready-to-run images have a module import helper which gets patched by the runtime on image load ModuleImport = new Import(EagerImports, new ReadyToRunHelperSignature( ILCompiler.ReadyToRunHelper.Module)); graph.AddRoot(ModuleImport, "Module import is required by the R2R format spec"); if (Target.Architecture != TargetArchitecture.X86) { Import personalityRoutineImport = new Import(EagerImports, new ReadyToRunHelperSignature( ILCompiler.ReadyToRunHelper.PersonalityRoutine)); PersonalityRoutine = new ImportThunk( ILCompiler.ReadyToRunHelper.PersonalityRoutine, this, personalityRoutineImport, useVirtualCall: false); graph.AddRoot(PersonalityRoutine, "Personality routine is faster to root early rather than referencing it from each unwind info"); Import filterFuncletPersonalityRoutineImport = new Import(EagerImports, new ReadyToRunHelperSignature( ILCompiler.ReadyToRunHelper.PersonalityRoutineFilterFunclet)); FilterFuncletPersonalityRoutine = new ImportThunk( ILCompiler.ReadyToRunHelper.PersonalityRoutineFilterFunclet, this, filterFuncletPersonalityRoutineImport, useVirtualCall: false); graph.AddRoot(FilterFuncletPersonalityRoutine, "Filter funclet personality routine is faster to root early rather than referencing it from each unwind info"); } MethodImports = new ImportSectionNode( "MethodImports", CorCompileImportType.CORCOMPILE_IMPORT_TYPE_STUB_DISPATCH, CorCompileImportFlags.CORCOMPILE_IMPORT_FLAGS_PCODE, (byte)Target.PointerSize, emitPrecode: false, emitGCRefMap: true); ImportSectionsTable.AddEmbeddedObject(MethodImports); DispatchImports = new ImportSectionNode( "DispatchImports", CorCompileImportType.CORCOMPILE_IMPORT_TYPE_STUB_DISPATCH, CorCompileImportFlags.CORCOMPILE_IMPORT_FLAGS_PCODE, (byte)Target.PointerSize, emitPrecode: false, emitGCRefMap: true); ImportSectionsTable.AddEmbeddedObject(DispatchImports); HelperImports = new ImportSectionNode( "HelperImports", CorCompileImportType.CORCOMPILE_IMPORT_TYPE_UNKNOWN, CorCompileImportFlags.CORCOMPILE_IMPORT_FLAGS_PCODE, (byte)Target.PointerSize, emitPrecode: false, emitGCRefMap: false); ImportSectionsTable.AddEmbeddedObject(HelperImports); PrecodeImports = new ImportSectionNode( "PrecodeImports", CorCompileImportType.CORCOMPILE_IMPORT_TYPE_UNKNOWN, CorCompileImportFlags.CORCOMPILE_IMPORT_FLAGS_PCODE, (byte)Target.PointerSize, emitPrecode: true, emitGCRefMap: false); ImportSectionsTable.AddEmbeddedObject(PrecodeImports); StringImports = new ImportSectionNode( "StringImports", CorCompileImportType.CORCOMPILE_IMPORT_TYPE_STRING_HANDLE, CorCompileImportFlags.CORCOMPILE_IMPORT_FLAGS_UNKNOWN, (byte)Target.PointerSize, emitPrecode: true, emitGCRefMap: false); ImportSectionsTable.AddEmbeddedObject(StringImports); graph.AddRoot(ImportSectionsTable, "Import sections table is always generated"); graph.AddRoot(ModuleImport, "Module import is always generated"); graph.AddRoot(EagerImports, "Eager imports are always generated"); graph.AddRoot(MethodImports, "Method imports are always generated"); graph.AddRoot(DispatchImports, "Dispatch imports are always generated"); graph.AddRoot(HelperImports, "Helper imports are always generated"); graph.AddRoot(PrecodeImports, "Precode helper imports are always generated"); graph.AddRoot(StringImports, "String imports are always generated"); graph.AddRoot(Header, "ReadyToRunHeader is always generated"); graph.AddRoot(CopiedCorHeaderNode, "MSIL COR header is always generated"); if (Win32ResourcesNode != null) { graph.AddRoot(Win32ResourcesNode, "Win32 Resources are placed if not empty"); } MetadataManager.AttachToDependencyGraph(graph); }
//Column manipulation, these two functions hide/restore matrix rows and columns from the search function. //It is important that the uncover function operates exactly in reverse order to the cover one. protected void CoverColumn(HeaderNode TargetNode) { RemoveLeftRight(TargetNode); for (Node i = TargetNode.Down; i != TargetNode; i = i.Down) { for (Node j = i.Right; j != i; j = j.Right) { RemoveUpDown(j); j.Header.Size--; } } }
//private bool ShouldRequestCompactBlock(HeaderNode lastHeader) //{ // return _status.SupportsDesiredCompactVersion // //TODO fix && this.blockFetcherManager.BlocksInDownload == 0 // && lastHeader.Previous?.IsValid(HeaderValidityStatuses.ValidChain) == true; //} private async Task FetchBlockAsync(HeaderNode blockToDownload) { #region Code that was into the headers processor to request block in place //if (!currentHeader.Validity.HasFlag(HeaderDataAvailability.HasBlockData) // we don't have data for this block // && !this.blockFetcherManager.IsDownloading(currentHeader) // it's not already in download // && (!this.IsWitnessEnabled(currentHeader.Previous) || this.status.CanServeWitness) //witness isn't enabled or the other peer can't serve witness // ) //{ // blocksToDownload.Add(currentHeader); //} //currentHeader = currentHeader.Previous; //var vGetData = new List<InventoryVector>(); //// Download as much as possible, from earliest to latest. //for (int i = blocksToDownload.Count - 1; i >= 0; i--) //{ // HeaderNode blockToDownload = blocksToDownload[i]; // UInt256 blockHash = blockToDownload.Hash; // if (this.blockDownloadStatus.BlocksInDownload.Count >= MAX_BLOCKS_IN_TRANSIT_PER_PEER) // { // break; // Can't download any more from this peer // } // uint fetchFlags = this.GetFetchFlags(); // if (ShouldRequestCompactBlock(lastValidatedHeaderNode)) // { // vGetData.Add(new InventoryVector { Type = InventoryType.MSG_CMPCT_BLOCK, Hash = blockHash }); // } // else // { // vGetData.Add(new InventoryVector { Type = InventoryType.MSG_BLOCK | fetchFlags, Hash = blockHash }); // } // if (this.blockFetcherManager.TryDownloadBlock(this.PeerContext, blockToDownload, out QueuedBlock? queuedBlock)) // { // if (this.blockDownloadStatus.BlocksInDownload.Count == 1) // { // // We're starting a block download (batch) from this peer. // this.blockDownloadStatus.DownloadingSince = this.dateTimeProvider.GetTime(); // } // } // this.logger.LogDebug("Requesting block {BlockHash}", blockHash); //} //if (vGetData.Count > 0) //{ // this.logger.LogDebug("Downloading blocks toward {HeaderNode} via headers direct fetch.", lastValidatedHeaderNode); // await this.SendMessageAsync(new GetDataMessage { Inventory = vGetData.ToArray() }).ConfigureAwait(false); //} #endregion /// when this method is called, we already gave back our availability to download this header so we shouldn't /// have to repeat checks we are already enforcing elsewhere, but we do it anyway to be safe (consider if remove checks) // we don't have data for this block and we can fetch it if (!blockToDownload.HasAvailability(HeaderDataAvailability.HasBlockData) && CanFetch(blockToDownload)) { _fetcherStatus.BlocksInDownload.Add(blockToDownload.Hash); var vGetData = new List <InventoryVector>(); uint fetchFlags = GetFetchFlags(); vGetData.Add(new InventoryVector { Type = InventoryType.MSG_BLOCK | fetchFlags, Hash = blockToDownload.Hash }); await SendMessageAsync(new GetDataMessage { Inventory = vGetData.ToArray() }).ConfigureAwait(false); } }
public void AttachToDependencyGraph(DependencyAnalyzerBase <NodeFactory> graph) { graph.ComputingDependencyPhaseChange += Graph_ComputingDependencyPhaseChange; var compilerIdentifierNode = new CompilerIdentifierNode(Target); Header.Add(Internal.Runtime.ReadyToRunSectionType.CompilerIdentifier, compilerIdentifierNode, compilerIdentifierNode); RuntimeFunctionsTable = new RuntimeFunctionsTableNode(this); Header.Add(Internal.Runtime.ReadyToRunSectionType.RuntimeFunctions, RuntimeFunctionsTable, RuntimeFunctionsTable); RuntimeFunctionsGCInfo = new RuntimeFunctionsGCInfoNode(); graph.AddRoot(RuntimeFunctionsGCInfo, "GC info is always generated"); ProfileDataSection = new ProfileDataSectionNode(); Header.Add(Internal.Runtime.ReadyToRunSectionType.ProfileDataInfo, ProfileDataSection, ProfileDataSection.StartSymbol); DelayLoadMethodCallThunks = new DelayLoadMethodCallThunkNodeRange(); Header.Add(Internal.Runtime.ReadyToRunSectionType.DelayLoadMethodCallThunks, DelayLoadMethodCallThunks, DelayLoadMethodCallThunks); ExceptionInfoLookupTableNode exceptionInfoLookupTableNode = new ExceptionInfoLookupTableNode(this); Header.Add(Internal.Runtime.ReadyToRunSectionType.ExceptionInfo, exceptionInfoLookupTableNode, exceptionInfoLookupTableNode); graph.AddRoot(exceptionInfoLookupTableNode, "ExceptionInfoLookupTable is always generated"); ManifestMetadataTable = new ManifestMetadataTableNode(this); Header.Add(Internal.Runtime.ReadyToRunSectionType.ManifestMetadata, ManifestMetadataTable, ManifestMetadataTable); Resolver.SetModuleIndexLookup(ManifestMetadataTable.ModuleToIndex); ManifestAssemblyMvidHeaderNode mvidTableNode = new ManifestAssemblyMvidHeaderNode(ManifestMetadataTable); Header.Add(Internal.Runtime.ReadyToRunSectionType.ManifestAssemblyMvids, mvidTableNode, mvidTableNode); AssemblyTableNode assemblyTable = null; if (CompilationModuleGroup.IsCompositeBuildMode) { assemblyTable = new AssemblyTableNode(Target); Header.Add(Internal.Runtime.ReadyToRunSectionType.ComponentAssemblies, assemblyTable, assemblyTable); } // Generate per assembly header tables int assemblyIndex = -1; foreach (EcmaModule inputModule in CompilationModuleGroup.CompilationModuleSet) { assemblyIndex++; HeaderNode tableHeader = Header; if (assemblyTable != null) { AssemblyHeaderNode perAssemblyHeader = new AssemblyHeaderNode(Target, ReadyToRunFlags.READYTORUN_FLAG_Component, assemblyIndex); assemblyTable.Add(perAssemblyHeader); tableHeader = perAssemblyHeader; } MethodEntryPointTableNode methodEntryPointTable = new MethodEntryPointTableNode(inputModule, Target); tableHeader.Add(Internal.Runtime.ReadyToRunSectionType.MethodDefEntryPoints, methodEntryPointTable, methodEntryPointTable); TypesTableNode typesTable = new TypesTableNode(Target, inputModule); tableHeader.Add(Internal.Runtime.ReadyToRunSectionType.AvailableTypes, typesTable, typesTable); InliningInfoNode inliningInfoTable = new InliningInfoNode(Target, inputModule); tableHeader.Add(Internal.Runtime.ReadyToRunSectionType.InliningInfo2, inliningInfoTable, inliningInfoTable); // Core library attributes are checked FAR more often than other dlls // attributes, so produce a highly efficient table for determining if they are // present. Other assemblies *MAY* benefit from this feature, but it doesn't show // as useful at this time. if (inputModule == TypeSystemContext.SystemModule) { AttributePresenceFilterNode attributePresenceTable = new AttributePresenceFilterNode(inputModule); Header.Add(Internal.Runtime.ReadyToRunSectionType.AttributePresence, attributePresenceTable, attributePresenceTable); } } InstanceEntryPointTable = new InstanceEntryPointTableNode(this); Header.Add(Internal.Runtime.ReadyToRunSectionType.InstanceMethodEntryPoints, InstanceEntryPointTable, InstanceEntryPointTable); ImportSectionsTable = new ImportSectionsTableNode(this); Header.Add(Internal.Runtime.ReadyToRunSectionType.ImportSections, ImportSectionsTable, ImportSectionsTable.StartSymbol); DebugInfoTable = new DebugInfoTableNode(Target); Header.Add(Internal.Runtime.ReadyToRunSectionType.DebugInfo, DebugInfoTable, DebugInfoTable); EagerImports = new ImportSectionNode( "EagerImports", CorCompileImportType.CORCOMPILE_IMPORT_TYPE_UNKNOWN, CorCompileImportFlags.CORCOMPILE_IMPORT_FLAGS_EAGER, (byte)Target.PointerSize, emitPrecode: false, emitGCRefMap: false); ImportSectionsTable.AddEmbeddedObject(EagerImports); // All ready-to-run images have a module import helper which gets patched by the runtime on image load ModuleImport = new Import(EagerImports, new ReadyToRunHelperSignature( ReadyToRunHelper.Module)); graph.AddRoot(ModuleImport, "Module import is required by the R2R format spec"); if (Target.Architecture != TargetArchitecture.X86) { Import personalityRoutineImport = new Import(EagerImports, new ReadyToRunHelperSignature( ReadyToRunHelper.PersonalityRoutine)); PersonalityRoutine = new ImportThunk(this, ReadyToRunHelper.PersonalityRoutine, EagerImports, useVirtualCall: false, useJumpableStub: false); graph.AddRoot(PersonalityRoutine, "Personality routine is faster to root early rather than referencing it from each unwind info"); Import filterFuncletPersonalityRoutineImport = new Import(EagerImports, new ReadyToRunHelperSignature( ReadyToRunHelper.PersonalityRoutineFilterFunclet)); FilterFuncletPersonalityRoutine = new ImportThunk(this, ReadyToRunHelper.PersonalityRoutineFilterFunclet, EagerImports, useVirtualCall: false, useJumpableStub: false); graph.AddRoot(FilterFuncletPersonalityRoutine, "Filter funclet personality routine is faster to root early rather than referencing it from each unwind info"); } if ((ProfileDataManager != null) && (ProfileDataManager.EmbedPgoDataInR2RImage)) { // Profile instrumentation data attaches here HashSet <MethodDesc> methodsToInsertInstrumentationDataFor = new HashSet <MethodDesc>(); foreach (EcmaModule inputModule in CompilationModuleGroup.CompilationModuleSet) { foreach (MethodDesc method in ProfileDataManager.GetMethodsForModuleDesc(inputModule)) { if (ProfileDataManager[method].SchemaData != null) { methodsToInsertInstrumentationDataFor.Add(method); } } } if (methodsToInsertInstrumentationDataFor.Count != 0) { MethodDesc[] methodsToInsert = methodsToInsertInstrumentationDataFor.ToArray(); methodsToInsert.MergeSort(new TypeSystemComparer().Compare); InstrumentationDataTable = new InstrumentationDataTableNode(this, methodsToInsert, ProfileDataManager); Header.Add(Internal.Runtime.ReadyToRunSectionType.PgoInstrumentationData, InstrumentationDataTable, InstrumentationDataTable); } } MethodImports = new ImportSectionNode( "MethodImports", CorCompileImportType.CORCOMPILE_IMPORT_TYPE_STUB_DISPATCH, CorCompileImportFlags.CORCOMPILE_IMPORT_FLAGS_PCODE, (byte)Target.PointerSize, emitPrecode: false, emitGCRefMap: true); ImportSectionsTable.AddEmbeddedObject(MethodImports); DispatchImports = new ImportSectionNode( "DispatchImports", CorCompileImportType.CORCOMPILE_IMPORT_TYPE_STUB_DISPATCH, CorCompileImportFlags.CORCOMPILE_IMPORT_FLAGS_PCODE, (byte)Target.PointerSize, emitPrecode: false, emitGCRefMap: true); ImportSectionsTable.AddEmbeddedObject(DispatchImports); HelperImports = new ImportSectionNode( "HelperImports", CorCompileImportType.CORCOMPILE_IMPORT_TYPE_UNKNOWN, CorCompileImportFlags.CORCOMPILE_IMPORT_FLAGS_PCODE, (byte)Target.PointerSize, emitPrecode: false, emitGCRefMap: false); ImportSectionsTable.AddEmbeddedObject(HelperImports); PrecodeImports = new ImportSectionNode( "PrecodeImports", CorCompileImportType.CORCOMPILE_IMPORT_TYPE_UNKNOWN, CorCompileImportFlags.CORCOMPILE_IMPORT_FLAGS_PCODE, (byte)Target.PointerSize, emitPrecode: true, emitGCRefMap: false); ImportSectionsTable.AddEmbeddedObject(PrecodeImports); StringImports = new ImportSectionNode( "StringImports", CorCompileImportType.CORCOMPILE_IMPORT_TYPE_STRING_HANDLE, CorCompileImportFlags.CORCOMPILE_IMPORT_FLAGS_UNKNOWN, (byte)Target.PointerSize, emitPrecode: true, emitGCRefMap: false); ImportSectionsTable.AddEmbeddedObject(StringImports); graph.AddRoot(ImportSectionsTable, "Import sections table is always generated"); graph.AddRoot(ModuleImport, "Module import is always generated"); graph.AddRoot(EagerImports, "Eager imports are always generated"); graph.AddRoot(MethodImports, "Method imports are always generated"); graph.AddRoot(DispatchImports, "Dispatch imports are always generated"); graph.AddRoot(HelperImports, "Helper imports are always generated"); graph.AddRoot(PrecodeImports, "Precode helper imports are always generated"); graph.AddRoot(StringImports, "String imports are always generated"); graph.AddRoot(Header, "ReadyToRunHeader is always generated"); graph.AddRoot(CopiedCorHeaderNode, "MSIL COR header is always generated for R2R files"); graph.AddRoot(DebugDirectoryNode, "Debug Directory will always contain at least one entry"); if (Win32ResourcesNode != null) { graph.AddRoot(Win32ResourcesNode, "Win32 Resources are placed if not empty"); } MetadataManager.AttachToDependencyGraph(graph); }
public QueuedBlock(HeaderNode headerNode, IBlockFetcher fetcher /*TODO: ,PartiallyDownloadedBlock partialBlock*/) { HeaderNode = headerNode; Fetcher = fetcher; }