Skip to content

Add MethodHandle support to the ProviderToInternalFactoryAdapter #1887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2025

Conversation

copybara-service[bot]
Copy link

Add MethodHandle support to the ProviderToInternalFactoryAdapter

This follows the pattern of how InjectorImpl.getProvider works and calls into the same method for generating a provider subtype. There are 2 critical differences

  1. We always set the linked flag to true for these 'Scoped' providers.
  2. The dependency is inferred from the InternalContext.getDependency method

The latter point adds some non-trivial complexity since getHandle accepts Dependency as a parameter and generally specializes behavior on it (checks if it is nullable, used in error messages, raw types are used for proxies and error messages). So we use the 'callsite' trick to bind the implementation to a patchable callsite that we can update whenever we see a new dependency.

The callsite will be implemented as a tableSwitch when possible and a hashmap holding method handles otherwise (<jdk17).

This follows the pattern of how `InjectorImpl.getProvider` works and calls into the same method for generating a provider subtype.  There are 2 critical differences

1. We always set the `linked` flag to `true` for these 'Scoped' providers.
2. The `dependency` is inferred from the `InternalContext.getDependency` method

The latter point adds some non-trivial complexity since `getHandle` accepts `Dependency` as a parameter and generally specializes behavior on it (checks if it is nullable, used in error messages, raw types are used for proxies and error messages).  So we use the 'callsite' trick to bind the implementation to a patchable callsite that we can update whenever we see a new dependency.

The callsite will be implemented as a `tableSwitch` when possible and a hashmap holding method handles otherwise (<jdk17).

PiperOrigin-RevId: 740381461
@copybara-service copybara-service bot merged commit 2257657 into master Mar 25, 2025
@copybara-service copybara-service bot deleted the test_737746596 branch March 25, 2025 16:44
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.

1 participant