Skip to content

Commit 18c3c92

Browse files
committed
[improve] Adapt startup scripts for Java 24 changes (#24236)
(cherry picked from commit 7e67290)
1 parent b12d303 commit 18c3c92

File tree

9 files changed

+44
-3
lines changed

9 files changed

+44
-3
lines changed

bin/bookkeeper

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,18 @@ OPTS="$OPTS --add-opens java.base/java.io=ALL-UNNAMED --add-opens java.base/java
197197
# https://github.com/netty/netty/blob/4.1/common/src/main/java/io/netty/util/internal/PlatformDependent0.java
198198
# https://github.com/netty/netty/issues/12265
199199
OPTS="$OPTS --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/jdk.internal.misc=ALL-UNNAMED"
200+
# Required by RocksDB java.lang.System::loadLibrary call
201+
OPTS="$OPTS --enable-native-access=ALL-UNNAMED"
200202

201203
OPTS="-cp $BOOKIE_CLASSPATH $OPTS"
202204

203205
# Disable ipv6 as it can cause issues
204206
OPTS="-Djava.net.preferIPv4Stack=true $OPTS"
207+
# Required to allow sun.misc.Unsafe on JDK 24 without warnings
208+
# Also required for enabling unsafe memory access for Netty since 4.1.121.Final
209+
if [[ $JAVA_MAJOR_VERSION -ge 23 ]]; then
210+
OPTS="--sun-misc-unsafe-memory-access=allow $OPTS"
211+
fi
205212

206213
OPTS="$OPTS $BOOKIE_MEM $BOOKIE_GC $BOOKIE_GC_LOG $BOOKIE_EXTRA_OPTS"
207214

bin/function-localrunner

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ PULSAR_MEM=${PULSAR_MEM:-"-Xmx128m -XX:MaxDirectMemorySize=128m"}
5454
# Garbage collection options
5555
if [ -z "$PULSAR_GC" ]; then
5656
PULSAR_GC="-XX:+PerfDisableSharedMem -XX:+AlwaysPreTouch"
57-
if [[ $JAVA_MAJOR_VERSION -ge 21 ]]; then
57+
if [[ $JAVA_MAJOR_VERSION -eq 21 || $JAVA_MAJOR_VERSION -eq 22 ]]; then
5858
PULSAR_GC="-XX:+UseZGC -XX:+ZGenerational ${PULSAR_GC}"
5959
else
6060
PULSAR_GC="-XX:+UseZGC ${PULSAR_GC}"
@@ -132,6 +132,11 @@ fi
132132
# rarely needed when trying to list many z-nodes under a
133133
# directory)
134134
OPTS="-Djava.net.preferIPv4Stack=true $OPTS -Djute.maxbuffer=10485760"
135+
# Required to allow sun.misc.Unsafe on JDK 24 without warnings
136+
# Also required for enabling unsafe memory access for Netty since 4.1.121.Final
137+
if [[ $JAVA_MAJOR_VERSION -ge 23 ]]; then
138+
OPTS="--sun-misc-unsafe-memory-access=allow $OPTS"
139+
fi
135140

136141
OPTS="-cp $PULSAR_CLASSPATH $OPTS"
137142

bin/pulsar

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ OPTS="$OPTS -Dlog4j.configurationFile=`basename $PULSAR_LOG_CONF`"
274274
# rarely needed when trying to list many z-nodes under a
275275
# directory)
276276
OPTS="-Djava.net.preferIPv4Stack=true $OPTS -Djute.maxbuffer=10485760"
277+
# Required to allow sun.misc.Unsafe on JDK 24 without warnings
278+
# Also required for enabling unsafe memory access for Netty since 4.1.121.Final
279+
if [[ $JAVA_MAJOR_VERSION -ge 23 ]]; then
280+
OPTS="--sun-misc-unsafe-memory-access=allow $OPTS"
281+
fi
282+
277283
# Enable TCP keepalive for all Zookeeper client connections
278284
OPTS="$OPTS -Dzookeeper.clientTcpKeepAlive=true"
279285

@@ -292,6 +298,8 @@ OPTS="$OPTS -Dorg.apache.pulsar.shade.io.netty.tryReflectionSetAccessible=true"
292298
OPTS="$OPTS --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/jdk.internal.misc=ALL-UNNAMED"
293299
# Required by LinuxInfoUtils
294300
OPTS="$OPTS --add-opens java.base/jdk.internal.platform=ALL-UNNAMED"
301+
# Required by RocksDB java.lang.System::loadLibrary call
302+
OPTS="$OPTS --enable-native-access=ALL-UNNAMED"
295303

296304
OPTS="-cp $PULSAR_CLASSPATH $OPTS"
297305

bin/pulsar-admin-common.cmd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ REM Allow Netty to use reflection access
6666
set "OPTS=%OPTS% -Dio.netty.tryReflectionSetAccessible=true"
6767
set "OPTS=%OPTS% -Dorg.apache.pulsar.shade.io.netty.tryReflectionSetAccessible=true"
6868

69+
if %JAVA_MAJOR_VERSION% GTR 23 (
70+
REM Required to allow sun.misc.Unsafe on JDK 24 without warnings
71+
REM Also required for enabling unsafe memory access for Netty since 4.1.121.Final
72+
set "OPTS=--sun-misc-unsafe-memory-access=allow %OPTS%"
73+
)
74+
6975
if %JAVA_MAJOR_VERSION% GTR 8 (
7076
set "OPTS=%OPTS% --add-opens java.base/sun.net=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED"
7177
REM Required by Pulsar client optimized checksum calculation on other than Linux x86_64 platforms

bin/pulsar-admin-common.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ PULSAR_CLASSPATH="$PULSAR_JAR:$PULSAR_CLASSPATH:$PULSAR_EXTRA_CLASSPATH"
105105
PULSAR_CLASSPATH="`dirname $PULSAR_LOG_CONF`:$PULSAR_CLASSPATH"
106106
OPTS="$OPTS -Dlog4j.configurationFile=`basename $PULSAR_LOG_CONF`"
107107
OPTS="-Djava.net.preferIPv4Stack=true $OPTS"
108+
# Required to allow sun.misc.Unsafe on JDK 24 without warnings
109+
# Also required for enabling unsafe memory access for Netty since 4.1.121.Final
110+
if [[ $JAVA_MAJOR_VERSION -ge 23 ]]; then
111+
OPTS="--sun-misc-unsafe-memory-access=allow $OPTS"
112+
fi
108113

109114
# Allow Netty to use reflection access
110115
OPTS="$OPTS -Dio.netty.tryReflectionSetAccessible=true"

bin/pulsar-perf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ fi
102102
PULSAR_CLASSPATH="$PULSAR_JAR:$PULSAR_CLASSPATH:$PULSAR_EXTRA_CLASSPATH"
103103
PULSAR_CLASSPATH="`dirname $PULSAR_LOG_CONF`:$PULSAR_CLASSPATH"
104104
OPTS="-Djava.net.preferIPv4Stack=true $OPTS -Dlog4j.configurationFile=`basename $PULSAR_LOG_CONF`"
105+
# Required to allow sun.misc.Unsafe on JDK 24 without warnings
106+
# Also required for enabling unsafe memory access for Netty since 4.1.121.Final
107+
if [[ $JAVA_MAJOR_VERSION -ge 23 ]]; then
108+
OPTS="--sun-misc-unsafe-memory-access=allow $OPTS"
109+
fi
105110

106111
# Allow Netty to use reflection access
107112
OPTS="$OPTS -Dio.netty.tryReflectionSetAccessible=true"

conf/bkenv.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ done
6161
BOOKIE_GC="${BOOKIE_GC:-${PULSAR_GC}}"
6262
if [ -z "$BOOKIE_GC" ]; then
6363
BOOKIE_GC="-XX:+PerfDisableSharedMem -XX:+AlwaysPreTouch"
64-
if [[ $JAVA_MAJOR_VERSION -ge 21 ]]; then
64+
if [[ $JAVA_MAJOR_VERSION -eq 21 || $JAVA_MAJOR_VERSION -eq 22 ]]; then
6565
BOOKIE_GC="-XX:+UseZGC -XX:+ZGenerational ${BOOKIE_GC}"
6666
else
6767
BOOKIE_GC="-XX:+UseZGC ${BOOKIE_GC}"

conf/pulsar_env.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ done
6767
# Garbage collection options
6868
if [ -z "$PULSAR_GC" ]; then
6969
PULSAR_GC="-XX:+PerfDisableSharedMem -XX:+AlwaysPreTouch"
70-
if [[ $JAVA_MAJOR_VERSION -ge 21 ]]; then
70+
if [[ $JAVA_MAJOR_VERSION -eq 21 || $JAVA_MAJOR_VERSION -eq 22 ]]; then
7171
PULSAR_GC="-XX:+UseZGC -XX:+ZGenerational ${PULSAR_GC}"
7272
else
7373
PULSAR_GC="-XX:+UseZGC ${PULSAR_GC}"

src/pulsar-io-gen.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ fi
109109
PULSAR_CLASSPATH="$PULSAR_JAR:$PULSAR_HOME/pulsar-io/docs/target/pulsar-io-docs.jar:$PULSAR_CLASSPATH:$PULSAR_EXTRA_CLASSPATH"
110110
PULSAR_CLASSPATH="`dirname $PULSAR_LOG_CONF`:$PULSAR_CLASSPATH"
111111
OPTS="-Djava.net.preferIPv4Stack=true $OPTS -Dlog4j.configurationFile=`basename $PULSAR_LOG_CONF`"
112+
# Required to allow sun.misc.Unsafe on JDK 24 without warnings
113+
# Also required for enabling unsafe memory access for Netty since 4.1.121.Final
114+
if [[ $JAVA_MAJOR_VERSION -ge 23 ]]; then
115+
OPTS="--sun-misc-unsafe-memory-access=allow $OPTS"
116+
fi
112117

113118
OPTS="-cp $PULSAR_CLASSPATH $OPTS"
114119
OPTS="$OPTS $PULSAR_EXTRA_OPTS"

0 commit comments

Comments
 (0)