Ejemplo n.º 1
0
 internal static Object valueOf <K>(K key, ReferenceQueue <K> refQueue)
 {
     return(key == null ? NULL_KEY : new CacheKey <>(key, refQueue));
     // null key means we can't weakly reference it,
     // so we use a NULL_KEY singleton as cache key
     // non-null key requires wrapping with a WeakReference
 }
Ejemplo n.º 2
0
        protected void Rehash(int newCapacity)
        {
            m_threshold = (int)(newCapacity / 2 * m_fillFactor);
            m_mask      = newCapacity / 2 - 1;
            m_mask2     = newCapacity - 1;

            int oldCapacity = m_data.Length;

            object[] oldData = m_data;

            m_data = new object[newCapacity];
            Arrays.Fill(m_data, FreeKey);

            m_queue = new ReferenceQueue <K>();

            m_size = 0;

            for (int i = 0; i < oldCapacity; i += 2)
            {
                object oldKey = oldData[i];
                if (oldKey != FreeKey && oldKey != RemovedKey)
                {
                    var    reference = (Reference <K>)oldKey;
                    object kk;
                    if ((kk = reference.Get()) != null && !reference.IsEnqueued)
                    {
                        Put((K)kk, (V)oldData[i + 1]);
                    }
                }
            }
        }
Ejemplo n.º 3
0
 protected internal Ref(PackFile pack, long position, ByteWindow v, ReferenceQueue
                        <ByteWindow> queue) : base(v, queue)
 {
     this.pack     = pack;
     this.position = position;
     this.size     = v.Size();
 }
Ejemplo n.º 4
0
        unsafe static MonoObject *CreateGCReferenceQueue(IntPtr callback)
        {
            var queue = new ReferenceQueue();

            queue.Callback = Marshal.GetDelegateForFunctionPointer <mono_reference_queue_callback> (callback);
            return((MonoObject *)GetMonoObject(queue));
        }
Ejemplo n.º 5
0
            public override void Run()
            {
                for (;;)
                {
                    Reference <Object> r;
                    lock (@lock)
                    {
                        if (Pending != null)
                        {
                            r            = Pending;
                            Pending      = r.Discovered;
                            r.Discovered = null;
                        }
                        else
                        {
                            // The waiting on the lock may cause an OOME because it may try to allocate
                            // exception objects, so also catch OOME here to avoid silent exit of the
                            // reference handler thread.
                            //
                            // Explicitly define the order of the two exceptions we catch here
                            // when waiting for the lock.
                            //
                            // We do not want to try to potentially load the InterruptedException class
                            // (which would be done if this was its first use, and InterruptedException
                            // were checked first) in this situation.
                            //
                            // This may lead to the VM not ever trying to load the InterruptedException
                            // class again.
                            try
                            {
                                try
                                {
                                    Monitor.Wait(@lock);
                                }
                                catch (OutOfMemoryError)
                                {
                                }
                            }
                            catch (InterruptedException)
                            {
                            }
                            continue;
                        }
                    }

                    // Fast path for cleaners
                    if (r is Cleaner)
                    {
                        ((Cleaner)r).clean();
                        continue;
                    }

                    ReferenceQueue <Object> q = r.Queue;
                    if (q != ReferenceQueue.NULL)
                    {
                        q.Enqueue(r);
                    }
                }
            }
