Skip to content

Commit 4b2c093

Browse files
committed
Prevent generateMetadata Profiles from generating GraalVM Reachability Metadata for arrays and JdkLogger
1 parent 1459727 commit 4b2c093

File tree

33 files changed

+311
-874
lines changed

33 files changed

+311
-874
lines changed

.github/workflows/graalvm.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ jobs:
6565
# TODO Remove this workaround after. The graalvm native image built with windows server is missing some GRMs for testcontainers
6666
- name: Run test with GraalVM CE
6767
if: matrix.os == 'windows-2025'
68-
run: ./mvnw -PgenerateMetadata -e -T 1C clean test
68+
run: ./mvnw -PgenerateMetadata -e -T 1C clean verify
6969
- name: Run nativeTest with GraalVM CE for ${{ matrix.java-version }}
7070
if: matrix.os == 'ubuntu-latest'
71-
run: ./mvnw -PnativeTestInShardingSphere -e clean test
71+
env:
72+
MAVEN_OPTS: "-Xmx512m"
73+
run: ./mvnw -PnativeTestInShardingSphere -e clean verify

.github/workflows/nightly-ci-dynamic.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ jobs:
134134
os: ${{ fromJson(github.event.inputs.os) }}
135135
steps:
136136
- uses: actions/checkout@v4
137+
- name: Setup Rancher Desktop without GUI on Windows Server
138+
if: matrix.os == 'windows-2025'
139+
run: |
140+
./test/native/src/test/resources/test-native/ps1/uninstall-docker-engine-for-wcow.ps1
141+
winget install --id jazzdelightsme.WingetPathUpdater --source winget
142+
winget install --id SUSE.RancherDesktop --source winget --skip-dependencies
143+
rdctl start --application.start-in-background --container-engine.name=moby --kubernetes.enabled=false
144+
./test/native/src/test/resources/test-native/ps1/wait-for-rancher-desktop-backend.ps1
137145
- uses: graalvm/setup-graalvm@v1
138146
with:
139147
java-version: '24.0.2'
@@ -142,4 +150,6 @@ jobs:
142150
cache: 'maven'
143151
native-image-job-reports: 'true'
144152
- name: Run nativeTest with GraalVM CE
145-
run: ./mvnw -PnativeTestInShardingSphere -e clean test
153+
env:
154+
MAVEN_OPTS: "-Xmx512m"
155+
run: ./mvnw -PnativeTestInShardingSphere -e clean verify

.github/workflows/nightly-ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ jobs:
132132
# TODO Remove this workaround after. The graalvm native image built with windows server is missing some GRMs for testcontainers
133133
- name: Run test with GraalVM CE
134134
if: matrix.os == 'windows-2025'
135-
run: ./mvnw -PgenerateMetadata -e -T 1C clean test
135+
run: ./mvnw -PgenerateMetadata -e -T 1C clean verify
136136
- name: Run nativeTest with GraalVM CE
137137
if: matrix.os == 'ubuntu-latest'
138-
run: ./mvnw -PnativeTestInShardingSphere -e clean test
138+
env:
139+
MAVEN_OPTS: "-Xmx512m"
140+
run: ./mvnw -PnativeTestInShardingSphere -e clean verify

distribution/proxy-native/Dockerfile-linux-mostly

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
#
1717

1818
FROM ghcr.io/graalvm/native-image-community:24.0.2 AS nativebuild
19+
ENV NATIVE_IMAGE_OPTIONS="--static-nolibc"
1920
WORKDIR /build
2021
COPY ./ .
21-
RUN --mount=type=cache,target=/root/.m2 ./mvnw -am -pl distribution/proxy-native -T1C -DskipTests "-Prelease.native" "-DbuildArgs=-H:+AddAllCharsets,-H:+IncludeAllLocales,--static-nolibc" clean package
22+
RUN --mount=type=cache,target=/root/.m2 ./mvnw -am -pl distribution/proxy-native -T1C -DskipTests "-Prelease.native" clean package
2223

2324
FROM gcr.io/distroless/base-debian12:latest
2425
LABEL org.opencontainers.image.authors="ShardingSphere [email protected]"

distribution/proxy-native/Dockerfile-linux-static

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
#
1717

1818
FROM ghcr.io/graalvm/native-image-community:24.0.2-muslib AS nativebuild
19+
ENV NATIVE_IMAGE_OPTIONS="--static,--libc=musl"
1920
WORKDIR /build
2021
COPY ./ .
21-
RUN --mount=type=cache,target=/root/.m2 ./mvnw -am -pl distribution/proxy-native -T1C -DskipTests "-Prelease.native" "-DbuildArgs=-H:+AddAllCharsets,-H:+IncludeAllLocales,--static,--libc=musl" clean package
22+
RUN --mount=type=cache,target=/root/.m2 ./mvnw -am -pl distribution/proxy-native -T1C -DskipTests "-Prelease.native" clean package
2223

