virtual-machine 0.0.37 → 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.
@@ -206,25 +206,91 @@ if (!("encodeInto" in cachedTextEncoder)) {
206
206
  };
207
207
  }
208
208
  var WASM_VECTOR_LEN = 0;
209
- function wasm_bindgen__convert__closures_____invoke__h633c7630e96bf7ba(arg0, arg1) {
210
- wasm.wasm_bindgen__convert__closures_____invoke__h633c7630e96bf7ba(arg0, arg1);
209
+ function wasm_bindgen__convert__closures_____invoke__ha9a06e4d93c772bf(arg0, arg1) {
210
+ wasm.wasm_bindgen__convert__closures_____invoke__ha9a06e4d93c772bf(arg0, arg1);
211
211
  }
212
- function wasm_bindgen__convert__closures_____invoke__h1ead60eaa5163c89(arg0, arg1) {
213
- wasm.wasm_bindgen__convert__closures_____invoke__h1ead60eaa5163c89(arg0, arg1);
212
+ function wasm_bindgen__convert__closures_____invoke__h3eb569f20d255f19(arg0, arg1) {
213
+ wasm.wasm_bindgen__convert__closures_____invoke__h3eb569f20d255f19(arg0, arg1);
214
214
  }
215
215
  function wasm_bindgen__convert__closures_____invoke__h39d3e89751b07765(arg0, arg1, arg2) {
216
216
  wasm.wasm_bindgen__convert__closures_____invoke__h39d3e89751b07765(arg0, arg1, arg2);
217
217
  }
218
- function wasm_bindgen__convert__closures_____invoke__hcefed207e507b803(arg0, arg1, arg2) {
219
- wasm.wasm_bindgen__convert__closures_____invoke__hcefed207e507b803(arg0, arg1, arg2);
218
+ function wasm_bindgen__convert__closures_____invoke__h320e929207365995(arg0, arg1, arg2) {
219
+ wasm.wasm_bindgen__convert__closures_____invoke__h320e929207365995(arg0, arg1, arg2);
220
220
  }
221
221
  var __wbindgen_enum_WorkerType = ["classic", "module"];
222
+ var JitWorkerContextFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
223
+ }, unregister: () => {
224
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_jitworkercontext_free(ptr >>> 0, 1));
222
225
  var WasmVmFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
223
226
  }, unregister: () => {
224
227
  } } : new FinalizationRegistry((ptr) => wasm.__wbg_wasmvm_free(ptr >>> 0, 1));
225
228
  var WorkerStateFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
226
229
  }, unregister: () => {
227
230
  } } : new FinalizationRegistry((ptr) => wasm.__wbg_workerstate_free(ptr >>> 0, 1));
