Example #1
0
File: GC.cs Project: wffy/corert
        public static void Collect(int generation, GCCollectionMode mode, bool blocking)
        {
            if (generation < 0)
            {
                throw new ArgumentOutOfRangeException("generation", SR.ArgumentOutOfRange_GenericPositive);
            }

            if ((mode < GCCollectionMode.Default) || (mode > GCCollectionMode.Optimized))
            {
                throw new ArgumentOutOfRangeException("mode", SR.ArgumentOutOfRange_Enum);
            }

            int iInternalModes = 0;

            if (mode == GCCollectionMode.Optimized)
            {
                iInternalModes |= (int)InternalGCCollectionMode.Optimized;
            }

            if (blocking)
            {
                iInternalModes |= (int)InternalGCCollectionMode.Blocking;
            }
            else
            {
                iInternalModes |= (int)InternalGCCollectionMode.NonBlocking;
            }

            RuntimeImports.RhCollect(generation, (InternalGCCollectionMode)iInternalModes);
        }
Example #2
0
        public static void Collect(int generation, GCCollectionMode mode, bool blocking)
        {
            if (generation < 0)
            {
                throw new ArgumentOutOfRangeException("generation", SR.ArgumentOutOfRange_GenericPositive);
            }

            if ((mode < GCCollectionMode.Default) || (mode > GCCollectionMode.Optimized))
            {
                throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_Enum);
            }

            int iInternalModes = 0;

            if (mode == GCCollectionMode.Optimized)
            {
                iInternalModes |= (int)InternalGCCollectionMode.Optimized;
            }

            if (blocking)
            {
                iInternalModes |= (int)InternalGCCollectionMode.Blocking;
            }
            else
            {
                iInternalModes |= (int)InternalGCCollectionMode.NonBlocking;
            }

            RuntimeImports.RhCollect(generation, (InternalGCCollectionMode)iInternalModes);
        }
Example #3
0
        private void HandleForceGC(string module, string[] args)
        {
            // Default is an full (gen2) but NON-forced GC.
            int gen = 2;
            GCCollectionMode mode = GCCollectionMode.Optimized;

            if (args.Length > 1)
            {
                // Any argument implies forced GC.
                mode = GCCollectionMode.Forced;
                switch (args[1].ToLower())
                {
                case "now":
                case "*":
                    gen = GC.MaxGeneration;
                    break;

                case "0":
                case "1":
                case "2":
                    gen = Convert.ToInt32(args[1]);
                    break;

                default:
                    m_log.Warn("Usage: forcegc [ 0|1|2|*|now ]");
                    return;
                }
            }

            GC.Collect(gen, mode, true);
        }
