@agoric/swingset-vat 0.32.3-dev-31be299.0 → 0.32.3-dev-0766b83.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/swingset-vat",
3
- "version": "0.32.3-dev-31be299.0+31be299",
3
+ "version": "0.32.3-dev-0766b83.0+0766b83",
4
4
  "description": "Vat/Container Launcher",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -27,15 +27,15 @@
27
27
  "@types/yargs-parser": "^21.0.0"
28
28
  },
29
29
  "dependencies": {
30
- "@agoric/internal": "0.3.3-dev-31be299.0+31be299",
31
- "@agoric/kmarshal": "0.1.1-dev-31be299.0+31be299",
32
- "@agoric/store": "0.9.3-dev-31be299.0+31be299",
33
- "@agoric/swing-store": "0.9.2-dev-31be299.0+31be299",
34
- "@agoric/swingset-liveslots": "0.10.3-dev-31be299.0+31be299",
35
- "@agoric/swingset-xsnap-supervisor": "0.10.3-dev-31be299.0+31be299",
36
- "@agoric/time": "0.3.3-dev-31be299.0+31be299",
37
- "@agoric/vat-data": "0.5.3-dev-31be299.0+31be299",
38
- "@agoric/xsnap-lockdown": "0.14.1-dev-31be299.0+31be299",
30
+ "@agoric/internal": "0.3.3-dev-0766b83.0+0766b83",
31
+ "@agoric/kmarshal": "0.1.1-dev-0766b83.0+0766b83",
32
+ "@agoric/store": "0.9.3-dev-0766b83.0+0766b83",
33
+ "@agoric/swing-store": "0.9.2-dev-0766b83.0+0766b83",
34
+ "@agoric/swingset-liveslots": "0.10.3-dev-0766b83.0+0766b83",
35
+ "@agoric/swingset-xsnap-supervisor": "0.10.3-dev-0766b83.0+0766b83",
36
+ "@agoric/time": "0.3.3-dev-0766b83.0+0766b83",
37
+ "@agoric/vat-data": "0.5.3-dev-0766b83.0+0766b83",
38
+ "@agoric/xsnap-lockdown": "0.14.1-dev-0766b83.0+0766b83",
39
39
  "@endo/base64": "^1.0.9",
40
40
  "@endo/bundle-source": "^4.0.0",
41
41
  "@endo/captp": "^4.4.5",
@@ -102,5 +102,5 @@
102
102
  "typeCoverage": {
103
103
  "atLeast": 76.25
104
104
  },
105
- "gitHead": "31be2992aec21c06633699b7d8095423845b0530"
105
+ "gitHead": "0766b83d0db59daae047c01ae7d25a94ec3e8a16"
106
106
  }
@@ -425,8 +425,12 @@ export async function makeSwingsetController(
425
425
  return kernel.shutdown();
426
426
  },
427
427
 
