Ejemplo n.º 1
0
 private void RetractPage()
 {
     UnmanagedPageList.pageCache.AddHead(this.stackPage);
     this.stackPage   = this.pageList.RemoveHead();
     this.stackBottom = UnmanagedPageList.FirstPageAddr(this.stackPage);
     this.stackTop    = UnmanagedPageList.EndPageAddr(this.stackPage);
     this.stackPtr    = this.stackTop;
 }
Ejemplo n.º 2
0
            private void SetCursor(UIntPtr pageAddr)
            {
                UIntPtr *preFirstAddr =
                    UnmanagedPageList.FirstPageAddr(pageAddr) - 1;

                if (pageAddr == lastPageStart)
                {
                    this.currentCursor = new PageCursor(preFirstAddr,
                                                        this.lastPageLimit);
                }
                else
                {
                    UIntPtr *endAddr = UnmanagedPageList.EndPageAddr(pageAddr);
                    this.currentCursor = new PageCursor(preFirstAddr, endAddr);
                }
            }
Ejemplo n.º 3
0
        private void AdvanceWritePage()
        {
            UIntPtr pageAddr;

            if (UnmanagedPageList.pageCache.IsEmpty)
            {
                bool    fCleanPages = true;
                UIntPtr page        = PageManager.EnsurePages(null, (UIntPtr)1,
                                                              PageType.System,
                                                              ref fCleanPages);
                pageAddr = PageTable.PageAddr(page);
            }
            else
            {
                pageAddr = UnmanagedPageList.pageCache.RemoveHead();
            }
            this.pageList.AddTail(pageAddr);
            this.writeCursor =
                new PageCursor(UnmanagedPageList.FirstPageAddr(pageAddr),
                               UnmanagedPageList.EndPageAddr(pageAddr));
        }
Ejemplo n.º 4
0
 private void AdvancePage()
 {
     if (this.stackPage != UIntPtr.Zero)
     {
         this.pageList.AddHead(this.stackPage);
     }
     if (UnmanagedPageList.pageCache.IsEmpty)
     {
         bool    fCleanPages = true;
         UIntPtr page        = PageManager.EnsurePages(null, (UIntPtr)1,
                                                       PageType.System,
                                                       ref fCleanPages);
         this.stackPage = PageTable.PageAddr(page);
     }
     else
     {
         this.stackPage = UnmanagedPageList.pageCache.RemoveHead();
     }
     this.stackBottom = UnmanagedPageList.FirstPageAddr(this.stackPage);
     this.stackPtr    = this.stackBottom;
     this.stackTop    = UnmanagedPageList.EndPageAddr(this.stackPage);
 }
Ejemplo n.º 5
0
        private void CompactPhaseCleanup(Thread currentThread,
                                         PageType generation,
                                         UIntPtr newLimitPtr)
        {
            VTable.Assert(IsValidGeneration((int)generation));

            registerThreadReferenceVisitor.Cleanup();
            // Free up skipped pages
            while (!this.skippedPageQueue.IsEmpty)
            {
                UIntPtr start  = this.skippedPageQueue.Read();
                UIntPtr finish = this.skippedPageQueue.Read();
                InteriorPtrTable.ClearFirst(start, finish);
                PageManager.FreePageRange(start, finish);
                if (GC.remsetType == RemSetType.Cards)
                {
                    OffsetTable.ClearLast(PageTable.PageAddr(start),
                                          PageTable.PageAddr(finish) - 1);
                }
            }
            this.skippedPageQueue.Cleanup(true);
            // Release the queue standby pages
            UnmanagedPageList.ReleaseStandbyPages();
            // Update the ownership information for the copied data
            PageType destGeneration =
                (generation == MAX_GENERATION) ?
                MAX_GENERATION :
                (PageType)(generation + 1);
            UIntPtr limitPage =
                PageTable.Page(PageTable.PagePad(newLimitPtr));

            for (UIntPtr i = UIntPtr.Zero; i < limitPage; i++)
            {
                if (IsMyZombiePage(i))
                {
                    PageTable.SetType(i, (PageType)destGeneration);
                }
            }
        }