Example #4
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        public static void Collect(int generation, GCCollectionMode mode, bool blocking)
        {
            if (generation < 0)
            {
                throw new ArgumentOutOfRangeException("generation", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive"));
            }

            if ((mode < GCCollectionMode.Default) || (mode > GCCollectionMode.Optimized))
            {
                throw new ArgumentOutOfRangeException(Environment.GetResourceString("ArgumentOutOfRange_Enum"));
            }

            Contract.EndContractBlock();

            int iInternalModes = 0;

            if (mode == GCCollectionMode.Optimized)
            {
                iInternalModes |= (int)InternalGCCollectionMode.Optimized;
            }

            if (blocking)
            {
                iInternalModes |= (int)InternalGCCollectionMode.Blocking;
            }
            else
            {
                iInternalModes |= (int)InternalGCCollectionMode.NonBlocking;
            }

            _Collect(generation, iInternalModes);
        }
Example #5
0
        public static void Collect(int generation, GCCollectionMode mode, bool blocking, bool compacting)
        {
            if (generation < 0)
            {
                throw new ArgumentOutOfRangeException("generation", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive"));
            }
            if (mode < GCCollectionMode.Default || mode > GCCollectionMode.Optimized)
            {
                throw new ArgumentOutOfRangeException(Environment.GetResourceString("ArgumentOutOfRange_Enum"));
            }
            int mode1 = 0;

            if (mode == GCCollectionMode.Optimized)
            {
                mode1 |= 4;
            }
            if (compacting)
            {
                mode1 |= 8;
            }
            if (blocking)
            {
                mode1 |= 2;
            }
            else if (!compacting)
            {
                mode1 |= 1;
            }
            GC._Collect(generation, mode1);
        }
Example #6
0
 // Perform garbage collection on a range of generations with the given
 // collection mode
 public static void Collect(int generation, GCCollectionMode mode)
 {
     if (generation != 0)
     {
         throw new ArgumentOutOfRangeException
                   ("generation", _("ArgRange_GCGeneration"));
     }
     CollectInternal(0);
 }
Example #7
0
 public static void Collect(int generation, GCCollectionMode mode)
 {
     if (generation < 0)
     {
         throw new ArgumentOutOfRangeException("generation", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive"));
     }
     if ((mode < GCCollectionMode.Default) || (mode > GCCollectionMode.Optimized))
     {
         throw new ArgumentOutOfRangeException(Environment.GetResourceString("ArgumentOutOfRange_Enum"));
     }
     nativeCollectGeneration(generation, (int)mode);
 }
Example #8
0
 public static void Collect(int generation, GCCollectionMode mode)
 {
     if (generation < 0)
     {
         throw new ArgumentOutOfRangeException("generation", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive"));
     }
     if ((mode < GCCollectionMode.Default) || (mode > GCCollectionMode.Optimized))
     {
         throw new ArgumentOutOfRangeException(Environment.GetResourceString("ArgumentOutOfRange_Enum"));
     }
     nativeCollectGeneration(generation, (int) mode);
 }
Example #9
0
        public static void Collect(int generation, GCCollectionMode mode, bool blocking, bool compacting)
        {
            if (generation < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(generation), SR.ArgumentOutOfRange_GenericPositive);
            }

            if ((mode < GCCollectionMode.Default) || (mode > GCCollectionMode.Aggressive))
            {
                throw new ArgumentOutOfRangeException(nameof(mode), SR.ArgumentOutOfRange_Enum);
            }


            int iInternalModes = 0;

            if (mode == GCCollectionMode.Optimized)
            {
                iInternalModes |= (int)InternalGCCollectionMode.Optimized;
            }
            else if (mode == GCCollectionMode.Aggressive)
            {
                iInternalModes |= (int)InternalGCCollectionMode.Aggressive;
                if (generation != MaxGeneration)
                {
                    throw new ArgumentException(SR.Argument_AggressiveGCRequiresMaxGeneration, nameof(generation));
                }
                if (!blocking)
                {
                    throw new ArgumentException(SR.Argument_AggressiveGCRequiresBlocking, nameof(blocking));
                }
                if (!compacting)
                {
                    throw new ArgumentException(SR.Argument_AggressiveGCRequiresCompacting, nameof(compacting));
                }
            }

            if (compacting)
            {
                iInternalModes |= (int)InternalGCCollectionMode.Compacting;
            }

            if (blocking)
            {
                iInternalModes |= (int)InternalGCCollectionMode.Blocking;
            }
            else if (!compacting)
            {
                iInternalModes |= (int)InternalGCCollectionMode.NonBlocking;
            }

            _Collect(generation, iInternalModes);
        }
Example #10
0
        public static void Collect_Int_GCCollectionMode(GCCollectionMode mode)
        {
            for (int gen = 0; gen <= 2; gen++)
            {
                var b = new byte[1024 * 1024 * 10];
                int oldCollectionCount = GC.CollectionCount(gen);
                b = null;

                GC.Collect(gen, GCCollectionMode.Default);

                Assert.True(GC.CollectionCount(gen) > oldCollectionCount);
            }
        }
Example #11
0
    private static void VerifyCollectionCount(GCCollectionMode mode)
    {
        for (int gen = 0; gen <= 2; gen++)
        {
            byte[] b = new byte[1024 * 1024 * 10];
            int oldCollectionCount = GC.CollectionCount(gen);
            b = null;

            GC.Collect(gen, GCCollectionMode.Default);

            Assert.True(GC.CollectionCount(gen) > oldCollectionCount);
        }
    }
Example #12
0
        public static void Collect_Int_GCCollectionMode(GCCollectionMode mode)
        {
            for (int gen = 0; gen <= 2; gen++)
            {
                var b = new byte[1024 * 1024 * 10];
                int oldCollectionCount = GC.CollectionCount(gen);
                b = null;

                GC.Collect(gen, mode);

                Assert.True(GC.CollectionCount(gen) > oldCollectionCount);
            }
        }
Example #13
0
    private static void VerifyCollectionCount(GCCollectionMode mode)
    {
        for (int gen = 0; gen <= 2; gen++)
        {
            byte[] b = new byte[1024 * 1024 * 10];
            int    oldCollectionCount = GC.CollectionCount(gen);
            b = null;

            GC.Collect(gen, GCCollectionMode.Default);

            Assert.True(GC.CollectionCount(gen) > oldCollectionCount);
        }
    }
Example #14
0
        public static void Collect(int generation, GCCollectionMode mode, bool blocking, bool compacting)
        {
            if (generation < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(generation), "generation", SR.ArgumentOutOfRange_GenericPositive);
            }
            if ((mode < GCCollectionMode.Default) || (mode > GCCollectionMode.Optimized))
            {
                throw new ArgumentOutOfRangeException(nameof(mode), SR.ArgumentOutOfRange_Enum);
            }

            InternalCollect(generation);
        }
Example #15
0
        public static void Collect(int generation, GCCollectionMode mode, bool blocking, bool compacting)
        {
            if (generation < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(generation), SR.ArgumentOutOfRange_GenericPositive);
            }

            if ((mode < GCCollectionMode.Default) || (mode > GCCollectionMode.Optimized))
            {
                throw new ArgumentOutOfRangeException(nameof(mode), SR.ArgumentOutOfRange_Enum);
            }

            Contract.EndContractBlock();

            int iInternalModes = 0;

            if (mode == GCCollectionMode.Optimized)
            {
                iInternalModes |= (int)InternalGCCollectionMode.Optimized;
            }

            if (compacting)
            {
                iInternalModes |= (int)InternalGCCollectionMode.Compacting;
            }

            if (blocking)
            {
                iInternalModes |= (int)InternalGCCollectionMode.Blocking;
            }
            else if (!compacting)
            {
                iInternalModes |= (int)InternalGCCollectionMode.NonBlocking;
            }

            _Collect(generation, iInternalModes);
        }
Example #16
0
        private static bool CollectGarbageInternal(bool compactLoh, Action afterCollect, bool forceByUser, int maxGeneration, GCCollectionMode gcCollectionMode, bool waitForPendingFinalizers)
        {
            if (!ShouldCollectNow() && !forceByUser)
            {
                return(false);
            }

            GcCollectLock.EnterWriteLock();
            try
            {
                ReleaseMemoryBeforeGC();
                memoryBeforeLastForcedGC = GC.GetTotalMemory(false);

                if (compactLoh)
                {
                    SetCompactLog.Value();
                }

                GC.Collect(maxGeneration, gcCollectionMode);
                if (afterCollect != null)
                {
                    afterCollect();
                }

                if (waitForPendingFinalizers)
                {
                    GC.WaitForPendingFinalizers();
                }
            }
            finally
            {
                GcCollectLock.ExitWriteLock();
            }

            memoryAfterLastForcedGC = GC.GetTotalMemory(false);
            memoryDifferenceLastGc  = DifferenceAsDecimalPercents(MemoryBeforeLastForcedGC, MemoryAfterLastForcedGC);

            log.Info("Finished GC, before was {0:#,#}kb, after is {1:#,#}kb", MemoryBeforeLastForcedGC, MemoryAfterLastForcedGC);

            // -> reset last time, increase delay threshold and disallow GC (too early!)
            lastForcedGCTime = SystemTime.UtcNow;

            var old = delayBetweenGCInMinutes;

            if (memoryDifferenceLastGc < 0.1)
            {
                delayBetweenGCInMinutes = Math.Max(5 + delayBetweenGCInMinutes, MaxDelayBetweenGCInMinutes);

                if (old != delayBetweenGCInMinutes)
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Increasing delay for forced GC (not enough memory released, so we need to back off). " +
                                  "New interval between GCs will be {0} minutes", delayBetweenGCInMinutes);
                    }
                }
            }
            else
            {
                if (old != delayBetweenGCInMinutes)
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Resetting delay for forced GC (enough memory was released to make it useful, so we don't need to back off). " +
                                  "New interval between GCs will be {0} minutes", delayBetweenGCInMinutes);
                    }
                }
                delayBetweenGCInMinutes = DefaultDelayBetweenGCInMinutes;
            }

            return(true);
        }
