> FloatEntryImpl.equals() and DoubleEntryImpl.equals() used == for comparison, 
> which returns false for NaN == NaN per IEEE 754. This caused two different 
> FloatEntry/DoubleEntry objects holding NaN to not be considered equal, 
> violating the equals/hashCode contract (same hashCode but equals returns 
> false).
> 
> Similarly, SplitConstantPool.findFloatEntry() and findDoubleEntry() used == 
> to match values, so NaN entries could never be found in the pool, causing 
> every floatEntry(Float.NaN) or doubleEntry(Double.NaN) call to create a 
> duplicate entry and bloat the constant pool.
> 
> Fix by using Float.floatToRawIntBits() and Double.doubleToRawLongBits() for 
> bitwise comparison, which correctly handles NaN and also properly 
> distinguishes +0.0 from -0.0.

Shaojin Wen has updated the pull request incrementally with two additional 
commits since the last revision:

 - Refactor findEntry loop to use while with direct width increment
   
   Change the loop from for-with-post-increment to a while loop that
   increments by e.width() directly, making the code clearer.
   
   Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
 - Add tests for Float/Double NaN with different bit patterns
   
   Since the code uses raw bit variants (floatToRawIntBits/doubleToRawLongBits)
   when converting floating-point values to integral bits for hashCode and
   equals, the tests should cover the cases of NaNs with different bit patterns.
   
   - testFloatNaNWithDifferentBitPatternsAreDistinct: Verify that NaNs with
     different bit patterns create distinct constant pool entries
   - testDoubleNaNWithDifferentBitPatternsAreDistinct: Same for Double
   - testFloatNaNWithDifferentBitPatternsAreNotEqual: Verify that NaNs with
     different bit patterns are not equal
   - testDoubleNaNWithDifferentBitPatternsAreNotEqual: Same for Double
   - testFloatNaNWithSameBitPatternIsDeduplicated: Verify that NaNs with the
     same bit pattern are deduplicated
   - testDoubleNaNWithSameBitPatternIsDeduplicated: Same for Double
   
   Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

-------------

Changes:
  - all: https://git.openjdk.org/jdk/pull/30196/files
  - new: https://git.openjdk.org/jdk/pull/30196/files/3ac3ec6c..5947b8d9

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=30196&range=02
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=30196&range=01-02

  Stats: 183 lines in 1 file changed: 181 ins; 0 del; 2 mod
  Patch: https://git.openjdk.org/jdk/pull/30196.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/30196/head:pull/30196

PR: https://git.openjdk.org/jdk/pull/30196

Reply via email to