Re: Non-Deterministic / Unpredictable Behavior (Again) [SOLVED]

Attila Szegedi <[email protected]> Sat, 12 Apr 2008 16:54:06 +0200
Newsgroups gmane.comp.windows.devel.java.advanced
Message-ID <[email protected]>
On 2008.04.12., at 16:12, Randall R Schulz wrote:
> The default hashCode() uses the JVM analog to the object's address
> (not
> really the virtual address of its storage, which can change during GC,
> but what Mac programmers in the good old days would have called
> a "handle"). Because of things like the GC thread and other
> unpredictable and variable circumstances from one invocation to the
> next (and, perhaps, because of the newer JRE's ability to share
> bytecodes between different instances of the JRE, the activity of
> other
> Java programs on the same host??), objects do not get the same
> identifier on every run.

In order to make it harder (ideally, impossible) to figure out an
object's address in the address space of the process, the identity
hash code function actually uses an automorphic transformation on the
address space, using the object's first allocated address (the
transformation in question ain't exactly a XOR if I remember correctly
from last time I dug in Sun JVM source code, but is similar). The key
for the transformation (i.e. the XOR value) is randomly chosen on each
JVM startup, which would explain the differing behavior.

Attila.

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com