Example #17
0
 public static void Collect(int generation, GCCollectionMode mode, bool blocking)
 {
     Collect(generation);
 }
Example #18
0
File: GC.cs Project: raj581/Marvin
 public static void Collect(int generation, GCCollectionMode mode)
 {
     Collect(generation);
 }
Example #19
0
		private static bool CollectGarbageInternal(bool compactLoh, Action afterCollect, bool forceByUser, int maxGeneration, GCCollectionMode gcCollectionMode, bool waitForPendingFinalizers)
		{
			if (!ShouldCollectNow() && !forceByUser)
				return false;

			GcCollectLock.EnterWriteLock();
			try
			{
				ReleaseMemoryBeforeGC();
				memoryBeforeLastForcedGC = GC.GetTotalMemory(false);

				if (compactLoh)
					SetCompactLog.Value();

				GC.Collect(maxGeneration, gcCollectionMode);
				if (afterCollect != null)
					afterCollect();

				if (waitForPendingFinalizers)
					GC.WaitForPendingFinalizers();
			}
			finally
			{
				GcCollectLock.ExitWriteLock();
			}

			memoryAfterLastForcedGC = GC.GetTotalMemory(false);
			memoryDifferenceLastGc = DifferenceAsDecimalPercents(MemoryBeforeLastForcedGC, MemoryAfterLastForcedGC);

			log.Info("Finished GC, before was {0:#,#}kb, after is {1:#,#}kb", MemoryBeforeLastForcedGC, MemoryAfterLastForcedGC);

			// -> reset last time, increase delay threshold and disallow GC (too early!)
			lastForcedGCTime = SystemTime.UtcNow;

			var old = delayBetweenGCInMinutes;
			if (memoryDifferenceLastGc < 0.1)
			{
				delayBetweenGCInMinutes = Math.Max(5 + delayBetweenGCInMinutes, MaxDelayBetweenGCInMinutes);

				if (old != delayBetweenGCInMinutes)
				{
					log.Debug("Increasing delay for forced GC (not enough memory released, so we need to back off). " +
							  "New interval between GCs will be {0} minutes", delayBetweenGCInMinutes);
				}
			}
			else
			{
				if (old != delayBetweenGCInMinutes)
				{
					log.Debug("Resetting delay for forced GC (enough memory was released to make it useful, so we don't need to back off). " +
							  "New interval between GCs will be {0} minutes", delayBetweenGCInMinutes);
				}
				delayBetweenGCInMinutes = DefaultDelayBetweenGCInMinutes;
			}

			return true;
		}
