Skip to content

Commit

Permalink
fix(swingset): add kernel processing of GC actions before each crank
Browse files Browse the repository at this point in the history
* change `getNextMessage` to check the GC Actions queue before considering
the regular run-queue: those actions will always have higher priority
* add `processGCMessage` to execute a single GC Action this simply deletes
  * the kernel object entry (for `retireExports`), then delivers the action
    to the given vat

One test was updated to accomodate the new definition of "empty queue".
  • Loading branch information
warner committed Jun 15, 2021
1 parent 1263777 commit 462e9fd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
32 changes: 32 additions & 0 deletions packages/SwingSet/src/kernel/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { makeMeterManager } from './metering.js';
import { makeKernelSyscallHandler, doSend } from './kernelSyscall.js';
import { makeSlogger, makeDummySlogger } from './slogger.js';
import { getKpidsToRetire } from './cleanup.js';
import { processNextGCAction } from './gc-actions.js';

import { makeVatRootObjectSlot, makeVatLoader } from './loadVat.js';
import { makeDeviceTranslators } from './deviceTranslator.js';
Expand Down Expand Up @@ -524,6 +525,29 @@ export default function buildKernel(
}
}

async function processGCMessage(message) {
// used for dropExports, retireExports, and retireImports
const { type, vatID, krefs } = message;
// console.log(`-- processGCMessage(${vatID} ${type} ${krefs.join(',')})`);
insistVatID(vatID);
// eslint-disable-next-line no-use-before-define
if (!vatWarehouse.lookup(vatID)) {
return; // can't collect from the dead
}
const kd = harden([type, krefs]);
if (type === 'retireExports') {
for (const kref of krefs) {
// const rc = kernelKeeper.getObjectRefCount(kref);
// console.log(` ${kref}: ${rc.reachable},${rc.recognizable}`);
kernelKeeper.deleteKernelObject(kref);
// console.log(` deleted ${kref}`);
}
}
// eslint-disable-next-line no-use-before-define
const vd = vatWarehouse.kernelDeliveryToVatDelivery(vatID, kd);
await deliverAndLogToVat(vatID, kd, vd);
}

async function processCreateVat(message) {
assert(vatAdminRootKref, `initializeKernel did not set vatAdminRootKref`);
const { vatID, source, dynamicOptions } = message;
Expand Down Expand Up @@ -582,6 +606,8 @@ export default function buildKernel(
}
}

const gcMessages = ['dropExports', 'retireExports', 'retireImports'];

let processQueueRunning;
async function processQueueMessage(message) {
kdebug(`processQ ${JSON.stringify(message)}`);
Expand Down Expand Up @@ -613,6 +639,8 @@ export default function buildKernel(
await processNotify(message);
} else if (message.type === 'create-vat') {
await processCreateVat(message);
} else if (gcMessages.includes(message.type)) {
await processGCMessage(message);
} else {
assert.fail(X`unable to process message.type ${message.type}`);
}
Expand Down Expand Up @@ -897,6 +925,10 @@ export default function buildKernel(
}

function getNextMessage() {
const gcMessage = processNextGCAction(kernelKeeper);
if (gcMessage) {
return gcMessage;
}
if (!kernelKeeper.isRunQueueEmpty()) {
return kernelKeeper.getNextMsg();
}
Expand Down
3 changes: 2 additions & 1 deletion packages/SwingSet/test/test-transcript.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import { buildVatController, loadBasedir } from '../src/index.js';

async function buildTrace(c, storage) {
const states = [];
while (c.dump().runQueue.length) {
while (c.dump().runQueue.length && c.dump().gcActions.length) {
states.push(getAllState(storage));
// eslint-disable-next-line no-await-in-loop
await c.step();
}
states.push(getAllState(storage));
await c.shutdown();
return states;
}

Expand Down

0 comments on commit 462e9fd

Please sign in to comment.