You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit f9e7a09
Browse filesBrowse the repository at this point in the historyBrowse files
A private WeakMap maps every canary that stands for a key to that key, so
lookups of canaries make no native call, and a value missing there was never
a key. The runtime does not call into JS for each canary it builds for a
keyed object: it counts them in a shared Int32Array, and the first lookup
that misses while the count is nonzero takes them all in one call. The key
lives on the object's canary record, where that call reads it, so keying an
object no longer gives it a state.
keyFor rules out plain JS objects first with maybeCanary, a V8 fast call, so
set, add, register and new WeakRef make no native call for them. Each WeakRef
keeps a native WeakRef to its canary for deref. A weakCollectionNativeCalls
counter counts the calls into the runtime.
Copy file name to clipboardExpand all lines: docs/ns-builtin-modules.md
+20-12Lines changed: 20 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -104,7 +104,7 @@ wrapper.
104
104
|`setConfig(key, value)`| Sets a runtime config key. Throws `TypeError` on an unknown key, an invalid value, or (for process-wide keys) when called from a worker isolate. |
105
105
|`getConfig(key)`| Returns the current value of a config key. Throws `TypeError` on an unknown key. Readable from any isolate. |
106
106
|`getWrapperLifetimeStats()`| Wrapper lifetime counters for the calling isolate (see [Wrapper lifetime](#wrapper-lifetime)). A fresh object on every call. |
107
-
|`getWrapperClassCounts()`| Per Java class name (`<unknown>` for a link whose class was never recorded), the calling isolate's live `wrappers`, the `canaries` among them and the canary `states`, which include those made only for a weak-collection key (see [Wrapper lifetime](#wrapper-lifetime)). |
107
+
|`getWrapperClassCounts()`| Per Java class name (`<unknown>` for a link whose class was never recorded), the calling isolate's live `wrappers`, the `canaries` among them and the canary `states` (see [Wrapper lifetime](#wrapper-lifetime)). |
108
108
|`escapeException(x)`| Returns an `Error` branded so that, when it is thrown back across a native callback boundary, the native caller receives the original native exception `x` carries rather than the runtime's wrapper exception. Idempotent: a branded error is returned unchanged. Throws `TypeError` when called with no argument. The global `interop.escapeException` is this same function (see [Legacy globals](#legacy-globals)). |
109
109
110
110
*Platform note (Android):* the original exception is the Java throwable `x`
@@ -189,17 +189,19 @@ every build on cold paths only:
189
189
|`collected`| wrappers released because Java had collected their object |
190
190
|`releasedExplicitly`| links released through `__releaseNativeCounterpart`|
191
191
|`releasedAccesses`| lookups of the Java object of a wrapper whose link was released or whose Java object Java had already collected: calling its methods, using its fields or passing it to Java. Resolving an overloaded method looks its arguments up too, so one call can count more than once |
192
-
|`canaryStates`|`"canary"` only: state objects created to hold JS properties, or to hold the key a weak collection made for the object, in which case no JS property was written|
192
+
|`canaryStates`|`"canary"` only: state objects created to hold JS properties |
193
193
|`canaryNativeDeaths`|`"canary"` only: state objects let go of because Java collected their object |
194
194
|`canaryInterceptedWrites`|`"canary"` only: writes to canaries the write handler saw. Canaries without state have no handler |
195
195
|`canaryCachedWrites`|`"canary"` only: of those writes, rewrites of a name the handler knew to be a plain data property of the state, mirrored with one store |
196
196
|`canaryCachedFieldWrites`|`"canary"` only: of those writes, Java field writes the handler placed from an earlier write of the same name through an object with the same prototype, without looking the name up along the prototype chain |
197
197
|`canaryRebuilds`|`"canary"` only: canaries built anew for a JS-extended instance whose previous canary died while Java kept the object |
198
+
|`weakCollectionNativeCalls`|`"canary"` only: calls the weak collections make into the runtime: to make the key of a canary's Java object, to find the canary for a key, and to learn about canaries built for keyed objects since the last such call. Lookups of a value that was never a key make none |
198
199
199
200
In `"canary"` mode only array buffers backed by Java buffers resurrect;
200
201
`weakened` counts objects held weakly because their canary died while they
201
-
had a record (JS state, or a JS-extended instance), and `collected` counts
202
-
canaries whose object had none, which Java no longer holds for JS.
202
+
had a record (JS state, a weak-collection key, or a JS-extended instance),
203
+
and `collected` counts canaries whose object had none, which Java no longer
204
+
holds for JS.
203
205
204
206
`"canary"` is the resurrection-free model the iOS runtime and the Node-API
205
207
runtimes share. Every wrapper of a Java object is a canary: a phantom-weak JS
@@ -274,21 +276,27 @@ on it, and lives as long as it does.
274
276
old one without keeping it, so in canary mode a builtin
275
277
(`js/weak-collections.js`) replaces `WeakMap`, `WeakSet`, `WeakRef` and
276
278
`FinalizationRegistry` with subclasses that key a Java object whose wrapper is
277
-
a canary by an opaque, frozen key its state holds. Entries and targets
278
-
therefore live exactly as long as the Java object; `WeakRef.prototype.deref`
279
+
a canary by an opaque, frozen key the object's record holds. Entries and
280
+
targets therefore live exactly as long as the Java object; `WeakRef.prototype.deref`
279
281
(and the `get` alias) returns the live canary, a new one with the object's
280
282
state, or `undefined` once Java collected the object. `set`, `add`,
281
-
`getOrInsert`, `new WeakRef` and `register` create the key; lookups never do,
282
-
so probing an object gives it no state. A Proxy around a Java object stays a
283
+
`getOrInsert`, `new WeakRef` and `register` create the key; lookups never do.
284
+
Neither gives the object a state. A Proxy around a Java object stays a
283
285
key of its own, and every other value passes through to the standard
284
286
collection. The cost is the other side of the same rooting: a `WeakMap` value
285
-
that references its Java key keeps the key, its state and so the Java object
287
+
that references its Java key keeps the key, its record and so the Java object
286
288
alive for as long as the map lives. And `deref` builds a canary, which holds
287
289
the Java object strongly until it dies again, so a `WeakRef` to a Java object
288
290
that is dereferenced on every frame or event may keep the object from ever
289
-
being collected. In canary mode, an operation on an object costs a native
290
-
call, and one that can create the key also checks its receiver first so that
291
-
a call that fails leaves no key behind; that check names `has` (or
291
+
being collected. In canary mode, an operation that can create the key costs a
292
+
native call for a Java object the collection does not hold yet; a plain JS
293
+
object costs only a V8 fast call that rules it out. Lookups (`get`, `has`,
294
+
`delete`, `unregister`, `deref`) make no native call, except a `deref` that
295
+
has to build a canary, and the first lookup that misses after the runtime
296
+
built canaries for keyed objects, which makes one call for all of them. An
297
+
operation that can create the
298
+
key also checks its receiver first so that a call that fails leaves no key
299
+
behind; that check names `has` (or
292
300
`unregister`) in its `TypeError`. The collections are subclasses of the
293
301
standard ones, which shows: `Object.getPrototypeOf(WeakMap.prototype)` is the
294
302
standard prototype, and `WeakMap.toString()` is not native code.
0 commit comments