Example #20
0
        public static TimeSpan StopTime(GCCollectionMode _mode, bool _block, int _generation)
        {
            CreateObjects();
            Timer.Start();

            GC.Collect(_generation, _mode, _block);

            Timer.Stop();
            var time = Timer.Elapsed;
            Timer.Reset();
            return time;
        }
Example #21
0
		public static bool CollectGarbage(int generation, GCCollectionMode collectionMode = GCCollectionMode.Default, bool forceByUser = false)
		{
			return CollectGarbageInternal(false, null, forceByUser, generation, collectionMode, false);
		}
Example #22
0
 public static void CollectGarbage(int generation, GCCollectionMode collectionMode = GCCollectionMode.Default)
 {
     GC.Collect(generation, collectionMode);
 }
Example #23
0
 public static void Collect(int generation, GCCollectionMode mode)
 {
     GC.Collect(generation, mode, true);
 }
Example #24
0
 public static void Collect(int generation, GCCollectionMode mode, bool blocking)
 {
     throw new NotImplementedException();
 }
Example #25
0
 public static bool CollectGarbage(int generation, GCCollectionMode collectionMode = GCCollectionMode.Default, bool forceByUser = false)
 {
     return(CollectGarbageInternal(false, null, forceByUser, generation, collectionMode, false));
 }
