derrickaw opened a new pull request, #41922:
URL: https://github.com/apache/beam/pull/41922

   ### Summary
   Follow-up to #41540 (`bd3f5ccf1b`).
   
   When running on a JVM with `-XX:+UseCompactObjectHeaders` (JEP 450/519, 
8-byte object headers), `CachesTest.testHashMapOverheadMatchesJamm` fails 
deterministically:
   
   ```text
   java.lang.AssertionError: size=0 expected:<40> but was:<48>
       at 
org.apache.beam.fn.harness.CachesTest.testHashMapOverheadMatchesJamm(CachesTest.java:948)
   ```
   
   With 8-byte object headers (and 8-byte alignment):
   - `HashMap` shell: 40B instead of 48B (−8B)
   - `HashMap.Node`: 24B instead of 32B (−8B per entry)
   - `Node[]`: `align(12 + 4 * cap, 8) == 16 + 4 * cap` (unchanged for 
power-of-two `cap >= 16`)
   
   Because `Caches.hashMapOverhead(int)` intentionally uses a deterministic, 
conservative 12-byte-header estimate (consistent with the other fast paths in 
`Caches`, such as `String`'s 2 bytes/char estimate under 
`-XX:+CompactStrings`), this PR leaves `Caches.java` unchanged and updates 
`CachesTest.testHashMapOverheadMatchesJamm` to detect `UseCompactObjectHeaders` 
via the standard `HotSpotDiagnostic` MBean (no `com.sun.*` imports) and 
subtract `8 * (1 + size)` bytes when comparing against Jamm — keeping exact 
byte-for-byte assertions in both modes.
   
   ### Verification
   - JDK 17 (standard 12-byte headers): `./gradlew :sdks:java:harness:test 
--tests org.apache.beam.fn.harness.CachesTest :sdks:java:harness:spotlessCheck 
:sdks:java:harness:checkstyleTest` (30/30 passed)
   - OpenJDK 25 with `-XX:+UseCompactObjectHeaders`: `./gradlew 
:sdks:java:harness:test --rerun --tests org.apache.beam.fn.harness.CachesTest` 
(30/30 passed)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to