Skip to content

Commit

Permalink
chore(liveslots): pass gcAndFinalize into liveslots for all workers
Browse files Browse the repository at this point in the history
This will be needed shortly for liveslots to drive GC during each crank.
  • Loading branch information
warner committed May 25, 2021
1 parent 549c301 commit 8c6a64e
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 11 deletions.
5 changes: 4 additions & 1 deletion packages/SwingSet/src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { xsnap, makeSnapstore } from '@agoric/xsnap';
import { WeakRef, FinalizationRegistry } from './weakref';
import { startSubprocessWorker } from './spawnSubprocessWorker';
import { waitUntilQuiescent } from './waitUntilQuiescent';
import { gcAndFinalize } from './gc';
import { insistStorageAPI } from './storageAPI';
import { insistCapData } from './capdata';
import { parseVatSlot } from './parseVatSlots';
Expand Down Expand Up @@ -271,7 +272,8 @@ export async function makeSwingsetController(
const supercode = require.resolve(
'./kernel/vatManager/supervisor-subprocess-node.js',
);
return startSubprocessWorker(process.execPath, ['-r', 'esm', supercode]);
const args = ['--expose-gc', '-r', 'esm', supercode];
return startSubprocessWorker(process.execPath, args);
}

const bundles = [
Expand All @@ -297,6 +299,7 @@ export async function makeSwingsetController(
writeSlogObject,
WeakRef,
FinalizationRegistry,
gcAndFinalize,
};

const kernelOptions = { verbose };
Expand Down
8 changes: 7 additions & 1 deletion packages/SwingSet/src/kernel/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export default function buildKernel(
writeSlogObject,
WeakRef,
FinalizationRegistry,
gcAndFinalize,
} = kernelEndowments;
deviceEndowments = { ...deviceEndowments }; // copy so we can modify
const { verbose, defaultManagerType = 'local' } = kernelOptions;
Expand Down Expand Up @@ -631,7 +632,12 @@ export default function buildKernel(
}
}

