Example #1
0
        /// <summary>
        /// Collect all freed page swapper ids, and pass them to the given callback, after which the freed ids will be
        /// eligible for reuse.
        /// This is done with careful synchronisation such that allocating and freeing of ids is allowed to mostly proceed
        /// concurrently.
        /// </summary>
        internal void Vacuum(System.Action <IntSet> evictAllLoadedPagesCallback)
        {
            // We do this complicated locking to avoid blocking allocate() and free() as much as possible, while still only
            // allow a single thread to do vacuum at a time, and at the same time have consistent locking around the
            // set of free ids.
            lock ( _vacuumLock )
            {
                // Collect currently free ids.
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.eclipse.collections.api.set.primitive.MutableIntSet freeIds = new org.eclipse.collections.impl.set.mutable.primitive.IntHashSet();
                MutableIntSet    freeIds         = new IntHashSet();
                SwapperMapping[] swapperMappings = this._swapperMappings;
                for (int id = 0; id < swapperMappings.Length; id++)
                {
                    SwapperMapping swapperMapping = swapperMappings[id];
                    if (swapperMapping == _tombstone)
                    {
                        freeIds.add(id);
                    }
                }

                // Evict all of them without holding up the lock on the free id set. This allows allocate() and free() to
                // proceed concurrently with our eviction. This is safe because we know that the ids we are evicting cannot
                // possibly be reused until we remove them from the free id set, which we won't do until after we've evicted
                // all of their loaded pages.
                evictAllLoadedPagesCallback(freeIds);

                // Finally, all of the pages that remained in memory with an unmapped swapper id have been evicted. We can
                // now safely allow those ids to be reused. Note, however, that free() might have been called while we were
                // doing this, so we can't just free.clear() the set; no, we have to explicitly remove only those specific
                // ids whose pages we evicted.
                lock (this)
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.eclipse.collections.api.iterator.IntIterator itr = freeIds.intIterator();
                    IntIterator itr = freeIds.intIterator();
                    while (itr.hasNext())
                    {
                        int freeId = itr.next();
                        swapperMappings[freeId] = null;
                    }
                    this._swapperMappings = swapperMappings;                              // Volatile store synchronizes-with loads in getters.
                }
                lock ( _free )
                {
                    _free.addAll(freeIds);
                }
            }
        }
Example #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void vacuumMustNotDustOffAnyIdsWhenNoneHaveBeenFreed()
        internal virtual void VacuumMustNotDustOffAnyIdsWhenNoneHaveBeenFreed()
        {
            PageSwapper swapper = new DummyPageSwapper("a", 42);

            for (int i = 0; i < 100; i++)
            {
                _set.allocate(swapper);
            }
            MutableIntSet vacuumedIds = new IntHashSet();

            _set.vacuum(vacuumedIds.addAll);
            if (!vacuumedIds.Empty)
            {
                throw new AssertionError("Vacuum found id " + vacuumedIds + " when it should have found nothing");
            }
        }
Example #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void freedAllocationsMustBecomeAvailableAfterVacuum()
        internal virtual void FreedAllocationsMustBecomeAvailableAfterVacuum()
        {
            MutableIntSet allocated = new IntHashSet();
            MutableIntSet freed     = new IntHashSet();
            MutableIntSet vacuumed  = new IntHashSet();
            MutableIntSet reused    = new IntHashSet();
            PageSwapper   swapper   = new DummyPageSwapper("a", 42);

            AllocateAndAddTenThousand(allocated, swapper);

            allocated.forEach(id =>
            {
                _set.free(id);
                freed.add(id);
            });
            _set.vacuum(vacuumed.addAll);

            AllocateAndAddTenThousand(reused, swapper);

            assertThat(allocated, @is(equalTo(freed)));
            assertThat(allocated, @is(equalTo(vacuumed)));
            assertThat(allocated, @is(equalTo(reused)));
        }