Exemplo n.º 1
0
        private void Dispose(bool disposing)
        {
            // This is just bookkeeping to ensure multiple threads can really
            // get enough memory, and this does not actually reserve memory
            // within the GC heap.
            if (_mustSubtractReservation)
            {
                RuntimeHelpers.PrepareConstrainedRegions();
                try {
                }
                finally {
                    SharedStatics.AddMemoryFailPointReservation(-((long)_reservedMemory));
                    _mustSubtractReservation = false;
                }
            }

            /*
             * // Prototype performance hack
             * // Let's pretend that we returned at least some free memory to
             * // the GC heap.  We don't know this is true - the objects could
             * // have a longer lifetime, and the memory could be elsewhere in the
             * // GC heap.  Additionally, we subtracted off the segment size, not
             * // this size.  That's ok - we don't mind if this slowly degrades
             * // and requires us to refresh the value a little bit sooner.
             * // But releasing the memory here should help us avoid probing for
             * // free address space excessively with large workItem sizes.
             * Interlocked.Add(ref LastKnownFreeAddressSpace, _reservedMemory);
             */
        }
Exemplo n.º 2
0
        // Token: 0x06001C0B RID: 7179 RVA: 0x00060884 File Offset: 0x0005EA84
        public string GetString(ref int position, bool bCreate)
        {
            int i;

            for (i = position; i < this.m_data.Length - 1; i += 2)
            {
                if (this.m_data[i] == 0 && this.m_data[i + 1] == 0)
                {
                    break;
                }
            }
            Tokenizer.StringMaker sharedStringMaker = SharedStatics.GetSharedStringMaker();
            string result;

            try
            {
                if (bCreate)
                {
                    sharedStringMaker._outStringBuilder = null;
                    sharedStringMaker._outIndex         = 0;
                    for (int j = position; j < i; j += 2)
                    {
                        char c = (char)((int)this.m_data[j] << 8 | (int)this.m_data[j + 1]);
                        if (sharedStringMaker._outIndex < 512)
                        {
                            char[] outChars = sharedStringMaker._outChars;
                            Tokenizer.StringMaker stringMaker = sharedStringMaker;
                            int outIndex = stringMaker._outIndex;
                            stringMaker._outIndex = outIndex + 1;
                            outChars[outIndex]    = c;
                        }
                        else
                        {
                            if (sharedStringMaker._outStringBuilder == null)
                            {
                                sharedStringMaker._outStringBuilder = new StringBuilder();
                            }
                            sharedStringMaker._outStringBuilder.Append(sharedStringMaker._outChars, 0, 512);
                            sharedStringMaker._outChars[0] = c;
                            sharedStringMaker._outIndex    = 1;
                        }
                    }
                }
                position = i + 2;
                if (bCreate)
                {
                    result = sharedStringMaker.MakeString();
                }
                else
                {
                    result = null;
                }
            }
            finally
            {
                SharedStatics.ReleaseSharedStringMaker(ref sharedStringMaker);
            }
            return(result);
        }
