Skip to content

refactor/eliminate finalization#823

Merged
joe-chacko merged 11 commits into
OpenLiberty:mainfrom
ngmr:refactor/eliminate-finalization
Jun 25, 2026
Merged

refactor/eliminate finalization#823
joe-chacko merged 11 commits into
OpenLiberty:mainfrom
ngmr:refactor/eliminate-finalization

Conversation

@ngmr

@ngmr ngmr commented Jun 24, 2026

Copy link
Copy Markdown
Member
  • refactor(rmi-impl): use ClassValue instead of Map for stub caching
  • refactor(rmi-impl): make MethodRef immutable with lazy initialization
  • refactor(rmi-impl): use MethodHandles and Supplier pattern for stub creation
  • refactor(rmi-impl): use MethodHandles for Externalizable object instantiation
  • refactor(yoko-util,yoko-core): use MethodHandles for simple constructors
  • refactor(yoko-core): remove assertion-only finalize() methods
  • feat(yoko-util): add YokoCleaner for Java 8-compatible resource cleanup
  • refactor: Replace DowncallStub finalizer with YokoCleaner
  • refactor(yoko-core): remove assertion-only finalizers from GIOPServerStarter and GIOPServer
  • refactor(yoko-core): remove Request finalizer
  • refactor(yoko-core): remove finalizers from Delegate and DirectServant
  • refactor(yoko-core): remove finalizer from ActiveObjectOnlyStrategy
  • refactor(yoko-core): remove finalizer from Transport_impl
  • refactor(yoko-core): remove finalizer from Connector_impl
  • refactor(yoko-core): remove finalizer from ORB_impl
  • refactor(yoko-core): remove finalizer from Acceptor_impl

Fixes #804

@ngmr ngmr self-assigned this Jun 24, 2026
@ngmr ngmr requested a review from joe-chacko June 24, 2026 11:02
@ngmr ngmr force-pushed the refactor/eliminate-finalization branch 2 times, most recently from c2f1325 to c378a21 Compare June 24, 2026 22:13
ngmr added 2 commits June 25, 2026 00:05
- Removed finalize() from ClientManager (assertions for destroyed state and empty collections)
- Removed finalize() from InitialServiceManager (assertion for destroy_ flag)
- Removed finalize() from ORBInstance (assertion for destroyCalled flag)
- Removed finalize() from ServerManager (assertions for destroy_ flag and empty collections)
- Removed finalize() from ThreadPool (assertion for destroy_ flag)
- Removed finalize() from ValueFactoryManager (assertion for destroy_ flag)
- Removed finalize() from POA_impl (assertion for destroyed state)
- Removed finalize() from PoaCurrentImpl (empty finalize method)
- Lines removed: 40

Co-authored-by-AI: IBM Bob 1.0.4
- Created YokoCleaner class using PhantomReference + ReferenceQueue
- Returns SimplyCloseable for manual cleanup triggering
- Uses LazyReference internally for idempotent, thread-safe cleanup
- Use LazyReference<Void> to defer thread creation until first register() call
- All threads calling close() block until cleanup completes
- Exceptions in cleanup actions are caught and logged
- Added comprehensive test suite with 10 passing tests
- Lines added: 382

Co-authored-by-AI: IBM Bob 1.0.4
@ngmr ngmr force-pushed the refactor/eliminate-finalization branch from c378a21 to 53adedf Compare June 24, 2026 23:05
Comment thread yoko-core/src/main/java/org/apache/yoko/orb/OB/DowncallStub.java Outdated
ngmr added 9 commits June 25, 2026 00:31
Phase 3 of finalization refactoring: Refactor DowncallStub to use
YokoCleaner for automatic resource cleanup instead of finalize().

Key changes:
- Added CleanupState static nested class using LazyReference pattern
  for thread-safe lazy initialization of clientProfilePairs
- Changed clientProfilePairs_ from Vector to LazyReference<Vector>
- Removed destroy() and finalize() methods
- Updated all references to use LazyReference.get()
- Cleanup action releases clients via ClientManager when object
  becomes phantom reachable
- Substantive lines added: 71, lines removed: 63

