virtual-machine 0.1.0 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/{chunk-5YNIY3JH.mjs → chunk-S3CJQKBH.mjs} +269 -17
- package/build/cli.js +333 -19
- package/build/index.d.ts +395 -10
- package/build/index.js +333 -19
- package/build/index.mjs +65 -3
- package/build/{riscv_vm-HI4USQXV.mjs → riscv_vm-B3MWUK6W.mjs} +3 -1
- package/build/worker.js +19 -18
- package/native/riscv-vm-native.darwin-arm64.node +0 -0
- package/native/riscv-vm-native.darwin-x64.node +0 -0
- package/native/riscv-vm-native.linux-arm64-gnu.node +0 -0
- package/native/riscv-vm-native.linux-arm64-musl.node +0 -0
- package/native/riscv-vm-native.linux-x64-gnu.node +0 -0
- package/native/riscv-vm-native.linux-x64-musl.node +0 -0
- package/native/riscv-vm-native.win32-x64-msvc.node +0 -0
- package/package.json +6 -1
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
|
|
4
|
+
declare class JitWorkerContext {
|
|
5
|
+
free(): void;
|
|
6
|
+
[Symbol.dispose](): void;
|
|
7
|
+
/**
|
|
8
|
+
* Create a new JIT worker context with custom configuration.
|
|
9
|
+
*
|
|
10
|
+
* # Arguments
|
|
11
|
+
* * `min_block_size` - Minimum number of instructions for JIT compilation
|
|
12
|
+
* * `debug_wat` - Enable debug WAT output
|
|
13
|
+
*/
|
|
14
|
+
static newWithConfig(min_block_size: number, debug_wat: boolean): JitWorkerContext;
|
|
15
|
+
/**
|
|
16
|
+
* Create a new JIT worker context with default configuration.
|
|
17
|
+
*/
|
|
18
|
+
constructor();
|
|
19
|
+
/**
|
|
20
|
+
* Compile a block from serialized request bytes.
|
|
21
|
+
*
|
|
22
|
+
* # Arguments
|
|
23
|
+
* * `request_bytes` - Bincode-serialized `CompileRequest`
|
|
24
|
+
*
|
|
25
|
+
* # Returns
|
|
26
|
+
* A JavaScript object with the compilation result:
|
|
27
|
+
* - On success: `{ success: true, pc: number, wasmBytes: Uint8Array }`
|
|
28
|
+
* - On unsuitable: `{ success: false, pc: number, status: 'unsuitable' }`
|
|
29
|
+
* - On error: `{ success: false, pc: number, status: 'error' }`
|
|
30
|
+
*/
|
|
31
|
+
compile(request_bytes: Uint8Array): any;
|
|
32
|
+
}
|
|
33
|
+
|
|
4
34
|
/**
|
|
5
35
|
* Network connection status for the WASM VM.
|
|
6
36
|
*/
|
|
@@ -16,7 +46,7 @@ declare class WasmVm {
|
|
|
16
46
|
[Symbol.dispose](): void;
|
|
17
47
|
/**
|
|
18
48
|
* Get a byte from the UART output buffer, if available.
|
|
19
|
-
*
|
|
49
|
+
*
|
|
20
50
|
* In SMP mode, this checks both the shared UART output buffer (for worker output)
|
|
21
51
|
* and the local UART buffer (for hart 0 output).
|
|
22
52
|
*/
|
|
@@ -30,6 +60,18 @@ declare class WasmVm {
|
|
|
30
60
|
* Print a status message to UART output (visible in browser).
|
|
31
61
|
*/
|
|
32
62
|
print_status(message: string): void;
|
|
63
|
+
/**
|
|
64
|
+
* Re-enable JIT after it was disabled by errors.
|
|
65
|
+
*/
|
|
66
|
+
reenableJit(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Get JIT statistics as JSON string.
|
|
69
|
+
*/
|
|
70
|
+
getJitStats(): string;
|
|
71
|
+
/**
|
|
72
|
+
* Enable or disable JIT debug WAT output.
|
|
73
|
+
*/
|
|
74
|
+
setJitDebug(debug: boolean): void;
|
|
33
75
|
/**
|
|
34
76
|
* Start worker threads for secondary harts (1..num_harts).
|
|
35
77
|
*
|
|
@@ -40,6 +82,14 @@ declare class WasmVm {
|
|
|
40
82
|
* * `worker_url` - URL to the worker script (e.g., "/worker.js")
|
|
41
83
|
*/
|
|
42
84
|
start_workers(worker_url: string): void;
|
|
85
|
+
/**
|
|
86
|
+
* Dump recent JIT trace events to console.
|
|
87
|
+
*/
|
|
88
|
+
dumpJitTrace(count?: number | null): void;
|
|
89
|
+
/**
|
|
90
|
+
* Check if JIT is currently enabled.
|
|
91
|
+
*/
|
|
92
|
+
isJitEnabled(): boolean;
|
|
43
93
|
/**
|
|
44
94
|
* Get the current network connection status.
|
|
45
95
|
* This checks the actual connection state by seeing if an IP was assigned.
|
|
@@ -53,15 +103,39 @@ declare class WasmVm {
|
|
|
53
103
|
* * `num_harts` - Number of harts (0 = auto-detect)
|
|
54
104
|
*/
|
|
55
105
|
static new_with_harts(kernel: Uint8Array, num_harts: number): WasmVm;
|
|
106
|
+
/**
|
|
107
|
+
* Clear JIT cache.
|
|
108
|
+
*/
|
|
109
|
+
clearJitCache(): void;
|
|
110
|
+
/**
|
|
111
|
+
* Enable or disable JIT compilation.
|
|
112
|
+
*/
|
|
113
|
+
setJitEnabled(enabled: boolean): void;
|
|
114
|
+
/**
|
|
115
|
+
* Enable or disable JIT execution tracing.
|
|
116
|
+
*/
|
|
117
|
+
setJitTracing(enabled: boolean): void;
|
|
56
118
|
/**
|
|
57
119
|
* Get current memory usage (DRAM size) in bytes.
|
|
58
120
|
*/
|
|
59
121
|
get_memory_usage(): bigint;
|
|
122
|
+
/**
|
|
123
|
+
* Reset all JIT error tracking.
|
|
124
|
+
*/
|
|
125
|
+
resetJitErrors(): void;
|
|
126
|
+
/**
|
|
127
|
+
* Get current JIT compilation threshold.
|
|
128
|
+
*/
|
|
129
|
+
getJitThreshold(): number;
|
|
60
130
|
/**
|
|
61
131
|
* Get the SharedArrayBuffer for external worker management.
|
|
62
132
|
* Returns None if not in SMP mode.
|
|
63
133
|
*/
|
|
64
134
|
get_shared_buffer(): SharedArrayBuffer | undefined;
|
|
135
|
+
/**
|
|
136
|
+
* Set JIT compilation threshold (min exec_count before compiling).
|
|
137
|
+
*/
|
|
138
|
+
setJitThreshold(threshold: number): void;
|
|
65
139
|
/**
|
|
66
140
|
* Terminate all workers.
|
|
67
141
|
*/
|
|
@@ -70,6 +144,22 @@ declare class WasmVm {
|
|
|
70
144
|
* Disconnect from the network.
|
|
71
145
|
*/
|
|
72
146
|
disconnect_network(): void;
|
|
147
|
+
/**
|
|
148
|
+
* Get number of cached JIT blocks.
|
|
149
|
+
*/
|
|
150
|
+
getJitCacheSize(): number;
|
|
151
|
+
/**
|
|
152
|
+
* Add a PC to the JIT blacklist.
|
|
153
|
+
*/
|
|
154
|
+
blacklistJitBlock(pc: bigint): void;
|
|
155
|
+
/**
|
|
156
|
+
* Clear the JIT blacklist.
|
|
157
|
+
*/
|
|
158
|
+
clearJitBlacklist(): void;
|
|
159
|
+
/**
|
|
160
|
+
* Get JIT diagnostics as JSON string.
|
|
161
|
+
*/
|
|
162
|
+
getJitDiagnostics(): string;
|
|
73
163
|
/**
|
|
74
164
|
* Check how many bytes are pending in the UART output buffer.
|
|
75
165
|
* Useful for debugging output issues.
|
|
@@ -85,6 +175,10 @@ declare class WasmVm {
|
|
|
85
175
|
* Called from JavaScript when the native WebTransport addon receives a packet.
|
|
86
176
|
*/
|
|
87
177
|
inject_network_packet(packet: Uint8Array): boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Enable TLB fast-path optimization.
|
|
180
|
+
*/
|
|
181
|
+
setJitTlbFastPath(enabled: boolean): void;
|
|
88
182
|
/**
|
|
89
183
|
* Signal that workers can start executing.
|
|
90
184
|
* Called by the main thread after hart 0 has finished initializing
|
|
@@ -96,19 +190,44 @@ declare class WasmVm {
|
|
|
96
190
|
* Returns the packet data or null if no packet is pending.
|
|
97
191
|
*/
|
|
98
192
|
extract_network_packet(): Uint8Array | undefined;
|
|
193
|
+
/**
|
|
194
|
+
* Check if JIT tracing is enabled.
|
|
195
|
+
*/
|
|
196
|
+
isJitTracingEnabled(): boolean;
|
|
197
|
+
/**
|
|
198
|
+
* Set maximum block size for JIT compilation.
|
|
199
|
+
*/
|
|
200
|
+
setJitMaxBlockSize(size: number): void;
|
|
99
201
|
/**
|
|
100
202
|
* Set up an external network backend for packet bridging.
|
|
101
203
|
* This is used by the Node.js CLI to bridge packets between the native
|
|
102
204
|
* WebTransport addon and the WASM VM.
|
|
103
|
-
*
|
|
205
|
+
*
|
|
104
206
|
* @param mac_bytes - MAC address as 6 bytes [0x52, 0x54, 0x00, 0x12, 0x34, 0x56]
|
|
105
207
|
*/
|
|
106
208
|
setup_external_network(mac_bytes: Uint8Array): void;
|
|
209
|
+
/**
|
|
210
|
+
* Get JIT cache hit ratio.
|
|
211
|
+
*/
|
|
212
|
+
getJitCacheHitRatio(): number;
|
|
213
|
+
/**
|
|
214
|
+
* Get JIT execution ratio (JIT executions / total executions).
|
|
215
|
+
* Calculated from CPU's block cache statistics.
|
|
216
|
+
*/
|
|
217
|
+
getJitExecutionRatio(): number;
|
|
218
|
+
/**
|
|
219
|
+
* Invalidate JIT cache for a specific address.
|
|
220
|
+
*/
|
|
221
|
+
invalidateJitCacheAt(pc: bigint): boolean;
|
|
107
222
|
/**
|
|
108
223
|
* Set the assigned IP address for the external network.
|
|
109
224
|
* Called when the native WebTransport addon receives an IP assignment.
|
|
110
225
|
*/
|
|
111
226
|
set_external_network_ip(ip_bytes: Uint8Array): boolean;
|
|
227
|
+
/**
|
|
228
|
+
* Get JIT cache memory usage in bytes.
|
|
229
|
+
*/
|
|
230
|
+
getJitCacheMemoryUsage(): number;
|
|
112
231
|
/**
|
|
113
232
|
* Get the number of pending RX packets.
|
|
114
233
|
*/
|
|
@@ -126,6 +245,10 @@ declare class WasmVm {
|
|
|
126
245
|
* Check if external network is connected (has IP assigned).
|
|
127
246
|
*/
|
|
128
247
|
is_external_network_connected(): boolean;
|
|
248
|
+
/**
|
|
249
|
+
* Set interrupt check interval (0 = disabled).
|
|
250
|
+
*/
|
|
251
|
+
setJitInterruptCheckInterval(interval: number): void;
|
|
129
252
|
/**
|
|
130
253
|
* Create a new VM instance and load a kernel (ELF or raw binary).
|
|
131
254
|
*
|
|
@@ -191,7 +314,7 @@ declare class WorkerState {
|
|
|
191
314
|
[Symbol.dispose](): void;
|
|
192
315
|
/**
|
|
193
316
|
* Execute a batch of instructions and return.
|
|
194
|
-
*
|
|
317
|
+
*
|
|
195
318
|
* This is designed to be called repeatedly from JavaScript, allowing
|
|
196
319
|
* the event loop to yield between batches. This prevents the worker
|
|
197
320
|
* from blocking indefinitely and allows it to respond to messages.
|
|
@@ -251,7 +374,7 @@ declare function worker_check_interrupts(hart_id: number, shared_mem: any): bigi
|
|
|
251
374
|
|
|
252
375
|
/**
|
|
253
376
|
* Legacy worker entry point - DEPRECATED.
|
|
254
|
-
*
|
|
377
|
+
*
|
|
255
378
|
* This function runs a blocking infinite loop. Use WorkerState + step_batch instead
|
|
256
379
|
* for cooperative scheduling that doesn't block the worker's event loop.
|
|
257
380
|
*/
|
|
@@ -261,22 +384,39 @@ type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Modul
|
|
|
261
384
|
|
|
262
385
|
interface InitOutput {
|
|
263
386
|
readonly memory: WebAssembly.Memory;
|
|
387
|
+
readonly __wbg_jitworkercontext_free: (a: number, b: number) => void;
|
|
264
388
|
readonly __wbg_wasmvm_free: (a: number, b: number) => void;
|
|
265
389
|
readonly __wbg_workerstate_free: (a: number, b: number) => void;
|
|
390
|
+
readonly jitworkercontext_compile: (a: number, b: number, c: number) => any;
|
|
391
|
+
readonly jitworkercontext_new: () => number;
|
|
392
|
+
readonly jitworkercontext_newWithConfig: (a: number, b: number) => number;
|
|
266
393
|
readonly wasmvm_allow_workers_to_start: (a: number) => void;
|
|
394
|
+
readonly wasmvm_blacklistJitBlock: (a: number, b: bigint) => void;
|
|
395
|
+
readonly wasmvm_clearJitBlacklist: (a: number) => void;
|
|
396
|
+
readonly wasmvm_clearJitCache: (a: number) => void;
|
|
267
397
|
readonly wasmvm_connect_webtransport: (a: number, b: number, c: number, d: number, e: number) => [number, number];
|
|
268
398
|
readonly wasmvm_disconnect_network: (a: number) => void;
|
|
399
|
+
readonly wasmvm_dumpJitTrace: (a: number, b: number) => void;
|
|
269
400
|
readonly wasmvm_entry_pc: (a: number) => bigint;
|
|
270
401
|
readonly wasmvm_external_network_rx_pending: (a: number) => number;
|
|
271
402
|
readonly wasmvm_external_network_tx_pending: (a: number) => number;
|
|
272
403
|
readonly wasmvm_extract_all_network_packets: (a: number) => any;
|
|
273
404
|
readonly wasmvm_extract_network_packet: (a: number) => any;
|
|
405
|
+
readonly wasmvm_getJitCacheHitRatio: (a: number) => number;
|
|
406
|
+
readonly wasmvm_getJitCacheMemoryUsage: (a: number) => number;
|
|
407
|
+
readonly wasmvm_getJitCacheSize: (a: number) => number;
|
|
408
|
+
readonly wasmvm_getJitDiagnostics: (a: number) => [number, number];
|
|
409
|
+
readonly wasmvm_getJitStats: (a: number) => [number, number];
|
|
410
|
+
readonly wasmvm_getJitThreshold: (a: number) => number;
|
|
274
411
|
readonly wasmvm_get_memory_usage: (a: number) => bigint;
|
|
275
412
|
readonly wasmvm_get_output: (a: number) => number;
|
|
276
413
|
readonly wasmvm_get_shared_buffer: (a: number) => any;
|
|
277
414
|
readonly wasmvm_halt_code: (a: number) => bigint;
|
|
278
415
|
readonly wasmvm_inject_network_packet: (a: number, b: any) => number;
|
|
279
416
|
readonly wasmvm_input: (a: number, b: number) => void;
|
|
417
|
+
readonly wasmvm_invalidateJitCacheAt: (a: number, b: bigint) => number;
|
|
418
|
+
readonly wasmvm_isJitEnabled: (a: number) => number;
|
|
419
|
+
readonly wasmvm_isJitTracingEnabled: (a: number) => number;
|
|
280
420
|
readonly wasmvm_is_external_network_connected: (a: number) => number;
|
|
281
421
|
readonly wasmvm_is_halted: (a: number) => number;
|
|
282
422
|
readonly wasmvm_is_smp: (a: number) => number;
|
|
@@ -287,6 +427,15 @@ interface InitOutput {
|
|
|
287
427
|
readonly wasmvm_num_harts: (a: number) => number;
|
|
288
428
|
readonly wasmvm_print_banner: (a: number) => void;
|
|
289
429
|
readonly wasmvm_print_status: (a: number, b: number, c: number) => void;
|
|
430
|
+
readonly wasmvm_reenableJit: (a: number) => void;
|
|
431
|
+
readonly wasmvm_resetJitErrors: (a: number) => void;
|
|
432
|
+
readonly wasmvm_setJitDebug: (a: number, b: number) => void;
|
|
433
|
+
readonly wasmvm_setJitEnabled: (a: number, b: number) => void;
|
|
434
|
+
readonly wasmvm_setJitInterruptCheckInterval: (a: number, b: number) => void;
|
|
435
|
+
readonly wasmvm_setJitMaxBlockSize: (a: number, b: number) => void;
|
|
436
|
+
readonly wasmvm_setJitThreshold: (a: number, b: number) => void;
|
|
437
|
+
readonly wasmvm_setJitTlbFastPath: (a: number, b: number) => void;
|
|
438
|
+
readonly wasmvm_setJitTracing: (a: number, b: number) => void;
|
|
290
439
|
readonly wasmvm_set_external_network_ip: (a: number, b: any) => number;
|
|
291
440
|
readonly wasmvm_setup_external_network: (a: number, b: any) => [number, number];
|
|
292
441
|
readonly wasmvm_start_workers: (a: number, b: number, c: number) => [number, number];
|
|
@@ -300,12 +449,13 @@ interface InitOutput {
|
|
|
300
449
|
readonly workerstate_new: (a: number, b: any, c: bigint) => number;
|
|
301
450
|
readonly workerstate_step_batch: (a: number, b: number) => number;
|
|
302
451
|
readonly workerstate_step_count: (a: number) => bigint;
|
|
303
|
-
readonly
|
|
304
|
-
readonly
|
|
305
|
-
readonly
|
|
306
|
-
readonly
|
|
452
|
+
readonly wasmvm_getJitExecutionRatio: (a: number) => number;
|
|
453
|
+
readonly wasm_bindgen__convert__closures_____invoke__ha9a06e4d93c772bf: (a: number, b: number) => void;
|
|
454
|
+
readonly wasm_bindgen__closure__destroy__h1292c9e7657b72ef: (a: number, b: number) => void;
|
|
455
|
+
readonly wasm_bindgen__convert__closures_____invoke__h3eb569f20d255f19: (a: number, b: number) => void;
|
|
307
456
|
readonly wasm_bindgen__convert__closures_____invoke__h39d3e89751b07765: (a: number, b: number, c: any) => void;
|
|
308
457
|
readonly wasm_bindgen__closure__destroy__hf225e18fc5ab9bc1: (a: number, b: number) => void;
|
|
458
|
+
readonly wasm_bindgen__convert__closures_____invoke__h320e929207365995: (a: number, b: number, c: any) => void;
|
|
309
459
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
310
460
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
311
461
|
readonly __wbindgen_exn_store: (a: number) => void;
|
|
@@ -340,6 +490,8 @@ declare function __wbg_init (module_or_path?: { module_or_path: InitInput | Prom
|
|
|
340
490
|
|
|
341
491
|
type __pkg_riscv_vm_InitInput = InitInput;
|
|
342
492
|
type __pkg_riscv_vm_InitOutput = InitOutput;
|
|
493
|
+
type __pkg_riscv_vm_JitWorkerContext = JitWorkerContext;
|
|
494
|
+
declare const __pkg_riscv_vm_JitWorkerContext: typeof JitWorkerContext;
|
|
343
495
|
type __pkg_riscv_vm_NetworkStatus = NetworkStatus;
|
|
344
496
|
declare const __pkg_riscv_vm_NetworkStatus: typeof NetworkStatus;
|
|
345
497
|
type __pkg_riscv_vm_SyncInitInput = SyncInitInput;
|
|
@@ -353,7 +505,7 @@ declare const __pkg_riscv_vm_initSync: typeof initSync;
|
|
|
353
505
|
declare const __pkg_riscv_vm_worker_check_interrupts: typeof worker_check_interrupts;
|
|
354
506
|
declare const __pkg_riscv_vm_worker_entry: typeof worker_entry;
|
|
355
507
|
declare namespace __pkg_riscv_vm {
|
|
356
|
-
export { type __pkg_riscv_vm_InitInput as InitInput, type __pkg_riscv_vm_InitOutput as InitOutput, __pkg_riscv_vm_NetworkStatus as NetworkStatus, type __pkg_riscv_vm_SyncInitInput as SyncInitInput, __pkg_riscv_vm_WasmVm as WasmVm, __pkg_riscv_vm_WorkerState as WorkerState, __pkg_riscv_vm_WorkerStepResult as WorkerStepResult, __wbg_init as default, __pkg_riscv_vm_initSync as initSync, __pkg_riscv_vm_worker_check_interrupts as worker_check_interrupts, __pkg_riscv_vm_worker_entry as worker_entry };
|
|
508
|
+
export { type __pkg_riscv_vm_InitInput as InitInput, type __pkg_riscv_vm_InitOutput as InitOutput, __pkg_riscv_vm_JitWorkerContext as JitWorkerContext, __pkg_riscv_vm_NetworkStatus as NetworkStatus, type __pkg_riscv_vm_SyncInitInput as SyncInitInput, __pkg_riscv_vm_WasmVm as WasmVm, __pkg_riscv_vm_WorkerState as WorkerState, __pkg_riscv_vm_WorkerStepResult as WorkerStepResult, __wbg_init as default, __pkg_riscv_vm_initSync as initSync, __pkg_riscv_vm_worker_check_interrupts as worker_check_interrupts, __pkg_riscv_vm_worker_entry as worker_entry };
|
|
357
509
|
}
|
|
358
510
|
|
|
359
511
|
/**
|
|
@@ -406,6 +558,209 @@ declare function isHalted(sharedMem: SharedArrayBuffer): boolean;
|
|
|
406
558
|
|
|
407
559
|
declare function WasmInternal(): Promise<typeof __pkg_riscv_vm>;
|
|
408
560
|
|
|
561
|
+
/**
|
|
562
|
+
* Message sent to JIT worker to request compilation.
|
|
563
|
+
*/
|
|
564
|
+
interface JitCompileRequest {
|
|
565
|
+
type: "compile";
|
|
566
|
+
/** Starting PC of the block */
|
|
567
|
+
pc: number;
|
|
568
|
+
/** Bincode-serialized CompileRequest bytes */
|
|
569
|
+
requestBytes: ArrayBuffer;
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
*
|
|
573
|
+
*
|
|
574
|
+
* Message received from JIT worker with compilation result.
|
|
575
|
+
*/
|
|
576
|
+
interface JitCompileResponse {
|
|
577
|
+
type: "compiled";
|
|
578
|
+
/** Starting PC of the compiled block */
|
|
579
|
+
pc: number;
|
|
580
|
+
/** Whether compilation succeeded */
|
|
581
|
+
success: boolean;
|
|
582
|
+
/** Compiled WASM bytes (if successful) */
|
|
583
|
+
wasmBytes?: Uint8Array;
|
|
584
|
+
/** Status if not successful */
|
|
585
|
+
status?: "unsuitable" | "error";
|
|
586
|
+
/** Compilation time in microseconds */
|
|
587
|
+
compileTimeUs?: number;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* JIT worker ready message.
|
|
591
|
+
*/
|
|
592
|
+
interface JitWorkerReadyMessage {
|
|
593
|
+
type: "ready";
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* JIT worker error message.
|
|
597
|
+
*/
|
|
598
|
+
interface JitWorkerErrorMessage {
|
|
599
|
+
type: "error";
|
|
600
|
+
message: string;
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* All possible JIT worker outbound messages.
|
|
604
|
+
*/
|
|
605
|
+
type JitWorkerOutboundMessage = JitCompileResponse | JitWorkerReadyMessage | JitWorkerErrorMessage;
|
|
606
|
+
/**
|
|
607
|
+
* All possible JIT worker inbound messages.
|
|
608
|
+
*/
|
|
609
|
+
type JitWorkerInboundMessage = JitCompileRequest;
|
|
610
|
+
/**
|
|
611
|
+
* Cache statistics from the JIT system.
|
|
612
|
+
*/
|
|
613
|
+
interface JitCacheStats {
|
|
614
|
+
/** Number of cache hits */
|
|
615
|
+
hits: number;
|
|
616
|
+
/** Number of cache misses */
|
|
617
|
+
misses: number;
|
|
618
|
+
/** Number of blocks inserted into cache */
|
|
619
|
+
insertions: number;
|
|
620
|
+
/** Number of blocks evicted from cache */
|
|
621
|
+
evictions: number;
|
|
622
|
+
/** Total bytes of WASM compiled */
|
|
623
|
+
bytesCompiled: number;
|
|
624
|
+
/** Number of cache invalidations */
|
|
625
|
+
invalidations: number;
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Execution trace statistics.
|
|
629
|
+
*/
|
|
630
|
+
interface JitTraceStats {
|
|
631
|
+
/** Number of JIT block executions */
|
|
632
|
+
jitExecutions: number;
|
|
633
|
+
/** Number of interpreter block executions */
|
|
634
|
+
interpExecutions: number;
|
|
635
|
+
/** Number of successful compilations */
|
|
636
|
+
compilations: number;
|
|
637
|
+
/** Number of failed compilations */
|
|
638
|
+
compilationFailures: number;
|
|
639
|
+
/** Total WASM bytes compiled */
|
|
640
|
+
totalWasmBytes: number;
|
|
641
|
+
/** Total compilation time in microseconds */
|
|
642
|
+
totalCompileTimeUs: number;
|
|
643
|
+
/** Number of traps during JIT execution */
|
|
644
|
+
traps: number;
|
|
645
|
+
/** Number of cache invalidations */
|
|
646
|
+
invalidations: number;
|
|
647
|
+
/** Number of cache hits */
|
|
648
|
+
cacheHits: number;
|
|
649
|
+
/** Number of cache misses */
|
|
650
|
+
cacheMisses: number;
|
|
651
|
+
/** Number of interrupt-triggered exits */
|
|
652
|
+
interruptExits: number;
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* Complete JIT diagnostics information.
|
|
656
|
+
*/
|
|
657
|
+
interface JitDiagnostics {
|
|
658
|
+
/** Whether JIT is currently enabled and operational */
|
|
659
|
+
enabled: boolean;
|
|
660
|
+
/** Whether JIT was disabled due to errors */
|
|
661
|
+
disabledByError: boolean;
|
|
662
|
+
/** Reason JIT was disabled (if applicable) */
|
|
663
|
+
disabledReason: string | null;
|
|
664
|
+
/** Number of consecutive compilation failures */
|
|
665
|
+
consecutiveFailures: number;
|
|
666
|
+
/** Total number of compilation failures */
|
|
667
|
+
totalFailures: number;
|
|
668
|
+
/** Total number of successful compilations */
|
|
669
|
+
successfulCompilations: number;
|
|
670
|
+
/** Number of blocks that failed to compile (blacklisted) */
|
|
671
|
+
failedBlocksCount: number;
|
|
672
|
+
/** Number of blocks currently in cache */
|
|
673
|
+
cacheEntries: number;
|
|
674
|
+
/** Current cache memory usage in bytes */
|
|
675
|
+
cacheBytes: number;
|
|
676
|
+
/** Cache statistics */
|
|
677
|
+
cacheStats: JitCacheStats;
|
|
678
|
+
/** Trace statistics */
|
|
679
|
+
traceStats: JitTraceStats;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* JIT configuration options.
|
|
683
|
+
*/
|
|
684
|
+
interface JitConfig {
|
|
685
|
+
/** Enable JIT compilation (default: true) */
|
|
686
|
+
enabled?: boolean;
|
|
687
|
+
/** Minimum execution count before compiling (default: 50) */
|
|
688
|
+
compileThreshold?: number;
|
|
689
|
+
/** Maximum block size in ops (default: 256) */
|
|
690
|
+
maxBlockSize?: number;
|
|
691
|
+
/** Maximum WASM module size in bytes (default: 65536) */
|
|
692
|
+
maxWasmSize?: number;
|
|
693
|
+
/** Maximum cache entries (default: 1024) */
|
|
694
|
+
cacheMaxEntries?: number;
|
|
695
|
+
/** Maximum cache size in bytes (default: 16MB) */
|
|
696
|
+
cacheMaxBytes?: number;
|
|
697
|
+
/** Enable debug WAT output to console (default: false) */
|
|
698
|
+
debugWat?: boolean;
|
|
699
|
+
/** Enable execution tracing (default: false) */
|
|
700
|
+
traceEnabled?: boolean;
|
|
701
|
+
/** Compilation timeout in ms (default: 100, 0=no timeout) */
|
|
702
|
+
compileTimeoutMs?: number;
|
|
703
|
+
/** Max consecutive failures before disabling (default: 10) */
|
|
704
|
+
maxConsecutiveFailures?: number;
|
|
705
|
+
/** Enable TLB fast-path optimization (default: false) */
|
|
706
|
+
enableTlbFastPath?: boolean;
|
|
707
|
+
/** Interrupt check interval in ops (default: 32, 0=disabled) */
|
|
708
|
+
interruptCheckInterval?: number;
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* Extended WasmVm interface with JIT methods.
|
|
712
|
+
*
|
|
713
|
+
* This interface extends the base WasmVm class exported from the WASM module
|
|
714
|
+
* with type definitions for all JIT-related methods.
|
|
715
|
+
*/
|
|
716
|
+
interface WasmVmJitMethods {
|
|
717
|
+
/** Enable or disable JIT compilation */
|
|
718
|
+
setJitEnabled(enabled: boolean): void;
|
|
719
|
+
/** Check if JIT is currently enabled and operational */
|
|
720
|
+
isJitEnabled(): boolean;
|
|
721
|
+
/** Re-enable JIT after it was disabled by errors */
|
|
722
|
+
reenableJit(): void;
|
|
723
|
+
/** Enable/disable JIT debug WAT output to console */
|
|
724
|
+
setJitDebug(debug: boolean): void;
|
|
725
|
+
/** Enable/disable JIT execution tracing */
|
|
726
|
+
setJitTracing(enabled: boolean): void;
|
|
727
|
+
/** Check if JIT tracing is enabled */
|
|
728
|
+
isJitTracingEnabled(): boolean;
|
|
729
|
+
/** Get JIT diagnostics as JSON string */
|
|
730
|
+
getJitDiagnostics(): string;
|
|
731
|
+
/** Get JIT statistics as JSON string */
|
|
732
|
+
getJitStats(): string;
|
|
733
|
+
/** Dump recent JIT trace events to console */
|
|
734
|
+
dumpJitTrace(count?: number): void;
|
|
735
|
+
/** Clear all entries from JIT cache */
|
|
736
|
+
clearJitCache(): void;
|
|
737
|
+
/** Invalidate JIT cache for a specific PC */
|
|
738
|
+
invalidateJitCacheAt(pc: bigint): boolean;
|
|
739
|
+
/** Get number of cached JIT blocks */
|
|
740
|
+
getJitCacheSize(): number;
|
|
741
|
+
/** Get JIT cache memory usage in bytes */
|
|
742
|
+
getJitCacheMemoryUsage(): number;
|
|
743
|
+
/** Set JIT compilation threshold */
|
|
744
|
+
setJitThreshold(threshold: number): void;
|
|
745
|
+
/** Get current JIT compilation threshold */
|
|
746
|
+
getJitThreshold(): number;
|
|
747
|
+
/** Set maximum block size for JIT compilation */
|
|
748
|
+
setJitMaxBlockSize(size: number): void;
|
|
749
|
+
/** Add a PC to the JIT blacklist */
|
|
750
|
+
blacklistJitBlock(pc: bigint): void;
|
|
751
|
+
/** Clear the JIT blacklist */
|
|
752
|
+
clearJitBlacklist(): void;
|
|
753
|
+
/** Reset all JIT error tracking */
|
|
754
|
+
resetJitErrors(): void;
|
|
755
|
+
/** Enable TLB fast-path optimization */
|
|
756
|
+
setJitTlbFastPath(enabled: boolean): void;
|
|
757
|
+
/** Set interrupt check interval (0 = disabled) */
|
|
758
|
+
setJitInterruptCheckInterval(interval: number): void;
|
|
759
|
+
/** Get JIT execution ratio (0.0 to 1.0) */
|
|
760
|
+
getJitExecutionRatio(): number;
|
|
761
|
+
/** Get JIT cache hit ratio (0.0 to 1.0) */
|
|
762
|
+
getJitCacheHitRatio(): number;
|
|
763
|
+
}
|
|
409
764
|
interface VmOptions {
|
|
410
765
|
/** Number of harts (auto-detected if not specified) */
|
|
411
766
|
harts?: number;
|
|
@@ -493,5 +848,35 @@ interface WorkerManager {
|
|
|
493
848
|
* Create a worker manager for manual worker control.
|
|
494
849
|
*/
|
|
495
850
|
declare function createWorkerManager(): WorkerManager;
|
|
851
|
+
/**
|
|
852
|
+
* Parse JIT diagnostics from the VM.
|
|
853
|
+
*
|
|
854
|
+
* @param vm - WasmVm instance with JIT methods
|
|
855
|
+
* @returns Parsed JIT diagnostics object
|
|
856
|
+
*/
|
|
857
|
+
declare function parseJitDiagnostics(vm: WasmVmJitMethods): JitDiagnostics;
|
|
858
|
+
/**
|
|
859
|
+
* Parse JIT trace statistics from the VM.
|
|
860
|
+
*
|
|
861
|
+
* @param vm - WasmVm instance with JIT methods
|
|
862
|
+
* @returns Parsed JIT trace statistics object
|
|
863
|
+
*/
|
|
864
|
+
declare function parseJitStats(vm: WasmVmJitMethods): JitTraceStats;
|
|
865
|
+
/**
|
|
866
|
+
* Configure JIT with a partial configuration object.
|
|
867
|
+
*
|
|
868
|
+
* @param vm - WasmVm instance with JIT methods
|
|
869
|
+
* @param config - Partial JIT configuration
|
|
870
|
+
*/
|
|
871
|
+
declare function configureJit(vm: WasmVmJitMethods, config: JitConfig): void;
|
|
872
|
+
/**
|
|
873
|
+
* Print JIT diagnostic summary to console.
|
|
874
|
+
*
|
|
875
|
+
* Displays a formatted summary of JIT status, compilations,
|
|
876
|
+
* cache statistics, and hit ratios.
|
|
877
|
+
*
|
|
878
|
+
* @param vm - WasmVm instance with JIT methods
|
|
879
|
+
*/
|
|
880
|
+
declare function printJitSummary(vm: WasmVmJitMethods): void;
|
|
496
881
|
|
|
497
|
-
export { NetworkStatus, REQUIRED_HEADERS, type SharedMemorySupport, type VmOptions, WasmInternal, WasmVm, type WorkerErrorMessage, type WorkerHaltedMessage, type WorkerInitMessage, type WorkerManager, type WorkerOutboundMessage, type WorkerReadyMessage, checkSharedMemorySupport, createVM, createWorkerManager, isCrossOriginIsolated, isHaltRequested, isHalted, requestHalt, runVM };
|
|
882
|
+
export { type JitCacheStats, type JitCompileRequest, type JitCompileResponse, type JitConfig, type JitDiagnostics, type JitTraceStats, type JitWorkerErrorMessage, type JitWorkerInboundMessage, type JitWorkerOutboundMessage, type JitWorkerReadyMessage, NetworkStatus, REQUIRED_HEADERS, type SharedMemorySupport, type VmOptions, WasmInternal, WasmVm, type WasmVmJitMethods, type WorkerErrorMessage, type WorkerHaltedMessage, type WorkerInitMessage, type WorkerManager, type WorkerOutboundMessage, type WorkerReadyMessage, checkSharedMemorySupport, configureJit, createVM, createWorkerManager, isCrossOriginIsolated, isHaltRequested, isHalted, parseJitDiagnostics, parseJitStats, printJitSummary, requestHalt, runVM };
|