Add collections module: HashMap bucket layout, treeification, and a real ConcurrentModificationException reproduction
Companion code for the ankurm.com post "Top 40 Java Collections Interview Questions (HashMap Internals to Fail-Fast Iterators)". Verified against JDK 25's own HashMap source (TREEIFY_THRESHOLD=8, UNTREEIFY_THRESHOLD=6, MIN_TREEIFY_CAPACITY=64), with every claim backed by a committed docs/output/*.txt transcript from a real run. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YXCrLgRKFgCh9RHKW8xaqJ
This commit is contained in:
Executable
+31
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regenerates every file in docs/output/ from scratch. Run from the module root
|
||||
# (java-interview-lab/collections).
|
||||
#
|
||||
# Needs JDK 25 (LTS) on PATH as `java`/`javac`, and a `mvn` that can reach Maven Central the
|
||||
# first time (surefire/compiler plugins must be cached locally before -o works).
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
echo "== compiling =="
|
||||
mvn -q -B compile
|
||||
|
||||
echo "== 01/02: reflection into HashMap internals, with and without --add-opens =="
|
||||
mkdir -p docs/output
|
||||
java -cp target/classes com.ankurm.interviewlab.collections.ReflectionAddOpensDemo \
|
||||
> docs/output/01-reflection-without-add-opens.txt 2>&1 || true
|
||||
java --add-opens java.base/java.util=ALL-UNNAMED -cp target/classes \
|
||||
com.ankurm.interviewlab.collections.ReflectionAddOpensDemo \
|
||||
> docs/output/02-reflection-with-add-opens.txt 2>&1
|
||||
|
||||
# Strip the sandbox's own proxy/trust-store banner (JAVA_TOOL_OPTIONS) - it is environment
|
||||
# noise, not part of either demonstration, and should not be in a committed transcript.
|
||||
for f in docs/output/01-reflection-without-add-opens.txt docs/output/02-reflection-with-add-opens.txt; do
|
||||
grep -v '^Picked up JAVA_TOOL_OPTIONS' "$f" > "$f.tmp" && mv "$f.tmp" "$f"
|
||||
done
|
||||
|
||||
echo "== 03-10: JUnit-driven transcripts (BucketLayoutTest, TreeifyTriggerTest, ConcurrentModificationTest, EqualsHashCodeContractTest) =="
|
||||
mvn -q -B test
|
||||
|
||||
echo "== done - docs/output now contains: =="
|
||||
ls -1 docs/output
|
||||
Reference in New Issue
Block a user