Skip to content

Commit b3de419

Browse files
authored
perf(build): record boot.pack from a start from a jar too, so it needs no app.pack (#84)
1 parent ee2cf53 commit b3de419

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

‎docs/browser.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ next to itself, or where `cheerpjInit({ runtime: "/path/to/dist/" })` says.
99
image, so a page reads only the classes it needs. `jdk/image.jar` holds
1010
`java.base` and the files around the classes, each other module is in
1111
`jdk/<module>.jar`, and `jdk/ct.sym.jar` holds what `javac --release` reads.
12-
`boot.pack` holds what a bare start reads. `jdk/app.pack` holds what a
12+
`boot.pack` holds what a bare start reads, from a class folder or a jar. `jdk/app.pack` holds what a
1313
typical program reads beyond that, and `jdk/javac.pack` what javac adds; a
1414
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
1515
full download of each image file a page reads.

‎docs/development.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ at `build/hotspot`. The build links the selected modules into `build/jdk/lib/mod
1010
`lib/packages.txt` indexes packages for the boot class loader. `pnpm build`
1111
puts it, with the files around it, in `dist/jdk/image.jar` and, for each module
1212
but `java.base`, `dist/jdk/<module>.jar`, all read by byte range.
13-
It packs the byte ranges a bare start reads into `boot.pack`, those the programs
13+
It packs the byte ranges a bare start reads, from a class folder or a jar, into `boot.pack`, those the programs
1414
in `scripts/packs` read beyond that into `jdk/app.pack` (with every `java.base`
1515
part javac reads), and the rest of what their compile reads into `jdk/javac.pack`. Without `localeData`, the VM leaves `jdk.localedata`
1616
out with `jdk.module.limitmods`, as `--limit-modules` does.

‎scripts/build-web.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { join, relative } from "node:path";
1010
import { build } from "esbuild";
1111
import { MemoryBackend, VFS } from "../src/fs.ts";
1212
import type { Backend } from "../src/fs.ts";
13-
import { JVM, LM_CLASS } from "../src/jvm.ts";
13+
import { JVM, LM_CLASS, LM_JAR } from "../src/jvm.ts";
1414
import { hotspot } from "./hotspot.ts";
1515
import { NodeBackend } from "../src/node.ts";
1616

@@ -103,8 +103,8 @@ class Recorder implements Backend {
103103
return d;
104104
}
105105
}
106-
// Runs main over the JDK through rec, with app mounted at /app.
107-
async function record(rec: Recorder, app: string, classpath: string[], main: string, args: string[] = []) {
106+
// Runs main (a class, or a jar in LM_JAR mode) over the JDK through rec, with app mounted at /app.
107+
async function record(rec: Recorder, app: string, classpath: string[], main: string, args: string[] = [], mode = LM_CLASS) {
108108
const vfs = new VFS();
109109
vfs.mount("/", new MemoryBackend());
110110
vfs.mount("/jdk", rec);
@@ -115,7 +115,7 @@ async function record(rec: Recorder, app: string, classpath: string[], main: str
115115
props: { "java.io.tmpdir": "/tmp", "user.home": "/tmp" },
116116
stdout: () => {}, stderr: (b) => process.stderr.write(b),
117117
});
118-
const code = await vm.run(LM_CLASS, main, args);
118+
const code = await vm.run(mode, main, args);
119119
if (code !== 0) throw new Error(`${main} exited with ${code}`);
120120
}
121121
const recorder = new Recorder(new NodeBackend(jdk));
@@ -134,6 +134,10 @@ javacTo("app", "-cp", join(fixtures, "lib"), join(packs, "App.java"));
134134
cpSync(join(packs, "app.properties"), join(fixtures, "app", "app.properties"));
135135
javacTo("driver", join(packs, "Compile.java"));
136136
for (const d of ["lib", "proc", "app"]) execFileSync(hotspot("jar"), ["cf", join(fixtures, `${d}.jar`), "-C", join(fixtures, d), "."]);
137+
// A bare start from a jar, by class name and as java -jar, reads a few more classes.
138+
execFileSync(hotspot("jar"), ["cfe", join(fixtures, "hello.jar"), "Hello", "-C", join(dist, "samples"), "Hello.class"]);
139+
await record(recorder, fixtures, ["/app/hello.jar"], "Hello");
140+
await record(recorder, fixtures, ["/app/hello.jar"], "/app/hello.jar", [], LM_JAR);
137141
cpSync(join(packs, "src"), join(fixtures, "src"), { recursive: true });
138142
const appRecorder = new Recorder(new NodeBackend(jdk));
139143
await record(appRecorder, fixtures, ["/app/app.jar", "/app/lib.jar"], "App");
@@ -197,7 +201,7 @@ function intersect(spans: [number, number][], within: [number, number][]): [numb
197201
}
198202
return out;
199203
}
200-
// boot.pack holds what a bare start reads. app.pack, fetched the first time a
204+
// boot.pack holds what a bare start reads, from a class folder or a jar. app.pack, fetched the first time a
201205
// program reads one of its parts, holds what the typical program reads beyond
202206
// that and every java.base part javac reads. javac.pack holds the rest of what
203207
// javac reads: the compiler's own modules.

0 commit comments

Comments
 (0)