Commit 55c414a
committed
refactor: production-ready ES2021 FinalizationRegistry with PhantomReferences
Complete rewrite addressing all PR #2058 feedback from aardvark179:
**Architecture Changes:**
- Replace WeakReference with PhantomReference for correct GC semantics
- Implement singleton FinalizationQueueManager with shared ReferenceQueue
- Add Context integration for proper JavaScript execution timing
- Thread-safe operations with ConcurrentHashMap and synchronized blocks
**Key Improvements:**
- Memory leak prevention with proper WeakReference usage in TokenKey
- O(1) token-based unregistration with reverse index
- Bounded cleanup queue (MAX_PENDING_CLEANUPS=10000) prevents OOM
- Complete cleanupSome() implementation with callback override support
- Comprehensive error handling with thread safety
**New Components:**
- FinalizationQueueManager.java - Singleton Cleaner-like infrastructure
- FinalizationRegistryCleanupBehaviorTest.java - 10 cleanup behavior tests
- FinalizationRegistryCrossRealmTest.java - 6 cross-realm scenarios
**Test Coverage:**
- 72+ tests across 5 test files
- Cross-realm support validated
- Internal implementation white-box testing
- GC integration verified
Ready for PR submission to Mozilla Rhino.1 parent cbc348e commit 55c414a
File tree
10 files changed
+1168
-249
lines changed- rhino/src/main/java/org/mozilla/javascript
- tests
- src/test/java/org/mozilla/javascript/tests/es2021
- testsrc
10 files changed
+1168
-249
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
520 | 520 | | |
521 | 521 | | |
522 | 522 | | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
523 | 530 | | |
524 | 531 | | |
525 | 532 | | |
| |||
555 | 562 | | |
556 | 563 | | |
557 | 564 | | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
558 | 569 | | |
559 | 570 | | |
560 | 571 | | |
| |||
2520 | 2531 | | |
2521 | 2532 | | |
2522 | 2533 | | |
| 2534 | + | |
| 2535 | + | |
| 2536 | + | |
| 2537 | + | |
| 2538 | + | |
| 2539 | + | |
| 2540 | + | |
| 2541 | + | |
| 2542 | + | |
| 2543 | + | |
| 2544 | + | |
| 2545 | + | |
| 2546 | + | |
| 2547 | + | |
| 2548 | + | |
| 2549 | + | |
| 2550 | + | |
| 2551 | + | |
| 2552 | + | |
| 2553 | + | |
| 2554 | + | |
| 2555 | + | |
| 2556 | + | |
| 2557 | + | |
| 2558 | + | |
| 2559 | + | |
| 2560 | + | |
| 2561 | + | |
| 2562 | + | |
| 2563 | + | |
| 2564 | + | |
| 2565 | + | |
| 2566 | + | |
| 2567 | + | |
| 2568 | + | |
2523 | 2569 | | |
2524 | 2570 | | |
2525 | 2571 | | |
| |||
2842 | 2888 | | |
2843 | 2889 | | |
2844 | 2890 | | |
| 2891 | + | |
2845 | 2892 | | |
2846 | 2893 | | |
2847 | 2894 | | |
| |||
0 commit comments