示例#1
0
        private int Sweep()
        {
            int nDeallocated = 0;
            long pos;
            gcDone = true;
            for (int i = dbFirstUserId, j = committedIndexSize; i < j; i++)
            {
                pos = GetGCPos(i);
                if (pos != 0 && ((int) pos & (dbPageObjectFlag | dbFreeHandleFlag)) == 0)
                {
                    int bit = (int) (SupportClass.URShift(pos, dbAllocationQuantumBits));
                    if ((blackBitmap[SupportClass.URShift(bit, 5)] & (1 << (bit & 31))) == 0)
                    {
                        // object is not accessible
                        if (GetPos(i) != pos)
                        {
                            throw new StorageError(StorageError.INVALID_OID);
                        }
                        int offs = (int) pos & (Page.pageSize - 1);
                        Page pg = pool.GetPage(pos - offs);
                        int typeOid = ObjectHeader.GetType(pg.data, offs);
                        if (typeOid != 0)
                        {
                            ClassDescriptor desc = FindClassDescriptor(typeOid);
                            nDeallocated += 1;
                            if (typeof(Btree).IsAssignableFrom(desc.cls))
                            {
                                Btree btree = new Btree(pg.data, ObjectHeader.Sizeof + offs);
                                pool.Unfix(pg);
                                btree.AssignOid(this, i, false);
                                btree.Deallocate();
                            }
                            else
                            {
                                int size = ObjectHeader.GetSize(pg.data, offs);
                                pool.Unfix(pg);
                                FreeId(i);
                                objectCache.Remove(i);
                                CloneBitmap(pos, size);
                            }
                            if (listener != null)
                            {
                                listener.DeallocateObject(desc.cls, i);
                            }
                        }
                    }
                }
            }

            greyBitmap = null;
            blackBitmap = null;
            allocatedDelta = 0;
            gcActive = false;

            if (listener != null)
                listener.GcCompleted(nDeallocated);

            return nDeallocated;
        }