Skip to content
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

Less reflection and move to MethodHandles in Hibernate Search extension #15152

Merged
merged 3 commits into from
Feb 18, 2021

Conversation

yrodiere
Copy link
Member

We don't need to enable runtime reflection on user classes, because:

  1. We perform all reflection operations, except getting values from entities,
    at static init.
  2. After static init, we hold references to all Methods/Fields that we
    will actually use at runtime. SubstrateVM is able to detect those and
    to properly build a native image that will handle calling invoke() on
    these Methods/Fields.

Also, when using GraalVM 21 or OpenJDK, we can move from java.lang.reflect to MethodHandles. Which is what Hibernate Search uses by default, and what we tested in most depth.

This supersedes #14739: I added conditional behavior so that we use java.lang.reflect on GraalVM 20 and below, but MethodHandles on OpenJDK and GraalVM 21+. The original PR was always using MethodHandles, which could be a problem with GraalVM 20 and below. I also added specific tests to check that property access works as expected.

Related: https://quarkusio.zulipchat.com/#narrow/stream/187038-dev/topic/MethodHandles.20in.20Hibernate.20Search

We don't need to, because:

1. We perform all reflection operations, except getting values from entities,
   at static init.
2. After static init, we hold references to all Methods/Fields that we
   will actually use at runtime. SubstrateVM is able to detect those and
   to properly build a native image that will handle calling invoke() on
   these Methods/Fields.

Signed-off-by: Yoann Rodière <[email protected]>
… Hibernate Search with GraalVM 21+

GraalVM 21.0 supports method handles, so let's use them. The main
benefit is that we'll use them in JVM mode too, where they should
theoretically perform slightly better.

Signed-off-by: Yoann Rodière <[email protected]>
@quarkus-bot quarkus-bot bot added the area/hibernate-search Hibernate Search label Feb 17, 2021
@yrodiere
Copy link
Member Author

Note I tested this patch locally by running the Hibernate Search integration tests with OpenJDK, GraalVM 20.3 (with -Pnative) and GraalVM 21.0 (with -Pnative). Everything passed. I also used debug mode during static init to check that version detection works as expected.

Copy link
Member

@gsmet gsmet left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks, nice cleanup!

@gsmet gsmet merged commit 939374d into quarkusio:master Feb 18, 2021
@quarkus-bot quarkus-bot bot added this to the 1.13 - master milestone Feb 18, 2021
@yrodiere yrodiere deleted the methodhandles branch May 17, 2021 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-search Hibernate Search
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants