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 ee97b64
Browse filesBrowse the repository at this point in the historyBrowse files
docs(runtime): weak collections: released canaries, polled WeakRefs, counts
- A released canary keeps what weak collections keyed on its object.
- A WeakRef to a Java object dereferenced on every frame or event builds
a canary each time its wrapper died, holding the object strongly, so
it may never clear.
- canaryStates and getWrapperClassCounts().states include states made
only to hold a weak-collection key.
- The receiver check names has/unregister in its TypeError, and the
collections show that they are subclasses.
Copy file name to clipboardExpand all lines: docs/ns-builtin-modules.md
+14-5Lines changed: 14 additions & 5 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` (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`, which include those made only for a weak-collection key (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,7 +189,7 @@ 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 |
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|
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. Other wrappers have no handler |
195
195
|`canaryRebuilds`|`"canary"` only: canaries built anew for a JS-extended instance whose previous canary died while Java kept the object |
@@ -256,7 +256,9 @@ no prototype change to the handler). Native `#private` fields are branded on
256
256
the canary and do not carry over.
257
257
A canary built after another died is a new JS object, which `===` cannot tell
258
258
because nothing kept the old one. `__releaseNativeCounterpart` drops the
259
-
object's state with its link.
259
+
object's state with its link, and the released canary is a plain JS object
260
+
from then on: what the weak collections keyed on its Java object stays keyed
261
+
on it, and lives as long as it does.
260
262
261
263
**Weak collections.** What could notice a new canary is whatever keys on the
262
264
old one without keeping it, so in canary mode a builtin
@@ -271,8 +273,15 @@ so probing an object gives it no state. A Proxy around a Java object stays a
271
273
key of its own, and every other value passes through to the standard
272
274
collection. The cost is the other side of the same rooting: a `WeakMap` value
273
275
that references its Java key keeps the key, its state and so the Java object
274
-
alive for as long as the map lives. Each operation costs one native call in
275
-
canary mode, whatever the key.
276
+
alive for as long as the map lives. And `deref` builds a canary, which holds
277
+
the Java object strongly until it dies again, so a `WeakRef` to a Java object
278
+
that is dereferenced on every frame or event may keep the object from ever
279
+
being collected. In canary mode, an operation on an object costs a native
280
+
call, and one that can create the key also checks its receiver first so that
281
+
a call that fails leaves no key behind; that check names `has` (or
282
+
`unregister`) in its `TypeError`. The collections are subclasses of the
283
+
standard ones, which shows: `Object.getPrototypeOf(WeakMap.prototype)` is the
284
+
standard prototype, and `WeakMap.toString()` is not native code.
0 commit comments