Ejemplo n.º 6
0
        private void AdvanceReadPage()
        {
            if (this.pageList.IsEmpty)
            {
                return;
            }
            if (this.readPage != UIntPtr.Zero)
            {
                UnmanagedPageList.pageCache.AddHead(this.readPage);
            }
            this.readPage = this.pageList.RemoveHead();
            UIntPtr *startPtr = UnmanagedPageList.FirstPageAddr(this.readPage);
            UIntPtr *limitPtr;

            if (this.pageList.IsEmpty)
            {
                limitPtr = this.writeCursor.cursor;
            }
            else
            {
                limitPtr = UnmanagedPageList.EndPageAddr(this.readPage);
            }
            this.readCursor = new PageCursor(startPtr, limitPtr);
        }
Ejemplo n.º 7
0
 internal Enumerator(ref UnmanagedPageList pageList) {
     this.movedToFirst = false;
     this.currentPage = pageList.Head;
     this.tailPage = pageList.Tail;
 }
        internal override void CollectStopped(int currentThreadIndex,
                                              int generation)
        {
#if SINGULARITY
#if DEBUG
    #if THREAD_TIME_ACCOUNTING
            UIntPtr preGcTotalBytes = SegregatedFreeList.TotalBytes;
    #endif
            DebugStub.WriteLine("~~~~~ Start MarkSweep Cleanup  [data={0:x8}, pid={1:x3}]",
                                __arglist(SegregatedFreeList.TotalBytes,
                                          PageTable.processTag >> 16));
#endif
#if SINGULARITY_KERNEL
    #if THREAD_TIME_ACCOUNTING
            TimeSpan ticks  = Thread.CurrentThread.ExecutionTime;
            TimeSpan ticks2 = SystemClock.KernelUpTime;
    #else
            TimeSpan ticks = SystemClock.KernelUpTime;
    #endif
#elif SINGULARITY_PROCESS
    #if THREAD_TIME_ACCOUNTING
            TimeSpan ticks  = ProcessService.GetThreadTime();
            TimeSpan ticks2 = ProcessService.GetUpTime();
    #else
            TimeSpan ticks = ProcessService.GetUpTime();
    #endif
#endif
#endif
            int before = 0;
            if (VTable.enableGCTiming)
            {
                before = Environment.TickCount;
            }
            if (GC.IsProfiling)
            {
                GcProfiler.NotifyPreGC(MinGeneration);
                // non-generational collector, so pretend Gen0
                // Calls like ResurrectCandidates below can cause
                // allocations and thus, potentially, profiler
                // notifications.  However, at that time the heap is
                // damaged in the sense that VPtrs have bits OR-ed in
                // for object marking.  We do not want to accept
                // profiling during this window.
                //
                // There is no synchronization issue with setting this
                // flag because it will only be consulted by the
                // thread that sets and resets it.
                HeapDamaged = true;
            }
            // 1) Mark the live objects
            CollectorStatistics.Event(GCEvent.TraceStart);
#if !VC
            TryAllManager.PreGCHookTryAll();
#endif
            MultiUseWord.PreGCHook(false /* don't use shadows */);
            Finalizer.PrepareCollectFinalizers();
            int countThreads =
                CallStack.ScanStacks(threadMarkReferenceVisitor,
                                     threadMarkReferenceVisitor);
            Thread.VisitBootstrapData(markAndProcessReferenceVisitor);
#if SINGULARITY_KERNEL
            Kernel.VisitSpecialData(markAndProcessReferenceVisitor);
#endif
            MultiUseWord.VisitStrongRefs(markAndProcessReferenceVisitor,
                                         false /* Don't use shadows */);
#if !VC
            TryAllManager.VisitStrongRefs(markAndProcessReferenceVisitor);
#endif
            StaticData.ScanStaticData(markAndProcessReferenceVisitor);
            CollectorStatistics.Event(GCEvent.TraceSpecial);
            WeakReference.Process(updateReferenceVisitor, true, true);
            Finalizer.ResurrectCandidates(updateReferenceVisitor,
                                          markAndProcessReferenceVisitor, true);
            markReferenceVisitor.Cleanup();
            UnmanagedPageList.ReleaseStandbyPages();
            // 2) Sweep the garbage objects
            int afterTrace = 0;
            if (VTable.enableGCTiming)
            {
                afterTrace = Environment.TickCount;
            }
            CollectorStatistics.Event(GCEvent.SweepStart, TotalMemory);
            WeakReference.Process(updateReferenceVisitor, true, false);
            MultiUseWord.VisitWeakRefs(updateReferenceVisitor,
                                       false /* Don't use shadows */);
#if !VC
            TryAllManager.VisitWeakRefs(updateReferenceVisitor);
#endif
            SegregatedFreeList.VisitAllObjects(sweepVisitor);
            SegregatedFreeList.RecycleGlobalPages();
            SegregatedFreeList.CommitFreedData();
            CollectorStatistics.Event(GCEvent.SweepSpecial);
            MultiUseWord.PostGCHook();
            if (GC.IsProfiling)
            {
                HeapDamaged = false;
                // Allocations may occur inside the PostGCHook.  Hopefully a
                // sufficiently limited quantity that we don't recursively
                // trigger a GC.
                GcProfiler.NotifyPostGC(ProfileRoots, ProfileObjects);
            }
            Finalizer.ReleaseCollectFinalizers();
#if !VC
            TryAllManager.PostGCHookTryAll();
#endif
            CollectorStatistics.Event(GCEvent.CollectionComplete,
                                      TotalMemory);
            if (VTable.enableGCTiming)
            {
                int after = Environment.TickCount;
                numCollections++;
                traceTime += (afterTrace - before);
                sweepTime += (after - afterTrace);
            }
            // 3) Determine a new collection trigger
            UIntPtr testTrigger = (UIntPtr)this.TotalMemory >> 2;
            UIntPtr minTrigger  = (UIntPtr)MinTrigger;
            UIntPtr maxTrigger  = (UIntPtr)MaxTrigger;
            collectionTrigger =
                (testTrigger > minTrigger) ?
                (testTrigger < maxTrigger ?
                 testTrigger : maxTrigger) : minTrigger;
#if SINGULARITY
#if SINGULARITY_KERNEL
    #if THREAD_TIME_ACCOUNTING
            int procId = Thread.CurrentProcess.ProcessId;
            ticks  = Thread.CurrentThread.ExecutionTime - ticks;
            ticks2 = SystemClock.KernelUpTime - ticks2;
    #else
            ticks = SystemClock.KernelUpTime - ticks;
    #endif
            //Thread.CurrentProcess.SetGcPerformanceCounters(ticks, (long) SegregatedFreeList.TotalBytes);
#elif SINGULARITY_PROCESS
    #if THREAD_TIME_ACCOUNTING
            ushort procId = ProcessService.GetCurrentProcessId();
            ticks  = ProcessService.GetThreadTime() - ticks;
            ticks2 = ProcessService.GetUpTime() - ticks2;
    #else
            ticks = ProcessService.GetUpTime() - ticks;
    #endif
            //ProcessService.SetGcPerformanceCounters(ticks, (long) SegregatedFreeList.TotalBytes);
#endif
#if DEBUG
#if THREAD_TIME_ACCOUNTING
            DebugStub.WriteLine("~~~~~ Finish MarkSweep Cleanup [data={0:x8}, diff={7:x8} pid={1:x3}, ms(Thread)={2:d6}, ms(System)={3:d6}, thds={4}, procId={5}, tid={6}]",
                                __arglist(SegregatedFreeList.TotalBytes,
                                          PageTable.processTag >> 16,
                                          ticks.Milliseconds,
                                          ticks2.Milliseconds,
                                          countThreads,
                                          procId,
                                          Thread.GetCurrentThreadIndex(),
                                          preGcTotalBytes - SegregatedFreeList.TotalBytes
                                          ));
#else
            DebugStub.WriteLine("~~~~~ Finish MarkSweep Cleanup [data={0:x8}, pid={1:x3}, ms={2:d6}, thds={3}]",
                                __arglist(SegregatedFreeList.TotalBytes,
                                          PageTable.processTag >> 16,
                                          ticks.Milliseconds,
                                          countThreads));
#endif
#endif
#endif
        }
