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 5653551
Browse filesBrowse the repository at this point in the historyBrowse files
Adds "wrapperLifetime": { "mode": "canary" }, the resurrection-free
model the iOS runtime (NativeScript/ios#561) and the Node-API runtimes
share. A wrapper in scope is a phantom-weak canary that dies with its JS
references. A masking setter/deleter/definer interceptor mirrors its JS
properties into a state object that lives until Java collects the object;
a canary built later gets them back. When a canary dies, the Java object
table holds an object with state through a watched weak reference and
releases the others; a daemon thread on the references' queue reports
Java collections, and the state is let go of on the runtime's thread.
JS-extended instances (extend(), interface implementations, instances
Java constructed) keep a record from registration, so Java can still call
into JS after their canary died: the runtime rebuilds the canary with the
instance's prototype, implementation object, internal fields and state.
Scope "extended" (default) makes canaries of JS-extended instances only;
other wrappers keep the resurrecting lifetime. "all" covers every wrapper
of a Java object. ns:runtime gains getWrapperClassCounts() and canary
counters.
Copy file name to clipboardExpand all lines: docs/ns-builtin-modules.md
+52-2Lines changed: 52 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -104,6 +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, the calling isolate's live `wrappers`, the `canaries` among them and the canary `states` (see [Wrapper lifetime](#wrapper-lifetime)). |
107
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)). |
108
109
109
110
*Platform note (Android):* the original exception is the Java throwable `x`
@@ -118,7 +119,7 @@ Config keys:
118
119
| key | values | scope | default |
119
120
|---|---|---|---|
120
121
|`debug`| comma-separated category list, e.g. `"esm,fetch"`| process-wide (main-isolate writes only; read live by every isolate) | the `NS_DEBUG` environment variable, or `""`|
121
-
|`wrapperLifetimeMode`|`"resurrecting"`| process-wide, read-only | the app config `"wrapperLifetime": { "mode": … }`, or `"resurrecting"`|
122
+
|`wrapperLifetimeMode`|`"resurrecting"`\|`"canary"`| process-wide, read-only | the app config `"wrapperLifetime": { "mode": … }`, or `"resurrecting"`|
122
123
|`wrapperLifetimeScope`|`"extended"`\|`"all"`| process-wide, read-only | the app config `"wrapperLifetime": { "scope": … }`, or `"extended"`|
123
124
124
125
iOS additionally registers `releasedObjectPolicy`, which governs access to a
@@ -160,7 +161,7 @@ top-level `"wrapperLifetime"` object of the app's `package.json`, the same key
A value that is not an object, or an unknown `mode` or `scope`, logs a warning
@@ -185,6 +186,55 @@ every build on cold paths only:
185
186
|`collected`| wrappers released because Java had collected their object |
186
187
|`releasedExplicitly`| links released through `__releaseNativeCounterpart`|
187
188
|`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 |
189
+
|`canaryStates`|`"canary"` only: state objects created to hold JS properties |
190
+
|`canaryNativeDeaths`|`"canary"` only: state objects let go of because Java collected their object |
191
+
|`canaryInterceptedWrites`|`"canary"` only: writes to canaries the write handler saw. Other wrappers have no handler |
192
+
|`canaryRebuilds`|`"canary"` only: canaries built anew for a JS-extended instance whose previous canary died while Java kept the object |
193
+
194
+
In `"canary"` mode, `weakened` counts objects held weakly because their
195
+
canary died while they had JS state, and `collected` counts canaries whose
196
+
object had none, which Java no longer holds for JS.
197
+
198
+
`"canary"` is the resurrection-free model the iOS runtime and the Node-API
199
+
runtimes share. A wrapper in scope is a canary: a phantom-weak JS object that
200
+
dies with its JS references.
201
+
202
+
-**State.** A masking named interceptor (a setter, a deleter and a definer,
203
+
nothing that runs on reads) mirrors every JS property written to a canary
204
+
into a separate state object and lets V8 apply the write to the canary too,
205
+
so reads cost what they cost on a plain object. A write that resolves to a
206
+
Java field, another inherited accessor or a read-only property is not state.
207
+
The state lives until Java collects the object; a canary built later for the
208
+
same object gets its properties back, attributes, accessors and symbol keys
209
+
included.
210
+
-**Java's side.** While a canary is alive, Java holds its object strongly.
211
+
When it dies, Java holds an object with state weakly and releases any other.
212
+
A thread watching those weak references tells the runtime when Java collects
213
+
an object, and its state is let go of on the runtime's thread.
0 commit comments