Ejemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void mustCountEvictions()
        internal virtual void MustCountEvictions()
        {
            using (EvictionRunEvent evictionRunEvent = _tracer.beginPageEvictions(2))
            {
                using (EvictionEvent evictionEvent = evictionRunEvent.BeginEviction())
                {
                    FlushEvent flushEvent = evictionEvent.FlushEventOpportunity().beginFlush(0, 0, _swapper);
                    flushEvent.AddBytesWritten(12);
                    flushEvent.Done();
                }

                using (EvictionEvent evictionEvent = evictionRunEvent.BeginEviction())
                {
                    FlushEvent flushEvent = evictionEvent.FlushEventOpportunity().beginFlush(0, 0, _swapper);
                    flushEvent.AddBytesWritten(12);
                    flushEvent.Done();
                    evictionEvent.ThrewException(new IOException());
                }

                using (EvictionEvent evictionEvent = evictionRunEvent.BeginEviction())
                {
                    FlushEvent flushEvent = evictionEvent.FlushEventOpportunity().beginFlush(0, 0, _swapper);
                    flushEvent.AddBytesWritten(12);
                    flushEvent.Done();
                    evictionEvent.ThrewException(new IOException());
                }

                evictionRunEvent.BeginEviction().close();
            }

            AssertCounts(0, 0, 0, 0, 4, 2, 3, 0, 36, 0, 0, 0d);
        }
Ejemplo n.º 2
0
 internal virtual void Vacuum(SwapperSet swappers)
 {
     if (FreelistHead is AtomicInteger && swappers.CountAvailableIds() > 200)
     {
         return;                         // We probably still have plenty of free pages left. Don't bother vacuuming just yet.
     }
     swappers.Vacuum(swapperIds =>
     {
         int pageCount = Pages.PageCount;
         try
         {
             using (EvictionRunEvent evictions = _pageCacheTracer.beginPageEvictions(0))
             {
                 for (int i = 0; i < pageCount; i++)
                 {
                     long pageRef = Pages.deref(i);
                     while (swapperIds.contains(Pages.getSwapperId(pageRef)))
                     {
                         if (Pages.tryEvict(pageRef, evictions))
                         {
                             AddFreePageToFreelist(pageRef);
                             break;
                         }
                     }
                 }
             }
         }
         catch (IOException e)
         {
             throw new UncheckedIOException(e);
         }
     });
 }
Ejemplo n.º 3
0
        internal virtual int EvictPages(int pageCountToEvict, int clockArm, EvictionRunEvent evictionRunEvent)
        {
            while (pageCountToEvict > 0 && !_closed)
            {
                if (clockArm == Pages.PageCount)
                {
                    clockArm = 0;
                }

                if (_closed)
                {
                    // The page cache has been shut down.
                    return(0);
                }

                long pageRef = Pages.deref(clockArm);
                if (Pages.isLoaded(pageRef) && Pages.decrementUsage(pageRef))
                {
                    try
                    {
                        pageCountToEvict--;
                        if (Pages.tryEvict(pageRef, evictionRunEvent))
                        {
                            ClearEvictorException();
                            AddFreePageToFreelist(pageRef);
                        }
                    }
                    catch (IOException e)
                    {
                        _evictorException = e;
                    }
                    catch (System.OutOfMemoryException)
                    {
                        _evictorException = _oomException;
                    }
                    catch (Exception th)
                    {
                        _evictorException = new IOException("Eviction thread encountered a problem", th);
                    }
                }

                clockArm++;
            }

            return(clockArm);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Scan through all the pages, one by one, and decrement their usage stamps.
        /// If a usage reaches zero, we try-write-locking it, and if we get that lock,
        /// we evict the page. If we don't, we move on to the next page.
        /// Once we have enough free pages, we park our thread. Page-faulting will
        /// unpark our thread as needed.
        /// </summary>
        internal virtual void ContinuouslySweepPages()
        {
            _evictionThread = Thread.CurrentThread;
            int clockArm = 0;

            while (!_closed)
            {
                int pageCountToEvict = ParkUntilEvictionRequired(_keepFree);
                using (EvictionRunEvent evictionRunEvent = _pageCacheTracer.beginPageEvictions(pageCountToEvict))
                {
                    clockArm = EvictPages(pageCountToEvict, clockArm, evictionRunEvent);
                }
            }

            // The last thing we do, is signalling the shutdown of the cache via
            // the freelist. This signal is looked out for in grabFreePage.
            FreelistHead = _shutdownSignal;
        }