Ejemplo n.º 9
0
        internal override void CollectGeneration(int generation,
                                                 UIntPtr generationPageCount)
        {
            UIntPtr fromSpacePageCountTotal = UIntPtr.Zero;

            for (int i = MinGeneration; i <= generation; i++)
            {
                fromSpacePageCountTotal += fromSpacePageCounts[i];
            }

            PageType maxDestGeneration = (generation < (int)MAX_GENERATION)
                ? (PageType)(generation + 1)
                : MAX_GENERATION;

            // The real work: find the roots, copy reachable objects
            CollectorStatistics.Event(GCEvent.ComputeRootSet);
#if !VC
            TryAllManager.PreGCHookTryAll();
#endif
            bool onlyNew = false;
            if (generation == (int)nurseryGeneration)
            {
                onlyNew = true;
            }
            MultiUseWord.PreGCHook(false, /* don't use shadows */
                                   onlyNew /* only scan new EMUs */);
            Finalizer.PrepareCollectFinalizers();
            CallStack.ScanStacks(null, pinnedReferenceVisitor);
            pinnedReferenceVisitor.ProcessPinnedPages(generalReferenceVisitor);
            CallStack.ScanStacks(threadReferenceVisitor, null);
            Thread.VisitBootstrapData(generalReferenceVisitor);
#if SINGULARITY
            Thread.UpdateAfterGC();
#endif
            Thread currentThread = Thread.threadTable[collectorThreadIndex];
#if SINGULARITY_KERNEL
            Kernel.VisitSpecialData(generalReferenceVisitor);
            Kernel.UpdateAfterGC(currentThread);
#endif
            MultiUseWord.VisitStrongRefs(generalReferenceVisitor,
                                         false /* Don't use shadows */);
#if !VC
            TryAllManager.VisitStrongRefs(generalReferenceVisitor);
#endif
            StaticData.ScanStaticData(generalReferenceVisitor);
            if ((PageType)generation < MAX_GENERATION)
            {
                installedRemSet.Clean();
                this.ScanRemSet((PageType)generation);
            }
            installedRemSet.Reset();
            CollectorStatistics.Event(GCEvent.TraceStart);
            this.ScanAndCopy(maxDestGeneration);
            CollectorStatistics.Event(GCEvent.TraceSpecial);
            WeakReference.Process(forwardOnlyReferenceVisitor, true, true);
            Finalizer.ResurrectCandidates(forwardOnlyReferenceVisitor,
                                          generalReferenceVisitor,
                                          true);
            this.ScanAndCopy(maxDestGeneration);
            WeakReference.Process(forwardOnlyReferenceVisitor, true, false);
            MultiUseWord.VisitWeakRefs(forwardOnlyReferenceVisitor,
                                       false /* Don't use shadows */);
#if !VC
            TryAllManager.VisitWeakRefs(forwardOnlyReferenceVisitor);
#endif
            CollectorStatistics.Event(GCEvent.CollectionComplete);
            // Clean up the auxiliary data structures
            for (int i = MinGeneration + 1; i <= (int)maxDestGeneration; i++)
            {
                copyScanners[i].Cleanup();
            }
            UnmanagedPageList.ReleaseStandbyPages();
            pinnedReferenceVisitor.CleanPinnedPages();
            MultiUseWord.PostGCHook(onlyNew);
            Finalizer.ReleaseCollectFinalizers();
#if !VC
            TryAllManager.PostGCHookTryAll();
#endif
        }