Ejemplo n.º 1
0
        public void TestGetFlowGraphInvalidArgumentWithNonNullParent()
        {
            IOperation parent = new BlockOperation(ImmutableArray <IOperation> .Empty, ImmutableArray <ILocalSymbol> .Empty,
                                                   semanticModel: null, syntax: null, isImplicit: false);

            TestGetFlowGraphInvalidArgumentCore(argumentExceptionMessage: CodeAnalysisResources.NotARootOperation, parent);
        }
Ejemplo n.º 2
0
 public OriginationModel(BlockRpcEntity block, BlockOperation <BlockOriginationContent> transactionOperation, BlockOriginationContent originationContent)
 {
     BlockHash          = block.hash;
     BlockLevel         = block.header.level;
     OperationHash      = transactionOperation.hash;
     Timestamp          = block.header.timestamp;
     OriginationContent = originationContent;
 }
Ejemplo n.º 3
0
 public BlockInstruction(BlockOperation operation, object parameter)
 {
     this.operation = operation;
     this.parameter = parameter;
 }
Ejemplo n.º 4
0
        private void TestGetFlowGraphInvalidArgumentCore(string argumentExceptionMessage, IOperation parent)
        {
            bool exceptionThrown = false;

            try
            {
                IBlockOperation block = new BlockOperation(
                    ImmutableArray <IOperation> .Empty, ImmutableArray <ILocalSymbol> .Empty,
                    semanticModel: null, syntax: null, isImplicit: false);
                block = Operation.SetParentOperation(block, parent);
                _     = ControlFlowGraph.Create(block);
            }
            catch (ArgumentException ex)
            {
                Assert.Equal(new ArgumentException(argumentExceptionMessage, "body").Message, ex.Message);
                exceptionThrown = true;
            }

            Assert.True(exceptionThrown);
            exceptionThrown = false;

            try
            {
                IFieldInitializerOperation initializer = new FieldInitializerOperation(
                    ImmutableArray <IFieldSymbol> .Empty, ImmutableArray <ILocalSymbol> .Empty,
                    value: null, semanticModel: null,
                    syntax: null, isImplicit: false);
                initializer = Operation.SetParentOperation(initializer, parent);
                _           = ControlFlowGraph.Create(initializer);
            }
            catch (ArgumentException ex)
            {
                Assert.Equal(new ArgumentException(argumentExceptionMessage, "initializer").Message, ex.Message);
                exceptionThrown = true;
            }

            Assert.True(exceptionThrown);
            exceptionThrown = false;

            try
            {
                IPropertyInitializerOperation initializer = new PropertyInitializerOperation(
                    ImmutableArray <IPropertySymbol> .Empty, ImmutableArray <ILocalSymbol> .Empty,
                    value: null, semanticModel: null,
                    syntax: null, isImplicit: false);
                initializer = Operation.SetParentOperation(initializer, parent);
                _           = ControlFlowGraph.Create(initializer);
            }
            catch (ArgumentException ex)
            {
                Assert.Equal(new ArgumentException(argumentExceptionMessage, "initializer").Message, ex.Message);
                exceptionThrown = true;
            }

            Assert.True(exceptionThrown);
            exceptionThrown = false;

            try
            {
                IParameterInitializerOperation initializer = new ParameterInitializerOperation(
                    parameter: null, locals: ImmutableArray <ILocalSymbol> .Empty,
                    value: null, semanticModel: null,
                    syntax: null, isImplicit: false);
                initializer = Operation.SetParentOperation(initializer, parent);
                _           = ControlFlowGraph.Create(initializer);
            }
            catch (ArgumentException ex)
            {
                Assert.Equal(new ArgumentException(argumentExceptionMessage, "initializer").Message, ex.Message);
                exceptionThrown = true;
            }

            Assert.True(exceptionThrown);
            exceptionThrown = false;

            try
            {
                IConstructorBodyOperation constructorBody = new ConstructorBodyOperation(
                    ImmutableArray <ILocalSymbol> .Empty,
                    initializer: null,
                    blockBody: null,
                    expressionBody: null,
                    semanticModel: null,
                    syntax: null,
                    isImplicit: false);
                constructorBody = Operation.SetParentOperation(constructorBody, parent);
                _ = ControlFlowGraph.Create(constructorBody);
            }
            catch (ArgumentException ex)
            {
                Assert.Equal(new ArgumentException(argumentExceptionMessage, "constructorBody").Message, ex.Message);
                exceptionThrown = true;
            }

            Assert.True(exceptionThrown);
            exceptionThrown = false;

            try
            {
                IMethodBodyOperation methodBody = new MethodBodyOperation(
                    blockBody: null,
                    expressionBody: null,
                    semanticModel: null,
                    syntax: null,
                    isImplicit: false);
                methodBody = Operation.SetParentOperation(methodBody, parent);
                _          = ControlFlowGraph.Create(methodBody);
            }
            catch (ArgumentException ex)
            {
                Assert.Equal(new ArgumentException(argumentExceptionMessage, "methodBody").Message, ex.Message);
                exceptionThrown = true;
            }

            Assert.True(exceptionThrown);
            exceptionThrown = false;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Looks to see if the block is in the cache.  if it is, it performs
        /// the cache hit operation on the data.  If the block was not in the cache
        /// it pulls the block holder out of the cache so that no other thread can
        /// access the block.  It then performs the blocking read/write disk i/o
        /// after giving up all locks.  Finally it gets the locks again to insert
        /// the new block back into the cache
        /// </summary>
        /// <param name="cacheHit">Operation to perform if the block is in cache (cannot block)</param>
        /// <param name="chacheMiss">Operation to perform if the block is not in cache (can block)</param>
        private int PerformBlockOperation(int blockNum,
                                          BlockOperation cacheHit, BlockOperation chacheMiss)
        {
            BlockHolder bh      = null;
            bool        success = false;

            do
            {
                lock (m_cache)
                {
                    bh = GetHolderForBlockNumInCache(blockNum);
                    if (bh == null)
                    {
                        // the block is not in cache
                        while (m_cache.Count == 0)
                        {
                            // condition wait on the cache until there is a block in
                            // the cache we can read into.  This is a very rare case.
                            // It would only happen if more threads were waiting on
                            // the cache than there were spaces for blocks in the cache
                        }
                        // remove the oldest thing on the cache.
                        lock (m_diskQueue)
                        {
                            if (!m_diskQueue.Contains(blockNum))
                            {
                                bh = GetOldestCacheItem();
                                m_diskQueue.Add(blockNum);
                            }
                            else
                            {
                                // someone else is already fetching this block from disk.
                                // After we release the lock
                            }
                        }
                    }
                    else
                    {
                        // the block is in the cache, so just perform the operation,
                        // and update it's position to maintain LRU semantics
                        cacheHit(bh);
                        UpdateLastUsedTime(bh);
                        success = true;
                    }
                }// unlock cache
                if (!success)
                {
                    if (bh == null)
                    {
                        // if we missed the cache (i.e. !success) and the holder is null
                        // it means another thread is fetching that block from disk.
                        lock (m_diskQueue)
                        {
                            while (m_diskQueue.Contains(blockNum))
                            {
                                // condition wait on m_diskQueue
                            }
                        }
                        // If we get here the block should be in the cache (at least for now)
                        // success is still false, so we'll loop in this method and hopefully
                        // get a cache hit, or else work on getting the block again.
                    }
                    else
                    {
                        // The holder is now isolated, so we can make all the blocking calls we want
                        chacheMiss(bh);
                        lock (m_cache)
                        {
                            lock (m_diskQueue)
                            {
                                AddMostRecentlyUsed(bh);
                                m_diskQueue.Remove(bh.BlockNum);
                                // broadcast on the condition variable associated with m_diskQueue
                            }
                            success = true;
                        }
                    }
                }
            } while (!success);

            return(0);
        }
Ejemplo n.º 6
0
 public BlockInstruction(BlockOperation operation, object parameter)
 {
     this.operation = operation;
     this.parameter = parameter;
 }