From cb10c802f46674453f57aa7d19af3ebbdbba5a60 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Tue, 23 Mar 2021 23:41:48 +0200 Subject: [PATCH] Support GraalVM 21.1 LocalizationFeature Fixes: #15962 (cherry picked from commit fffd6c38d3414e3b5c2177fab5734ca7800d6ce3) --- .../steps/NativeImageAutoFeatureStep.java | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/steps/NativeImageAutoFeatureStep.java b/core/deployment/src/main/java/io/quarkus/deployment/steps/NativeImageAutoFeatureStep.java index 3cb12a9ffb3f4..dc1f22ebaee2f 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/steps/NativeImageAutoFeatureStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/steps/NativeImageAutoFeatureStep.java @@ -35,6 +35,7 @@ import io.quarkus.deployment.builditem.nativeimage.RuntimeReinitializedClassBuildItem; import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; import io.quarkus.deployment.builditem.nativeimage.UnsafeAccessedFieldBuildItem; +import io.quarkus.gizmo.AssignableResultHandle; import io.quarkus.gizmo.CatchBlockCreator; import io.quarkus.gizmo.ClassCreator; import io.quarkus.gizmo.ClassOutput; @@ -66,7 +67,8 @@ public class NativeImageAutoFeatureStep { static final String JNI_RUNTIME_ACCESS = "com.oracle.svm.core.jni.JNIRuntimeAccess"; static final String BEFORE_ANALYSIS_ACCESS = Feature.BeforeAnalysisAccess.class.getName(); static final String DYNAMIC_PROXY_REGISTRY = "com.oracle.svm.core.jdk.proxy.DynamicProxyRegistry"; - static final String LOCALIZATION_FEATURE = "com.oracle.svm.core.jdk.LocalizationFeature"; + static final String LEGACY_LOCALIZATION_FEATURE = "com.oracle.svm.core.jdk.LocalizationFeature"; + static final String LOCALIZATION_FEATURE = "com.oracle.svm.core.jdk.localization.LocalizationFeature"; @BuildStep void generateFeature(BuildProducer nativeImageClass, @@ -217,12 +219,28 @@ public void write(String s, byte[] bytes) { } if (!resourceBundles.isEmpty()) { - ResultHandle locClass = overallCatch.loadClass(LOCALIZATION_FEATURE); + AssignableResultHandle registerMethod = overallCatch.createVariable(Method.class); + AssignableResultHandle locClass = overallCatch.createVariable(Class.class); + TryBlock locTryBlock = overallCatch.tryBlock(); + ResultHandle legacyLocClass = locTryBlock.loadClass(LEGACY_LOCALIZATION_FEATURE); + locTryBlock.assign(locClass, legacyLocClass); + + ResultHandle legacyParams = locTryBlock.marshalAsArray(Class.class, locTryBlock.loadClass(String.class)); + ResultHandle legacyRegisterMethod = locTryBlock.invokeVirtualMethod( + ofMethod(Class.class, "getDeclaredMethod", Method.class, String.class, Class[].class), legacyLocClass, + locTryBlock.load("addBundleToCache"), legacyParams); + locTryBlock.assign(registerMethod, legacyRegisterMethod); + + CatchBlockCreator locCatchBlock = locTryBlock.addCatch(NoClassDefFoundError.class); + ResultHandle newLocClass = locCatchBlock.loadClass(LOCALIZATION_FEATURE); + locCatchBlock.assign(locClass, newLocClass); + + ResultHandle newParams = locCatchBlock.marshalAsArray(Class.class, locCatchBlock.loadClass(String.class)); + ResultHandle newRegisterMethod = locCatchBlock.invokeVirtualMethod( + ofMethod(Class.class, "getDeclaredMethod", Method.class, String.class, Class[].class), newLocClass, + locCatchBlock.load("prepareBundle"), newParams); + locCatchBlock.assign(registerMethod, newRegisterMethod); - ResultHandle params = overallCatch.marshalAsArray(Class.class, overallCatch.loadClass(String.class)); - ResultHandle registerMethod = overallCatch.invokeVirtualMethod( - ofMethod(Class.class, "getDeclaredMethod", Method.class, String.class, Class[].class), locClass, - overallCatch.load("addBundleToCache"), params); overallCatch.invokeVirtualMethod(ofMethod(AccessibleObject.class, "setAccessible", void.class, boolean.class), registerMethod, overallCatch.load(true));