const gcTools = harden({ WeakRef, FinalizationRegistry, waitUntilQuiescent });
const gcTools = harden({
WeakRef,
FinalizationRegistry,
waitUntilQuiescent,
gcAndFinalize,
});
const vatManagerFactory = makeVatManagerFactory({
allVatPowers,
kernelKeeper,
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/kernel/liveSlots.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const DEFAULT_VIRTUAL_OBJECT_CACHE_SIZE = 3; // XXX ridiculously small value to
* @param {boolean} enableDisavow
* @param {*} vatPowers
* @param {*} vatParameters
* @param {*} gcTools { WeakRef, FinalizationRegistry, waitUntilQuiescent }
* @param {*} gcTools { WeakRef, FinalizationRegistry, waitUntilQuiescent, gcAndFinalize }
* @param {Console} console
* @returns {*} { vatGlobals, inescapableGlobalProperties, dispatch, setBuildRootObject }
*
Expand Down
3 changes: 1 addition & 2 deletions packages/SwingSet/src/kernel/vatManager/manager-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export function makeLocalVatManagerFactory(tools) {
kernelSlog,
} = tools;

const { waitUntilQuiescent } = gcTools;
const { makeGetMeter, refillAllMeters, stopGlobalMeter } = meterManager;
const baseVP = {
makeMarshal: allVatPowers.makeMarshal,
Expand All @@ -42,7 +41,7 @@ export function makeLocalVatManagerFactory(tools) {
assert.typeof(dispatch, 'function');
// this 'deliverToWorker' never throws, even if liveslots has an internal error
const deliverToWorker = makeMeteredDispatch(
makeSupervisorDispatch(dispatch, waitUntilQuiescent),
makeSupervisorDispatch(dispatch),
mtools,
);
mk.setDeliverToWorker(deliverToWorker);
Expand Down
4 changes: 1 addition & 3 deletions packages/SwingSet/src/kernel/vatManager/supervisor-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ import '../../types';
* manager process.
*
* @param { VatDispatcherSyncAsync } dispatch
* @param { WaitUntilQuiescent } waitUntilQuiescent
* @returns { VatDispatcher }
*/
function makeSupervisorDispatch(dispatch, waitUntilQuiescent) {
assert.typeof(waitUntilQuiescent, 'function');
function makeSupervisorDispatch(dispatch) {
/**
* @param { VatDeliveryObject } delivery
* @returns { Promise<VatDeliveryResult> }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { assert, details as X } from '@agoric/assert';
import { importBundle } from '@agoric/import-bundle';
import { makeMarshal } from '@agoric/marshal';
import { WeakRef, FinalizationRegistry } from '../../weakref';
import { gcAndFinalize } from '../../gc';
import { waitUntilQuiescent } from '../../waitUntilQuiescent';
import { makeLiveSlots } from '../liveSlots';
import {
Expand Down Expand Up @@ -78,6 +79,7 @@ parentPort.on('message', ([type, ...margs]) => {
WeakRef,
FinalizationRegistry,
waitUntilQuiescent,
gcAndFinalize,
});
const ls = makeLiveSlots(
syscall,
Expand All @@ -102,7 +104,7 @@ parentPort.on('message', ([type, ...margs]) => {
workerLog(`got vatNS:`, Object.keys(vatNS).join(','));
sendUplink(['gotBundle']);
ls.setBuildRootObject(vatNS.buildRootObject);
dispatch = makeSupervisorDispatch(ls.dispatch, waitUntilQuiescent);
dispatch = makeSupervisorDispatch(ls.dispatch);
workerLog(`got dispatch:`, Object.keys(dispatch).join(','));
sendUplink(['dispatchReady']);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { assert, details as X } from '@agoric/assert';
import { importBundle } from '@agoric/import-bundle';
import { makeMarshal } from '@agoric/marshal';
import { WeakRef, FinalizationRegistry } from '../../weakref';
import { gcAndFinalize } from '../../gc';
import { arrayEncoderStream, arrayDecoderStream } from '../../worker-protocol';
import {
netstringEncoderStream,
Expand Down Expand Up @@ -91,6 +92,7 @@ fromParent.on('data', ([type, ...margs]) => {
WeakRef,
FinalizationRegistry,
waitUntilQuiescent,
gcAndFinalize,
});
const ls = makeLiveSlots(
syscall,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { makeMarshal } from '@agoric/marshal';
import '../../types';
// grumble... waitUntilQuiescent is exported and closes over ambient authority
import { waitUntilQuiescent } from '../../waitUntilQuiescent';
import { gcAndFinalize } from '../../gc';
import { insistVatDeliveryObject, insistVatSyscallResult } from '../../message';

import { makeLiveSlots } from '../liveSlots';
Expand Down Expand Up @@ -184,6 +185,7 @@ function makeWorker(port) {
WeakRef,
FinalizationRegistry,
waitUntilQuiescent,
gcAndFinalize,
});

const ls = makeLiveSlots(
Expand Down Expand Up @@ -213,7 +215,7 @@ function makeWorker(port) {
workerLog(`got vatNS:`, Object.keys(vatNS).join(','));
ls.setBuildRootObject(vatNS.buildRootObject);
assert(ls.dispatch);
dispatch = makeSupervisorDispatch(ls.dispatch, waitUntilQuiescent);
dispatch = makeSupervisorDispatch(ls.dispatch);
workerLog(`got dispatch`);
return ['dispatchReady'];
}
Expand Down
8 changes: 7 additions & 1 deletion packages/SwingSet/test/liveslots-helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { WeakRef, FinalizationRegistry } from '../src/weakref';
import { waitUntilQuiescent } from '../src/waitUntilQuiescent';
import { gcAndFinalize } from '../src/gc';
import { makeLiveSlots } from '../src/kernel/liveSlots';

export function buildSyscall() {
Expand Down Expand Up @@ -38,7 +39,12 @@ export function makeDispatch(
vatID = 'vatA',
enableDisavow = false,
) {
const gcTools = harden({ WeakRef, FinalizationRegistry, waitUntilQuiescent });
const gcTools = harden({
WeakRef,
FinalizationRegistry,
waitUntilQuiescent,
gcAndFinalize,
});
const { setBuildRootObject, dispatch } = makeLiveSlots(
syscall,
vatID,
Expand Down
3 changes: 3 additions & 0 deletions packages/SwingSet/test/test-liveslots.js
Original file line number Diff line number Diff line change
Expand Up @@ -811,12 +811,15 @@ function makeMockGC() {
return allFRs;
}

function mockGCAndFinalize() {}

return harden({
WeakRef: mockWeakRef,
FinalizationRegistry: mockFinalizationRegistry,
kill,
getAllFRs,
waitUntilQuiescent,
gcAndFinalize: mockGCAndFinalize,
});
}

Expand Down

0 comments on commit 8c6a64e

Please sign in to comment.