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
Fishy implementation of WeakHashSet in a compiler #7150
Comments
Imported From: https://issues.scala-lang.org/browse/SI-7150?orig=1 |
@dragos said: |
@gkossakowski said (edited on Mar 4, 2013 8:00:45 PM UTC): |
@mt2309 said: |
@gkossakowski said: |
@adriaanm said: |
@retronym said: 2.11.0-M4 ad63f3630705bd192d9c983399c572b655b3612b |
It turns out that we have an implementation of WeakHashSet in a compiler:
https://github.com/scala/scala/blob/master/src/reflect/scala/reflect/internal/util/WeakHashSet.scala
However, it's semantics are very fishy. I noticed two problems:
WeakReferenceWithEquals
cacheshashCode
. Now imagine that two WeakReferenceWithEquals point at different objects so they store differenthashCode
s. Later on the underlaying objects get GCed so nowequals
return true (becausenull == null
) buthashCode
would be still different. That breaks the basic contract betweenequals
andhashCode
.ReferenceQueue
soWeakReferenceWithEquals
instances themselves are never GC'ed and they block slots in hash table. Check implementation of Java'sWeakHashmap
for inspiration how pruning of slots should be done.The text was updated successfully, but these errors were encountered: