Skip to content

Commit

Permalink
fix(swingset): add GC syscall stubs
Browse files Browse the repository at this point in the history
This adda `syscall.retireImports` and `syscall.retireExports` to the
pre-existing `syscall.dropImports`. All three are no-ops, but vats should be
able to call them without ill effects, so kernel and liveslots development
can continue in parallel.

refs #2724
  • Loading branch information
warner committed Apr 26, 2021
1 parent 5e659e6 commit a18a860
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 11 deletions.
19 changes: 16 additions & 3 deletions packages/SwingSet/src/kernel/kernelSyscall.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ export function makeKernelSyscallHandler(tools) {
return OKNULL;
}

function retireImports(koids) {
assert(Array.isArray(koids), X`retireImports given non-Array ${koids}`);
console.log(`-- kernel ignoring retireImports ${koids.join(',')}`);
return OKNULL;
}

function retireExports(koids) {
assert(Array.isArray(koids), X`retireExports given non-Array ${koids}`);
console.log(`-- kernel ignoring retireExports ${koids.join(',')}`);
return OKNULL;
}

function doKernelSyscall(ksc) {
const [type, ...args] = ksc;
switch (type) {
Expand All @@ -140,16 +152,17 @@ export function makeKernelSyscallHandler(tools) {
return vatstoreDelete(...args);
case 'dropImports':
return dropImports(...args);
case 'retireImports':
return retireImports(...args);
case 'retireExports':
return retireExports(...args);
default:
assert.fail(X`unknown vatSyscall type ${type}`);
}
}

const kernelSyscallHandler = harden({
send, // TODO remove these individual ones
invoke,
subscribe,
resolve,
doKernelSyscall,
});
return kernelSyscallHandler;
Expand Down
2 changes: 2 additions & 0 deletions packages/SwingSet/src/kernel/vatManager/supervisor-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ function makeSupervisorSyscall(syscallToManager, workerCanBlock) {
resolve: resolutions => doSyscall(['resolve', resolutions]),
exit: (isFailure, data) => doSyscall(['exit', isFailure, data]),
dropImports: vrefs => doSyscall(['dropImports', vrefs]),
retireImports: vrefs => doSyscall(['retireImports', vrefs]),
retireExports: vrefs => doSyscall(['retireExports', vrefs]),

// These syscalls should be omitted if the worker cannot get a
// synchronous return value back from the kernel, such as when the worker
Expand Down
41 changes: 34 additions & 7 deletions packages/SwingSet/src/kernel/vatTranslator.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,43 @@ function makeTranslateVatSyscallToKernelSyscall(vatID, kernelKeeper) {
}

function translateDropImports(vrefs) {
assert(Array.isArray(vrefs), X`dropImport() given non-Array ${vrefs}`);
// We delete clist entries as we translate, which will (TODO) decref the
// krefs. When we're done with that loop, we hand the set of krefs to
// kernelSyscall so it can (TODO) check newly-decremented refcounts
// against zero, and maybe delete even more.
assert(Array.isArray(vrefs), X`dropImports() given non-Array ${vrefs}`);
// TODO: dropImports does not affect the c-list, but makes the kernel
// calculate the refcount of a kref, possibly causing further action.
const krefs = vrefs.map(vref => {
insistVatType('object', vref);
insistVatType('object', vref); // TODO: probably device nodes too
const kref = mapVatSlotToKernelSlot(vref);
vatKeeper.deleteCListEntry(kref, vref);
return kref;
});
return harden(['dropImports', krefs]);
}

function translateRetireImports(vrefs) {
assert(Array.isArray(vrefs), X`retireImports() given non-Array ${vrefs}`);
// TODO: retireImports will delete clist entries as we translate, which
// will (TODO) decref the krefs. When we're done with that loop, we hand
// the set of krefs to kernelSyscall so it can (TODO) check
// newly-decremented refcounts against zero, and maybe delete even more.
const krefs = vrefs.map(vref => {
insistVatType('object', vref); // TODO: probably device nodes too
const kref = mapVatSlotToKernelSlot(vref);
// vatKeeper.deleteCListEntry(kref, vref);
return kref;
});
return harden(['retireImports', krefs]);
}

function translateRetireExports(vrefs) {
assert(Array.isArray(vrefs), X`retireExports() given non-Array ${vrefs}`);
// TODO: not sure how the kernel should react to this yet
const krefs = vrefs.map(vref => {
insistVatType('object', vref); // TODO: probably device nodes too
const kref = mapVatSlotToKernelSlot(vref);
return kref;
});
return harden(['retireExports', krefs]);
}

function translateCallNow(target, method, args) {
insistCapData(args);
const dev = mapVatSlotToKernelSlot(target);
Expand Down Expand Up @@ -276,6 +299,10 @@ function makeTranslateVatSyscallToKernelSyscall(vatID, kernelKeeper) {
return translateVatstoreDelete(...args);
case 'dropImports':
return translateDropImports(...args);
case 'retireImports':
return translateRetireImports(...args);
case 'retireExports':
return translateRetireExports(...args);
default:
assert.fail(X`unknown vatSyscall type ${type}`);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/SwingSet/src/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ export function insistVatSyscallObject(vso) {
assert.typeof(key, 'string');
break;
}
case 'dropImports': {
case 'dropImports':
case 'retireImports':
case 'retireExports': {
const [slots] = rest;
assert(Array.isArray(slots));
for (const slot of slots) {
Expand Down
3 changes: 3 additions & 0 deletions packages/SwingSet/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,13 @@
* @typedef { [tag: 'vatstoreSet', key: string, data: string ]} VatSyscallVatstoreSet
* @typedef { [tag: 'vatstoreDelete', key: string ]} VatSyscallVatstoreDelete
* @typedef { [tag: 'dropImports', slots: string[] ]} VatSyscallDropImports
* @typedef { [tag: 'retireImports', slots: string[] ]} VatSyscallRetireImports
* @typedef { [tag: 'retireExports', slots: string[] ]} VatSyscallRetireExports
*
* @typedef { VatSyscallSend | VatSyscallCallNow | VatSyscallSubscribe
* | VatSyscallResolve | VatSyscallVatstoreGet | VatSyscallVatstoreSet
* | VatSyscallVatstoreDelete | VatSyscallDropImports
* | VatSyscallRetireImports | VatSyscallRetireExports
* } VatSyscallObject
*
* @typedef { [tag: 'ok', data: SwingSetCapData | string | null ]} VatSyscallResultOk
Expand Down
6 changes: 6 additions & 0 deletions packages/SwingSet/test/liveslots-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export function buildSyscall() {
dropImports(slots) {
log.push({ type: 'dropImports', slots });
},
retireImports(slots) {
log.push({ type: 'retireImports', slots });
},
retireExports(slots) {
log.push({ type: 'retireExports', slots });
},
exit(isFailure, info) {
log.push({ type: 'exit', isFailure, info });
},
Expand Down

0 comments on commit a18a860

Please sign in to comment.