diff --git a/docs/browser.md b/docs/browser.md index 949d13e..fd086ad 100644 --- a/docs/browser.md +++ b/docs/browser.md @@ -9,7 +9,7 @@ next to itself, or where `cheerpjInit({ runtime: "/path/to/dist/" })` says. image, so a page reads only the classes it needs. `jdk/image.jar` holds `java.base` and the files around the classes, each other module is in `jdk/.jar`, and `jdk/ct.sym.jar` holds what `javac --release` reads. - `boot.pack` holds what a bare start reads. `jdk/app.pack` holds what a + `boot.pack` holds what a bare start reads, from a class folder or a jar. `jdk/app.pack` holds what a typical program reads beyond that, and `jdk/javac.pack` what javac adds; a page fetches each the first time it reads a class in it. A host that compresses ranged responses still works, at the cost of one full download of each image file a page reads. diff --git a/docs/development.md b/docs/development.md index 4540df2..f6cbca8 100644 --- a/docs/development.md +++ b/docs/development.md @@ -10,7 +10,7 @@ at `build/hotspot`. The build links the selected modules into `build/jdk/lib/mod `lib/packages.txt` indexes packages for the boot class loader. `pnpm build` puts it, with the files around it, in `dist/jdk/image.jar` and, for each module but `java.base`, `dist/jdk/.jar`, all read by byte range. -It packs the byte ranges a bare start reads into `boot.pack`, those the programs +It packs the byte ranges a bare start reads, from a class folder or a jar, into `boot.pack`, those the programs in `scripts/packs` read beyond that into `jdk/app.pack` (with every `java.base` part javac reads), and the rest of what their compile reads into `jdk/javac.pack`. Without `localeData`, the VM leaves `jdk.localedata` out with `jdk.module.limitmods`, as `--limit-modules` does. diff --git a/scripts/build-web.ts b/scripts/build-web.ts index 3e7c7da..fc6adc0 100644 --- a/scripts/build-web.ts +++ b/scripts/build-web.ts @@ -10,7 +10,7 @@ import { join, relative } from "node:path"; import { build } from "esbuild"; import { MemoryBackend, VFS } from "../src/fs.ts"; import type { Backend } from "../src/fs.ts"; -import { JVM, LM_CLASS } from "../src/jvm.ts"; +import { JVM, LM_CLASS, LM_JAR } from "../src/jvm.ts"; import { hotspot } from "./hotspot.ts"; import { NodeBackend } from "../src/node.ts"; @@ -103,8 +103,8 @@ class Recorder implements Backend { return d; } } -// Runs main over the JDK through rec, with app mounted at /app. -async function record(rec: Recorder, app: string, classpath: string[], main: string, args: string[] = []) { +// Runs main (a class, or a jar in LM_JAR mode) over the JDK through rec, with app mounted at /app. +async function record(rec: Recorder, app: string, classpath: string[], main: string, args: string[] = [], mode = LM_CLASS) { const vfs = new VFS(); vfs.mount("/", new MemoryBackend()); vfs.mount("/jdk", rec); @@ -115,7 +115,7 @@ async function record(rec: Recorder, app: string, classpath: string[], main: str props: { "java.io.tmpdir": "/tmp", "user.home": "/tmp" }, stdout: () => {}, stderr: (b) => process.stderr.write(b), }); - const code = await vm.run(LM_CLASS, main, args); + const code = await vm.run(mode, main, args); if (code !== 0) throw new Error(`${main} exited with ${code}`); } const recorder = new Recorder(new NodeBackend(jdk)); @@ -134,6 +134,10 @@ javacTo("app", "-cp", join(fixtures, "lib"), join(packs, "App.java")); cpSync(join(packs, "app.properties"), join(fixtures, "app", "app.properties")); javacTo("driver", join(packs, "Compile.java")); for (const d of ["lib", "proc", "app"]) execFileSync(hotspot("jar"), ["cf", join(fixtures, `${d}.jar`), "-C", join(fixtures, d), "."]); +// A bare start from a jar, by class name and as java -jar, reads a few more classes. +execFileSync(hotspot("jar"), ["cfe", join(fixtures, "hello.jar"), "Hello", "-C", join(dist, "samples"), "Hello.class"]); +await record(recorder, fixtures, ["/app/hello.jar"], "Hello"); +await record(recorder, fixtures, ["/app/hello.jar"], "/app/hello.jar", [], LM_JAR); cpSync(join(packs, "src"), join(fixtures, "src"), { recursive: true }); const appRecorder = new Recorder(new NodeBackend(jdk)); await record(appRecorder, fixtures, ["/app/app.jar", "/app/lib.jar"], "App"); @@ -197,7 +201,7 @@ function intersect(spans: [number, number][], within: [number, number][]): [numb } return out; } -// boot.pack holds what a bare start reads. app.pack, fetched the first time a +// boot.pack holds what a bare start reads, from a class folder or a jar. app.pack, fetched the first time a // program reads one of its parts, holds what the typical program reads beyond // that and every java.base part javac reads. javac.pack holds the rest of what // javac reads: the compiler's own modules.