2324
FROM scratch
2425
LABEL org.opencontainers.image.authors="ShardingSphere [email protected]"

distribution/proxy-native/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
<mainClass>org.apache.shardingsphere.proxy.Bootstrap</mainClass>
7676
<imageName>${proxy.native.image.filename}</imageName>
7777
<buildArgs>
78+
<buildArg>-H:+UnlockExperimentalVMOptions</buildArg>
7879
<buildArg>-H:+AddAllCharsets</buildArg>
7980
<buildArg>-H:+IncludeAllLocales</buildArg>
8081
</buildArgs>

docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.cn.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ java.beans.Introspector was unintentionally initialized at build time. To see wh
5656
<extensions>true</extensions>
5757
<configuration>
5858
<buildArgs>
59+
<buildArg>-H:+UnlockExperimentalVMOptions</buildArg>
5960
<buildArg>-H:+AddAllCharsets</buildArg>
6061
<buildArg>-H:+IncludeAllLocales</buildArg>
6162
</buildArgs>
@@ -102,10 +103,12 @@ dependencies {
102103
graalvmNative {
103104
binaries {
104105
main {
106+
buildArgs.add('-H:+UnlockExperimentalVMOptions')
105107
buildArgs.add('-H:+AddAllCharsets')
106108
buildArgs.add('-H:+IncludeAllLocales')
107109
}
108110
test {
111+
buildArgs.add('-H:+UnlockExperimentalVMOptions')
109112
buildArgs.add('-H:+AddAllCharsets')
110113
buildArgs.add('-H:+IncludeAllLocales')
111114
}

docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.en.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ and the documentation of GraalVM Native Build Tools shall prevail.
5757
<extensions>true</extensions>
5858
<configuration>
5959
<buildArgs>
60+
<buildArg>-H:+UnlockExperimentalVMOptions</buildArg>
6061
<buildArg>-H:+AddAllCharsets</buildArg>
6162
<buildArg>-H:+IncludeAllLocales</buildArg>
6263
</buildArgs>
@@ -105,10 +106,12 @@ dependencies {
105106
graalvmNative {
106107
binaries {
107108
main {
109+
buildArgs.add('-H:+UnlockExperimentalVMOptions')
108110
buildArgs.add('-H:+AddAllCharsets')
109111
buildArgs.add('-H:+IncludeAllLocales')
110112
}
111113
test {
114+
buildArgs.add('-H:+UnlockExperimentalVMOptions')
112115
buildArgs.add('-H:+AddAllCharsets')
113116
buildArgs.add('-H:+IncludeAllLocales')
114117
}

docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/development/_index.cn.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,40 @@ class SolutionTest {
265265
266266
`org.apache.shardingsphere.test.natived.proxy.transactions.base.SeataTest` 已被禁用,
267267
因为在 Github Actions Runner 执行此单元测试将导致其他单元测试出现 JDBC 连接泄露。
268+
269+
### `CodeCachePoolMXBean` 限制
270+
271+
当前执行 `./mvnw -PnativeTestInShardingSphere -e -T 1C clean verify` 将涉及到针对 `com.oracle.svm.core.code.CodeCachePoolMXBean` 的警告日志,
272+
273+
```shell
274+
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access
275+
276+
com.oracle.svm.core.code.CodeCachePoolMXBean$CodeAndDataPool.getConstructors()
277+
278+
without it being registered for runtime reflection. Add com.oracle.svm.core.code.CodeCachePoolMXBean$CodeAndDataPool.getConstructors() to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
279+
[email protected]/java.lang.Class.getConstructors(DynamicHub.java:1128)
280+
[email protected]/com.sun.jmx.mbeanserver.MBeanIntrospector.findConstructors(MBeanIntrospector.java:459)
281+
[email protected]/com.sun.jmx.mbeanserver.MBeanIntrospector.getClassMBeanInfo(MBeanIntrospector.java:430)
282+
[email protected]/com.sun.jmx.mbeanserver.MBeanIntrospector.getMBeanInfo(MBeanIntrospector.java:389)
283+
[email protected]/com.sun.jmx.mbeanserver.MBeanSupport.<init>(MBeanSupport.java:137)
284+
[email protected]/com.sun.jmx.mbeanserver.MXBeanSupport.<init>(MXBeanSupport.java:66)
285+
[email protected]/javax.management.StandardMBean.construct(StandardMBean.java:174)
286+
[email protected]/javax.management.StandardMBean.<init>(StandardMBean.java:268)
287+
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access
288+
289+
com.oracle.svm.core.code.CodeCachePoolMXBean$NativeMetadataPool.getConstructors()
290+
291+
without it being registered for runtime reflection. Add com.oracle.svm.core.code.CodeCachePoolMXBean$NativeMetadataPool.getConstructors() to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
292+
[email protected]/java.lang.Class.getConstructors(DynamicHub.java:1128)
293+
[email protected]/com.sun.jmx.mbeanserver.MBeanIntrospector.findConstructors(MBeanIntrospector.java:459)
294+
[email protected]/com.sun.jmx.mbeanserver.MBeanIntrospector.getClassMBeanInfo(MBeanIntrospector.java:430)
295+
[email protected]/com.sun.jmx.mbeanserver.MBeanIntrospector.getMBeanInfo(MBeanIntrospector.java:389)
296+
[email protected]/com.sun.jmx.mbeanserver.MBeanSupport.<init>(MBeanSupport.java:137)
297+
[email protected]/com.sun.jmx.mbeanserver.MXBeanSupport.<init>(MXBeanSupport.java:66)
298+
[email protected]/javax.management.StandardMBean.construct(StandardMBean.java:174)
299+
[email protected]/javax.management.StandardMBean.<init>(StandardMBean.java:268)
300+
```
301+
302+
相关警告在 `GraalVM CE For JDK 24.0.2` 上无法避免。
303+
因为 `com.oracle.svm.core.code.CodeCachePoolMXBean` 的无参构造函数通过 Java 类 `org.graalvm.nativeimage.Platform.HOSTED_ONLY` 被标记为无论实际的 Platform 是什么,
304+
仅在 Native Image 生成期间可见,且无法在 Runtime 使用的元素。

docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/development/_index.en.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,41 @@ the unit test of `org.apache.shardingsphere.test.natived.jdbc.modes.cluster.Etcd
275275
276276
`org.apache.shardingsphere.test.natived.proxy.transactions.base.SeataTest` has been disabled
277277
because executing this unit test in Github Actions Runner will cause JDBC connection leaks in other unit tests.
278+
279+
### `CodeCachePoolMXBean` limitation
280+
281+
Currently executing `./mvnw -PnativeTestInShardingSphere -e -T 1C clean verify` will involve warning logs for `com.oracle.svm.core.code.CodeCachePoolMXBean`.
282+
283+
```shell
284+
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access
285+
286+
com.oracle.svm.core.code.CodeCachePoolMXBean$CodeAndDataPool.getConstructors()
287+
288+
without it being registered for runtime reflection. Add com.oracle.svm.core.code.CodeCachePoolMXBean$CodeAndDataPool.getConstructors() to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
289+
[email protected]/java.lang.Class.getConstructors(DynamicHub.java:1128)
290+
[email protected]/com.sun.jmx.mbeanserver.MBeanIntrospector.findConstructors(MBeanIntrospector.java:459)
291+
[email protected]/com.sun.jmx.mbeanserver.MBeanIntrospector.getClassMBeanInfo(MBeanIntrospector.java:430)
292+
[email protected]/com.sun.jmx.mbeanserver.MBeanIntrospector.getMBeanInfo(MBeanIntrospector.java:389)
293+
[email protected]/com.sun.jmx.mbeanserver.MBeanSupport.<init>(MBeanSupport.java:137)
294+
[email protected]/com.sun.jmx.mbeanserver.MXBeanSupport.<init>(MXBeanSupport.java:66)
295+
[email protected]/javax.management.StandardMBean.construct(StandardMBean.java:174)
296+
[email protected]/javax.management.StandardMBean.<init>(StandardMBean.java:268)
297+
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access
298+
299+
com.oracle.svm.core.code.CodeCachePoolMXBean$NativeMetadataPool.getConstructors()
300+
301+
without it being registered for runtime reflection. Add com.oracle.svm.core.code.CodeCachePoolMXBean$NativeMetadataPool.getConstructors() to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
302+
[email protected]/java.lang.Class.getConstructors(DynamicHub.java:1128)
303+
[email protected]/com.sun.jmx.mbeanserver.MBeanIntrospector.findConstructors(MBeanIntrospector.java:459)
304+
[email protected]/com.sun.jmx.mbeanserver.MBeanIntrospector.getClassMBeanInfo(MBeanIntrospector.java:430)
305+
[email protected]/com.sun.jmx.mbeanserver.MBeanIntrospector.getMBeanInfo(MBeanIntrospector.java:389)
306+
[email protected]/com.sun.jmx.mbeanserver.MBeanSupport.<init>(MBeanSupport.java:137)
307+
[email protected]/com.sun.jmx.mbeanserver.MXBeanSupport.<init>(MXBeanSupport.java:66)
308+
[email protected]/javax.management.StandardMBean.construct(StandardMBean.java:174)
309+
[email protected]/javax.management.StandardMBean.<init>(StandardMBean.java:268)
310+
```
311+
312+
The relevant warning cannot be avoided on `GraalVM CE For JDK 24.0.2`.
313+
Because the no-argument constructor of `com.oracle.svm.core.code.CodeCachePoolMXBean` is marked as an element that is only visible during Native Image generation and cannot be used at Runtime,
314+
regardless of the actual Platform,
315+
through the Java class `org.graalvm.nativeimage.Platform.HOSTED_ONLY`.

0 commit comments

Comments
 (0)