Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/browser.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ and `cjFileBlob(path)` also work.
- `preloadProgress(done, total)` reports the bytes of the runtime downloaded at start.
`total` is 0 while the server has not sent a length; the last call has `done === total`.
- `cheerpjInit({ warmSnapshot: true })` saves a library VM once its calls have warmed it up (see below).
- `cheerpjInit({ debug: true })` logs VM events to the console, such as whether a warm snapshot was saved, skipped as busy (and why) or restored.
- A file Java closes under `/files/downloads/` is downloaded by the browser.
`/files/uploads/` exists for files the page adds there.
- The browser console gets whole lines, so two `print` calls and a `println` log one
Expand Down Expand Up @@ -135,4 +136,11 @@ starts with the same class path restore that image, after checking that the
files, missing paths and directory listings those calls used are unchanged; the
first javac compile after it took 2.7 s instead of 5.3 s in Chromium on a
Raspberry Pi 5. An image is about 18 MB. IndexedDB keeps the 2 most recent warm images separately
from boot snapshots.
from boot snapshots. With `debug: true`, the console says whether a VM was
saved, skipped as busy (with the reason) or restored, and why a restore missed.

The image is only reused while every file the warm-up read is unchanged, so
warm up with calls that read fixed files: for example, compile a small source
that never changes before the first real compile. A first compile of the user's
own project records that project's files and directory listings, and the image
then misses as soon as one of them changes.
6 changes: 6 additions & 0 deletions docs/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,9 @@ are unchanged; a javac compile from it takes about 1 s instead of 6 s on a
Raspberry Pi 5. An image is about 18 MB; warm snapshots share the snapshot
directory and keep the 2 most recent. They build on boot snapshots, so with
`snapshotDir: null` there are none.

The image is only reused while every file the warm-up read is unchanged, so
warm up with calls that read fixed files: for example, compile a small source
that never changes before the first real compile. A first compile of the user's
own project records that project's files and directory listings, and the image
then misses as soon as one of them changes.
6 changes: 4 additions & 2 deletions src/browser/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ export interface InitOptions {
env?: string[];
// load the formats and names of locales other than English
localeData?: boolean;
// save and restore library VMs after their first idle call
// save library VMs once their calls have warmed them up, and restore them on later starts
warmSnapshot?: boolean;
// log VM events (snapshots, missing natives) to the console, as --debug does under Node
debug?: boolean;
// where java-web.js, the worker and jdk/ live; defaults to the script's directory
runtime?: string;
// receives output instead of the page console element
Expand Down Expand Up @@ -180,7 +182,7 @@ export function cheerpjInit(options: InitOptions = {}): Promise<void> {
};
});
natives = options.natives ?? {};
send({ type: "init", runtime, app: appBase, props, hostName: options.hostName, env, localeData: !!options.localeData, warmSnapshot: !!options.warmSnapshot, natives: Object.keys(natives), progress: !!options.preloadProgress });
send({ type: "init", runtime, app: appBase, props, hostName: options.hostName, env, localeData: !!options.localeData, warmSnapshot: !!options.warmSnapshot, debug: !!options.debug, natives: Object.keys(natives), progress: !!options.preloadProgress });
initStarted(ready);
return ready;
}
Expand Down
1 change: 1 addition & 0 deletions src/browser/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface InitMessage {
env: Record<string, string>;
localeData: boolean;
warmSnapshot: boolean;
debug: boolean;
// JNI names of natives the page implements
natives: string[];
// report the download of the runtime
Expand Down
1 change: 1 addition & 0 deletions src/browser/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ function newVm(classpath: string[], vmId: number, library = false): JVM {
stderr: (data) => post({ type: "out", fd: 2, data }, [data.buffer as ArrayBuffer]),
stdin: readStdin,
hostName: config!.hostName,
debug: config!.debug,
env: config!.env,
loadNativeLibrary,
fileClosed,
Expand Down
Loading
⌂ Proxy