Skip to content

Commit 962655a

Browse files
authored
Prevent generateMetadata Profiles from generating GraalVM Reachability Metadata for arrays and JdkLogger (#36067)
1 parent 535361b commit 962655a

File tree

35 files changed

+342
-905
lines changed

35 files changed

+342
-905
lines changed

.github/workflows/graalvm.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,18 @@ jobs:
6060
java-version: ${{ matrix.java-version }}
6161
distribution: 'graalvm-community'
6262
github-token: ${{ secrets.GITHUB_TOKEN }}
63-
cache: 'maven'
6463
native-image-job-reports: 'true'
64+
- uses: actions/cache@v4
65+
with:
66+
path: ~/.m2/repository
67+
key: ${{ needs.global-environment.outputs.GLOBAL_CACHE_PREFIX }}-maven-third-party-cache-${{ github.sha }}
68+
restore-keys: |
69+
${{ needs.global-environment.outputs.GLOBAL_CACHE_PREFIX }}-maven-third-party-cache-
70+
${{ needs.global-environment.outputs.GLOBAL_CACHE_PREFIX }}-maven-third-party-
6571
# TODO Remove this workaround after. The graalvm native image built with windows server is missing some GRMs for testcontainers
6672
- name: Run test with GraalVM CE
6773
if: matrix.os == 'windows-2025'
68-
run: ./mvnw -PgenerateMetadata -e -T 1C clean test
74+
run: ./mvnw -PgenerateMetadata -e -T 1C clean verify
6975
- name: Run nativeTest with GraalVM CE for ${{ matrix.java-version }}
7076
if: matrix.os == 'ubuntu-latest'
71-
run: ./mvnw -PnativeTestInShardingSphere -e clean test
77+
run: ./mvnw -PnativeTestInShardingSphere -e "-DjvmArgs=-XX:MaxRAMPercentage=70.0" clean verify

.github/workflows/nightly-build.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,18 @@ jobs:
126126
with:
127127
distribution: 'temurin'
128128
java-version: 11
129-
cache: 'maven'
130129
- uses: docker/login-action@v3
131130
with:
132131
registry: ${{ env.HUB }}
133132
username: ${{ github.actor }}
134133
password: ${{ secrets.GITHUB_TOKEN }}
134+
- uses: actions/cache@v4
135+
with:
136+
path: ~/.m2/repository
137+
key: ${{ needs.global-environment.outputs.GLOBAL_CACHE_PREFIX }}-maven-third-party-cache-${{ github.sha }}
138+
restore-keys: |
139+
${{ needs.global-environment.outputs.GLOBAL_CACHE_PREFIX }}-maven-third-party-cache-
140+
${{ needs.global-environment.outputs.GLOBAL_CACHE_PREFIX }}-maven-third-party-
135141
- name: Push Docker Image by arm64 or x64
136142
run: |
137143
./mvnw -am -pl distribution/proxy-native -T1C "-Pdocker.push.native.linux" -Dproxy.native.image.repository=${{ env.PROXY_NATIVE }} -Dproxy.native.image.tag=${{ github.sha }} "-DskipTests" clean package
@@ -158,12 +164,18 @@ jobs:
158164
with:
159165
distribution: 'temurin'
160166
java-version: '11'
161-
cache: 'maven'
162167
- uses: docker/login-action@v3
163168
with:
164169
registry: ${{ env.HUB }}
165170
username: ${{ github.actor }}
166171
password: ${{ secrets.GITHUB_TOKEN }}
172+
- uses: actions/cache@v4
173+
with:
174+
path: ~/.m2/repository
175+
key: ${{ needs.global-environment.outputs.GLOBAL_CACHE_PREFIX }}-maven-third-party-cache-${{ github.sha }}
176+
restore-keys: |
177+
${{ needs.global-environment.outputs.GLOBAL_CACHE_PREFIX }}-maven-third-party-cache-
178+
${{ needs.global-environment.outputs.GLOBAL_CACHE_PREFIX }}-maven-third-party-
167179
- name: Push Docker Image
168180
run: |
169181
./mvnw -am -pl distribution/agent -Prelease,default-dep,docker.buildx.push -B -T1C -DskipTests -Dagent.image.repository=${{ env.AGENT }} -Dagent.image.tag=${{ github.sha }} clean package

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,26 @@ 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'
140148
distribution: 'graalvm-community'
141149
github-token: ${{ secrets.GITHUB_TOKEN }}
142-
cache: 'maven'
143150
native-image-job-reports: 'true'
151+
- uses: actions/cache@v4
152+
with:
153+
path: ~/.m2/repository
154+
key: ${{ needs.global-environment.outputs.GLOBAL_CACHE_PREFIX }}-maven-third-party-cache-${{ github.sha }}
155+
restore-keys: |
156+
${{ needs.global-environment.outputs.GLOBAL_CACHE_PREFIX }}-maven-third-party-cache-
157+
${{ needs.global-environment.outputs.GLOBAL_CACHE_PREFIX }}-maven-third-party-
144158
- name: Run nativeTest with GraalVM CE
145-
run: ./mvnw -PnativeTestInShardingSphere -e clean test
159+
run: ./mvnw -PnativeTestInShardingSphere -e "-DjvmArgs=-XX:MaxRAMPercentage=70.0" clean verify

.github/workflows/nightly-ci.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,18 @@ jobs:
127127
java-version: '24.0.2'
128128
distribution: 'graalvm-community'
129129
github-token: ${{ secrets.GITHUB_TOKEN }}
130-
cache: 'maven'
131130
native-image-job-reports: 'true'
131+
- uses: actions/cache@v4
132+
with:
133+
path: ~/.m2/repository
134+
key: ${{ needs.global-environment.outputs.GLOBAL_CACHE_PREFIX }}-maven-third-party-cache-${{ github.sha }}
135+
restore-keys: |
136+
${{ needs.global-environment.outputs.GLOBAL_CACHE_PREFIX }}-maven-third-party-cache-
137+
${{ needs.global-environment.outputs.GLOBAL_CACHE_PREFIX }}-maven-third-party-
132138
# TODO Remove this workaround after. The graalvm native image built with windows server is missing some GRMs for testcontainers
133139
- name: Run test with GraalVM CE
134140
if: matrix.os == 'windows-2025'
135-
run: ./mvnw -PgenerateMetadata -e -T 1C clean test
141+
run: ./mvnw -PgenerateMetadata -e -T 1C clean verify
136142
- name: Run nativeTest with GraalVM CE
137143
if: matrix.os == 'ubuntu-latest'
138-
run: ./mvnw -PnativeTestInShardingSphere -e clean test
144+
run: ./mvnw -PnativeTestInShardingSphere -e "-DjvmArgs=-XX:MaxRAMPercentage=70.0" 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 使用的元素。

0 commit comments

Comments
 (0)