diff --git a/docs/browser.md b/docs/browser.md index 89089cf..58a1e72 100644 --- a/docs/browser.md +++ b/docs/browser.md @@ -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 @@ -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. diff --git a/docs/node.md b/docs/node.md index 71cd8df..bb3e525 100644 --- a/docs/node.md +++ b/docs/node.md @@ -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. diff --git a/src/browser/api.ts b/src/browser/api.ts index 723ea3b..70711ec 100644 --- a/src/browser/api.ts +++ b/src/browser/api.ts @@ -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 @@ -180,7 +182,7 @@ export function cheerpjInit(options: InitOptions = {}): Promise { }; }); 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; } diff --git a/src/browser/protocol.ts b/src/browser/protocol.ts index 0c24ec5..f30b724 100644 --- a/src/browser/protocol.ts +++ b/src/browser/protocol.ts @@ -13,6 +13,7 @@ export interface InitMessage { env: Record; localeData: boolean; warmSnapshot: boolean; + debug: boolean; // JNI names of natives the page implements natives: string[]; // report the download of the runtime diff --git a/src/browser/worker.ts b/src/browser/worker.ts index 90dabd5..e2a3796 100644 --- a/src/browser/worker.ts +++ b/src/browser/worker.ts @@ -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,