If I call the Object.hashcode ()
method on an object, then this internal address Object (default implementation) Does this know a logical or physical address?
Memory compaction takes place in memory in garbage collection due to object transfer. If I call Hashak before and after GC, then he will return the same hashcode (this will return) and if so why (compaction can change due to address)?
@Ericsson is more or less accurate. Does not change the life span of the java.lang.Object.hashCode ()
.
The manner in which it (usually) is implemented is clever. When an object is transferred by the garbage collector, its original hashtod has to be stored again if it is used again. The obvious way to implement it is to add a 32 bit field to the object header to capture the shadow . But it will add a word overhead to each object, and will ruin the place in the most common case ... where the Hashod
method of an object is not called.
The solution is to add two flag bits to the object's flag word, and use them (broadly) the following type. The first flag is set when the hashode
is called the method. The second flag hashcode
indicates that the existing address of the object is to be used as a hashode, or to use a stored value. When GC runs and moves an object, it checks for these flags. If the first flag is set and the second is not set, then GC allocates an additional word at the end of the object and stores the original object location in that word. Then it sets two flags, since then, the hashode
method gets the hashshad value from the word at the end of the object.
In fact, an identityHashCode
implementation is to behave like this to complete the following procedure:
"Whenever it is applied during execution of more than one object on a single Java application, the hash code method should return the same integer continuously, provided that the object is used in parallel comparison Any information made is not modified . This integer is used for any application Execution should not be consistent with other execution. The same application. "
A hypothetical implementation of identityHashCode () has created a current < / Strong> The address of the machine will violate the highlighted part / when GC takes the object to a different address. The only way around this (Hypertical) will be for JVM that ensures that once the Hashod
is not called on it once. And this will give rise to serious and uncomfortable problems with piles fragmentation.
Comments
Post a Comment