Commit 14e217e
Officina: Java runs too, and the isolation headers come back off
Java compiles and runs in the page: ecj compiles the cell, a WebAssembly JVM
runs the class. 23 worked examples, from a first program to a sieve.
Two findings shaped it, both measured rather than assumed.
The isolation headers added with the C/C++ toolchain were not needed and are
removed. emception wants a SharedArrayBuffer for interactive stdin and does
without one when it cannot have it — clang, wasm-ld and the programs they
build all run on a page that is not cross-origin isolated. Keeping the headers
would have bought a stdin this notebook does not offer, and it would have cost
Java outright: CheerpJ runs its JVM in an iframe on its own origin that sends
no COEP header of its own, so `require-corp` blocks it and every call hangs
with no error at all. That was an hour of a JVM that answered nothing.
CheerpJ ships a JRE, not a JDK, so `com.sun.tools.javac.Main` is not there to
call. The compiler is ecj, served from this origin, pinned to the 3.26 line:
later releases need Java 17 to run, and on 17 they refuse to start with
"invalid location for system libraries" because a modular JDK has no rt.jar to
read. Java 8 has one, 3.26 runs on 8.
The loader is the first and only thing this site fetches from another origin.
CheerpJ's free licence permits its runtime to be served only from the vendor's
domain, so the choice was that or no Java. scripts/audit.mjs now carries the
exception, scoped to that origin and that one page, and prints it on every
run rather than passing in silence — and /officina credits CheerpJ, as the
licence asks.
Java's entry point is a class, so the file is named after whatever the cell
declares: `public class Foo` must live in Foo.java, and always writing
Main.java would reject good programs over a filename the reader never chose.
Output is collected by borrowing console.log for the length of a run, because
CheerpJ offers no stdout of its own, and ecj's diagnostics say "your code"
where they would otherwise print a scratch path.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>1 parent 667c5d2 commit 14e217e
8 files changed
Lines changed: 632 additions & 43 deletions
File tree
- public
- java
- scripts
- src
- content/recipes
- pages
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | 121 | | |
145 | 122 | | |
146 | 123 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
13 | 11 | | |
14 | 12 | | |
15 | 13 | | |
16 | 14 | | |
17 | 15 | | |
18 | 16 | | |
19 | 17 | | |
20 | | - | |
21 | | - | |
22 | 18 | | |
23 | 19 | | |
24 | 20 | | |
| |||
Binary file not shown.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
20 | 40 | | |
21 | 41 | | |
22 | 42 | | |
| |||
71 | 91 | | |
72 | 92 | | |
73 | 93 | | |
| 94 | + | |
74 | 95 | | |
75 | 96 | | |
76 | 97 | | |
| |||
98 | 119 | | |
99 | 120 | | |
100 | 121 | | |
101 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
102 | 126 | | |
103 | 127 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
980 | 980 | | |
981 | 981 | | |
982 | 982 | | |
983 | | - | |
| 983 | + | |
984 | 984 | | |
985 | 985 | | |
986 | 986 | | |
987 | 987 | | |
988 | 988 | | |
989 | 989 | | |
990 | | - | |
991 | | - | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
992 | 993 | | |
993 | 994 | | |
994 | 995 | | |
| |||
998 | 999 | | |
999 | 1000 | | |
1000 | 1001 | | |
1001 | | - | |
| 1002 | + | |
1002 | 1003 | | |
1003 | 1004 | | |
1004 | 1005 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
0 commit comments