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

Use new RuntimeProxyCreation public API with GraalVM >= 22.3 #27745

Merged
merged 1 commit into from
Sep 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,10 @@ public void write(String s, byte[] bytes) {
}

if (!proxies.isEmpty()) {
// Needed to access DYNAMIC_PROXY_REGISTRY
// Needed to access DYNAMIC_PROXY_REGISTRY in GraalVM 22.2
exports.produce(new JPMSExportBuildItem("org.graalvm.nativeimage.builder", "com.oracle.svm.core.jdk.proxy",
GraalVM.Version.VERSION_22_1_0));
GraalVM.Version.VERSION_22_1_0, GraalVM.Version.VERSION_22_3_0));

ResultHandle proxySupportClass = overallCatch.loadClassFromTCCL(DYNAMIC_PROXY_REGISTRY);
ResultHandle proxySupport = overallCatch.invokeStaticMethod(
IMAGE_SINGLETONS_LOOKUP,
proxySupportClass);
for (NativeImageProxyDefinitionBuildItem proxy : proxies) {
ResultHandle array = overallCatch.newArray(Class.class, overallCatch.load(proxy.getClasses().size()));
int i = 0;
Expand All @@ -281,8 +277,29 @@ public void write(String s, byte[] bytes) {
overallCatch.writeArrayValue(array, i++, clazz);

}
overallCatch.invokeInterfaceMethod(ofMethod(DYNAMIC_PROXY_REGISTRY,
"addProxyClass", void.class, Class[].class), proxySupport, array);

BranchResult graalVm22_3Test = overallCatch
.ifGreaterEqualZero(overallCatch.invokeVirtualMethod(VERSION_COMPARE_TO,
overallCatch.invokeStaticMethod(VERSION_CURRENT),
overallCatch.marshalAsArray(int.class, overallCatch.load(22), overallCatch.load(3))));
/* GraalVM >= 22.3 */
try (BytecodeCreator greaterThan22_2 = graalVm22_3Test.trueBranch()) {
MethodDescriptor registerMethod = ofMethod("org.graalvm.nativeimage.hosted.RuntimeProxyCreation",
"register", void.class, Class[].class);
greaterThan22_2.invokeStaticMethod(
registerMethod,
array);
}
/* GraalVM < 22.3 */
try (BytecodeCreator smallerThan22_3 = graalVm22_3Test.falseBranch()) {
ResultHandle proxySupportClass = smallerThan22_3.loadClassFromTCCL(DYNAMIC_PROXY_REGISTRY);
ResultHandle proxySupport = smallerThan22_3.invokeStaticMethod(
IMAGE_SINGLETONS_LOOKUP,
proxySupportClass);
smallerThan22_3.invokeInterfaceMethod(ofMethod(DYNAMIC_PROXY_REGISTRY,
"addProxyClass", void.class, Class[].class), proxySupport, array);
}

}
}

Expand Down