Lines Matching defs:segment
42 import com.google.common.cache.LocalCache.Segment;
211 // share capacity over each segment, then round up to nearest power of two
419 Segment<Object, Object> segment = map.segments[0];
427 ReferenceEntry<Object, Object> entry = segment.getEntry(key, hash);
432 checkEvictionQueues(map, segment, readOrder, writeOrder);
434 assertTrue(segment.recencyQueue.isEmpty());
446 assertTrue(segment.recencyQueue.size() <= DRAIN_THRESHOLD);
449 int undrainedIndex = reads.size() - segment.recencyQueue.size();
450 checkAndDrainRecencyQueue(map, segment
453 checkEvictionQueues(map, segment, readOrder, writeOrder);
475 Segment<Object, Object> segment = map.segments[0];
476 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
488 segment.count++;
492 assertEquals(1, segment.count);
497 assertEquals(2, segment.count);
504 Segment<Object, Object> segment = map.segments[0];
505 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
517 segment.count++;
521 assertEquals(1, segment.count);
526 assertEquals(1, segment.count);
565 Segment<Object, Object> segment = map.segments[0];
566 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
603 ReferenceEntry<Object, Object> entry = segment.getEntry(one, hash);
604 ReferenceEntry<Object, Object> newEntry = segment.copyEntry(entry, null);
704 Segment<Object, Object> segment = map.segments[0];
708 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
717 assertNull(segment.refresh(key, hash, identityLoader()));
798 Segment<Object, Object> segment = map.segments[0];
810 ReferenceEntry<Object, Object> entry = segment.getEntry(one, hash);
876 // Segment core tests
965 Segment<Object, Object> segment = map.segments[0];
971 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
978 assertNull(segment.get(key, hash));
982 assertNull(segment.get(key, hash));
983 assertFalse(segment.containsKey(key, hash));
984 assertFalse(segment.containsValue(value));
987 segment.count++;
988 assertSame(value, segment.get(key, hash));
989 assertTrue(segment.containsKey(key, hash));
990 assertTrue(segment.containsValue(value));
992 assertNull(segment.get(new Object(), hash));
1001 assertSame(value, segment.get(key, hash));
1002 assertTrue(segment.containsKey(key, hash));
1003 assertTrue(segment.containsValue(value));
1004 assertFalse(segment.containsValue(nullValue));
1012 assertSame(value, segment.get(key, hash));
1013 assertTrue(segment.containsKey(key, hash));
1014 assertTrue(segment.containsValue(value));
1015 assertTrue(segment.containsValue(dummyValue));
1024 assertSame(dummyValue, segment.get(key, hash));
1025 assertTrue(segment.containsKey(key, hash));
1026 assertTrue(segment.containsValue(value));
1027 assertTrue(segment.containsValue(dummyValue));
1031 assertNull(segment.get(key, hash));
1032 assertFalse(segment.containsKey(key, hash));
1033 assertTrue(segment.containsValue(value));
1034 assertFalse(segment.containsValue(dummyValue));
1040 Segment<Object, Object> segment = map.segments[0];
1047 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
1055 assertFalse(segment.replace(key, hash, oldValue, newValue));
1056 assertEquals(0, segment.count);
1060 segment.count++;
1061 assertEquals(1, segment.count);
1062 assertSame(oldValue, segment.get(key, hash));
1063 assertTrue(segment.replace(key, hash, oldValue, newValue));
1064 assertEquals(1, segment.count);
1065 assertSame(newValue, segment.get(key, hash));
1068 assertFalse(segment.replace(key, hash, oldValue, newValue));
1069 assertEquals(1, segment.count);
1070 assertSame(newValue, segment.get(key, hash));
1074 assertSame(oldValue, segment.get(key, hash));
1076 assertFalse(segment.replace(key, hash, oldValue, newValue));
1077 assertEquals(0, segment.count);
1078 assertNull(segment.get(key, hash));
1084 Segment<Object, Object> segment = map.segments[0];
1091 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
1099 assertNull(segment.replace(key, hash, newValue));
1100 assertEquals(0, segment.count);
1104 segment.count++;
1105 assertEquals(1, segment.count);
1106 assertSame(oldValue, segment.get(key, hash));
1107 assertSame(oldValue, segment.replace(key, hash, newValue));
1108 assertEquals(1, segment.count);
1109 assertSame(newValue, segment.get(key, hash));
1113 assertSame(oldValue, segment.get(key, hash));
1115 assertNull(segment.replace(key, hash, newValue));
1116 assertEquals(0, segment.count);
1117 assertNull(segment.get(key, hash));
1123 Segment<Object, Object> segment = map.segments[0];
1132 assertEquals(0, segment.count);
1133 assertNull(segment.put(key, hash, oldValue, false));
1134 assertEquals(1, segment.count);
1137 assertSame(oldValue, segment.put(key, hash, newValue, false));
1138 assertEquals(1, segment.count);
1139 assertSame(newValue, segment.get(key, hash));
1142 ReferenceEntry<Object, Object> entry = segment.getEntry(key, hash);
1145 assertSame(oldValue, segment.get(key, hash));
1147 assertNull(segment.put(key, hash, newValue, false));
1148 assertEquals(1, segment.count);
1149 assertSame(newValue, segment.get(key, hash));
1155 Segment<Object, Object> segment = map.segments[0];
1164 assertEquals(0, segment.count);
1165 assertNull(segment.put(key, hash, oldValue, true));
1166 assertEquals(1, segment.count);
1169 assertSame(oldValue, segment.put(key, hash, newValue, true));
1170 assertEquals(1, segment.count);
1171 assertSame(oldValue, segment.get(key, hash));
1174 ReferenceEntry<Object, Object> entry = segment.getEntry(key, hash);
1177 assertSame(oldValue, segment.get(key, hash));
1179 assertNull(segment.put(key, hash, newValue, true));
1180 assertEquals(1, segment.count);
1181 assertSame(newValue, segment.get(key, hash));
1187 Segment<Object, Object> segment = map.segments[0];
1188 assertEquals(1, segment.table.length());
1195 assertNull(segment.put(key, hash, value, false));
1196 assertTrue(segment.table.length() > i);
1227 Segment<Object, Object> segment = map.segments[0];
1231 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
1241 assertEquals(0, segment.count);
1242 assertNull(segment.get(key, hash));
1243 assertTrue(segment.storeLoadedValue(key, hash, valueRef, value));
1244 assertSame(value, segment.get(key, hash));
1245 assertEquals(1, segment.count);
1250 assertFalse(segment.storeLoadedValue(key, hash, valueRef, value2));
1251 assertEquals(1, segment.count);
1252 assertSame(value, segment.get(key, hash));
1262 assertEquals(0, segment.count);
1264 assertTrue(segment.storeLoadedValue(key, hash, valueRef, value3));
1265 assertSame(value3, segment.get(key, hash));
1266 assertEquals(1, segment.count);
1275 assertSame(value3, segment.get(key, hash));
1276 assertEquals(1, segment.count);
1277 assertTrue(segment.storeLoadedValue(key, hash, valueRef, value4));
1278 assertSame(value4, segment.get(key, hash));
1279 assertEquals(1, segment.count);
1288 assertSame(value3, segment.get(key, hash));
1289 assertEquals(1, segment.count);
1291 assertTrue(segment.storeLoadedValue(key, hash, valueRef, value4));
1292 assertSame(value4, segment.get(key, hash));
1293 assertEquals(1, segment.count);
1302 Segment<Object, Object> segment = map.segments[0];
1307 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
1315 assertEquals(0, segment.count);
1316 assertNull(segment.remove(key, hash));
1317 assertEquals(0, segment.count);
1321 segment.count++;
1322 assertEquals(1, segment.count);
1323 assertSame(oldValue, segment.get(key, hash));
1324 assertSame(oldValue, segment.remove(key, hash));
1325 assertEquals(0, segment.count);
1326 assertNull(segment.get(key, hash));
1330 segment.count++;
1331 assertEquals(1, segment.count);
1332 assertSame(oldValue, segment.get(key, hash));
1334 assertNull(segment.remove(key, hash));
1335 assertEquals(0, segment.count);
1336 assertNull(segment.get(key, hash));
1341 Segment<Object, Object> segment = map.segments[0];
1347 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
1355 assertEquals(0, segment.count);
1356 assertNull(segment.remove(key, hash));
1357 assertEquals(0, segment.count);
1361 segment.count++;
1362 assertEquals(1, segment.count);
1363 assertSame(oldValue, segment.get(key, hash));
1364 assertTrue(segment.remove(key, hash, oldValue));
1365 assertEquals(0, segment.count);
1366 assertNull(segment.get(key, hash));
1370 segment.count++;
1371 assertEquals(1, segment.count);
1372 assertSame(oldValue, segment.get(key, hash));
1373 assertFalse(segment.remove(key, hash, newValue));
1374 assertEquals(1, segment.count);
1375 assertSame(oldValue, segment.get(key, hash));
1378 assertSame(oldValue, segment.get(key, hash));
1380 assertFalse(segment.remove(key, hash, oldValue));
1381 assertEquals(0, segment.count);
1382 assertNull(segment.get(key, hash));
1388 Segment<Object, Object> segment = map.segments[0];
1389 assertEquals(1, segment.table.length());
1403 segment.table.set(0, entry);
1404 segment.count = originalCount;
1411 segment.expand();
1413 assertEquals(i, segment.table.length());
1415 assertEquals(originalCount, segment.count);
1428 Segment<Object, Object> segment = map.segments[0];
1429 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
1449 assertFalse(segment.reclaimKey(entryOne, hashOne));
1452 assertFalse(segment.reclaimKey(entryTwo, hashTwo));
1455 assertFalse(segment.reclaimKey(entryThree, hashThree));
1460 segment.count = 1;
1461 assertTrue(segment.reclaimKey(entryOne, hashOne));
1466 assertFalse(segment.accessQueue.contains(entryOne));
1467 assertFalse(segment.writeQueue.contains(entryOne));
1468 assertEquals(0, segment.count);
1474 Segment<Object, Object> segment = map.segments[0];
1492 assertNull(segment.removeEntryFromChain(entryOne, entryOne));
1495 assertSame(entryOne, segment.removeEntryFromChain(entryTwo, entryTwo));
1498 ReferenceEntry<Object, Object> newFirst = segment.removeEntryFromChain(entryThree, entryTwo);
1505 newFirst = segment.removeEntryFromChain(entryThree, entryOne);
1519 Segment<Object, Object> segment = map.segments[0];
1520 assertEquals(1, segment.table.length());
1538 segment.table.set(0, entry);
1539 segment.count = originalCount;
1541 assertEquals(1, segment.table.length());
1549 segment.expand();
1551 assertEquals(i, segment.table.length());
1554 assertTrue(segment.count >= liveCount);
1555 assertTrue(segment.count <= originalCount);
1562 for (Segment<K, V> segment : map.segments) {
1563 AtomicReferenceArray<ReferenceEntry<K, V>> table = segment.table;
1581 Segment<Object, Object> segment = map.segments[0];
1582 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
1589 segment.recordWrite(entry, 1, map.ticker.read());
1590 segment.table.set(0, entry);
1591 segment.readCount.incrementAndGet();
1592 segment.count = 1;
1593 segment.totalWeight = 1;
1596 assertSame(entry, segment.accessQueue.peek());
1597 assertSame(entry, segment.writeQueue.peek());
1599 segment.clear();
1601 assertTrue(segment.accessQueue.isEmpty());
1602 assertTrue(segment.writeQueue.isEmpty());
1603 assertEquals(0, segment.readCount.get());
1604 assertEquals(0, segment.count);
1605 assertEquals(0, segment.totalWeight);
1616 Segment<Object, Object> segment = map.segments[0];
1617 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
1624 segment.recordWrite(entry, 1, map.ticker.read());
1625 segment.table.set(0, entry);
1626 segment.readCount.incrementAndGet();
1627 segment.count = 1;
1628 segment.totalWeight = 1;
1631 assertSame(entry, segment.accessQueue.peek());
1632 assertSame(entry, segment.writeQueue.peek());
1634 segment.clear();
1636 assertTrue(segment.accessQueue.isEmpty());
1637 assertTrue(segment.writeQueue.isEmpty());
1638 assertEquals(0, segment.readCount.get());
1639 assertEquals(0, segment.count);
1640 assertEquals(0, segment.totalWeight);
1651 Segment<Object, Object> segment = map.segments[0];
1652 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
1661 assertFalse(segment.removeEntry(entry, hash, RemovalCause.COLLECTED));
1664 segment.recordWrite(entry, 1, map.ticker.read());
1666 segment.count = 1;
1667 assertTrue(segment.removeEntry(entry, hash, RemovalCause.COLLECTED));
1670 assertFalse(segment.accessQueue.contains(entry));
1671 assertFalse(segment.writeQueue.contains(entry));
1672 assertEquals(0, segment.count);
1685 Segment<Object, Object> segment = map.segments[0];
1686 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
1697 assertFalse(segment.reclaimValue(key, hash, valueRef));
1700 segment.recordWrite(entry, 1, map.ticker.read());
1702 segment.count = 1;
1703 assertTrue(segment.reclaimValue(key, hash, valueRef));
1708 assertFalse(segment.accessQueue.contains(entry));
1709 assertFalse(segment.writeQueue.contains(entry));
1710 assertEquals(0, segment.count);
1717 assertFalse(segment.reclaimValue(key, hash, valueRef));
1719 assertTrue(segment.reclaimValue(key, hash, otherValueRef));
1732 Segment<Object, Object> segment = map.segments[0];
1733 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
1743 assertFalse(segment.removeLoadingValue(key, hash, valueRef));
1748 assertTrue(segment.removeLoadingValue(key, hash, valueRef));
1751 assertEquals(0, segment.count);
1760 segment.count = 1;
1761 assertTrue(segment.removeLoadingValue(key, hash, valueRef));
1763 assertSame(value, segment.get(key, hash));
1769 assertFalse(segment.removeLoadingValue(key, hash, valueRef));
1771 assertTrue(segment.removeLoadingValue(key, hash, valueRef));
1781 // Segment eviction tests
1786 Segment<Object, Object> segment = map.segments[0];
1788 if (segment.recencyQueue != DISCARDING_QUEUE) {
1795 assertTrue(segment.recencyQueue.isEmpty());
1800 assertFalse(segment.recencyQueue.isEmpty());
1803 assertTrue(segment.recencyQueue.isEmpty());
1811 Segment<Object, Object> segment = map.segments[0];
1813 if (segment.recencyQueue != DISCARDING_QUEUE) {
1820 assertTrue(segment.recencyQueue.isEmpty());
1825 assertFalse(segment.recencyQueue.isEmpty());
1829 assertTrue(segment.recencyQueue.size() <= DRAIN_THRESHOLD);
1837 assertTrue(segment.recencyQueue.isEmpty());
1842 assertFalse(segment.recencyQueue.isEmpty());
1846 assertTrue(segment.recencyQueue.size() <= DRAIN_THRESHOLD);
1855 Segment<Object, Object> segment = map.segments[0];
1865 segment.recordWrite(entry, 1, map.ticker.read());
1870 checkEvictionQueues(map, segment, readOrder, writeOrder);
1880 segment.recordRead(entry, map.ticker.read());
1885 checkAndDrainRecencyQueue(map, segment, reads);
1888 checkEvictionQueues(map, segment, readOrder, writeOrder);
1896 Segment<Object, Object> segment = map.segments[0];
1905 ReferenceEntry<Object, Object> entry = segment.getEntry(key, hash);
1910 checkEvictionQueues(map, segment, readOrder, writeOrder);
1912 assertTrue(segment.recencyQueue.isEmpty());
1924 assertTrue(segment.recencyQueue.size() <= DRAIN_THRESHOLD);
1927 int undrainedIndex = reads.size() - segment.recencyQueue.size();
1928 checkAndDrainRecencyQueue(map, segment, reads.subList(undrainedIndex, reads.size()));
1931 checkEvictionQueues(map, segment, readOrder, writeOrder);
1939 Segment<Object, Object> segment = map.segments[0];
1948 segment.recordWrite(entry, 1, map.ticker.read());
1952 checkEvictionQueues(map, segment, writeOrder, writeOrder);
1962 segment.recordWrite(entry, 1, map.ticker.read());
1969 checkEvictionQueues(map, segment, writeOrder, writeOrder);
1975 Segment<K, V> segment, List<ReferenceEntry<K, V>> reads) {
1977 assertSameEntries(reads, ImmutableList.copyOf(segment.recencyQueue));
1979 segment.drainRecencyQueue();
1983 Segment<K, V> segment, List<ReferenceEntry<K, V>> readOrder,
1986 assertSameEntries(readOrder, ImmutableList.copyOf(segment.accessQueue));
1989 assertSameEntries(writeOrder, ImmutableList.copyOf(segment.writeQueue));
2010 for (Segment<K, V> segment : map.segments) {
2013 for (ReferenceEntry<K, V> e : segment.recencyQueue) {
2024 for (ReferenceEntry<K, V> e : segment.accessQueue) {
2029 for (ReferenceEntry<K, V> e : segment.writeQueue) {
2043 Segment<Object, Object> segment = map.segments[0];
2051 segment.writeQueue.add(entry);
2053 assertSame(entry, segment.writeQueue.peek());
2054 assertEquals(1, segment.writeQueue.size());
2056 segment.recordRead(entry, ticker.read());
2057 segment.expireEntries(ticker.read());
2059 assertSame(entry, segment.writeQueue.peek());
2060 assertEquals(1, segment.writeQueue.size());
2063 segment.recordRead(entry, ticker.read());
2064 segment.expireEntries(ticker.read());
2066 assertSame(entry, segment.writeQueue.peek());
2067 assertEquals(1, segment.writeQueue.size());
2071 segment.expireEntries(ticker.read());
2073 assertTrue(segment.writeQueue.isEmpty());
2082 Segment<Object, Object> segment = map.segments[0];
2090 segment.accessQueue.add(entry);
2092 assertSame(entry, segment.accessQueue.peek());
2093 assertEquals(1, segment.accessQueue.size());
2095 segment.recordRead(entry, ticker.read());
2096 segment.expireEntries(ticker.read());
2098 assertSame(entry, segment.accessQueue.peek());
2099 assertEquals(1, segment.accessQueue.size());
2102 segment.recordRead(entry, ticker.read());
2103 segment.expireEntries(ticker.read());
2105 assertSame(entry, segment.accessQueue.peek());
2106 assertEquals(1, segment.accessQueue.size());
2109 segment.recordRead(entry, ticker.read());
2110 segment.expireEntries(ticker.read());
2112 assertSame(entry, segment.accessQueue.peek());
2113 assertEquals(1, segment.accessQueue.size());
2116 segment.expireEntries(ticker.read());
2118 assertSame(entry, segment.accessQueue.peek());
2119 assertEquals(1, segment.accessQueue.size());
2124 segment.expireEntries(ticker.read());
2127 assertTrue(segment.accessQueue.isEmpty());
2134 Segment<Object, Object> segment = map.segments[0];
2143 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
2150 segment.recordWrite(entry, 1, map.ticker.read());
2154 segment.count = originalCount;
2155 segment.totalWeight = originalCount;
2164 segment.evictEntries();
2176 Segment<Object, Object> segment = map.segments[0];
2185 ReferenceEntry<Object, Object> entry = segment.getEntry(keyOne, hashOne);
2196 assertNull(segment.keyReferenceQueue.poll());
2206 Segment<Object, Object> segment = map.segments[0];
2215 ReferenceEntry<Object, Object> entry = segment.getEntry(keyOne, hashOne);
2227 assertNull(segment.valueReferenceQueue.poll());
2237 Segment<Object, Object> segment = map.segments[0];
2245 ReferenceEntry<Object, Object> entry = segment.getEntry(keyOne, hashOne);
2258 assertNull(segment.keyReferenceQueue.poll());
2268 Segment<Object, Object> segment = map.segments[0];
2276 ReferenceEntry<Object, Object> entry = segment.getEntry(keyOne, hashOne);
2290 assertNull(segment.valueReferenceQueue.poll());