Example #26
0
 public static void Collection_InvalidCollectionMode_ThrowsArgumentOutOfRangeException(GCCollectionMode mode)
 {
     AssertExtensions.Throws <ArgumentOutOfRangeException>("mode", "Enum value was out of legal range.", () => GC.Collect(2, mode));
     AssertExtensions.Throws <ArgumentOutOfRangeException>("mode", "Enum value was out of legal range.", () => GC.Collect(2, mode, false));
 }
Example #27
0
 public static void Collect(int generation, GCCollectionMode mode)
 {
 }
Example #28
0
        public static long MeasureMilisElapsed(int generation, GCCollectionMode mode, bool blocking)
        {
            var stringArray = new Object[10000];
            for (int i = 0; i < 10000; i++)
            {
                //stringArray[i] = new string[100]; //small objects
                stringArray[i] = new string[10000]; // big objects
            }
            stringArray = null;

            stopWatch.Start();
            GC.Collect(generation, mode, blocking);
            stopWatch.Stop();

            var elapsed = stopWatch.ElapsedMilliseconds;
            stopWatch.Reset();
            return elapsed;
        }
Example #29
0
 public static void Collect(int generation, GCCollectionMode mode)
 {
     throw new Exception("not impl");
 }
Example #30
0
        public static void CollectGarbage(int generation, GCCollectionMode collectionMode = GCCollectionMode.Default)
        {
            ReleaseMemoryBeforeGC();

            GC.Collect(generation, collectionMode);
        }
Example #31
0
 public static void Collect(int generation, GCCollectionMode mode, bool blocking, bool compacting)
 {
     throw new Exception("not impl");
 }
Example #32
0
 [System.Security.SecuritySafeCritical]  // auto-generated
 public static void Collect(int generation, GCCollectionMode mode) 
 {
     Collect(generation, mode, true);
 }
Example #33
0
 [System.Security.SecuritySafeCritical]  // auto-generated
 public static void Collect(int generation, GCCollectionMode mode, bool blocking) 
 {
     Collect(generation, mode, blocking, false);
 }
Example #34
0
 public static void Collect(int generation, GCCollectionMode mode, bool blocking)
 {
     GC.Collect(generation, mode, blocking, false);
 }
Example #35
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        public static void Collect(int generation, GCCollectionMode mode, bool blocking, bool compacting)
        {
            if (generation<0) 
            {
                throw new ArgumentOutOfRangeException("generation", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive"));
            }

            if ((mode < GCCollectionMode.Default) || (mode > GCCollectionMode.Optimized))
            {
                throw new ArgumentOutOfRangeException(Environment.GetResourceString("ArgumentOutOfRange_Enum"));
            }

            Contract.EndContractBlock();

            int iInternalModes = 0;

            if (mode == GCCollectionMode.Optimized)
            {
                iInternalModes |= (int)InternalGCCollectionMode.Optimized;
            }

            if (compacting)
                iInternalModes |= (int)InternalGCCollectionMode.Compacting;

            if (blocking)
            {
                iInternalModes |= (int)InternalGCCollectionMode.Blocking;
            }
            else if (!compacting)
            {
                iInternalModes |= (int)InternalGCCollectionMode.NonBlocking;
            }

            _Collect(generation, iInternalModes);
        }
Example #36
0
		public static void CollectGarbage(int generation, GCCollectionMode collectionMode = GCCollectionMode.Default)
		{
			ReleaseMemoryBeforeGC();

			GC.Collect(generation, collectionMode);
		}
Example #37
0
 public static void Collect(int generation, GCCollectionMode mode, bool blocking)
 {
     throw new PlatformNotSupportedException();
 }
Example #38
0
 public static void Collection_InvalidCollectionMode_ThrowsArgumentOutOfRangeException(GCCollectionMode mode)
 {
     AssertExtensions.Throws <ArgumentOutOfRangeException>("mode", null, () => GC.Collect(2, mode));
     AssertExtensions.Throws <ArgumentOutOfRangeException>("mode", null, () => GC.Collect(2, mode, false));
 }
Example #39
0
		public static void CollectGarbage(int generation, GCCollectionMode collectionMode = GCCollectionMode.Default)
		{
			GC.Collect(generation, collectionMode);
		}