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);
        }
        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);
        }
Exemple #3
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);
        }
Exemple #4
0
        public void Reset(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 && _cache[j].PageNumber == pageNumber)
                        {
                            _cache[j]        = new PageHandlePtrV3();
                            _fingerprints[j] = Invalid;
                        }
                    }

                    throw new InvalidOperationException("This cant happen");
                }
            }
        }
Exemple #5
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);
        }
Exemple #6
0
        public void Reset(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;
            }

            return;

            Found1 : i += 1; goto Found;
            Found2 : i += 2; goto Found;
            Found3 : i += 3;
Found:
            if (_cache[i].PageNumber == pageNumber)
            {
                _cache[i]        = new PageHandlePtrV3();
                _fingerprints[i] = Invalid;
            }
        }
        public void Reset(long pageNumber)
        {
            ushort fingerprint = GetFingerprint(pageNumber);

            for (int i = 0; i < _cacheSize; i++)
            {
                if (_fingerprints[i] == fingerprint)
                {
                    if (_cache[i].PageNumber == pageNumber)
                    {
                        _cache[i]        = new PageHandlePtrV3();
                        _fingerprints[i] = Invalid;
                    }

                    return;
                }
            }
        }
Exemple #8
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);
        }