Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KqJyCidz3ZgRyHABv2GVJh
compact-strings — Compact Strings (JEP 254) measured with JOL, plus compact object headers
Companion code for the ankurm.com article Compact Strings in Java: Measured with JOL on JDK 25 (plus Compact Object Headers). The explanation lives in the article, in collapsible sections; this folder holds the runnable sources and the transcripts they produced.
JDK25=/path/to/jdk-25 JDK27=/path/to/jdk-27 ./run.sh # regenerates output/01-21 (about 40 seconds; downloads JOL 0.17 and checks its sha1)
./jmh/fetch.sh && JDK25=/path/to/jdk-25 ./jmh/run-jmh.sh # output/30-jmh.txt (about 6 minutes; machine dependent)
src/StringLayout.java— JOLClassLayoutofString, of a Latin-1 and a UTF-16 instance and of thebyte[]behind each; a footprint table by length. Needs--add-opens java.base/java.lang=ALL-UNNAMEDto readcoder.src/MillionStrings.java— one million random lower-case strings (30 to 55 characters), measured withGraphLayout, then the same strings with one€appended.src/Upgrade.java— thecoderof strings produced by concatenation,substring,replace,toLowerCase,new String(bytes, UTF_8),StringBuilder.toString().jmh/— a JMH 1.37 benchmark of six read-onlyStringoperations with and without-XX:-CompactStrings.output/—01-06layouts,11-16the million-string runs, each under six flag sets (JDK 25 default,-XX:-CompactStrings,-XX:+UseCompactObjectHeaders, both; JDK 27 default and-XX:-UseCompactObjectHeaders),20coder transcript,21PrintFlagsFinal,30JMH.
| Thing | Version |
|---|---|
| JDK 25 | Temurin 25.0.4.1+1 |
| JDK 27 | Amazon Corretto 27+35 (corretto.aws/downloads/latest/amazon-corretto-27-x64-linux-jdk.tar.gz) |
| JOL | 0.17 (org.openjdk.jol:jol-core, latest release in Maven Central's maven-metadata.xml) |
| JMH | 1.37 |
Everything except the JMH numbers is byte-stable. JOL 0.17 on JDK 27 prints one Unable to attach Serviceability Agent line (it reads a flag that no longer exists); it is kept in the transcripts because it is real.