diff --git a/packages/SwingSet/src/controller.js b/packages/SwingSet/src/controller.js index f14eea28caf..653061c19ee 100644 --- a/packages/SwingSet/src/controller.js +++ b/packages/SwingSet/src/controller.js @@ -18,6 +18,7 @@ import { makeMeteringTransformer } from '@agoric/transform-metering'; import { makeTransform } from '@agoric/transform-eventual-send'; import { locateWorkerBin } from '@agoric/xs-vat-worker'; +import { WeakRef, FinalizationRegistry } from './weakref'; import { startSubprocessWorker } from './spawnSubprocessWorker'; import { waitUntilQuiescent } from './waitUntilQuiescent'; import { insistStorageAPI } from './storageAPI'; @@ -183,6 +184,8 @@ export async function makeSwingsetController( startSubprocessWorkerNode, startSubprocessWorkerXS, writeSlogObject, + WeakRef, + FinalizationRegistry, }; const kernelOptions = { verbose }; diff --git a/packages/SwingSet/src/kernel/kernel.js b/packages/SwingSet/src/kernel/kernel.js index 536280dc4f4..97e427382bd 100644 --- a/packages/SwingSet/src/kernel/kernel.js +++ b/packages/SwingSet/src/kernel/kernel.js @@ -99,6 +99,8 @@ export default function buildKernel( startSubprocessWorkerNode, startSubprocessWorkerXS, writeSlogObject, + WeakRef, + FinalizationRegistry, } = kernelEndowments; deviceEndowments = { ...deviceEndowments }; // copy so we can modify const { verbose } = kernelOptions; @@ -529,6 +531,7 @@ export default function buildKernel( } } + const gcTools = harden({ WeakRef, FinalizationRegistry }); const vatManagerFactory = makeVatManagerFactory({ allVatPowers, kernelKeeper, @@ -540,6 +543,7 @@ export default function buildKernel( makeNodeWorker, startSubprocessWorkerNode, startSubprocessWorkerXS, + gcTools, }); function buildVatSyscallHandler(vatID, translators) { diff --git a/packages/SwingSet/src/kernel/vatManager/factory.js b/packages/SwingSet/src/kernel/vatManager/factory.js index 8e6bbdf7714..fa4a207e9fb 100644 --- a/packages/SwingSet/src/kernel/vatManager/factory.js +++ b/packages/SwingSet/src/kernel/vatManager/factory.js @@ -14,6 +14,7 @@ export function makeVatManagerFactory({ makeNodeWorker, startSubprocessWorkerNode, startSubprocessWorkerXS, + gcTools, }) { const localFactory = makeLocalVatManagerFactory({ allVatPowers, @@ -22,6 +23,7 @@ export function makeVatManagerFactory({ meterManager, transformMetering, waitUntilQuiescent, + gcTools, }); const nodeWorkerFactory = makeNodeWorkerVatManagerFactory({ diff --git a/packages/SwingSet/src/kernel/vatManager/localVatManager.js b/packages/SwingSet/src/kernel/vatManager/localVatManager.js index dd53bfe7726..8434470bf0a 100644 --- a/packages/SwingSet/src/kernel/vatManager/localVatManager.js +++ b/packages/SwingSet/src/kernel/vatManager/localVatManager.js @@ -13,6 +13,7 @@ export function makeLocalVatManagerFactory(tools) { meterManager, transformMetering, waitUntilQuiescent, + gcTools, } = tools; const { makeGetMeter, refillAllMeters, stopGlobalMeter } = meterManager; @@ -107,7 +108,7 @@ export function makeLocalVatManagerFactory(tools) { // we might or might not use this, depending upon whether the vat exports // 'buildRootObject' or a default 'setup' function - const ls = makeLiveSlots(syscall, vatID, vatPowers, vatParameters); + const ls = makeLiveSlots(syscall, vatID, vatPowers, vatParameters, gcTools); let meterRecord = null; if (metered) { diff --git a/packages/SwingSet/src/kernel/vatManager/nodeWorkerSupervisor.js b/packages/SwingSet/src/kernel/vatManager/nodeWorkerSupervisor.js index 9561e88410c..d4503b6a19f 100644 --- a/packages/SwingSet/src/kernel/vatManager/nodeWorkerSupervisor.js +++ b/packages/SwingSet/src/kernel/vatManager/nodeWorkerSupervisor.js @@ -7,6 +7,7 @@ import anylogger from 'anylogger'; import { assert } from '@agoric/assert'; import { importBundle } from '@agoric/import-bundle'; import { Remotable, getInterfaceOf, makeMarshal } from '@agoric/marshal'; +import { WeakRef, FinalizationRegistry } from '../../weakref'; import { waitUntilQuiescent } from '../../waitUntilQuiescent'; import { makeLiveSlots } from '../liveSlots'; @@ -113,7 +114,8 @@ parentPort.on('message', ([type, ...margs]) => { makeMarshal, testLog, }; - const ls = makeLiveSlots(syscall, vatID, vatPowers, vatParameters); + const gcTools = harden({ WeakRef, FinalizationRegistry }); + const ls = makeLiveSlots(syscall, vatID, vatPowers, vatParameters, gcTools); const endowments = { ...ls.vatGlobals, diff --git a/packages/SwingSet/src/kernel/vatManager/subprocessSupervisor.js b/packages/SwingSet/src/kernel/vatManager/subprocessSupervisor.js index 40621ec5e2f..e7d788719fd 100644 --- a/packages/SwingSet/src/kernel/vatManager/subprocessSupervisor.js +++ b/packages/SwingSet/src/kernel/vatManager/subprocessSupervisor.js @@ -7,6 +7,7 @@ import fs from 'fs'; import { assert } from '@agoric/assert'; import { importBundle } from '@agoric/import-bundle'; import { Remotable, getInterfaceOf, makeMarshal } from '@agoric/marshal'; +import { WeakRef, FinalizationRegistry } from '../../weakref'; import { arrayEncoderStream, arrayDecoderStream } from '../../worker-protocol'; import { netstringEncoderStream, @@ -133,7 +134,8 @@ fromParent.on('data', ([type, ...margs]) => { makeMarshal, testLog, }; - const ls = makeLiveSlots(syscall, vatID, vatPowers, vatParameters); + const gcTools = harden({ WeakRef, FinalizationRegistry }); + const ls = makeLiveSlots(syscall, vatID, vatPowers, vatParameters, gcTools); const endowments = { ...ls.vatGlobals, diff --git a/packages/SwingSet/test/test-kernel.js b/packages/SwingSet/test/test-kernel.js index dfc7322df25..2bec7a73110 100644 --- a/packages/SwingSet/test/test-kernel.js +++ b/packages/SwingSet/test/test-kernel.js @@ -2,6 +2,7 @@ import '@agoric/install-ses'; import test from 'ava'; import anylogger from 'anylogger'; import { initSwingStore } from '@agoric/swing-store-simple'; +import { WeakRef, FinalizationRegistry } from '../src/weakref'; import { waitUntilQuiescent } from '../src/waitUntilQuiescent'; import buildKernel from '../src/kernel/index'; @@ -49,6 +50,8 @@ function makeEndowments() { hostStorage: initSwingStore().storage, runEndOfCrank: () => {}, makeConsole, + WeakRef, + FinalizationRegistry, }; } diff --git a/packages/SwingSet/test/test-liveslots.js b/packages/SwingSet/test/test-liveslots.js index 71c62c7ba7c..1eee852a10d 100644 --- a/packages/SwingSet/test/test-liveslots.js +++ b/packages/SwingSet/test/test-liveslots.js @@ -1,6 +1,7 @@ import '@agoric/install-ses'; import test from 'ava'; import { E } from '@agoric/eventual-send'; +import { WeakRef, FinalizationRegistry } from '../src/weakref'; import { waitUntilQuiescent } from '../src/waitUntilQuiescent'; import { makeLiveSlots } from '../src/kernel/liveSlots'; @@ -37,7 +38,14 @@ function buildSyscall() { } function makeDispatch(syscall, build) { - const { setBuildRootObject, dispatch } = makeLiveSlots(syscall, 'vatA'); + const gcTools = harden({ WeakRef, FinalizationRegistry }); + const { setBuildRootObject, dispatch } = makeLiveSlots( + syscall, + 'vatA', + {}, + {}, + gcTools, + ); setBuildRootObject(build); return dispatch; } diff --git a/packages/SwingSet/test/test-marshal.js b/packages/SwingSet/test/test-marshal.js index d6dd9d58b93..4a99dc292a0 100644 --- a/packages/SwingSet/test/test-marshal.js +++ b/packages/SwingSet/test/test-marshal.js @@ -2,10 +2,13 @@ import '@agoric/install-ses'; import test from 'ava'; import { makePromiseKit } from '@agoric/promise-kit'; +import { WeakRef, FinalizationRegistry } from '../src/weakref'; import { makeMarshaller } from '../src/kernel/liveSlots'; import { buildVatController } from '../src/index'; +const gcTools = harden({ WeakRef, FinalizationRegistry }); + async function prep() { const config = {}; const controller = await buildVatController(config); @@ -13,7 +16,7 @@ async function prep() { } test('serialize exports', t => { - const { m } = makeMarshaller(); + const { m } = makeMarshaller(undefined, gcTools); const ser = val => m.serialize(val); const o1 = harden({}); const o2 = harden({ @@ -38,7 +41,7 @@ test('serialize exports', t => { test('deserialize imports', async t => { await prep(); - const { m } = makeMarshaller(); + const { m } = makeMarshaller(undefined, gcTools); const a = m.unserialize({ body: '{"@qclass":"slot","index":0}', slots: ['o-1'], @@ -63,7 +66,7 @@ test('deserialize imports', async t => { }); test('deserialize exports', t => { - const { m } = makeMarshaller(); + const { m } = makeMarshaller(undefined, gcTools); const o1 = harden({}); m.serialize(o1); // allocates slot=1 const a = m.unserialize({ @@ -75,7 +78,7 @@ test('deserialize exports', t => { test('serialize imports', async t => { await prep(); - const { m } = makeMarshaller(); + const { m } = makeMarshaller(undefined, gcTools); const a = m.unserialize({ body: '{"@qclass":"slot","index":0}', slots: ['o-1'], @@ -94,7 +97,7 @@ test('serialize promise', async t => { }, }; - const { m } = makeMarshaller(syscall); + const { m } = makeMarshaller(syscall, gcTools); const { promise, resolve } = makePromiseKit(); t.deepEqual(m.serialize(promise), { body: '{"@qclass":"slot","index":0}', @@ -130,7 +133,7 @@ test('unserialize promise', async t => { }, }; - const { m } = makeMarshaller(syscall); + const { m } = makeMarshaller(syscall, gcTools); const p = m.unserialize({ body: '{"@qclass":"slot","index":0}', slots: ['p-1'], diff --git a/packages/SwingSet/test/test-vpid-kernel.js b/packages/SwingSet/test/test-vpid-kernel.js index 0a47846d56a..fac2c5b0640 100644 --- a/packages/SwingSet/test/test-vpid-kernel.js +++ b/packages/SwingSet/test/test-vpid-kernel.js @@ -1,9 +1,8 @@ -// eslint-disable-next-line no-redeclare - import '@agoric/install-ses'; import test from 'ava'; import anylogger from 'anylogger'; import { initSwingStore } from '@agoric/swing-store-simple'; +import { WeakRef, FinalizationRegistry } from '../src/weakref'; import { waitUntilQuiescent } from '../src/waitUntilQuiescent'; import buildKernel from '../src/kernel/index'; @@ -36,6 +35,8 @@ function makeEndowments() { hostStorage: initSwingStore().storage, runEndOfCrank: () => {}, makeConsole, + WeakRef, + FinalizationRegistry, }; } diff --git a/packages/SwingSet/test/test-vpid-liveslots.js b/packages/SwingSet/test/test-vpid-liveslots.js index e3758088e10..4133a75995b 100644 --- a/packages/SwingSet/test/test-vpid-liveslots.js +++ b/packages/SwingSet/test/test-vpid-liveslots.js @@ -6,6 +6,7 @@ import test from 'ava'; import { E } from '@agoric/eventual-send'; import { makePromiseKit } from '@agoric/promise-kit'; +import { WeakRef, FinalizationRegistry } from '../src/weakref'; import { makeLiveSlots } from '../src/kernel/liveSlots'; const RETIRE_VPIDS = true; @@ -190,7 +191,14 @@ function resolutionOf(vpid, mode, targets) { } function makeDispatch(syscall, build) { - const { setBuildRootObject, dispatch } = makeLiveSlots(syscall, 'vatA'); + const gcTools = harden({ WeakRef, FinalizationRegistry }); + const { setBuildRootObject, dispatch } = makeLiveSlots( + syscall, + 'vatA', + {}, + {}, + gcTools, + ); setBuildRootObject(build); return dispatch; }