Repository navigation
Commit 5ca0268
committed
feat(event-loop): merge timers into the ordered lane; route __runOnMainThread through the internal lane
Timers merge (with tombstones):
- Timers no longer owns a Java Handler: each scheduled timer posts one
anonymous token through the EventLoop's ordered lane, and the token
drain runs the earliest due item across timers and ordered macrotasks
- one due-ordered domain, still strictly FIFO with Handler.post on
the same looper. Token 'when' computation is unchanged, so the
quiescent setTimeout-vs-Handler.post contract is preserved exactly.
- clearTimeout/clearInterval tombstone the sorted entry instead of
erasing it: the cleared timer's already-queued token consumes its own
slot as a no-op, so no token gains surplus capacity to run a
later-scheduled item (timer or macrotask) ahead of foreign Java
messages queued between the two token positions. This also fixes the
pre-existing congestion deviation where a leftover token could fire a
later timer early.
- FireTimer's internals (sub-ms sorted list, chromium-style interval
catch-up, nesting clamp, TryCatch discipline) are untouched; the
check-and-run happens in one OrderedTaskSource::RunIfEarliest call
under a single Locker acquisition, because background threads mutate
the timer bookkeeping through setTimeout under multithreaded JS.
- TimerHandler.java is deleted.
__runOnMainThread promotion:
- The 2MB main-looper pipe and RunOnMainThreadFdCallback are replaced
by bare internal-lane entries on the main runtime's EventLoop. Bare
entries skip the loop's Locker/checkpoint: the closure locks the
CALLER's isolate (a worker's, under multithreaded JS), and taking the
main isolate's Locker first would nest Lockers across isolates and
can deadlock against worker->main JNI entry paths. Delivery stays
one-per-poll, matching the old fd callback.
- The callback cache is now mutex-guarded: it was written from
arbitrary threads under different isolates' Lockers, which provide no
mutual exclusion; RemoveIsolateEntries also no longer erases while
range-iterating.
- Uncaught exceptions in the callbacks now surface as pending Java
exceptions via the loop's guard instead of unwinding C++ through the
ALooper callback frame.
Tests: tombstone ordering specs (cleared timer's token vs java posts,
for both a later timer and a queued macrotask), against the native
__ns__ timers - the test app's global setTimeout is an old
Handler-based polyfill with colliding ids, not the runtime timers.1 parent 8da0d88 commit 5ca0268
10 files changed
Lines changed: 308 additions & 230 deletions
File tree
- test-app
- app/src/main/assets/app/tests
- runtime/src/main
- cpp
- java/com/tns
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
90 | 92 | | |
91 | 93 | | |
92 | | - | |
| 94 | + | |
93 | 95 | | |
94 | 96 | | |
95 | 97 | | |
| |||
116 | 118 | | |
117 | 119 | | |
118 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
119 | 157 | | |
120 | 158 | | |
121 | 159 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
684 | 684 | | |
685 | 685 | | |
686 | 686 | | |
687 | | - | |
688 | | - | |
689 | | - | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
690 | 693 | | |
691 | | - | |
692 | | - | |
693 | | - | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
694 | 702 | | |
695 | 703 | | |
696 | | - | |
697 | | - | |
698 | | - | |
699 | | - | |
700 | | - | |
701 | | - | |
702 | | - | |
703 | | - | |
704 | | - | |
705 | | - | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
706 | 713 | | |
707 | 714 | | |
708 | | - | |
709 | 715 | | |
710 | 716 | | |
711 | 717 | | |
712 | | - | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
713 | 728 | | |
714 | 729 | | |
715 | 730 | | |
716 | | - | |
717 | | - | |
718 | 731 | | |
719 | 732 | | |
720 | 733 | | |
721 | 734 | | |
722 | 735 | | |
723 | 736 | | |
724 | 737 | | |
| 738 | + | |
725 | 739 | | |
726 | 740 | | |
727 | | - | |
728 | | - | |
729 | 741 | | |
730 | 742 | | |
731 | 743 | | |
| |||
1611 | 1623 | | |
1612 | 1624 | | |
1613 | 1625 | | |
1614 | | - | |
1615 | | - | |
1616 | | - | |
| 1626 | + | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
1617 | 1634 | | |
1618 | 1635 | | |
1619 | 1636 | | |
1620 | 1637 | | |
| 1638 | + | |
1621 | 1639 | | |
1622 | 1640 | | |
1623 | 1641 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
76 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
77 | 80 | | |
78 | 81 | | |
79 | 82 | | |
| |||
241 | 244 | | |
242 | 245 | | |
243 | 246 | | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
244 | 251 | | |
245 | 252 | | |
246 | 253 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
119 | 123 | | |
120 | 124 | | |
121 | 125 | | |
| |||
216 | 220 | | |
217 | 221 | | |
218 | 222 | | |
219 | | - | |
| 223 | + | |
220 | 224 | | |
221 | 225 | | |
222 | 226 | | |
223 | 227 | | |
224 | 228 | | |
225 | 229 | | |
226 | 230 | | |
227 | | - | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
228 | 240 | | |
229 | 241 | | |
230 | 242 | | |
231 | 243 | | |
232 | 244 | | |
233 | 245 | | |
234 | 246 | | |
235 | | - | |
| 247 | + | |
236 | 248 | | |
237 | 249 | | |
238 | 250 | | |
239 | 251 | | |
240 | 252 | | |
241 | 253 | | |
242 | 254 | | |
243 | | - | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
244 | 274 | | |
245 | 275 | | |
246 | 276 | | |
247 | 277 | | |
248 | 278 | | |
249 | 279 | | |
250 | 280 | | |
251 | | - | |
| 281 | + | |
252 | 282 | | |
253 | 283 | | |
254 | 284 | | |
| |||
288 | 318 | | |
289 | 319 | | |
290 | 320 | | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
291 | 332 | | |
292 | 333 | | |
293 | 334 | | |
| |||
313 | 354 | | |
314 | 355 | | |
315 | 356 | | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
316 | 363 | | |
317 | 364 | | |
318 | 365 | | |
| |||
370 | 417 | | |
371 | 418 | | |
372 | 419 | | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
373 | 441 | | |
374 | 442 | | |
375 | 443 | | |
| |||
378 | 446 | | |
379 | 447 | | |
380 | 448 | | |
381 | | - | |
382 | | - | |
383 | | - | |
| 449 | + | |
| 450 | + | |
384 | 451 | | |
385 | | - | |
386 | 452 | | |
387 | 453 | | |
388 | 454 | | |
| |||
0 commit comments