Ejemplo n.º 1
0
        public MyPage GetReadOnlyPage(long pageNumber)
        {
            ushort fingerprint = GetFingerprint(pageNumber);

            int i;

            for (i = 0; i < _cacheSize; i++)
            {
                // This is used to force the JIT to layout the code as if unlikely() compiler directive exists.
                if (_fingerprints[i] == fingerprint)
                {
                    goto Found;
                }
            }

            // If we got here, there was a cache miss
            _current                = (_current + 1) % _cacheSize;
            _cache[_current]        = new PageHandlePtrV3(pageNumber, LowLevelTransactionStub.GetPage(pageNumber), false);
            _fingerprints[_current] = fingerprint;
            return(_cache[_current].Value);

Found:
            // This is not the common case on the loop and we are returning anyways. It doesnt matter the jump is far.
            if (_cache[i].PageNumber == pageNumber)
            {
                return(_cache[i].Value);
            }

            _cache[i] = new PageHandlePtrV3(pageNumber, LowLevelTransactionStub.GetPage(pageNumber), false);
            return(_cache[i].Value);
        }
Ejemplo n.º 2
0
        public MyPage GetWritablePage(long pageNumber)
        {
            var lookup = new Vector <long>(pageNumber);

            for (int i = 0; i < _cacheSize; i += Vector <long> .Count)
            {
                var  pageNumbers = new Vector <long>(_pages, i);
                var  comparison  = Vector.Equals(pageNumbers, lookup);
                var  result      = Vector.ConditionalSelect(comparison, Vector <long> .One, Vector <long> .Zero);
                long index       = Vector.Dot(_indexes, result);
                if (index != 0)
                {
                    int j = i + (int)index - 1;
                    if (!_writeable[j])
                    {
                        _cache[j]     = LowLevelTransactionStub.ModifyPage(pageNumber);
                        _writeable[j] = true;
                    }
                    return(_cache[j]);
                }
            }

            // If we got here, there was a cache miss
            _current             = (_current + 1) % _cacheSize;
            _cache[_current]     = LowLevelTransactionStub.ModifyPage(pageNumber);
            _pages[_current]     = pageNumber;
            _writeable[_current] = true;

            return(_cache[_current]);
        }
Ejemplo n.º 3
0
        public MyPage GetWritablePage(long pageNumber)
        {
            ushort fingerprint = GetFingerprint(pageNumber);

            int i;

            for (i = 0; i < _cacheSize; i++)
            {
                // This is used to force the JIT to layout the code as if unlikely() compiler directive exists.
                if (_fingerprints[i] == fingerprint)
                {
                    goto Found;
                }
            }

            // If we got here, there was a cache miss
            _current                = (_current + 1) % _cacheSize;
            _cache[_current]        = new PageHandlePtrV3(pageNumber, LowLevelTransactionStub.ModifyPage(pageNumber), true);
            _fingerprints[_current] = fingerprint;

            return(_cache[_current].Value);

Found:

            if (_cache[i].PageNumber == pageNumber && _cache[i].IsWritable)
            {
                return(_cache[i].Value);
            }

            _cache[i] = new PageHandlePtrV3(pageNumber, LowLevelTransactionStub.ModifyPage(pageNumber), true);
            return(_cache[i].Value);
        }
Ejemplo n.º 4
0
        public MyPage GetWritablePage(long pageNumber)
        {
            int position = _current;

            int itemsLeft = _cache.Length;

            while (itemsLeft > 0)
            {
                int i = position % _cache.Length;

                // If the page number is equal to the page number we are looking for (therefore it's valid)
                // Will not fail at PageNumber=0 because the accesor will handle that.
                if (_cache[i].PageNumber != pageNumber)
                {
                    // we continue.
                    itemsLeft--;
                    position++;

                    continue;
                }

                if (!_cache[i].IsWritable)
                {
                    _cache[i] = new PageHandlePtrV1(LowLevelTransactionStub.ModifyPage(pageNumber), true);
                }

                return(_cache[i].Value);
            }

            _current         = (_current + 1) % _cache.Length;
            _cache[_current] = new PageHandlePtrV1(LowLevelTransactionStub.ModifyPage(pageNumber), true);
            return(_cache[_current].Value);
        }
