|
| 1 | +# The Valhalla laboratory |
| 2 | + |
| 3 | +The three-truths method (`.claude/knowledge/valhalla-three-truths-method.md`) applied to this |
| 4 | +project's small semantic value vocabulary — `LaneId`, `Ordinal`, `MaskId`, `RowRange`, `Row` — and |
| 5 | +to the mission's mandatory headline experiment: does Valhalla rescue per-entity materialization at |
| 6 | +65,536-row scale, or only the tiny descriptor vocabulary around it? |
| 7 | + |
| 8 | +**Same experiment source, compiled twice** — once against a stable JDK where the vocabulary types |
| 9 | +are plain `record`s, once against the JEP 401 early-access JDK where they are `value record`s — so |
| 10 | +the comparison is genuinely apples-to-apples, not two different programs. |
| 11 | + |
| 12 | +## Layout |
| 13 | + |
| 14 | +``` |
| 15 | +src/shared/ experiment logic, byte-identical on both compiles |
| 16 | +src/stable/ Vocab.java (record), Containers.java, Platform.java — the stable-JDK half of the A/B |
| 17 | +src/valhalla/ Vocab.java (value record), Containers.java, Platform.java — the Valhalla half |
| 18 | +``` |
| 19 | + |
| 20 | +`Platform` is the one seam between them: same signatures on both sides, so `src/shared/` never |
| 21 | +branches on which platform it's running on except by asking `Platform` — never by calling a |
| 22 | +Valhalla-only API (like `Class::isValue` or `jdk.internal.value.ValueClass`) directly. That is a |
| 23 | +real rule, not a style preference: `Class::isValue` does not exist at all on a stable JDK, so a |
| 24 | +direct call would fail to *compile* the stable half, not just report the wrong answer. |
| 25 | + |
| 26 | +`NativeAccess` (in `src/shared/`, package `com.adaworldapi.lancegraph`) is a read-only, split-package |
| 27 | +escape hatch into the shipped library's package-private handle — documented in the file itself. It |
| 28 | +exists because the lab has to build the very thing the thesis says you should not build (65,536 Java |
| 29 | +objects) from the *same bytes* the native kernel reads, or the comparison proves nothing. Nothing |
| 30 | +under `java/` changes to support this. |
| 31 | + |
| 32 | +## Build and run |
| 33 | + |
| 34 | +### Stable half (JDK 26 GA, plain `record`s) |
| 35 | + |
| 36 | +```sh |
| 37 | +javac -d out-stable $(find ../java/src/main/java src/shared src/stable -name '*.java') |
| 38 | + |
| 39 | +java --enable-native-access=ALL-UNNAMED \ |
| 40 | + -Dlgj.library=../target/release/liblgj_abi.so \ |
| 41 | + -cp out-stable com.adaworldapi.lancegraph.lab.RunAll |
| 42 | +``` |
| 43 | + |
| 44 | +### Valhalla half (the JEP 401 EA build, `value record`s) |
| 45 | + |
| 46 | +`--release` cannot be combined with `--add-exports` (a real javac restriction — `--release` uses a |
| 47 | +stricter cross-compilation module model). Use `-source` instead when compiling *for* the JDK you are |
| 48 | +also running on, which is the case here. |
| 49 | + |
| 50 | +```sh |
| 51 | +javac --enable-preview -source 27 \ |
| 52 | + --add-exports java.base/jdk.internal.value=ALL-UNNAMED \ |
| 53 | + --add-exports java.base/jdk.internal.vm.annotation=ALL-UNNAMED \ |
| 54 | + -d out-valhalla $(find ../java/src/main/java src/shared src/valhalla -name '*.java') |
| 55 | + |
| 56 | +java --enable-preview --enable-native-access=ALL-UNNAMED \ |
| 57 | + --add-exports java.base/jdk.internal.value=ALL-UNNAMED \ |
| 58 | + --add-exports java.base/jdk.internal.vm.annotation=ALL-UNNAMED \ |
| 59 | + -Dlgj.library=../target/release/liblgj_abi.so \ |
| 60 | + -cp out-valhalla com.adaworldapi.lancegraph.lab.RunAll |
| 61 | +``` |
| 62 | + |
| 63 | +Both need the JDK paths from `.claude/knowledge/jdk-toolchain-facts.md` — do not use `/usr/bin/java` |
| 64 | +(JDK 21, no value classes at all) for either. |
| 65 | + |
| 66 | +## What each experiment measures |
| 67 | + |
| 68 | +| Class | Question | |
| 69 | +|---|---| |
| 70 | +| `IdentityExperiment` | Truth (a), semantic: is identity actually unobservable? `Class::isValue`, reference equality, array flatness, `synchronized` legality — measured on both platforms, asked to agree everywhere except reference equality (which no caller in the production API uses). | |
| 71 | +| `FootprintExperiment` | Truth (b)/(c), representation: per-object bytes, array layout, field flattening, call-argument passing — via `jol-core`'s real VM instrumentation where available, allocation-delta measurement elsewhere. | |
| 72 | +| `FfmAddressingExperiment` | Is the wrapper free where it actually touches native memory — a `RowRange`/`Ordinal` around an FFM offset vs a bare `long`? | |
| 73 | +| `ThesisExperiment` | The mandatory headline: 65,536 rows as (1) one native lane + one packed mask + one crossing, vs (2)/(3) hydrated Java objects, on the SAME question and the SAME answer. Heap cost and wall time, both platforms. | |
| 74 | + |
| 75 | +## Measured headline (2026-08-17, this environment) |
| 76 | + |
| 77 | +Real numbers from a real run — reproduce with the commands above before citing a different number. |
| 78 | + |
| 79 | +| | native, one crossing | hydrate 65,536 `Row`, then scan | |
| 80 | +|---|---:|---:| |
| 81 | +| stable JDK 26 | 19.5 µs, 289 KiB Java-side | 746 µs, 2.00 MiB | |
| 82 | +| Valhalla (JDK 27 EA) | 15.7 µs, 289.5 KiB Java-side | 900 µs, 2.50 MiB | |
| 83 | + |
| 84 | +The native path wins by roughly **38–57×** on time and **7–9×** on Java heap, on **both** platforms — |
| 85 | +Valhalla does not close this gap, because `Row` (multiple fields) measured `NOT-FLAT` even under |
| 86 | +Valhalla, while the single-field `LaneId` measured `FLAT` (2.90 B/element vs 16.00 B on stable, ~5.5× |
| 87 | +smaller). This is the mission thesis's prediction, confirmed rather than assumed: **Valhalla helps |
| 88 | +the tiny descriptor vocabulary; it does not rescue per-entity materialization at this scale.** See |
| 89 | +`IdentityExperiment`'s and `FootprintExperiment`'s full output for the field-by-field evidence. |
| 90 | + |
| 91 | +## A defect found and fixed while wiring this up |
| 92 | + |
| 93 | +The first version of `IdentityExperiment`/stable `Platform` called `Class::isValue()` directly for |
| 94 | +four of the five vocabulary types (`Ordinal`/`MaskId`/`RowRange`/`Row`), with a comment incorrectly |
| 95 | +claiming it was "final API on JDK 26." It is not — `javac` on JDK 26 GA does not have that method at |
| 96 | +all, confirmed by a real compile failure, not by reading documentation. Fixed by routing every |
| 97 | +identity query through `Platform.isValueClass(Class<?>)`, which the stable half answers `false` (a |
| 98 | +JDK with no value-class concept can never produce one, so the answer is exact, not a guess) and the |
| 99 | +Valhalla half answers with the real `type.isValue()`. See `EPIPHANIES.md` |
| 100 | +`E-LGJ-CORE-SLICE-GREEN-DISABLE-VERIFIED-1` for the audit discipline this caught it under. |
0 commit comments