From 7f8617e6767bc435f19aae198614b617e9703a65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Mon, 1 Feb 2021 12:26:20 +0100 Subject: [PATCH] Use MethodHandles rather than java.lang.reflect for entity reading in Hibernate Search with GraalVM 21+ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../HibernateSearchElasticsearchRecorder.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchRecorder.java b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchRecorder.java index 4ff5112031168..fc6c5dc3b64ba 100644 --- a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchRecorder.java +++ b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchRecorder.java @@ -11,6 +11,7 @@ import javax.enterprise.inject.literal.NamedLiteral; +import org.graalvm.home.Version; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.boot.Metadata; @@ -111,6 +112,8 @@ public void onMetadataInitialized(Metadata metadata, BootstrapContext bootstrapC private static final class HibernateSearchIntegrationStaticInitListener implements HibernateOrmIntegrationStaticInitListener { + private static final Version GRAAL_VM_VERSION_21 = Version.create(21); + private final HibernateSearchElasticsearchBuildTimeConfigPersistenceUnit buildTimeConfig; private HibernateSearchIntegrationStaticInitListener( @@ -135,8 +138,15 @@ public void contributeBootProperties(BiConsumer propertyCollecto @Override public void onMetadataInitialized(Metadata metadata, BootstrapContext bootstrapContext, BiConsumer propertyCollector) { + Version graalVMVersion = Version.getCurrent(); + boolean isGraalVM20OrBelow = !graalVMVersion.isSnapshot() // isSnapshot() will be true on OpenJDK + && graalVMVersion.compareTo(GRAAL_VM_VERSION_21) < 0; HibernateOrmIntegrationBooter booter = HibernateOrmIntegrationBooter.builder(metadata, bootstrapContext) - .valueReadHandleFactory(ValueReadHandleFactory.usingJavaLangReflect()) + .valueReadHandleFactory( + // GraalVM 20 or below doesn't support method handles + isGraalVM20OrBelow ? ValueReadHandleFactory.usingJavaLangReflect() + // GraalVM 21+ and OpenJDK can handle the default (method handles) + : null) .build(); booter.preBoot(propertyCollector); }