@ GuardedBy ( "evictionLock" ) boolean admit ( K candidateKey , K victimKey ) { int victimFreq = frequencySketch ( ) . frequency ( victimKey ) ; int candidateFreq = frequencySketch ( ) . frequency ( candidateKey ) ; if ( candidateFreq > victimFreq ) { return true ; } else if ( candidateFreq <= 5 ) { // The maximum frequency is 15 and halved to 7 after a reset to age the history. An attack // exploits that a hot candidate is rejected in favor of a hot victim. The threshold of a warm // candidate reduces the number of random acceptances to minimize the impact on the hit rate. return false ; } int random = ThreadLocalRandom . current ( ) . nextInt ( ) ; return ( ( random & 127 ) == 0 ) ; }
Determines if the candidate should be accepted into the main space as determined by its frequency relative to the victim . A small amount of randomness is used to protect against hash collision attacks where the victim s frequency is artificially raised so that no new entries are admitted .