Exemplo n.º 3
0
        public string GetString(ref int position, bool bCreate)
        {
            int index1 = position;

            while (index1 < this.m_data.Length - 1 && ((int)this.m_data[index1] != 0 || (int)this.m_data[index1 + 1] != 0))
            {
                index1 += 2;
            }
            Tokenizer.StringMaker sharedStringMaker = SharedStatics.GetSharedStringMaker();
            try
            {
                if (bCreate)
                {
                    sharedStringMaker._outStringBuilder = (StringBuilder)null;
                    sharedStringMaker._outIndex         = 0;
                    int index2 = position;
                    while (index2 < index1)
                    {
                        char ch = (char)((uint)this.m_data[index2] << 8 | (uint)this.m_data[index2 + 1]);
                        if (sharedStringMaker._outIndex < 512)
                        {
                            char[] chArray = sharedStringMaker._outChars;
                            Tokenizer.StringMaker stringMaker = sharedStringMaker;
                            int num1 = stringMaker._outIndex;
                            int num2 = num1 + 1;
                            stringMaker._outIndex = num2;
                            int index3 = num1;
                            int num3   = (int)ch;
                            chArray[index3] = (char)num3;
                        }
                        else
                        {
                            if (sharedStringMaker._outStringBuilder == null)
                            {
                                sharedStringMaker._outStringBuilder = new StringBuilder();
                            }
                            sharedStringMaker._outStringBuilder.Append(sharedStringMaker._outChars, 0, 512);
                            sharedStringMaker._outChars[0] = ch;
                            sharedStringMaker._outIndex    = 1;
                        }
                        index2 += 2;
                    }
                }
                position = index1 + 2;
                if (bCreate)
                {
                    return(sharedStringMaker.MakeString());
                }
                return((string)null);
            }
            finally
            {
                SharedStatics.ReleaseSharedStringMaker(ref sharedStringMaker);
            }
        }
 // Token: 0x06002BA1 RID: 11169 RVA: 0x000A3AD0 File Offset: 0x000A1CD0
 internal void BasicInitialization()
 {
     this.LineNo            = 1;
     this._inProcessingTag  = 0;
     this._inSavedCharacter = -1;
     this._inIndex          = 0;
     this._inSize           = 0;
     this._inNestedSize     = 0;
     this._inNestedIndex    = 0;
     this._inTokenSource    = Tokenizer.TokenSource.Other;
     this._maker            = SharedStatics.GetSharedStringMaker();
 }
Exemplo n.º 5
0
        public string GetString(ref int position, bool bCreate)
        {
            string str;
            int    index = position;

            while (index < (this.m_data.Length - 1))
            {
                if ((this.m_data[index] == 0) && (this.m_data[index + 1] == 0))
                {
                    break;
                }
                index += 2;
            }
            Tokenizer.StringMaker sharedStringMaker = SharedStatics.GetSharedStringMaker();
            try
            {
                if (bCreate)
                {
                    sharedStringMaker._outStringBuilder = null;
                    sharedStringMaker._outIndex         = 0;
                    for (int i = position; i < index; i += 2)
                    {
                        char ch = (char)((this.m_data[i] << 8) | this.m_data[i + 1]);
                        if (sharedStringMaker._outIndex < 0x200)
                        {
                            sharedStringMaker._outChars[sharedStringMaker._outIndex++] = ch;
                        }
                        else
                        {
                            if (sharedStringMaker._outStringBuilder == null)
                            {
                                sharedStringMaker._outStringBuilder = new StringBuilder();
                            }
                            sharedStringMaker._outStringBuilder.Append(sharedStringMaker._outChars, 0, 0x200);
                            sharedStringMaker._outChars[0] = ch;
                            sharedStringMaker._outIndex    = 1;
                        }
                    }
                }
                position = index + 2;
                if (bCreate)
                {
                    return(sharedStringMaker.MakeString());
                }
                str = null;
            }
            finally
            {
                SharedStatics.ReleaseSharedStringMaker(ref sharedStringMaker);
            }
            return(str);
        }
Exemplo n.º 6
0
 private void Dispose(bool disposing)
 {
     if (this._mustSubtractReservation)
     {
         RuntimeHelpers.PrepareConstrainedRegions();
         try
         {
         }
         finally
         {
             SharedStatics.AddMemoryFailPointReservation((long)(-(long)this._reservedMemory));
             this._mustSubtractReservation = false;
         }
     }
 }
Exemplo n.º 7
0
        private void Dispose(bool disposing)
        {
            // This is just bookkeeping to ensure multiple threads can really
            // get enough memory, and this does not actually reserve memory
            // within the GC heap.
            if (_mustSubtractReservation)
            {
                RuntimeHelpers.PrepareConstrainedRegions();
                try {
                }
                finally {
                    SharedStatics.AddMemoryFailPointReservation(-((long)_reservedMemory));
                    _mustSubtractReservation = false;
                }
            }

            /*
             * //
             * Interlocked.Add(ref LastKnownFreeAddressSpace, _reservedMemory);
             */
        }
