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

Support building ShardingSphere and its corresponding GraalVM Native Image through JDK 22 #30778

Merged
merged 1 commit into from
Apr 5, 2024

Conversation

linghengqian
Copy link
Member

@linghengqian linghengqian commented Apr 4, 2024

Fixes #30552.

Changes proposed in this pull request:

  • Support building ShardingSphere and its corresponding GraalVM Native Image through JDK 22. Mainly due to the influence of byte-buddy.
  • Due to Truffle Unchained, the new version of GraalVM Truffle can still be used on GraalVM For JDK21. Reference https://medium.com/graalvm/whats-new-in-truffle-and-graal-languages-40027a59c401 .
  • Setting Espresso Context's allowValueSharing from true to false, I personally tested it locally and solved the strange phenomenon discovered in Refactor EspressoInlineExpressionParser to use Truffle Context with life cycle #30398 .
    • If this option is set to true (default) then any value that is associated with one context will be automatically migrated when passed to another context. Primitive, host and proxy values can be migrated without limitation. When guest language values are migrated, they capture and remember their original context. Guest language objects need to be accessed when their respective context is entered, therefore before any access their original context is entered and subsequently left. Entering the original context may fail, for example when the context of a original context value only allows single threaded access to values or if it was closed in the mean time.
    • If this option is set to false then any value passed from one context to another will fail with an error indicating that sharing is disallowed. Turning sharing off can be useful when strict safety is required and it would be considered an error if a value of one context is passed to another.
    • image
  • Because the --strict-image-heap parameter mentioned in https://github.com/oracle/graal/blob/vm-24.0.0/substratevm/CHANGELOG.md is enabled by default, GraalVM Reachability Metadata entries for third-party dependencies such as com.ctc.wstx.stax.** start to be recorded, and these JSON entries should be excluded. reflect-config.json also requires adding some new JSON entries due to the use of this parameter. Otherwise there is an Error Log.
  • (GR-48612) Enable --strict-image-heap by default. The option is now deprecated and can be removed from your argument list. A blog post with more information will follow shortly.
  • (GR-39406) Simulation of class initializer: Class initializer of classes that are not marked for initialization at image build time are simulated at image build time to avoid executing them at image run time.
  • (GR-39406) New option --strict-image-heap: All classes can now be used at image build time, even when they are not explicitly configured as --initialize-at-build-time. Note, however, that still only classes configured as --initialize-at-build-time are allowed in the image heap. Adopt this option as it will become the default in the next release of GraalVM.
[ERROR] 2024-04-05 03:48:05.929 [Etcd-EventListener-0] o.a.s.m.r.c.etcd.EtcdRepository - Dispatch event failed
java.util.concurrent.CompletionException: org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively invoke method

   public synchronized void org.apache.shardingsphere.mode.manager.cluster.coordinator.subscriber.ResourceMetaDataChangedSubscriber.renew(org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.SchemaAddedEvent)

 without it being registered for runtime reflection. Add public synchronized void org.apache.shardingsphere.mode.manager.cluster.coordinator.subscriber.ResourceMetaDataChangedSubscriber.renew(org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.SchemaAddedEvent) to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
        at java.base@22/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315)
        at java.base@22/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320)
        at java.base@22/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1807)
        at java.base@22/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
        at java.base@22/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
        at java.base@22/java.lang.Thread.runWith(Thread.java:1583)
        at java.base@22/java.lang.Thread.run(Thread.java:1570)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:853)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:829)
Caused by: org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively invoke method

   public synchronized void org.apache.shardingsphere.mode.manager.cluster.coordinator.subscriber.ResourceMetaDataChangedSubscriber.renew(org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.SchemaAddedEvent)

 without it being registered for runtime reflection. Add public synchronized void org.apache.shardingsphere.mode.manager.cluster.coordinator.subscriber.ResourceMetaDataChangedSubscriber.renew(org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.SchemaAddedEvent) to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.reflect.MissingReflectionRegistrationUtils.forQueriedOnlyExecutable(MissingReflectionRegistrationUtils.java:74)
        at java.base@22/java.lang.reflect.Method.acquireMethodAccessor(Method.java:77)
        at java.base@22/java.lang.reflect.Method.invoke(Method.java:577)
        at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:85)
        at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:142)
        at com.google.common.eventbus.Subscriber.lambda$dispatchEvent$0(Subscriber.java:71)
        at com.google.common.util.concurrent.DirectExecutor.execute(DirectExecutor.java:31)
        at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:68)
        at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:109)
        at com.google.common.eventbus.EventBus.post(EventBus.java:270)
        at org.apache.shardingsphere.infra.util.eventbus.EventBusContext.post(EventBusContext.java:51)
        at java.base@22/java.util.Optional.ifPresent(Optional.java:178)
        at org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcherFactory.lambda$watch$0(GovernanceWatcherFactory.java:55)
        at org.apache.shardingsphere.mode.repository.cluster.etcd.EtcdRepository.lambda$dispatchEvent$3(EtcdRepository.java:184)
        at java.base@22/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804)
        ... 6 common frames omitted
