diff --git a/packages/SwingSet/src/controller.js b/packages/SwingSet/src/controller.js index 21f0ca130fa..7de56351f11 100644 --- a/packages/SwingSet/src/controller.js +++ b/packages/SwingSet/src/controller.js @@ -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'; @@ -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 = [ @@ -297,6 +299,7 @@ export async function makeSwingsetController( writeSlogObject, WeakRef, FinalizationRegistry, + gcAndFinalize, }; const kernelOptions = { verbose }; diff --git a/packages/SwingSet/src/kernel/kernel.js b/packages/SwingSet/src/kernel/kernel.js index 607e543ee84..77bdf37f813 100644 --- a/packages/SwingSet/src/kernel/kernel.js +++ b/packages/SwingSet/src/kernel/kernel.js @@ -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; @@ -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, diff --git a/packages/SwingSet/src/kernel/liveSlots.js b/packages/SwingSet/src/kernel/liveSlots.js index 48f9ed308f5..d0fd49a8f55 100644 --- a/packages/SwingSet/src/kernel/liveSlots.js +++ b/packages/SwingSet/src/kernel/liveSlots.js @@ -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 } * diff --git a/packages/SwingSet/src/kernel/vatManager/manager-local.js b/packages/SwingSet/src/kernel/vatManager/manager-local.js index 0a244e4bc9f..f1c2e3fa759 100644 --- a/packages/SwingSet/src/kernel/vatManager/manager-local.js +++ b/packages/SwingSet/src/kernel/vatManager/manager-local.js @@ -20,7 +20,6 @@ export function makeLocalVatManagerFactory(tools) { kernelSlog, } = tools; - const { waitUntilQuiescent } = gcTools; const { makeGetMeter, refillAllMeters, stopGlobalMeter } = meterManager; const baseVP = { makeMarshal: allVatPowers.makeMarshal, @@ -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); diff --git a/packages/SwingSet/src/kernel/vatManager/supervisor-helper.js b/packages/SwingSet/src/kernel/vatManager/supervisor-helper.js index 78e03f34601..7a2a0833746 100644 --- a/packages/SwingSet/src/kernel/vatManager/supervisor-helper.js +++ b/packages/SwingSet/src/kernel/vatManager/supervisor-helper.js @@ -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 } diff --git a/packages/SwingSet/src/kernel/vatManager/supervisor-nodeworker.js b/packages/SwingSet/src/kernel/vatManager/supervisor-nodeworker.js index 4890fab2f5c..b468aba2262 100644 --- a/packages/SwingSet/src/kernel/vatManager/supervisor-nodeworker.js +++ b/packages/SwingSet/src/kernel/vatManager/supervisor-nodeworker.js @@ -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 { @@ -78,6 +79,7 @@ parentPort.on('message', ([type, ...margs]) => { WeakRef, FinalizationRegistry, waitUntilQuiescent, + gcAndFinalize, }); const ls = makeLiveSlots( syscall, @@ -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']); }, diff --git a/packages/SwingSet/src/kernel/vatManager/supervisor-subprocess-node.js b/packages/SwingSet/src/kernel/vatManager/supervisor-subprocess-node.js index 87b3268ce3f..49dda5f201a 100644 --- a/packages/SwingSet/src/kernel/vatManager/supervisor-subprocess-node.js +++ b/packages/SwingSet/src/kernel/vatManager/supervisor-subprocess-node.js @@ -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, @@ -91,6 +92,7 @@ fromParent.on('data', ([type, ...margs]) => { WeakRef, FinalizationRegistry, waitUntilQuiescent, + gcAndFinalize, }); const ls = makeLiveSlots( syscall, diff --git a/packages/SwingSet/src/kernel/vatManager/supervisor-subprocess-xsnap.js b/packages/SwingSet/src/kernel/vatManager/supervisor-subprocess-xsnap.js index 803b122424d..965a8c46bec 100644 --- a/packages/SwingSet/src/kernel/vatManager/supervisor-subprocess-xsnap.js +++ b/packages/SwingSet/src/kernel/vatManager/supervisor-subprocess-xsnap.js @@ -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'; @@ -184,6 +185,7 @@ function makeWorker(port) { WeakRef, FinalizationRegistry, waitUntilQuiescent, + gcAndFinalize, }); const ls = makeLiveSlots( @@ -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']; } diff --git a/packages/SwingSet/test/liveslots-helpers.js b/packages/SwingSet/test/liveslots-helpers.js index 90a54637d5e..9bede1a2284 100644 --- a/packages/SwingSet/test/liveslots-helpers.js +++ b/packages/SwingSet/test/liveslots-helpers.js @@ -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() { @@ -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, diff --git a/packages/SwingSet/test/test-liveslots.js b/packages/SwingSet/test/test-liveslots.js index 41ec69857c4..66bc53b1f5b 100644 --- a/packages/SwingSet/test/test-liveslots.js +++ b/packages/SwingSet/test/test-liveslots.js @@ -811,12 +811,15 @@ function makeMockGC() { return allFRs; } + function mockGCAndFinalize() {} + return harden({ WeakRef: mockWeakRef, FinalizationRegistry: mockFinalizationRegistry, kill, getAllFRs, waitUntilQuiescent, + gcAndFinalize: mockGCAndFinalize, }); }