Skip to content

Commit

Permalink
feat: The Slogulator Mk I
Browse files Browse the repository at this point in the history
  • Loading branch information
FUDCo committed Nov 14, 2020
1 parent d5bc319 commit 53c6e7d
Show file tree
Hide file tree
Showing 13 changed files with 913 additions and 14 deletions.
1 change: 1 addition & 0 deletions packages/SwingSet/src/kernel/initializeKernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export function initializeKernel(config, hostStorage, verbose = false) {
]);
creationOptions.vatParameters = vatParameters;
creationOptions.description = `static name=${name}`;
creationOptions.name = name;

const vatID = kernelKeeper.allocateVatIDForNameIfNeeded(name);
logStartup(`assigned VatID ${vatID} for genesis vat ${name}`);
Expand Down
3 changes: 2 additions & 1 deletion packages/SwingSet/src/kernel/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default function buildKernel(
? makeSlogger(writeSlogObject)
: makeDummySlogger(makeConsole);

const kernelKeeper = makeKernelKeeper(enhancedCrankBuffer);
const kernelKeeper = makeKernelKeeper(enhancedCrankBuffer, kernelSlog);

const meterManager = makeMeterManager(replaceGlobalMeter);

Expand Down Expand Up @@ -529,6 +529,7 @@ export default function buildKernel(
didAbort = true;
}
terminateVat(vatID, shouldReject, info);
kernelSlog.terminateVat(vatID, shouldReject, info);
kdebug(`vat terminated: ${JSON.stringify(info)}`);
}
if (!didAbort) {
Expand Down
10 changes: 6 additions & 4 deletions packages/SwingSet/src/kernel/loadVat.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export function makeVatLoader(stuff) {

const allowedStaticOptions = [
'description',
'name',
'vatParameters',
'managerType',
'enableSetup',
Expand Down Expand Up @@ -149,14 +150,15 @@ export function makeVatLoader(stuff) {
enableSetup = false,
enablePipelining = false,
virtualObjectCacheSize,
name,
} = options;
let terminated = false;

// TODO: maybe hash the bundle object somehow for the description
const sourceDesc = source.bundle
? '(from source bundle)'
: `(from bundleName: ${source.bundleName})`;
const description = `${options.description || ''} ${sourceDesc}`;
? 'from source bundle'
: `from bundleName: ${source.bundleName}`;
const description = `${options.description || ''} (${sourceDesc})`.trim();

function notifyTermination(shouldReject, info) {
insistCapData(info);
Expand Down Expand Up @@ -189,7 +191,7 @@ export function makeVatLoader(stuff) {
throw Error(`vat creation requires a bundle, not a plain string`);
}

kernelSlog.addVat(vatID, isDynamic, description, vatSourceBundle);
kernelSlog.addVat(vatID, isDynamic, description, name, vatSourceBundle);
const managerOptions = {
bundle: vatSourceBundle,
metered,
Expand Down
34 changes: 31 additions & 3 deletions packages/SwingSet/src/kernel/slogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export function makeDummySlogger(makeConsole) {
startup: () => () => 0, // returns nop finish() function
delivery: () => () => 0,
syscall: () => () => 0,
changeCList: () => () => 0,
terminateVat: () => () => 0,
});
}

Expand Down Expand Up @@ -85,14 +87,38 @@ export function makeSlogger(writeObj) {
}
return harden(finish);
}
return harden({ vatConsole, startup, delivery, syscall });

// mode: 'import' | 'export' | 'drop'
function changeCList(crank, mode, kobj, vobj) {
write({ type: 'clist', crankNum: crank, mode, vatID, kobj, vobj });
}

function terminateVat(shouldReject, info) {
write({ type: 'terminate', vatID, shouldReject, info });
}

return harden({
vatConsole,
startup,
delivery,
syscall,
changeCList,
terminateVat,
});
}

function addVat(vatID, dynamic, description, vatSourceBundle) {
function addVat(vatID, dynamic, description, name, vatSourceBundle) {
assert(!vatSlogs.has(vatID), `already have slog for ${vatID}`);
const vatSlog = makeVatSlog(vatID);
vatSlogs.set(vatID, vatSlog);
write({ type: 'create-vat', vatID, dynamic, description, vatSourceBundle });
write({
type: 'create-vat',
vatID,
dynamic,
description,
name,
vatSourceBundle,
});
return vatSlog;
}

Expand All @@ -106,5 +132,7 @@ export function makeSlogger(writeObj) {
startup: (vatID, ...args) => vatSlogs.get(vatID).startup(...args),
delivery: (vatID, ...args) => vatSlogs.get(vatID).delivery(...args),
syscall: (vatID, ...args) => vatSlogs.get(vatID).syscall(...args),
changeCList: (vatID, ...args) => vatSlogs.get(vatID).changeCList(...args),
terminateVat: (vatID, ...args) => vatSlogs.get(vatID).terminateVat(...args),
});
}
4 changes: 3 additions & 1 deletion packages/SwingSet/src/kernel/state/kernelKeeper.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const FIRST_OBJECT_ID = 20;
const FIRST_DEVNODE_ID = 30;
const FIRST_PROMISE_ID = 40;