231
+ var JitWorkerContext = class _JitWorkerContext {
232
+ static __wrap(ptr) {
233
+ ptr = ptr >>> 0;
234
+ const obj = Object.create(_JitWorkerContext.prototype);
235
+ obj.__wbg_ptr = ptr;
236
+ JitWorkerContextFinalization.register(obj, obj.__wbg_ptr, obj);
237
+ return obj;
238
+ }
239
+ __destroy_into_raw() {
240
+ const ptr = this.__wbg_ptr;
241
+ this.__wbg_ptr = 0;
242
+ JitWorkerContextFinalization.unregister(this);
243
+ return ptr;
244
+ }
245
+ free() {
246
+ const ptr = this.__destroy_into_raw();
247
+ wasm.__wbg_jitworkercontext_free(ptr, 0);
248
+ }
249
+ /**
250
+ * Create a new JIT worker context with custom configuration.
251
+ *
252
+ * # Arguments
253
+ * * `min_block_size` - Minimum number of instructions for JIT compilation
254
+ * * `debug_wat` - Enable debug WAT output
255
+ * @param {number} min_block_size
256
+ * @param {boolean} debug_wat
257
+ * @returns {JitWorkerContext}
258
+ */
259
+ static newWithConfig(min_block_size, debug_wat) {
260
+ const ret = wasm.jitworkercontext_newWithConfig(min_block_size, debug_wat);
261
+ return _JitWorkerContext.__wrap(ret);
262
+ }
263
+ /**
264
+ * Create a new JIT worker context with default configuration.
265
+ */
266
+ constructor() {
267
+ const ret = wasm.jitworkercontext_new();
268
+ this.__wbg_ptr = ret >>> 0;
269
+ JitWorkerContextFinalization.register(this, this.__wbg_ptr, this);
270
+ return this;
271
+ }
272
+ /**
273
+ * Compile a block from serialized request bytes.
274
+ *
275
+ * # Arguments
276
+ * * `request_bytes` - Bincode-serialized `CompileRequest`
277
+ *
278
+ * # Returns
279
+ * A JavaScript object with the compilation result:
280
+ * - On success: `{ success: true, pc: number, wasmBytes: Uint8Array }`
281
+ * - On unsuitable: `{ success: false, pc: number, status: 'unsuitable' }`
282
+ * - On error: `{ success: false, pc: number, status: 'error' }`
283
+ * @param {Uint8Array} request_bytes
284
+ * @returns {any}
285
+ */
286
+ compile(request_bytes) {
287
+ const ptr0 = passArray8ToWasm0(request_bytes, wasm.__wbindgen_malloc);
288
+ const len0 = WASM_VECTOR_LEN;
289
+ const ret = wasm.jitworkercontext_compile(this.__wbg_ptr, ptr0, len0);
290
+ return ret;
291
+ }
292
+ };
293
+ if (Symbol.dispose) JitWorkerContext.prototype[Symbol.dispose] = JitWorkerContext.prototype.free;
228
294
  var NetworkStatus = Object.freeze({
229
295
  Disconnected: 0,
230
296
  "0": "Disconnected",
@@ -280,6 +346,35 @@ var WasmVm = class _WasmVm {
280
346
  const len0 = WASM_VECTOR_LEN;
281
347
  wasm.wasmvm_print_status(this.__wbg_ptr, ptr0, len0);
282
348
  }
349
+ /**
350
+ * Re-enable JIT after it was disabled by errors.
351
+ */
352
+ reenableJit() {
353
+ wasm.wasmvm_reenableJit(this.__wbg_ptr);
354
+ }
355
+ /**
356
+ * Get JIT statistics as JSON string.
357
+ * @returns {string}
358
+ */
359
+ getJitStats() {
360
+ let deferred1_0;
361
+ let deferred1_1;
362
+ try {
363
+ const ret = wasm.wasmvm_getJitStats(this.__wbg_ptr);
364
+ deferred1_0 = ret[0];
365
+ deferred1_1 = ret[1];
366
+ return getStringFromWasm0(ret[0], ret[1]);
367
+ } finally {
368
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
369
+ }
370
+ }
371
+ /**
372
+ * Enable or disable JIT debug WAT output.
373
+ * @param {boolean} debug
374
+ */
375
+ setJitDebug(debug) {
376
+ wasm.wasmvm_setJitDebug(this.__wbg_ptr, debug);
377
+ }
283
378
  /**
284
379
  * Start worker threads for secondary harts (1..num_harts).
285
380
  *
@@ -298,6 +393,21 @@ var WasmVm = class _WasmVm {
298
393
  throw takeFromExternrefTable0(ret[0]);
299
394
  }
300
395
  }
396
+ /**
397
+ * Dump recent JIT trace events to console.
398
+ * @param {number | null} [count]
399
+ */
400
+ dumpJitTrace(count) {
401
+ wasm.wasmvm_dumpJitTrace(this.__wbg_ptr, isLikeNone(count) ? 4294967297 : count >>> 0);
402
+ }
403
+ /**
404
+ * Check if JIT is currently enabled.
405
+ * @returns {boolean}
406
+ */
407
+ isJitEnabled() {
408
+ const ret = wasm.wasmvm_isJitEnabled(this.__wbg_ptr);
409
+ return ret !== 0;
410
+ }
301
411
  /**
302
412
  * Get the current network connection status.
303
413
  * This checks the actual connection state by seeing if an IP was assigned.
@@ -326,6 +436,26 @@ var WasmVm = class _WasmVm {
326
436
  }
327
437
  return _WasmVm.__wrap(ret[0]);
328
438
  }
439
+ /**
440
+ * Clear JIT cache.
441
+ */
442
+ clearJitCache() {
443
+ wasm.wasmvm_clearJitCache(this.__wbg_ptr);
444
+ }
445
+ /**
446
+ * Enable or disable JIT compilation.
447
+ * @param {boolean} enabled
448
+ */
449
+ setJitEnabled(enabled) {
450
+ wasm.wasmvm_setJitEnabled(this.__wbg_ptr, enabled);
451
+ }
452
+ /**
453
+ * Enable or disable JIT execution tracing.
454
+ * @param {boolean} enabled
455
+ */
456
+ setJitTracing(enabled) {
457
+ wasm.wasmvm_setJitTracing(this.__wbg_ptr, enabled);
458
+ }
329
459
  /**
330
460
  * Get current memory usage (DRAM size) in bytes.
331
461
  * @returns {bigint}
@@ -334,6 +464,20 @@ var WasmVm = class _WasmVm {
334
464
  const ret = wasm.wasmvm_get_memory_usage(this.__wbg_ptr);
335
465
  return BigInt.asUintN(64, ret);
336
466
  }
467
+ /**
468
+ * Reset all JIT error tracking.
469
+ */
470
+ resetJitErrors() {
471
+ wasm.wasmvm_resetJitErrors(this.__wbg_ptr);
472
+ }
473
+ /**
474
+ * Get current JIT compilation threshold.
475
+ * @returns {number}
476
+ */
477
+ getJitThreshold() {
478
+ const ret = wasm.wasmvm_getJitThreshold(this.__wbg_ptr);
479
+ return ret >>> 0;
480
+ }
337
481
  /**
338
482
  * Get the SharedArrayBuffer for external worker management.
339
483
  * Returns None if not in SMP mode.
@@ -343,6 +487,13 @@ var WasmVm = class _WasmVm {
343
487
  const ret = wasm.wasmvm_get_shared_buffer(this.__wbg_ptr);
344
488
  return ret;
345
489
  }
490
+ /**
491
+ * Set JIT compilation threshold (min exec_count before compiling).
492
+ * @param {number} threshold
493
+ */
494
+ setJitThreshold(threshold) {
495
+ wasm.wasmvm_setJitThreshold(this.__wbg_ptr, threshold);
496
+ }
346
497
  /**
347
498
  * Terminate all workers.
348
499
  */
@@ -355,6 +506,43 @@ var WasmVm = class _WasmVm {
355
506
  disconnect_network() {
356
507
  wasm.wasmvm_disconnect_network(this.__wbg_ptr);
357
508
  }
509
+ /**
510
+ * Get number of cached JIT blocks.
511
+ * @returns {number}
512
+ */
513
+ getJitCacheSize() {
514
+ const ret = wasm.wasmvm_getJitCacheSize(this.__wbg_ptr);
515
+ return ret >>> 0;
516
+ }
517
+ /**
518
+ * Add a PC to the JIT blacklist.
519
+ * @param {bigint} pc
520
+ */
521
+ blacklistJitBlock(pc) {
522
+ wasm.wasmvm_blacklistJitBlock(this.__wbg_ptr, pc);
523
+ }
524
+ /**
525
+ * Clear the JIT blacklist.
526
+ */
527
+ clearJitBlacklist() {
528
+ wasm.wasmvm_clearJitBlacklist(this.__wbg_ptr);
529
+ }
530
+ /**
531
+ * Get JIT diagnostics as JSON string.
532
+ * @returns {string}
533
+ */
534
+ getJitDiagnostics() {
535
+ let deferred1_0;
536
+ let deferred1_1;
537
+ try {
538
+ const ret = wasm.wasmvm_getJitDiagnostics(this.__wbg_ptr);
539
+ deferred1_0 = ret[0];
540
+ deferred1_1 = ret[1];
541
+ return getStringFromWasm0(ret[0], ret[1]);
542
+ } finally {
543
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
544
+ }
545
+ }
358
546
  /**
359
547
  * Check how many bytes are pending in the UART output buffer.
360
548
  * Useful for debugging output issues.
@@ -390,6 +578,13 @@ var WasmVm = class _WasmVm {
390
578
  const ret = wasm.wasmvm_inject_network_packet(this.__wbg_ptr, packet);
391
579
  return ret !== 0;
392
580
  }
581
+ /**
582
+ * Enable TLB fast-path optimization.
583
+ * @param {boolean} enabled
584
+ */
585
+ setJitTlbFastPath(enabled) {
586
+ wasm.wasmvm_setJitTlbFastPath(this.__wbg_ptr, enabled);
587
+ }
393
588
  /**
394
589
  * Signal that workers can start executing.
395
590
  * Called by the main thread after hart 0 has finished initializing
@@ -407,6 +602,21 @@ var WasmVm = class _WasmVm {
407
602
  const ret = wasm.wasmvm_extract_network_packet(this.__wbg_ptr);
408
603
  return ret;
409
604
  }
605
+ /**
606
+ * Check if JIT tracing is enabled.
607
+ * @returns {boolean}
608
+ */
609
+ isJitTracingEnabled() {
610
+ const ret = wasm.wasmvm_isJitTracingEnabled(this.__wbg_ptr);
611
+ return ret !== 0;
612
+ }
613
+ /**
614
+ * Set maximum block size for JIT compilation.
615
+ * @param {number} size
616
+ */
617
+ setJitMaxBlockSize(size) {
618
+ wasm.wasmvm_setJitMaxBlockSize(this.__wbg_ptr, size);
619
+ }
410
620
  /**
411
621
  * Set up an external network backend for packet bridging.
412
622
  * This is used by the Node.js CLI to bridge packets between the native
@@ -421,6 +631,32 @@ var WasmVm = class _WasmVm {
421
631
  throw takeFromExternrefTable0(ret[0]);
422
632
  }
423
633
  }
634
+ /**
635
+ * Get JIT cache hit ratio.
636
+ * @returns {number}
637
+ */
638
+ getJitCacheHitRatio() {
639
+ const ret = wasm.wasmvm_getJitCacheHitRatio(this.__wbg_ptr);
640
+ return ret;
641
+ }
642
+ /**
643
+ * Get JIT execution ratio (JIT executions / total executions).
644
+ * Calculated from CPU's block cache statistics.
645
+ * @returns {number}
646
+ */
647
+ getJitExecutionRatio() {
648
+ const ret = wasm.wasmvm_getJitCacheHitRatio(this.__wbg_ptr);
649
+ return ret;
650
+ }
651
+ /**
652
+ * Invalidate JIT cache for a specific address.
653
+ * @param {bigint} pc
654
+ * @returns {boolean}
655
+ */
656
+ invalidateJitCacheAt(pc) {
657
+ const ret = wasm.wasmvm_invalidateJitCacheAt(this.__wbg_ptr, pc);
658
+ return ret !== 0;
659
+ }
424
660
  /**
425
661
  * Set the assigned IP address for the external network.
426
662
  * Called when the native WebTransport addon receives an IP assignment.
@@ -431,6 +667,14 @@ var WasmVm = class _WasmVm {
431
667
  const ret = wasm.wasmvm_set_external_network_ip(this.__wbg_ptr, ip_bytes);
432
668
  return ret !== 0;
433
669
  }
670
+ /**
671
+ * Get JIT cache memory usage in bytes.
672
+ * @returns {number}
673
+ */
674
+ getJitCacheMemoryUsage() {
675
+ const ret = wasm.wasmvm_getJitCacheMemoryUsage(this.__wbg_ptr);
676
+ return ret >>> 0;
677
+ }
434
678
  /**
435
679
  * Get the number of pending RX packets.
436
680
  * @returns {number}
@@ -464,6 +708,13 @@ var WasmVm = class _WasmVm {
464
708
  const ret = wasm.wasmvm_is_external_network_connected(this.__wbg_ptr);
465
709
  return ret !== 0;
466
710
  }
711
+ /**
712
+ * Set interrupt check interval (0 = disabled).
713
+ * @param {number} interval
714
+ */
715
+ setJitInterruptCheckInterval(interval) {
716
+ wasm.wasmvm_setJitInterruptCheckInterval(this.__wbg_ptr, interval);
717
+ }
467
718
  /**
468
719
  * Create a new VM instance and load a kernel (ELF or raw binary).
469
720
  *
@@ -1066,23 +1317,23 @@ function __wbg_get_imports() {
1066
1317
  const ret = getStringFromWasm0(arg0, arg1);
1067
1318
  return ret;
1068
1319
  };
1069
- imports.wbg.__wbindgen_cast_705cb87c37628e08 = function(arg0, arg1) {
1070
- const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h219b6c77d9281450, wasm_bindgen__convert__closures_____invoke__hcefed207e507b803);
1320
+ imports.wbg.__wbindgen_cast_32327f67251393a4 = function(arg0, arg1) {
1321
+ const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h1292c9e7657b72ef, wasm_bindgen__convert__closures_____invoke__ha9a06e4d93c772bf);
1071
1322
  return ret;
1072
1323
  };
1073
- imports.wbg.__wbindgen_cast_bcc7883475928b3d = function(arg0, arg1) {
1074
- const ret = makeClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h219b6c77d9281450, wasm_bindgen__convert__closures_____invoke__h1ead60eaa5163c89);
1324
+ imports.wbg.__wbindgen_cast_82c798e194eb44f0 = function(arg0, arg1) {
1325
+ const ret = makeClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h1292c9e7657b72ef, wasm_bindgen__convert__closures_____invoke__h3eb569f20d255f19);
1075
1326
  return ret;
1076
1327
  };
1077
- imports.wbg.__wbindgen_cast_ce1738ca1cf90a8c = function(arg0, arg1) {
1078
- const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h219b6c77d9281450, wasm_bindgen__convert__closures_____invoke__h633c7630e96bf7ba);
1328
+ imports.wbg.__wbindgen_cast_a93ea42108a71f00 = function(arg0, arg1) {
1329
+ const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h1292c9e7657b72ef, wasm_bindgen__convert__closures_____invoke__h320e929207365995);
1079
1330
  return ret;
1080
1331
  };
1081
1332
  imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
1082
1333
  const ret = arg0;
1083
1334
  return ret;
1084
1335
  };
1085
- imports.wbg.__wbindgen_cast_f1c9170db27db6a8 = function(arg0, arg1) {
1336
+ imports.wbg.__wbindgen_cast_dc00c1264d481122 = function(arg0, arg1) {
1086
1337
  const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__hf225e18fc5ab9bc1, wasm_bindgen__convert__closures_____invoke__h39d3e89751b07765);
1087
1338
  return ret;
1088
1339
  };
@@ -1140,6 +1391,7 @@ async function __wbg_init(module_or_path) {
1140
1391
  var riscv_vm_default = __wbg_init;
1141
1392
 
1142
1393
  export {
1394
+ JitWorkerContext,
1143
1395
  NetworkStatus,
1144
1396
  WasmVm,
1145
1397
  WorkerState,