428
- reapAllVats() {
429
- kernel.reapAllVats();
428
+ reapAllVats(previousVatPos) {
429
+ return kernel.reapAllVats(previousVatPos);
430
+ },
431
+
432
+ async snapshotAllVats() {
433
+ return kernel.snapshotAllVats();
430
434
  },
431
435
 
432
436
  changeKernelOptions(options) {
@@ -1946,15 +1946,63 @@ export default function buildKernel(
1946
1946
  }
1947
1947
  }
1948
1948
 
1949
- function reapAllVats() {
1949
+ /** @returns {Generator<VatID>} */
1950
+ function* getAllVatIds() {
1950
1951
  for (const [_, vatID] of kernelKeeper.getStaticVats()) {
1951
- kernelKeeper.scheduleReap(vatID);
1952
+ yield vatID;
1952
1953
  }
1953
1954
  for (const vatID of kernelKeeper.getDynamicVats()) {
1954
- kernelKeeper.scheduleReap(vatID);
1955
+ yield vatID;
1955
1956
  }
1956
1957
  }
1957
1958
 
1959
+ function* getAllVatPosEntries() {
1960
+ for (const vatID of getAllVatIds()) {
1961
+ const vatKeeper = kernelKeeper.provideVatKeeper(vatID);
1962
+ yield /** @type {const} */ ([
1963
+ vatID,
1964
+ vatKeeper.getTranscriptEndPosition(),
1965
+ ]);
1966
+ }
1967
+ }
1968
+
1969
+ function reapAllVats(previousVatPos = {}) {
1970
+ /** @type {Record<string, number>} */
1971
+ const currentVatPos = {};
1972
+
1973
+ for (const [vatID, endPos] of getAllVatPosEntries()) {
1974
+ const vatUsesTranscript = endPos !== 0;
1975
+ if (!vatUsesTranscript) {
1976
+ // The comms vat is a little special. It doesn't use a transcript,
1977
+ // doesn't implement BOYD, and is created with a never reap threshold.
1978
+ //
1979
+ // Here we conflate a vat that doesn't use a transcript with a vat
1980
+ // that cannot reap. We do not bother checking the vat options because
1981
+ // in tests we would actually like to force reap normal vats that may
1982
+ // have been configured with a never threshold.
1983
+ continue;
1984
+ } else if ((previousVatPos[vatID] ?? 0) < endPos) {
1985
+ kernelKeeper.scheduleReap(vatID);
1986
+ // We just added one delivery
1987
+ currentVatPos[vatID] = endPos + 1;
1988
+ } else {
1989
+ currentVatPos[vatID] = endPos;
1990
+ }
1991
+ }
1992
+
1993
+ return harden(currentVatPos);
1994
+ }
1995
+
1996
+ async function snapshotAllVats() {
1997
+ const snapshottedVats = [];
1998
+ await null;
1999
+ for (const vatID of getAllVatIds()) {
2000
+ const snapshotted = await vatWarehouse.maybeSaveSnapshot(vatID, 2);
2001
+ if (snapshotted) snapshottedVats.push(vatID);
2002
+ }
2003
+ return harden(snapshottedVats);
2004
+ }
2005
+
1958
2006
  async function step() {
1959
2007
  if (kernelPanic) {
1960
2008
  throw kernelPanic;
@@ -2159,6 +2207,7 @@ export default function buildKernel(
2159
2207
  run,
2160
2208
  shutdown,
2161
2209
  reapAllVats,
2210
+ snapshotAllVats,
2162
2211
  changeKernelOptions,
2163
2212
 
2164
2213
  // the rest are for testing and debugging
@@ -566,18 +566,20 @@ export function makeVatWarehouse({
566
566
 
567
567
  /**
568
568
  * Save a heap snapshot for the given vatID, if the snapshotInterval
569
- * is satisified
569
+ * is satisfied or a lower explicit delivery count has been reached.
570
570
  *
571
571
  * @param {VatID} vatID
572
+ * @param {number} [minDeliveryCount]
572
573
  */
573
- async function maybeSaveSnapshot(vatID) {
574
- const recreate = true; // PANIC in the failure case
575
- const { manager } = await ensureVatOnline(vatID, recreate);
576
- if (!manager.makeSnapshot) {
577
- return false; // worker cannot make snapshots
574
+ async function maybeSaveSnapshot(vatID, minDeliveryCount = snapshotInterval) {
575
+ kernelKeeper.vatIsAlive(vatID) || Fail`${q(vatID)}: not alive`;
576
+ const vatKeeper = kernelKeeper.provideVatKeeper(vatID);
577
+ const vatOptions = vatKeeper.getOptions();
578
+
579
+ if (!vatOptions.useTranscript) {
580
+ return false;
578
581
  }
579
582
 
580
- const vatKeeper = kernelKeeper.provideVatKeeper(vatID);
581
583
  let reason;
582
584
 
583
585
  const hasSnapshot = !!vatKeeper.getSnapshotInfo();
@@ -586,15 +588,21 @@ export function makeVatWarehouse({
586
588
  if (!hasSnapshot && deliveriesInSpan >= snapshotInitial) {
587
589
  // begin snapshot after 'snapshotInitial' deliveries in an incarnation
588
590
  reason = { snapshotInitial };
589
- } else if (deliveriesInSpan >= snapshotInterval) {
591
+ } else if (deliveriesInSpan >= minDeliveryCount) {
590
592
  // begin snapshot after 'snapshotInterval' deliveries in a span
591
- reason = { snapshotInterval };
593
+ reason = { snapshotInterval: minDeliveryCount };
592
594
  }
593
595
  // console.log('maybeSaveSnapshot: reason:', reason);
594
596
  if (!reason) {
595
597
  return false; // not time to make a snapshot
596
598
  }
597
599
 
600
+ const recreate = true; // PANIC in the failure case
601
+ const { manager } = await ensureVatOnline(vatID, recreate);
602
+ if (!manager.makeSnapshot) {
603
+ return false; // worker cannot make snapshots
604
+ }
605
+
598
606
  // always do a bringOutYourDead just before a snapshot, to shake
599
607
  // loose as much garbage as we can, and to minimize the GC
600
608
  // sensitivity effects of the forced GC that snapshots perform