[GR-38070] Share reflection invocation stubs with same signature. #4517
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR changes how reflective method invocations are done: instead of a generated stub that unpacks the parameters and then does a virtual/special/static call to invoke the actual target, now the invoke is always a function pointer call. This allows re-using the stubs for all reflective invocations with the same signature. To further increase sharing, the type check for the receiver is no longer done in the generated stub. This allows sharing of instance method invokes with different receiver classes.
For my usual Spring petclinic-jdbc benchmark, there are 1346 unique signatures for 7855 methods that are registered for reflection.
The PR also ensure that the generated graphs and the
SubstrateMethodAccessor
instances do not hold on tojava.lang.reflect.Method
objects. That removes many unnecessaryMethod
objects from the image heap (at the cost of a little worse error message when invoking a method with wrong parameter types).The first commit will be merged out separately by Codrut beforehand. The commit that introduces
KnownAccessors
is mostly a refactoring to make the vtable base offset easier available without the need to have aRuntimeConfiguration
instance.