Workbench / The TiffinBox Build
S43 · V3·42
One Runtime, Rebuilt
Volume 3, chapter 42. TiffinBox's jars were reproducible with fixed timestamps, until they were built on JDK 25: 13 of 106 class files changed, because the two compilers name lambdas differently. A slim jlink runtime cut the Java installation from 286 MB to 54 MB but quietly dropped the class-data-sharing archive, and had no JFR, which the code never names. This stage adds a check that rebuilds the jars from source and compares them byte for byte, naming the JDK; a runtime image built from a list of modules with a reason for each, a regenerated CDS archive and a check that the code needs nothing missing from the list; a stable module name for the core library; and measurements of what modules, records and runtimes change for the code that depends on them.
Stage 43: one runtime, rebuilt
The brief
What you'll build.
tools/reproduce.sh: compiles core, server and tbx from source in a scratch directory, jars them the way the build scripts do, compares the result byte for byte with the build's jars, and prints the JDK it used.deploy/runtime-modules.txtanddeploy/runtime.sh: the JDK modules TiffinBox ships (java.base,java.net.http,jdk.jfr), each with a reason; ajlinkimage of exactly those, with--generate-cds-archive; and a check thatjdepsfinds no module the code needs that the list doesn't have.Automatic-Module-Name: in.tiffinbox.corein the core jar's manifest.- Release-check steps: the jars reproduce; the runtime image builds, serves
/healthwith an application CDS archive, and starts JFR. - Measurements in
exp/43:repro.sh,startup.py,mod/(a module's encapsulation on the class path and the module path),rec/(stage 42's record change, compiled and run across versions).
Why a real company needs this. "What's running in production, and could we build it again?" is a question auditors, incident responders and security teams ask. A runtime image that starts slower, or can't be profiled when an incident needs it, is a cost that shows up at the worst moment.
Why now. Chapter 42 is modules and packaging: artifacts, the class path and module path, jlink, fat JARs and dependency conflicts. TiffinBox ships two self-contained jars and runs on whatever JDK the machine has; this stage pins down what it ships.
What you'll have at the end.
- a check that the jars come from the source, on a named JDK;
- an 80 MB runtime image that starts as fast as the full JDK and can record with JFR;
- ADR-0045: what TiffinBox ships, and on which runtime.
Theory to own
- Reproducibility. What, besides source and timestamps, decides a JAR's bytes? (Companion, Gaps 1 and Theory 1.)
- Runtime images. What does a
jlinkimage leave out that the full JDK has? (The chapter, "jlink and jpackage"; Companion, Gaps 2 and Code walkthrough.) - Encapsulation. When does a
module-infostop other code using your internal packages? (The chapter, "The module path and JPMS in practice"; Companion, Gaps 3.) - Compatibility. Which kinds of compatibility does a change to a record's components affect? (The chapter, "Binary versus source compatibility"; Companion, Gaps 4.)
Build it
Step 1: build on another JDK
Write exp/43/build-with.sh (compile core and server with a given JDK, --release 21, then jar as the build does) and exp/43/repro.sh: build twice with JDK 21 and once with JDK 25, and compare the jars, the manifests, the class files and the lambda names in one class.
Checkpoint. exp/43/repro.out.
Step 2: rebuild and compare, every release
Write tools/reproduce.sh and add it to the release check. It must compare against the jars the build actually made (with the lint plugin and tests), not against a second scratch build.
Checkpoint. The release check prints same bytes: server/out/tiffinbox-server.jar (4c65f5dea3005d3b), the same for tbx.jar, and built with javac 21.0.12.1.
Step 3: the runtime image
Run jdeps --print-module-deps on both jars. Build an image of just those modules with jlink; start the server on it with -XX:StartFlightRecording, and attach jcmd <pid> JFR.start to one started without it. Then write deploy/runtime-modules.txt and deploy/runtime.sh.
Checkpoint. exp/43/sizes.out, the JFR lines in exp/43/startup.out; deploy/runtime.sh prints runtime: 80 MB, modules java.base,java.net.http,jdk.jfr (the code needs java.base,java.net.http).
Step 4: how fast it starts
Write exp/43/startup.py: launch the server, poll /health every 2 ms, record the time to the first 200, 11 runs plus a warm-up run, for the full JDK (with and without -Xshare:off), the image without and with CDS, and with an application archive.
Checkpoint. exp/43/startup.out.
Step 5: modules, measured
In exp/43/mod/, make a module kit that exports kit.api and not kit.internal, and an App that calls both. Compile and run App with kit.jar on the class path, then on the module path. Then add Automatic-Module-Name to the core jar's manifest and check it with jar --describe-module.
Checkpoint. exp/43/modules.out; in.tiffinbox.core automatic.
Step 6: stage 42's record, across versions
In exp/43/rec/, compile Client.java (it uses IdempotencyKey.of, the String constructor, hex(), a record pattern and getRecordComponents()) against stage 41's IdempotencyKey, run it with stage 41's and with stage 42's, then recompile it against stage 42's.
Checkpoint. exp/43/record.out.
Senior and architect lens
1. Name every input of an artifact. Source, dependencies, the JDK and its vendor, the build options, the time. Reproducibility you can check is worth more than reproducibility you assume; the release check now checks it.
2. ADR-0045: what TiffinBox ships, and on which runtime. Write it with these points:
- Artifacts: two self-contained jars (server, tbx), each including core; reproducible from source on JDK 21.0.12, checked every release.
- Runtime: a
jlinkimage of the modules indeploy/runtime-modules.txt, with a regenerated CDS archive and an application archive created on first start. Every module has a reason;jdk.jfris there for operations. - Modules: no
module-infowhile the code runs on the class path and has no outside consumers; core carriesAutomatic-Module-Name. Revisit when a second team consumes core. - Compatibility: core's public types, including record components, change only with a version bump and a note.
3. Small is a means, not a goal. The image is a third the size of the JDK, which matters for pulls and attack surface. It must still start as fast and be as observable; measure both before calling it done.
What breaks first, and when it's addressed:
| Pressure | What breaks | Where it's addressed |
|---|---|---|
| a JDK upgrade in CI | different bytes; the reproduce step fails until the JDK is updated on purpose | stage 44 (build systems: a pinned toolchain) |
| core's API changing silently (as in Step 6) | consumers that recompile | stage 44 (build systems: an API compatibility check) |
| the runtime image built on a developer's Mac | the CDS plugin refuses a different platform | stage 44 (build systems: images built in a container) |
| a second deployable needing core | two copies of core classes on one class path | stage 44 (build systems: publishing core as its own artifact) |
Evidence
exp/43/repro.out(13 of 106 classes differ on JDK 25).exp/43/sizes.out,startup.out(with the CDS and JFR lines).exp/43/modules.out,record.out.tools/reproduce.sh,deploy/runtime.shanddeploy/runtime-modules.txt; the release check's two new steps pass.- Core 52, server 48 and tbx 21 tests;
golden master: 47 exchanges, identical; the suite passes. - ADR-0045 is committed.
Carry forward
- The JDK is part of the build, printed with every reproduce check.
runtime-modules.txt: a reason for every module, checked againstjdeps.- Startup measured on the image that ships, not on a developer's JDK.