export default function makeKernelKeeper(storage) {
export default function makeKernelKeeper(storage, kernelSlog) {
insistEnhancedStorageAPI(storage);

function getRequired(key) {
Expand Down Expand Up @@ -736,13 +736,15 @@ export default function makeKernelKeeper(storage) {
);
const vk = makeVatKeeper(
storage,
kernelSlog,
vatID,
addKernelObject,
addKernelPromiseForVat,
incrementRefCount,
decrementRefCount,
incStat,
decStat,
getCrankNumber,
);
ephemeral.vatKeepers.set(vatID, vk);
return vk;
Expand Down
28 changes: 28 additions & 0 deletions packages/SwingSet/src/kernel/state/vatKeeper.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function initializeVatState(storage, vatID) {
* Produce a vat keeper for a vat.
*
* @param {*} storage The storage in which the persistent state will be kept
* @param {*} kernelSlog
* @param {string} vatID The vat ID string of the vat in question
* @param {*} addKernelObject Kernel function to add a new object to the kernel's
* mapping tables.
Expand All @@ -44,17 +45,20 @@ export function initializeVatState(storage, vatID) {
* @param {*} decrementRefCount
* @param {*} incStat
* @param {*} decStat
* @param {*} getCrankNumber
* @returns {*} an object to hold and access the kernel's state for the given vat
*/
export function makeVatKeeper(
storage,
kernelSlog,
vatID,
addKernelObject,
addKernelPromiseForVat,
incrementRefCount,
decrementRefCount,
incStat,
decStat,
getCrankNumber,
) {
insistVatID(vatID);

Expand Down Expand Up @@ -105,6 +109,14 @@ export function makeVatKeeper(
incStat('clistEntries');
storage.set(kernelKey, vatSlot);
storage.set(vatKey, kernelSlot);
kernelSlog &&
kernelSlog.changeCList(
vatID,
getCrankNumber(),
'export',
kernelSlot,
vatSlot,
);
kdebug(`Add mapping v->k ${kernelKey}<=>${vatKey}`);
} else {
// the vat didn't allocate it, and the kernel didn't allocate it
Expand Down Expand Up @@ -153,6 +165,14 @@ export function makeVatKeeper(
incStat('clistEntries');
storage.set(vatKey, kernelSlot);
storage.set(kernelKey, vatSlot);
kernelSlog &&
kernelSlog.changeCList(
vatID,
getCrankNumber(),
'import',
kernelSlot,
vatSlot,
);
kdebug(`Add mapping k->v ${kernelKey}<=>${vatKey}`);
}

Expand All @@ -171,6 +191,14 @@ export function makeVatKeeper(
const kernelKey = `${vatID}.c.${kernelSlot}`;
const vatKey = `${vatID}.c.${vatSlot}`;
kdebug(`Delete mapping ${kernelKey}<=>${vatKey}`);
kernelSlog &&
kernelSlog.changeCList(
vatID,
getCrankNumber(),
'drop',
kernelSlot,
vatSlot,
);
if (storage.has(kernelKey)) {
decrementRefCount(kernelSlot, `${vatID}|del|clist`);
decStat('clistEntries');
Expand Down
Loading

0 comments on commit 53c6e7d

Please sign in to comment.