Add hashmap-vs-concurrenthashmap module: JDK 25 sizeCtl/treeify internals, forced and measured lost updates

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b7rnC7jppGGdHGESvy
This commit is contained in:
2026-10-28 18:07:37 +00:00
co-authored by Claude Sonnet 5.5
parent 715036b640
commit f80e1079a8
24 changed files with 958 additions and 0 deletions
@@ -0,0 +1,16 @@
ConcurrentHashMap.sizeCtl vs HashMap.threshold, single-threaded, read by reflection
===================================================================================
new ConcurrentHashMap() sizeCtl=0 table=null
after 1st put sizeCtl=12 table.length=16
after 12 puts (size=12) sizeCtl=24 table.length=32
baseCount=12 counterCells=null size()=12 mappingCount()=12 (single thread: no CounterCell was ever needed)
Sizing constructors: ask for 32 and see what each map really allocates
new ConcurrentHashMap(32) sizeCtl=64 (table not allocated yet)
after 1st put sizeCtl=48 table.length=64
new HashMap(32) threshold=32 table=null (threshold holds the initial capacity until first put)
after 1st put threshold=24 table.length=32
What sizeCtl holds while a resize is running (computed, not caught live):
resizeStamp(16)=32795 (rs << 16) + 2 = -2145714174 -> negative, so every other thread sees 'resize in progress'