Skip to content

Commit

Permalink
Use MethodHandles rather than java.lang.reflect for entity reading in…
Browse files Browse the repository at this point in the history
… 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]>
  • Loading branch information
yrodiere committed Feb 17, 2021
1 parent e23e2ff commit 7f8617e
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -135,8 +138,15 @@ public void contributeBootProperties(BiConsumer<String, Object> propertyCollecto
@Override
public void onMetadataInitialized(Metadata metadata, BootstrapContext bootstrapContext,
BiConsumer<String, Object> 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);
}
Expand Down

0 comments on commit 7f8617e

Please sign in to comment.