-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bug in semispace cache that allowed gen1 to contain values in evi… #1162
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,12 +16,12 @@ sealed abstract case class SemispaceCache[K, V](gen0: Map[K, V], gen1: Map[K, V] | |
assert(gen0.size <= max) | ||
assert(gen1.size <= max) | ||
|
||
def insert(k: K, v: V): SemispaceCache[K, V] = | ||
if (max == 0) SemispaceCache(gen0, gen1, max, evicted + v) // immediately evict | ||
else if (gen0.size < max) SemispaceCache(gen0 + (k -> v), gen1, max, evicted - v) // room in gen0, done! | ||
else SemispaceCache(Map(k -> v), gen0, max, evicted ++ gen1.values - v)// no room in gen0, slide it down | ||
def insert(k: K, v: V): SemispaceCache[K, V] = | ||
if (max == 0) SemispaceCache(gen0, gen1, max, evicted + v) // immediately evict | ||
else if (gen0.size < max) SemispaceCache(gen0 + (k -> v), gen1 - k, max, evicted - v) // room in gen0, remove from gen1, done! | ||
else SemispaceCache(Map(k -> v), gen0, max, evicted ++ gen1.values - v) // no room in gen0, slide it down | ||
|
||
def lookup(k: K): Option[(SemispaceCache[K, V], V)] = | ||
def lookup(k: K): Option[(SemispaceCache[K, V], V)] = | ||
gen0.get(k).tupleLeft(this) orElse // key is in gen0, done! | ||
gen1.get(k).map(v => (insert(k, v), v)) // key is in gen1, copy to gen0 | ||
|
||
|
@@ -40,8 +40,14 @@ sealed abstract case class SemispaceCache[K, V](gen0: Map[K, V], gen1: Map[K, V] | |
|
||
object SemispaceCache { | ||
|
||
private def apply[K, V](gen0: Map[K, V], gen1: Map[K, V], max: Int, evicted: EvictionSet[V]): SemispaceCache[K, V] = | ||
new SemispaceCache[K, V](gen0, gen1, max, evicted) {} | ||
private def apply[K, V](gen0: Map[K, V], gen1: Map[K, V], max: Int, evicted: EvictionSet[V]): SemispaceCache[K, V] = { | ||
val r = new SemispaceCache[K, V](gen0, gen1, max, evicted) {} | ||
val gen0Intersection: Set[V] = (gen0.values.toSet intersect evicted.toList.toSet) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drop these assertions now? I worry a bit about all these set creations/intersections on each constructor? |
||
val gen1Intersection: Set[V] = (gen1.values.toSet intersect evicted.toList.toSet) | ||
assert(gen0Intersection.isEmpty, s"gen0 has overlapping values in evicted: ${gen0Intersection}") | ||
assert(gen1Intersection.isEmpty, s"gen1 has overlapping values in evicted: ${gen1Intersection}") | ||
r | ||
} | ||
|
||
def empty[K, V](max: Int, trackEviction: Boolean): SemispaceCache[K, V] = | ||
SemispaceCache[K, V](Map.empty, Map.empty, max max 0, if (trackEviction) EvictionSet.empty else new EvictionSet.ZeroEvictionSet) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
gen0
orgen1
contains(k, v0)
such thatv0 != v
, we should addv0
to evicted list. Likewise below.