/** Promote the node from probation to protected on an access. */ @GuardedBy("evictionLock") void reorderProbation(Node<K, V> node) { if (!accessOrderProbationDeque().contains(node)) { // Ignore stale accesses for an entry that is no longer present return; } else if (node.getPolicyWeight() > mainProtectedMaximum()) { return; } long mainProtectedWeightedSize = mainProtectedWeightedSize() + node.getPolicyWeight(); accessOrderProbationDeque().remove(node); accessOrderProtectedDeque().add(node); node.makeMainProtected(); long mainProtectedMaximum = mainProtectedMaximum(); while (mainProtectedWeightedSize > mainProtectedMaximum) { Node<K, V> demoted = accessOrderProtectedDeque().pollFirst(); if (demoted == null) { break; } demoted.makeMainProbation(); accessOrderProbationDeque().add(demoted); mainProtectedWeightedSize -= demoted.getPolicyWeight(); } lazySetMainProtectedWeightedSize(mainProtectedWeightedSize); }
/** * Evicts entries from the eden space into the main space while the eden size exceeds a maximum. * * @return the number of candidate entries evicted from the eden space */ @GuardedBy("evictionLock") int evictFromEden() { int candidates = 0; Node<K, V> node = accessOrderEdenDeque().peek(); while (edenWeightedSize() > edenMaximum()) { // The pending operations will adjust the size to reflect the correct weight if (node == null) { break; } Node<K, V> next = node.getNextInAccessOrder(); if (node.getWeight() != 0) { node.makeMainProbation(); accessOrderEdenDeque().remove(node); accessOrderProbationDeque().add(node); candidates++; lazySetEdenWeightedSize(edenWeightedSize() - node.getPolicyWeight()); } node = next; } return candidates; }
if ((victim != null) && (victim.getPolicyWeight() == 0)) { victim = victim.getNextInAccessOrder(); continue; } else if ((candidate != null) && (candidate.getPolicyWeight() == 0)) { candidate = candidate.getPreviousInAccessOrder(); candidates--; if (candidate.getPolicyWeight() > maximum()) { candidates--; Node<K, V> evict = candidate;
/** Promote the node from probation to protected on an access. */ @GuardedBy("evictionLock") void reorderProbation(Node<K, V> node) { if (!accessOrderProbationDeque().contains(node)) { // Ignore stale accesses for an entry that is no longer present return; } else if (node.getPolicyWeight() > mainProtectedMaximum()) { return; } long mainProtectedWeightedSize = mainProtectedWeightedSize() + node.getPolicyWeight(); accessOrderProbationDeque().remove(node); accessOrderProtectedDeque().add(node); node.makeMainProtected(); long mainProtectedMaximum = mainProtectedMaximum(); while (mainProtectedWeightedSize > mainProtectedMaximum) { Node<K, V> demoted = accessOrderProtectedDeque().pollFirst(); if (demoted == null) { break; } demoted.makeMainProbation(); accessOrderProbationDeque().add(demoted); mainProtectedWeightedSize -= demoted.getPolicyWeight(); } lazySetMainProtectedWeightedSize(mainProtectedWeightedSize); }
/** * Evicts entries from the eden space into the main space while the eden size exceeds a maximum. * * @return the number of candidate entries evicted from the eden space */ @GuardedBy("evictionLock") int evictFromEden() { int candidates = 0; Node<K, V> node = accessOrderEdenDeque().peek(); while (edenWeightedSize() > edenMaximum()) { // The pending operations will adjust the size to reflect the correct weight if (node == null) { break; } Node<K, V> next = node.getNextInAccessOrder(); if (node.getWeight() != 0) { node.makeMainProbation(); accessOrderEdenDeque().remove(node); accessOrderProbationDeque().add(node); candidates++; lazySetEdenWeightedSize(edenWeightedSize() - node.getPolicyWeight()); } node = next; } return candidates; }
if ((victim != null) && (victim.getPolicyWeight() == 0)) { victim = victim.getNextInAccessOrder(); continue; } else if ((candidate != null) && (candidate.getPolicyWeight() == 0)) { candidate = candidate.getPreviousInAccessOrder(); candidates--; if (candidate.getPolicyWeight() > maximum()) { candidates--; Node<K, V> evict = candidate;