Ejemplo n.º 6
0
        private WindowCache(WindowCacheConfig cfg)
        {
            tableSize = TableSize(cfg);
            int lockCount = LockCount(cfg);

            if (tableSize < 1)
            {
                throw new ArgumentException(JGitText.Get().tSizeMustBeGreaterOrEqual1);
            }
            if (lockCount < 1)
            {
                throw new ArgumentException(JGitText.Get().lockCountMustBeGreaterOrEqual1);
            }
            queue = new ReferenceQueue <ByteWindow>();
            clock = new AtomicLong(1);
            table = new AtomicReferenceArray <WindowCache.Entry>(tableSize);
            locks = new WindowCache.Lock[lockCount];
            for (int i = 0; i < locks.Length; i++)
            {
                locks[i] = new WindowCache.Lock();
            }
            evictLock = new ReentrantLock();
            int eb = (int)(tableSize * .1);

            if (64 < eb)
            {
                eb = 64;
            }
            else
            {
                if (eb < 4)
                {
                    eb = 4;
                }
            }
            if (tableSize < eb)
            {
                eb = tableSize;
            }
            evictBatch      = eb;
            maxFiles        = cfg.GetPackedGitOpenFiles();
            maxBytes        = cfg.GetPackedGitLimit();
            mmap            = cfg.IsPackedGitMMAP();
            windowSizeShift = Bits(cfg.GetPackedGitWindowSize());
            windowSize      = 1 << windowSizeShift;
            openFiles       = new AtomicInteger();
            openBytes       = new AtomicLong();
            if (maxFiles < 1)
            {
                throw new ArgumentException(JGitText.Get().openFilesMustBeAtLeast1);
            }
            if (maxBytes < windowSize)
            {
                throw new ArgumentException(JGitText.Get().windowSizeMustBeLesserThanLimit);
            }
        }
Ejemplo n.º 7
0
 public SoftReference(T val, ReferenceQueue <T> queue)
 {
     this.value = val;
     this.queue = queue;
 }
 internal DeltaCache(PackConfig pc)
 {
     size       = pc.GetDeltaCacheSize();
     entryLimit = pc.GetDeltaCacheLimit();
     queue      = new ReferenceQueue <byte[]>();
 }
Ejemplo n.º 9
0
 public SoftReference(T prm1, ReferenceQueue <global::System.Object> prm2)
 {
 }
Ejemplo n.º 10
0
 internal CacheEntry(K key, V value, ReferenceQueue <V> queue)
     : base(value, queue)
 {
     _key = key;
 }
Ejemplo n.º 11
0
 internal CacheKey(K key, ReferenceQueue <K> refQueue) : base(key, refQueue)
 {
     this.Hash = System.identityHashCode(key);                 // compare by identity
 }
Ejemplo n.º 12
0
 /**
  * Constructs a new soft reference to the given referent. The newly created
  * reference is registered with the given reference queue.
  *
  * @param r the referent to track
  * @param q the queue to register to the reference object with. A null value
  *          results in a weak reference that is not associated with any
  *          queue.
  */
 public SoftReference(T r, ReferenceQueue <T> q)
     : base()
 {
     initReference(r, q);
 }
Ejemplo n.º 13
0
 public PhantomReference(T referent, ReferenceQueue <T> queue)
     : base()
 {
     initReference(referent, queue);
 }
Ejemplo n.º 14
0
 internal LocalSlot(ReferenceQueue <LocalSlot <T> > referenceQueue)
 {
     SlotWeakReference = new LocalSlotReference <T>(this, referenceQueue);
 }
Ejemplo n.º 15
0
 private WeakValue(WeakValueHashMap <K, V> _enclosing, K key, T value, ReferenceQueue
                   <T> queue) : base(value, queue)
 {
     this._enclosing = _enclosing;
     this.key        = key;
 }
 internal Ref(byte[] array, ReferenceQueue <byte[]> queue) : base(array, queue)
 {
     cost = array.Length;
 }
Ejemplo n.º 17
0
 public WeakValueHashMap()
 {
     references     = new Dictionary <K, WeakValueHashMap.WeakValue <V> >();
     referenceQueue = new ReferenceQueue <V>();
 }
Ejemplo n.º 18
0
 internal Entry(Object key, int hash, T value, ReferenceQueue <Object> queue, Entry <T> next) : base(key, queue)
 {
     this.Hash  = hash;
     this.Value = value;
     this.Next  = next;
 }
Ejemplo n.º 19
0
 public PhantomReference(T prm1, ReferenceQueue <global::System.Object> prm2)
 {
 }