[ERROR] 2024-04-05 03:48:07.007 [Curator-SafeNotifyService-0] o.a.c.f.l.MappingListenerManager - Listener (org.apache.curator.framework.recipes.cache.CuratorCacheListenerBuilderImpl$2@362b7797) threw an exception
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively invoke method

   public synchronized void org.apache.shardingsphere.mode.manager.cluster.coordinator.subscriber.ResourceMetaDataChangedSubscriber.renew(org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.SchemaAddedEvent)

 without it being registered for runtime reflection. Add public synchronized void org.apache.shardingsphere.mode.manager.cluster.coordinator.subscriber.ResourceMetaDataChangedSubscriber.renew(org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.SchemaAddedEvent) to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.reflect.MissingReflectionRegistrationUtils.forQueriedOnlyExecutable(MissingReflectionRegistrationUtils.java:74)
        at java.base@22/java.lang.reflect.Method.acquireMethodAccessor(Method.java:77)
        at java.base@22/java.lang.reflect.Method.invoke(Method.java:577)
        at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:85)
        at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:142)
        at com.google.common.eventbus.Subscriber.lambda$dispatchEvent$0(Subscriber.java:71)
        at com.google.common.util.concurrent.DirectExecutor.execute(DirectExecutor.java:31)
        at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:68)
        at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:109)
        at com.google.common.eventbus.EventBus.post(EventBus.java:270)
        at org.apache.shardingsphere.infra.util.eventbus.EventBusContext.post(EventBusContext.java:51)
        at java.base@22/java.util.Optional.ifPresent(Optional.java:178)
        at org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcherFactory.lambda$watch$0(GovernanceWatcherFactory.java:55)
        at org.apache.shardingsphere.mode.repository.cluster.zookeeper.ZookeeperRepository.lambda$watch$0(ZookeeperRepository.java:251)
        at org.apache.curator.framework.recipes.cache.TreeCacheListenerWrapper.sendEvent(TreeCacheListenerWrapper.java:61)
        at org.apache.curator.framework.recipes.cache.TreeCacheListenerWrapper.event(TreeCacheListenerWrapper.java:37)
        at org.apache.curator.framework.recipes.cache.CuratorCacheListenerBuilderImpl$2.lambda$event$0(CuratorCacheListenerBuilderImpl.java:128)
        at java.base@22/java.util.ArrayList.forEach(ArrayList.java:1597)
        at org.apache.curator.framework.recipes.cache.CuratorCacheListenerBuilderImpl$2.event(CuratorCacheListenerBuilderImpl.java:128)
        at org.apache.curator.framework.recipes.cache.CuratorCacheImpl.lambda$putStorage$7(CuratorCacheImpl.java:238)
        at org.apache.curator.framework.listen.MappingListenerManager.lambda$forEach$0(MappingListenerManager.java:82)
        at org.apache.curator.framework.listen.MappingListenerManager.forEach(MappingListenerManager.java:80)
        at org.apache.curator.framework.listen.StandardListenerManager.forEach(StandardListenerManager.java:81)
        at org.apache.curator.framework.recipes.cache.CuratorCacheImpl.lambda$callListeners$10(CuratorCacheImpl.java:249)
        at java.base@22/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804)
        at java.base@22/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
        at java.base@22/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
        at java.base@22/java.lang.Thread.runWith(Thread.java:1583)
        at java.base@22/java.lang.Thread.run(Thread.java:1570)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:853)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:829)

Before committing this PR, I'm sure that I have checked the following options:

  • My code follows the code of conduct of this project.
  • I have self-reviewed the commit code.
  • I have (or in comment I request) added corresponding labels for the pull request.
  • I have passed maven check locally : ./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e.
  • I have made corresponding changes to the documentation.
  • I have added corresponding unit tests for my changes.

@linghengqian linghengqian added this to the 5.5.0 milestone Apr 4, 2024
@linghengqian linghengqian marked this pull request as ready for review April 4, 2024 21:02
@linghengqian linghengqian added the type: dependencies Pull requests that update a dependency file label Apr 4, 2024
@linghengqian linghengqian force-pushed the jdk-22 branch 2 times, most recently from 503077b to af0655d Compare April 4, 2024 21:59
@strongduanmu strongduanmu merged commit e02e1df into apache:master Apr 5, 2024
145 checks passed
@linghengqian linghengqian deleted the jdk-22 branch April 5, 2024 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: build type: dependencies Pull requests that update a dependency file type: enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ShardingSphere build fails on OpenJDK 22
2 participants