JDK 9 RFR of JDK-8035279: Clean up internal deprecations in BigInteger
john.r.rose at oracle.com
Fri Feb 21 00:28:46 UTC 2014
On Feb 20, 2014, at 12:09 PM, David Holmes <david.holmes at oracle.com> wrote:
> If the sentinel values were the default zero values there would be no issue
This is an instance of the "stable value" pattern; see the javadoc for java/lang/invoke/Stable.
Using zero for the sentinel in this pattern is the safest option.
If I'm reading the JMM argument right, using a non-default value (perhaps even an explicitly set zero value) relies on accidental effects from nearby final variables, which is fragile even if correct on HotSpot or in a future JMM.
If zero is also a valid result, and the "+1" values everywhere are odious, make a wrapper method that returns the corrected value, and applies the correction in just one place. That is much preferable to risking an initial race condition on your stable value.
More information about the core-libs-dev