title: If Java's garbage collector moves objects, what is Object.hashCode and System.identityHashCode?
body: <p>I've often heard that these methods (<code>Object.hashCode</code> and <code>System.identityHashCode</code>) return the address of the object, or something computed quickly from the address; but I'm also pretty sure the garbage collector moves and compacts objects.  Since the hash code cannot change, this presents a problem.  I know this is not something one needs to know for everyday work, but I'd like to understand the internals.   So, does anyone know how this is implemented in Java?  Or .NET, since they are probably similar.</p>