Benefits:
- Eliminates finalizer overhead and unpredictability
- Thread-safe lazy initialization via LazyReference
- Explicit cleanup via SimplyCloseable when needed
- Automatic cleanup on garbage collection via YokoCleaner

Tests: All 91,844 yoko-core tests pass, test-osgi tests pass
…Starter and GIOPServer

Phase 3 of finalization refactoring: Remove assertion-only finalize()
methods from GIOPServerStarter and GIOPServer classes.

- Removed finalize() from GIOPServerStarter (checked serverState == CLOSED)
- Removed finalize() from GIOPServer (checked destroy_ and starter_ == null)
- Both finalizers only contained Assert.ensure() calls with no cleanup logic
- Lines added: 1, lines removed: 18

Tests: All 91,844 yoko-core tests pass

Co-authored-by-AI: IBM Bob 1.0.4
Phase 3 of finalization refactoring: Remove finalize() method from
Request class.

- Removed finalizer that called multi.removeDeferredRequest(this)
- Finalizer was redundant: Request objects in deferredRequests_ list
  have strong references and cannot be GC'd until removed from list
- Finalizer could only run after request already removed (redundant)
  or during ORB shutdown (edge case not worth finalizer overhead)
- Removed TODO comment about RequestStateSent memory leak
- Lines removed: 32

Tests: All yoko-core tests pass

Co-authored-by-AI: IBM Bob 1.0.4
Phase 3 of finalization refactoring: Remove finalize() methods from
Delegate and DirectServant classes.

- Removed Delegate.finalize() that called directServant.destroy()
  - directServant.destroy() is already called explicitly when needed
  - Finalizer was redundant safety net with no practical benefit
- Removed DirectServant.finalize() assertion-only finalizer
  - Only contained ensure(deactivated_) assertion check
  - No actual cleanup logic
- Lines added: 1, lines removed: 17

Tests: All yoko-core tests pass

Co-authored-by-AI: IBM Bob 1.0.4
Phase 3 of finalization refactoring: Remove finalize() method from
DirectSeqEntry inner class in ActiveObjectOnlyStrategy.

- Removed finalizer that called deactivate()
- deactivate() is already called explicitly in completeDeactivate()
- Finalizer was redundant safety net with no practical benefit
- Lines removed: 5

Tests: All yoko-core tests pass

Co-authored-by-AI: IBM Bob 1.0.4
Phase 3 of finalization refactoring: Remove finalize() method from
Transport_impl class.

- Removed finalizer that called close() if socket_ was not null
- close() is already called explicitly when transport is destroyed
- Finalizer was redundant safety net with no practical benefit
- Lines removed: 7

Tests: All yoko-core tests pass

Co-authored-by-AI: IBM Bob 1.0.4
Phase 3 of finalization refactoring: Remove finalize() method from
Connector_impl class.

- Removed finalizer that called close() if socket_ was not null
- close() is already called explicitly when connector is destroyed
- Finalizer was redundant safety net with no practical benefit
- Lines removed: 7

Tests: All yoko-core tests pass

Co-authored-by-AI: IBM Bob 1.0.4
Phase 3 of finalization refactoring: Remove finalize() method from
ORB_impl class.

- Removed finalizer that logged warning if destroy() wasn't called
- Finalizer was diagnostic-only with no actual cleanup logic
- Warning was unreliable due to unpredictable finalization timing
- Lines removed: 7

Tests: All yoko-core tests pass

Co-authored-by-AI: IBM Bob 1.0.4
Phase 3 of finalization refactoring: Remove finalize() method from
Acceptor_impl class.

- Removed finalizer that called close() and removed from listenMap_
- close() is already called explicitly in GIOPServerStarter classes
- listenMap_ cleanup was redundant as acceptors are explicitly managed
- Removed TODO comment about using phantom refs in AccFactory_impl
- Lines removed: 12

Tests: All yoko-core tests pass

Co-authored-by-AI: IBM Bob 1.0.4
@ngmr ngmr force-pushed the refactor/eliminate-finalization branch from 53adedf to 9666ecc Compare June 24, 2026 23:32
@joe-chacko joe-chacko merged commit 664c2ef into OpenLiberty:main Jun 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Java 18: Eliminate use of finalization

2 participants