Skip to content

refactor/use method handles for simple constructors#822

Merged
joe-chacko merged 5 commits into
OpenLiberty:mainfrom
ngmr:refactor/use-method-handles-for-simple-constructors
Jun 24, 2026
Merged

refactor/use method handles for simple constructors#822
joe-chacko merged 5 commits into
OpenLiberty:mainfrom
ngmr:refactor/use-method-handles-for-simple-constructors

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

Fixes #807

@ngmr ngmr self-assigned this Jun 24, 2026
@ngmr ngmr requested a review from joe-chacko June 24, 2026 00:59
@ngmr ngmr force-pushed the refactor/use-method-handles-for-simple-constructors branch from bc5d089 to af42bee Compare June 24, 2026 03:24
ngmr added 5 commits June 24, 2026 12:35
- Replaced stub_map with ClassValue<Constructor<? extends Stub>> in RMIState
- Replaced static_stub_map with ClassValue<Optional<Constructor<? extends Stub>>>
- Moved stub constructor computation logic from PortableRemoteObjectImpl to RMIState.computeRMIStubConstructor()
- Simplified PortableRemoteObjectImpl.getRMIStubClassConstructor() to delegate to ClassValue
- Refactored stub class creation to use Optional for cleaner null handling
- Removed NoDeleteSynchronizedMap.java (no longer needed)
- Removed unused codebase parameter from getStaticStub() and related methods

Benefits:
- Thread-safe caching without explicit synchronization via ClassValue
- Better performance through ClassValue's optimized per-class caching
- Cleaner separation of concerns with stub construction centralized in RMIState
- More idiomatic code using Optional for null handling

- Lines added: 81, lines removed: 190

Co-authored-by-AI: IBM Bob 1.0.4
- Converted MethodRef from mutable to immutable class
- Replaced direct field access with lazy-initialized references using LazyReference
- Changed getParameterTypes() and getExceptionTypes() to return unmodifiable Lists instead of arrays
- Updated BCELClassBuilder to work with List-based API instead of array-based API
- Removed unused import of java.util.logging.Level
- Fixed escaped quote in license header
- Substantive lines added: 45, lines removed: 89

Co-authored-by-AI: IBM Bob 1.0.4
…reation

- Replaced reflection-based Constructor.newInstance() with MethodHandle.invoke()
- Introduced Supplier<Stub> pattern throughout RMIState for lazy stub instantiation
- Deduplicated genStubSupplier() methods by creating overloaded version taking Constructor
- Added NULL_STUB_SUPPLIER constant to replace repeated () -> null lambdas
- Simplified stub creation logic in PortableRemoteObjectImpl using Optional
- Renamed tie_map to tieMap for consistency
- Substantive lines added: 82, lines removed: 108

Co-authored-by-AI: IBM Bob 1.0.4
…ntiation

- Introduced NULL_SERIALIZABLE_SUPPLIER constant to eliminate duplicate lambda expressions
- Made genBlankInstanceSupplier() package-private to allow subclass overrides
- Made createBlankInstance() private to enforce proper encapsulation
- Refactored Externalizable instantiation to use MethodHandles for better performance
- Kept Constructor.newInstance() for Serializable types (required by ReflectionFactory)
- Updated FVDUncustomizableValueDescriptor to override genBlankInstanceSupplier()
- Updated UncustomizableValueDescriptor to override genBlankInstanceSupplier()
- Added explanatory comments for why Serializable types cannot use MethodHandles
- Simplified exception handling in MethodHandle supplier using multi-catch
- Lines added: 60, lines removed: 58

Co-authored-by-AI: IBM Bob 1.0.4
- Introduce InstanceFactory utility class with cached MethodHandle-based instantiation
- Replace reflection-based Constructor.newInstance() calls with MethodHandles for better performance
- Add CannotInstantiateException as unchecked wrapper for instantiation failures
- Update YokoInputStream to use createNoArgsInstance for stub creation
- Update PluginManager to use createNoArgsInstance for plugin initialization
- Update ValueFactoryManager to use createNoArgsInstance and simplify error handling
- Update ValueReader to use createNoArgsInstance for value and helper instantiation
- Update ValueWriter to use createNoArgsInstance for helper instantiation
- Update ORB_impl to use createNoArgsInstance for ORB initializer creation
- Update iiop plugin to use createNoArgsInstance for connection helper creation
- Update SecurityContext to use createNoArgsInstance for delegate creation
- Refactor RepIds.toClass() to simplify control flow and reduce nesting
- Substantive lines added: 149, lines removed: 84

Co-authored-by-AI: IBM Bob 1.0.4
@ngmr ngmr force-pushed the refactor/use-method-handles-for-simple-constructors branch from af42bee to 203071e Compare June 24, 2026 11:35

@joe-chacko joe-chacko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good work. Let's merge it and see what happens.

@joe-chacko joe-chacko merged commit a858e9c into OpenLiberty:main Jun 24, 2026
2 checks passed
@ngmr ngmr deleted the refactor/use-method-handles-for-simple-constructors branch June 24, 2026 22:48
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 7: Replace method invocation via reflection with use of MethodHandles

2 participants