# On Generating Identity Hash Codes

DevFeed: [On Generating Identity Hash Codes](<https://devfeed.tech/articles/on-generating-identity-hash-codes-24843.md>)

Original publisher: [Read original article](<https://alidg.me/blog/2020/7/15/hash-code>)

Author: Alimate

Published: 2020-07-15T00:00:00Z

Content type: article

Language: en

Sources: [Ali Dehghan - Kemikit](<https://devfeed.tech/sources/ali-dehghan-kemikit.md>)

Topics: [hashCode](<https://devfeed.tech/topics/hashcode.md>), [hashing](<https://devfeed.tech/topics/hashing.md>), [Algorithms](<https://devfeed.tech/topics/algorithms.md>), [computational complexity](<https://devfeed.tech/topics/computational-complexity.md>)

Tags: [algorithm](<https://devfeed.tech/tags/algorithm.md>), [cas](<https://devfeed.tech/tags/cas.md>), [experimental](<https://devfeed.tech/tags/experimental.md>), [flag](<https://devfeed.tech/tags/flag.md>), [function](<https://devfeed.tech/tags/function.md>), [generate](<https://devfeed.tech/tags/generate.md>), [generator](<https://devfeed.tech/tags/generator.md>), [hash](<https://devfeed.tech/tags/hash.md>), [hashcode](<https://devfeed.tech/tags/hashcode.md>), [hotspot](<https://devfeed.tech/tags/hotspot.md>), [identity](<https://devfeed.tech/tags/identity.md>), [java](<https://devfeed.tech/tags/java.md>), [jvm](<https://devfeed.tech/tags/jvm.md>), [memory](<https://devfeed.tech/tags/memory.md>), [random](<https://devfeed.tech/tags/random.md>), [retry](<https://devfeed.tech/tags/retry.md>), [threads](<https://devfeed.tech/tags/threads.md>), [variable](<https://devfeed.tech/tags/variable.md>)

## AI overview

HotSpot JVM's identity hash code generation strategy is controlled by an experimental tuning flag, and the excerpt describes several approaches. The Park-Miller/Lehmer RNG strategy atomically updates a global seed; concurrent first-time hash requests can cause compare-and-swap failures and retries. Two strategies derive the hash code from a function of the object's memory address. A static-number strategy always returns 1, which the author guesses may serve as a benchmark baseline. The excerpt begins to introduce a sequential-number strategy but cuts off before explaining it, and omits code and values needed to detail the other strategies.

## Source excerpt

Have you ever wondered how does the HotSpot JVM generate identity hashcodes?