Ejemplo n.º 5
0
        public MyPage GetReadOnlyPage(long pageNumber)
        {
            ushort sfingerprint = (ushort)pageNumber;
            int    fingerprint  = sfingerprint;

            int i    = 0;
            int size = _cacheSize;

            while (i < size)
            {
                int f1 = _fingerprints[i + 0];
                int f2 = _fingerprints[i + 1];
                int f3 = _fingerprints[i + 2];
                int f4 = _fingerprints[i + 3];

                // This is used to force the JIT to layout the code as if unlikely() compiler directive existed.
                if (f1 == fingerprint)
                {
                    goto Found;
                }

                if (f2 == fingerprint)
                {
                    goto Found1;
                }

                if (f3 == fingerprint)
                {
                    goto Found2;
                }

                if (f4 == fingerprint)
                {
                    goto Found3;
                }

                i += 4;
            }


            // If we got here, there was a cache miss
            _current                = (_current + 1) % _cacheSize;
            _cache[_current]        = new PageHandlePtrV3(pageNumber, LowLevelTransactionStub.GetPage(pageNumber), false);
            _fingerprints[_current] = sfingerprint;

            return(_cache[_current].Value);

            Found1 : i += 1; goto Found;
            Found2 : i += 2; goto Found;
            Found3 : i += 3;
Found:
            // This is not the common case on the loop and we are returning anyways. It doesnt matter the jump is far.
            if (_cache[i].PageNumber == pageNumber)
            {
                return(_cache[i].Value);
            }

            _cache[i] = new PageHandlePtrV3(pageNumber, LowLevelTransactionStub.GetPage(pageNumber), false);
            return(_cache[i].Value);
        }
Ejemplo n.º 6
0
        public MyPage GetWritablePage(long pageNumber)
        {
            ushort sfingerprint = (ushort)pageNumber;
            int    fingerprint  = sfingerprint;

            int i    = 0;
            int size = _cacheSize;

            while (i < size)
            {
                int f1 = _fingerprints[i + 0];
                int f2 = _fingerprints[i + 1];
                int f3 = _fingerprints[i + 2];
                int f4 = _fingerprints[i + 3];

                // This is used to force the JIT to layout the code as if unlikely() compiler directive existed.
                if (f1 == fingerprint)
                {
                    goto Found;
                }

                if (f2 == fingerprint)
                {
                    goto Found1;
                }

                if (f3 == fingerprint)
                {
                    goto Found2;
                }

                if (f4 == fingerprint)
                {
                    goto Found3;
                }

                i += 4;
            }


            // If we got here, there was a cache miss
            _current                = (_current + 1) % _cacheSize;
            _cache[_current]        = new PageHandlePtrV3(pageNumber, LowLevelTransactionStub.ModifyPage(pageNumber), true);
            _fingerprints[_current] = sfingerprint;

            return(_cache[_current].Value);

            Found1 : i += 1; goto Found;
            Found2 : i += 2; goto Found;
            Found3 : i += 3;
Found:
            if (_cache[i].PageNumber == pageNumber && _cache[i].IsWritable)
            {
                return(_cache[i].Value);
            }

            _cache[i] = new PageHandlePtrV3(pageNumber, LowLevelTransactionStub.ModifyPage(pageNumber), true);
            return(_cache[i].Value);
        }
Ejemplo n.º 7
0
        public MyPage GetReadOnlyPage(long pageNumber)
        {
            int fingerprint = (int)pageNumber;
            var lookup      = new Vector <int>(fingerprint);
            int count       = Vector <short> .Count;

            for (int i = 0; i < _cacheSize; i += count)
            {
                var pageNumbers = new Vector <int>(_fingerprints, i);

                if (Vector.EqualsAny(pageNumbers, lookup))
                {
                    for (int index = 0; index < count; index++)
                    {
                        int j = i + index;
                        if (_fingerprints[j] == fingerprint)
                        {
                            if (_cache[j].PageNumber == pageNumber)
                            {
                                return(_cache[j].Value);
                            }

                            _cache[j] = new PageHandlePtrV3(pageNumber, LowLevelTransactionStub.GetPage(pageNumber), false);
                            return(_cache[j].Value);
                        }
                    }

                    throw new InvalidOperationException("This cant happen");
                }
            }

            // If we got here, there was a cache miss
            _current                = (_current + 1) % _cacheSize;
            _cache[_current]        = new PageHandlePtrV3(pageNumber, LowLevelTransactionStub.GetPage(pageNumber), false);
            _fingerprints[_current] = fingerprint;
            return(_cache[_current].Value);
        }