Exemplo n.º 8
0
        static public PolicyLevel LoadPolicyLevelFromFile(String path, PolicyLevelType type)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            ConfigId id = SharedStatics.GetNextConfigId();

            ConfigRetval retval = Config.InitData(id, path);

            if ((retval & ConfigRetval.ConfigFile) == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_PolicyFileDoesNotExist"));
            }

            String name = Enum.GetName(typeof(PolicyLevelType), type);

            if (name == null)
            {
                return(null);
            }

            String fullPath = Path.GetFullPath(path);

            FileIOPermission perm = new FileIOPermission(PermissionState.None);

            perm.AddPathList(FileIOPermissionAccess.Read, fullPath);
            perm.AddPathList(FileIOPermissionAccess.Write, fullPath);
            perm.Demand();

            PolicyLevel level = new PolicyLevel(name, id, type == PolicyLevelType.Machine);

            level.ThrowOnLoadError = true;
            level.CheckLoaded(false);
            return(level);
        }
Exemplo n.º 9
0
        public MemoryFailPoint(int sizeInMegabytes)
        {
            if (sizeInMegabytes <= 0)
            {
                throw new ArgumentOutOfRangeException("sizeInMegabytes", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            Contract.EndContractBlock();

            ulong size = ((ulong)sizeInMegabytes) << 20;

            _reservedMemory = size;
#if FEATURE_PAL
            // Allow the fail point to succeed, unless we have a
            // platform-independent way of checking the amount of free memory.
            // We could allocate a byte[] then discard it, but we don't want
            // to generate garbage like that.
#else
            // Check to see that we both have enough memory on the system
            // and that we have enough room within the user section of the
            // process's address space.  Also, we need to use the GC segment
            // size, not the amount of memory the user wants to allocate.
            // Consider correcting this to reflect free memory within the GC
            // heap, and to check both the normal & large object heaps.
            ulong segmentSize = (ulong)(Math.Ceiling((double)size / GCSegmentSize) * GCSegmentSize);
            if (segmentSize >= TopOfMemory)
            {
                throw new InsufficientMemoryException(Environment.GetResourceString("InsufficientMemory_MemFailPoint_TooBig"));
            }

            ulong requestedSizeRounded = (ulong)(Math.Ceiling((double)sizeInMegabytes / MemoryCheckGranularity) * MemoryCheckGranularity);
            //re-convert into bytes
            requestedSizeRounded <<= 20;

            ulong availPageFile         = 0; // available VM (physical + page file)
            ulong totalAddressSpaceFree = 0; // non-contiguous free address space

            // Check for available memory, with 2 attempts at getting more
            // memory.
            // Stage 0: If we don't have enough, trigger a GC.
            // Stage 1: If we don't have enough, try growing the swap file.
            // Stage 2: Update memory state, then fail or leave loop.
            //
            // (In the future, we could consider adding another stage after
            // Stage 0 to run finalizers.  However, before doing that make sure
            // that we could abort this constructor when we call
            // GC.WaitForPendingFinalizers, noting that this method uses a CER
            // so it can't be aborted, and we have a critical finalizer.  It
            // would probably work, but do some thinking first.)
            for (int stage = 0; stage < 3; stage++)
            {
                CheckForAvailableMemory(out availPageFile, out totalAddressSpaceFree);

                // If we have enough room, then skip some stages.
                // Note that multiple threads can still ---- on our free chunk
                // of address space, which can't be easily solved.
                ulong reserved         = SharedStatics.MemoryFailPointReservedMemory;
                ulong segPlusReserved  = segmentSize + reserved;
                bool  overflow         = segPlusReserved < segmentSize || segPlusReserved < reserved;
                bool  needPageFile     = availPageFile < (requestedSizeRounded + reserved + LowMemoryFudgeFactor) || overflow;
                bool  needAddressSpace = totalAddressSpaceFree < segPlusReserved || overflow;

                // Ensure our cached amount of free address space is not stale.
                long now = Environment.TickCount;  // Handle wraparound.
                if ((now > LastTimeCheckingAddressSpace + CheckThreshold || now < LastTimeCheckingAddressSpace) ||
                    LastKnownFreeAddressSpace < (long)segmentSize)
                {
                    CheckForFreeAddressSpace(segmentSize, false);
                }
                bool needContiguousVASpace = (ulong)LastKnownFreeAddressSpace < segmentSize;

                BCLDebug.Trace("MEMORYFAILPOINT", "MemoryFailPoint: Checking for {0} MB, for allocation size of {1} MB, stage {9}.  Need page file? {2}  Need Address Space? {3}  Need Contiguous address space? {4}  Avail page file: {5} MB  Total free VA space: {6} MB  Contiguous free address space (found): {7} MB  Space reserved via process's MemoryFailPoints: {8} MB",
                               segmentSize >> 20, sizeInMegabytes, needPageFile,
                               needAddressSpace, needContiguousVASpace,
                               availPageFile >> 20, totalAddressSpaceFree >> 20,
                               LastKnownFreeAddressSpace >> 20, reserved, stage);

                if (!needPageFile && !needAddressSpace && !needContiguousVASpace)
                {
                    break;
                }

                switch (stage)
                {
                case 0:
                    // The GC will release empty segments to the OS.  This will
                    // relieve us from having to guess whether there's
                    // enough memory in either GC heap, and whether
                    // internal fragmentation will prevent those
                    // allocations from succeeding.
                    GC.Collect();
                    continue;

                case 1:
                    // Do this step if and only if the page file is too small.
                    if (!needPageFile)
                    {
                        continue;
                    }

                    // Attempt to grow the OS's page file.  Note that we ignore
                    // any allocation routines from the host intentionally.
                    RuntimeHelpers.PrepareConstrainedRegions();
                    try {
                    }
                    finally {
                        // This shouldn't overflow due to the if clauses above.
                        UIntPtr numBytes = new UIntPtr(segmentSize);
                        unsafe {
                            void *pMemory = Win32Native.VirtualAlloc(null, numBytes, Win32Native.MEM_COMMIT, Win32Native.PAGE_READWRITE);
                            if (pMemory != null)
                            {
                                bool r = Win32Native.VirtualFree(pMemory, UIntPtr.Zero, Win32Native.MEM_RELEASE);
                                if (!r)
                                {
                                    __Error.WinIOError();
                                }
                            }
                        }
                    }
                    continue;

                case 2:
                    // The call to CheckForAvailableMemory above updated our
                    // state.
                    if (needPageFile || needAddressSpace)
                    {
                        InsufficientMemoryException e = new InsufficientMemoryException(Environment.GetResourceString("InsufficientMemory_MemFailPoint"));
#if _DEBUG
                        e.Data["MemFailPointState"] = new MemoryFailPointState(sizeInMegabytes, segmentSize,
                                                                               needPageFile, needAddressSpace, needContiguousVASpace,
                                                                               availPageFile >> 20, totalAddressSpaceFree >> 20,
                                                                               LastKnownFreeAddressSpace >> 20, reserved);
#endif
                        throw e;
                    }

                    if (needContiguousVASpace)
                    {
                        InsufficientMemoryException e = new InsufficientMemoryException(Environment.GetResourceString("InsufficientMemory_MemFailPoint_VAFrag"));
#if _DEBUG
                        e.Data["MemFailPointState"] = new MemoryFailPointState(sizeInMegabytes, segmentSize,
                                                                               needPageFile, needAddressSpace, needContiguousVASpace,
                                                                               availPageFile >> 20, totalAddressSpaceFree >> 20,
                                                                               LastKnownFreeAddressSpace >> 20, reserved);
#endif
                        throw e;
                    }

                    break;

                default:
                    Contract.Assert(false, "Fell through switch statement!");
                    break;
                }
            }

            // Success - we have enough room the last time we checked.
            // Now update our shared state in a somewhat atomic fashion
            // and handle a simple ---- with other MemoryFailPoint instances.
            AddToLastKnownFreeAddressSpace(-((long)size));
            if (LastKnownFreeAddressSpace < 0)
            {
                CheckForFreeAddressSpace(segmentSize, true);
            }

            RuntimeHelpers.PrepareConstrainedRegions();
            try {
            }
            finally {
                SharedStatics.AddMemoryFailPointReservation((long)size);
                _mustSubtractReservation = true;
            }
#endif // FEATURE_PAL
        }
Exemplo n.º 10
0
 private static int GetNextSeqNum()
 {
     return(SharedStatics.Remoting_Identity_GetNextSeqNum());
 }
Exemplo n.º 11
0
        public unsafe MemoryFailPoint(int sizeInMegabytes)
        {
            if (sizeInMegabytes <= 0)
            {
                throw new ArgumentOutOfRangeException("sizeInMegabytes", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            ulong num = (ulong)((ulong)((long)sizeInMegabytes) << 20);

            this._reservedMemory = num;
            ulong num2 = (ulong)(Math.Ceiling(num / MemoryFailPoint.GCSegmentSize) * MemoryFailPoint.GCSegmentSize);

            if (num2 >= MemoryFailPoint.TopOfMemory)
            {
                throw new InsufficientMemoryException(Environment.GetResourceString("InsufficientMemory_MemFailPoint_TooBig"));
            }
            ulong num3 = (ulong)(Math.Ceiling((double)sizeInMegabytes / 16.0) * 16.0);

            num3 <<= 20;
            ulong num4 = 0UL;
            ulong num5 = 0UL;
            int   i    = 0;

            while (i < 3)
            {
                MemoryFailPoint.CheckForAvailableMemory(out num4, out num5);
                ulong memoryFailPointReservedMemory = SharedStatics.MemoryFailPointReservedMemory;
                ulong num6  = num2 + memoryFailPointReservedMemory;
                bool  flag  = num6 < num2 || num6 < memoryFailPointReservedMemory;
                bool  flag2 = num4 < num3 + memoryFailPointReservedMemory + 16777216UL || flag;
                bool  flag3 = num5 < num6 || flag;
                long  num7  = (long)Environment.TickCount;
                if (num7 > MemoryFailPoint.LastTimeCheckingAddressSpace + 10000L || num7 < MemoryFailPoint.LastTimeCheckingAddressSpace || MemoryFailPoint.LastKnownFreeAddressSpace < (long)num2)
                {
                    MemoryFailPoint.CheckForFreeAddressSpace(num2, false);
                }
                bool flag4 = MemoryFailPoint.LastKnownFreeAddressSpace < (long)num2;
                if (!flag2 && !flag3 && !flag4)
                {
                    break;
                }
                switch (i)
                {
                case 0:
                    GC.Collect();
                    break;

                case 1:
                    if (flag2)
                    {
                        RuntimeHelpers.PrepareConstrainedRegions();
                        try
                        {
                            break;
                        }
                        finally
                        {
                            UIntPtr numBytes = new UIntPtr(num2);
                            void *  ptr      = Win32Native.VirtualAlloc(null, numBytes, 4096, 4);
                            if (ptr != null && !Win32Native.VirtualFree(ptr, UIntPtr.Zero, 32768))
                            {
                                __Error.WinIOError();
                            }
                        }
                        goto IL_183;
                    }
                    break;

                case 2:
                    goto IL_183;
                }
IL_1B6:
                i++;
                continue;
IL_183:
                if (flag2 || flag3)
                {
                    InsufficientMemoryException ex = new InsufficientMemoryException(Environment.GetResourceString("InsufficientMemory_MemFailPoint"));
                    throw ex;
                }
                if (flag4)
                {
                    InsufficientMemoryException ex2 = new InsufficientMemoryException(Environment.GetResourceString("InsufficientMemory_MemFailPoint_VAFrag"));
                    throw ex2;
                }
                goto IL_1B6;
            }
            MemoryFailPoint.AddToLastKnownFreeAddressSpace((long)(-(long)num));
            if (MemoryFailPoint.LastKnownFreeAddressSpace < 0L)
            {
                MemoryFailPoint.CheckForFreeAddressSpace(num2, true);
            }
            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
            }
            finally
            {
                SharedStatics.AddMemoryFailPointReservation((long)num);
                this._mustSubtractReservation = true;
            }
        }
 // Token: 0x06002BA2 RID: 11170 RVA: 0x000A3B20 File Offset: 0x000A1D20
 public void Recycle()
 {
     SharedStatics.ReleaseSharedStringMaker(ref this._maker);
 }
Exemplo n.º 13
0
        public unsafe MemoryFailPoint(int sizeInMegabytes)
        {
            if (sizeInMegabytes <= 0)
            {
                throw new ArgumentOutOfRangeException("sizeInMegabytes", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            ulong num1 = (ulong)sizeInMegabytes << 20;

            this._reservedMemory = num1;
            ulong size = (ulong)(Math.Ceiling((double)num1 / (double)MemoryFailPoint.GCSegmentSize) * (double)MemoryFailPoint.GCSegmentSize);

            if (size >= MemoryFailPoint.TopOfMemory)
            {
                throw new InsufficientMemoryException(Environment.GetResourceString("InsufficientMemory_MemFailPoint_TooBig"));
            }
            ulong num2                  = (ulong)(Math.Ceiling((double)sizeInMegabytes / 16.0) * 16.0) << 20;
            ulong availPageFile         = 0;
            ulong totalAddressSpaceFree = 0;

            for (int index = 0; index < 3; ++index)
            {
                MemoryFailPoint.CheckForAvailableMemory(out availPageFile, out totalAddressSpaceFree);
                ulong pointReservedMemory = SharedStatics.MemoryFailPointReservedMemory;
                ulong num3  = size + pointReservedMemory;
                bool  flag1 = num3 < size || num3 < pointReservedMemory;
                bool  flag2 = availPageFile < num2 + pointReservedMemory + 16777216UL | flag1;
                bool  flag3 = totalAddressSpaceFree < num3 | flag1;
                long  num4  = (long)Environment.TickCount;
                if (num4 > MemoryFailPoint.LastTimeCheckingAddressSpace + 10000L || num4 < MemoryFailPoint.LastTimeCheckingAddressSpace || MemoryFailPoint.LastKnownFreeAddressSpace < (long)size)
                {
                    MemoryFailPoint.CheckForFreeAddressSpace(size, false);
                }
                bool flag4 = (ulong)MemoryFailPoint.LastKnownFreeAddressSpace < size;
                if (flag2 || flag3 || flag4)
                {
                    switch (index)
                    {
                    case 0:
                        GC.Collect();
                        break;

                    case 1:
                        if (flag2)
                        {
                            RuntimeHelpers.PrepareConstrainedRegions();
                            try
                            {
                            }
                            finally
                            {
                                void *address = Win32Native.VirtualAlloc((void *)null, new UIntPtr(size), 4096, 4);
                                if ((IntPtr)address != IntPtr.Zero && !Win32Native.VirtualFree(address, UIntPtr.Zero, 32768))
                                {
                                    __Error.WinIOError();
                                }
                            }
                            break;
                        }
                        break;

                    case 2:
                        if (flag2 | flag3)
                        {
                            throw new InsufficientMemoryException(Environment.GetResourceString("InsufficientMemory_MemFailPoint"));
                        }
                        if (flag4)
                        {
                            throw new InsufficientMemoryException(Environment.GetResourceString("InsufficientMemory_MemFailPoint_VAFrag"));
                        }
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
            MemoryFailPoint.AddToLastKnownFreeAddressSpace(-(long)num1);
            if (MemoryFailPoint.LastKnownFreeAddressSpace < 0L)
            {
                MemoryFailPoint.CheckForFreeAddressSpace(size, true);
            }
            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
            }
            finally
            {
                SharedStatics.AddMemoryFailPointReservation((long)num1);
                this._mustSubtractReservation = true;
            }
        }
        public unsafe MemoryFailPoint(int sizeInMegabytes)
        {
            if (sizeInMegabytes <= 0)
            {
                throw new ArgumentOutOfRangeException("sizeInMegabytes", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            ulong num = ((ulong)sizeInMegabytes) << 20;

            this._reservedMemory = num;
            ulong size = (ulong)(Math.Ceiling((double)(((float)num) / ((float)GCSegmentSize))) * GCSegmentSize);

            if (size >= TopOfMemory)
            {
                throw new InsufficientMemoryException(Environment.GetResourceString("InsufficientMemory_MemFailPoint_TooBig"));
            }
            ulong availPageFile         = 0L;
            ulong totalAddressSpaceFree = 0L;

            for (int i = 0; i < 3; i++)
            {
                CheckForAvailableMemory(out availPageFile, out totalAddressSpaceFree);
                ulong memoryFailPointReservedMemory = SharedStatics.MemoryFailPointReservedMemory;
                ulong num7      = size + memoryFailPointReservedMemory;
                bool  flag      = (num7 < size) || (num7 < memoryFailPointReservedMemory);
                bool  flag2     = (availPageFile < (num7 + ((ulong)0x1000000L))) || flag;
                bool  flag3     = (totalAddressSpaceFree < num7) || flag;
                long  tickCount = Environment.TickCount;
                if (((tickCount > (LastTimeCheckingAddressSpace + 0x2710L)) || (tickCount < LastTimeCheckingAddressSpace)) || (LastKnownFreeAddressSpace < size))
                {
                    CheckForFreeAddressSpace(size, false);
                }
                bool flag4 = LastKnownFreeAddressSpace < size;
                if ((!flag2 && !flag3) && !flag4)
                {
                    break;
                }
                switch (i)
                {
                case 0:
                {
                    GC.Collect();
                    continue;
                }

                case 1:
                    if (!flag2)
                    {
                        continue;
                    }
                    RuntimeHelpers.PrepareConstrainedRegions();
                    try
                    {
                        continue;
                    }
                    finally
                    {
                        UIntPtr numBytes = new UIntPtr(size);
                        void *  address  = Win32Native.VirtualAlloc(null, numBytes, 0x1000, 4);
                        if ((address != null) && !Win32Native.VirtualFree(address, UIntPtr.Zero, 0x8000))
                        {
                            __Error.WinIOError();
                        }
                    }
                    break;

                case 2:
                    break;

                default:
                {
                    continue;
                }
                }
                if (flag2 || flag3)
                {
                    InsufficientMemoryException exception = new InsufficientMemoryException(Environment.GetResourceString("InsufficientMemory_MemFailPoint"));
                    throw exception;
                }
                if (flag4)
                {
                    InsufficientMemoryException exception2 = new InsufficientMemoryException(Environment.GetResourceString("InsufficientMemory_MemFailPoint_VAFrag"));
                    throw exception2;
                }
            }
            Interlocked.Add(ref LastKnownFreeAddressSpace, (long)-num);
            if (LastKnownFreeAddressSpace < 0L)
            {
                CheckForFreeAddressSpace(size, true);
            }
            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
            }
            finally
            {
                SharedStatics.AddMemoryFailPointReservation((long)num);
                this._mustSubtractReservation = true;
            }
        }
Exemplo n.º 15
0
 private static int GetNextSeqNum() => SharedStatics.Remoting_Identity_GetNextSeqNum();