Skip to content

Commit ae4dfdf

Browse files
committed
ARTEMIS-5734 upgrade to Netty 4.2.12.Final
1 parent f5062d4 commit ae4dfdf

28 files changed

Lines changed: 191 additions & 97 deletions

File tree

artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/bin/artemis

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ if [ -f "$ARTEMIS_OOME_DUMP" ] ; then
119119
mv $ARTEMIS_OOME_DUMP $ARTEMIS_OOME_DUMP.bkp
120120
fi
121121

122+
# Whether to allow Unsafe
123+
$JAVACMD --sun-misc-unsafe-memory-access=allow --version > /dev/null 2>&1 && ALLOW_UNSAFE="--sun-misc-unsafe-memory-access=allow"
124+
122125
exec "$JAVACMD" \
123126
$LOGGING_ARGS \
124127
$JAVA_ARGS \
@@ -132,6 +135,7 @@ exec "$JAVACMD" \
132135
-Djava.io.tmpdir="$ARTEMIS_INSTANCE/tmp" \
133136
-Ddata.dir="$ARTEMIS_DATA_DIR" \
134137
-Dartemis.instance.etc="$ARTEMIS_INSTANCE_ETC" \
138+
$ALLOW_UNSAFE \
135139
$DEBUG_ARGS \
136140
$JAVA_ARGS_APPEND \
137141
org.apache.activemq.artemis.boot.Artemis "$@"

artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/artemis-utility.profile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if [ -z "$LOGGING_ARGS" ]; then
2424
fi
2525

2626
if [ -z "$JAVA_ARGS" ]; then
27-
JAVA_ARGS="-Dlog4j2.disableJmx=true --add-opens java.base/jdk.internal.misc=ALL-UNNAMED ${java-utility-opts}"
27+
JAVA_ARGS="-Dlog4j2.disableJmx=true --add-opens java.base/jdk.internal.misc=ALL-UNNAMED --enable-native-access=ALL-UNNAMED ${java-utility-opts}"
2828
fi
2929

3030
# Uncomment to enable remote debugging

artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/artemis.profile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ HAWTIO_ROLES='${role}'
3030

3131
# Java Opts
3232
if [ -z "$JAVA_ARGS" ]; then
33-
JAVA_ARGS="-XX:AutoBoxCacheMax=20000 -XX:+PrintClassHistogram -XX:+UseG1GC -XX:+UseStringDeduplication -Xms512M -Xmx${java-memory} -Dhawtio.disableProxy=true -Dhawtio.realm=activemq -Dhawtio.offline=true -Dhawtio.rolePrincipalClasses=org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal -Dhawtio.http.strictTransportSecurity=max-age=31536000;includeSubDomains;preload -Djolokia.policyLocation=classpath:jolokia-access.xml -Dlog4j2.disableJmx=true --add-opens java.base/jdk.internal.misc=ALL-UNNAMED ${java-opts}"
33+
JAVA_ARGS="-XX:AutoBoxCacheMax=20000 -XX:+PrintClassHistogram -XX:+UseG1GC -XX:+UseStringDeduplication -Xms512M -Xmx${java-memory} -Dhawtio.disableProxy=true -Dhawtio.realm=activemq -Dhawtio.offline=true -Dhawtio.rolePrincipalClasses=org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal -Dhawtio.http.strictTransportSecurity=max-age=31536000;includeSubDomains;preload -Djolokia.policyLocation=classpath:jolokia-access.xml -Dlog4j2.disableJmx=true --add-opens java.base/jdk.internal.misc=ALL-UNNAMED --enable-native-access=ALL-UNNAMED ${java-opts}"
3434
fi
3535

3636
# Uncomment to enable logging for Safepoint JVM pauses
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.activemq.artemis.utils;
19+
20+
import io.netty.channel.epoll.Epoll;
21+
import io.netty.channel.kqueue.KQueue;
22+
import io.netty.channel.uring.IoUring;
23+
import org.apache.activemq.artemis.logs.ActiveMQUtilLogger;
24+
25+
/**
26+
* This class will check if certain dependencies are available, and return false in case of NoClassDefFoundError
27+
*/
28+
public class CheckDependencies {
29+
30+
public static final boolean isEpollAvailable() {
31+
try {
32+
return Env.isLinuxOs() && Epoll.isAvailable();
33+
} catch (NoClassDefFoundError noClassDefFoundError) {
34+
ActiveMQUtilLogger.LOGGER.unableToCheckEpollAvailabilityNoClass();
35+
return false;
36+
} catch (Throwable e) {
37+
ActiveMQUtilLogger.LOGGER.unableToCheckEpollAvailability(e);
38+
return false;
39+
}
40+
}
41+
42+
public static final boolean isKQueueAvailable() {
43+
try {
44+
return Env.isMacOs() && KQueue.isAvailable();
45+
} catch (NoClassDefFoundError noClassDefFoundError) {
46+
ActiveMQUtilLogger.LOGGER.unableToCheckKQueueAvailabilityNoClass();
47+
return false;
48+
} catch (Throwable e) {
49+
ActiveMQUtilLogger.LOGGER.unableToCheckKQueueAvailability(e);
50+
return false;
51+
}
52+
}
53+
54+
public static final boolean isIoUringAvailable() {
55+
try {
56+
return Env.isLinuxOs() && IoUring.isAvailable();
57+
} catch (NoClassDefFoundError noClassDefFoundError) {
58+
ActiveMQUtilLogger.LOGGER.unableToCheckIoUringAvailabilityNoClass();
59+
return false;
60+
} catch (Throwable e) {
61+
ActiveMQUtilLogger.LOGGER.unableToCheckIoUringAvailability(e);
62+
return false;
63+
}
64+
}
65+
66+
}

artemis-commons/src/main/java/org/apache/activemq/artemis/utils/SpawnedVMSupport.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ public static Process spawnVM(String classPath,
204204
commandList.add(jacocoAgent);
205205
}
206206

207+
String javaVersion = System.getProperty("java.version");
208+
if (javaVersion.startsWith("24") || javaVersion.startsWith("25")) {
209+
commandList.add("--enable-native-access=ALL-UNNAMED");
210+
commandList.add("--sun-misc-unsafe-memory-access=allow");
211+
}
212+
207213
commandList.add(className);
208214
for (String arg : args) {
209215
commandList.add(arg);

artemis-commons/src/test/java/org/apache/activemq/artemis/utils/ByteUtilTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ public void shouldZeroesDirectByteBuffer() {
223223

224224
@Test
225225
public void shouldZeroesLimitedDirectByteBuffer() {
226+
assumeTrue(PlatformDependent.hasUnsafe());
226227
final byte one = (byte) 1;
227228
final int capacity = 64;
228229
final int bytes = 32;

artemis-core-client-osgi/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<Import-Package>
7272
org.glassfish.json*;resolution:=optional,
7373
de.dentrassi.crypto.pem;resolution:=optional,
74-
io.netty.buffer;io.netty.*;version="[4.1,5)",
74+
io.netty.*;version="[4.2,5)",
7575
*
7676
</Import-Package>
7777
<_exportcontents>org.apache.activemq.artemis.*;-noimport:=true</_exportcontents>

artemis-core-client/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,6 @@
109109
<groupId>io.netty</groupId>
110110
<artifactId>netty-handler-proxy</artifactId>
111111
</dependency>
112-
<dependency>
113-
<groupId>io.netty</groupId>
114-
<artifactId>netty-codec</artifactId>
115-
</dependency>
116112
<dependency>
117113
<groupId>io.netty</groupId>
118114
<artifactId>netty-codec-socks</artifactId>

artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnector.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
*/
1717
package org.apache.activemq.artemis.core.remoting.impl.netty;
1818

19-
import static org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants.NETTY_HTTP_HEADER_PREFIX;
20-
2119
import javax.net.ssl.SNIHostName;
2220
import javax.net.ssl.SSLContext;
2321
import javax.net.ssl.SSLEngine;
2422
import javax.net.ssl.SSLParameters;
2523
import java.io.IOException;
24+
import java.lang.invoke.MethodHandles;
2625
import java.net.ConnectException;
2726
import java.net.InetAddress;
2827
import java.net.InetSocketAddress;
@@ -63,15 +62,16 @@
6362
import io.netty.channel.ChannelPipeline;
6463
import io.netty.channel.ChannelPromise;
6564
import io.netty.channel.EventLoopGroup;
65+
import io.netty.channel.MultiThreadIoEventLoopGroup;
6666
import io.netty.channel.SimpleChannelInboundHandler;
6767
import io.netty.channel.WriteBufferWaterMark;
68-
import io.netty.channel.epoll.EpollEventLoopGroup;
68+
import io.netty.channel.epoll.EpollIoHandler;
6969
import io.netty.channel.epoll.EpollSocketChannel;
7070
import io.netty.channel.group.ChannelGroup;
7171
import io.netty.channel.group.DefaultChannelGroup;
72-
import io.netty.channel.kqueue.KQueueEventLoopGroup;
72+
import io.netty.channel.kqueue.KQueueIoHandler;
7373
import io.netty.channel.kqueue.KQueueSocketChannel;
74-
import io.netty.channel.nio.NioEventLoopGroup;
74+
import io.netty.channel.nio.NioIoHandler;
7575
import io.netty.channel.socket.nio.NioSocketChannel;
7676
import io.netty.handler.codec.base64.Base64;
7777
import io.netty.handler.codec.http.DefaultFullHttpRequest;
@@ -92,11 +92,11 @@
9292
import io.netty.handler.codec.http.LastHttpContent;
9393
import io.netty.handler.codec.http.cookie.ClientCookieDecoder;
9494
import io.netty.handler.codec.http.cookie.Cookie;
95-
import io.netty.handler.ssl.SslContext;
9695
import io.netty.handler.codec.socksx.SocksVersion;
9796
import io.netty.handler.proxy.ProxyHandler;
9897
import io.netty.handler.proxy.Socks4ProxyHandler;
9998
import io.netty.handler.proxy.Socks5ProxyHandler;
99+
import io.netty.handler.ssl.SslContext;
100100
import io.netty.handler.ssl.SslHandler;
101101
import io.netty.resolver.NoopAddressResolverGroup;
102102
import io.netty.util.AttributeKey;
@@ -128,8 +128,8 @@
128128
import org.apache.activemq.artemis.utils.PasswordMaskingUtil;
129129
import org.slf4j.Logger;
130130
import org.slf4j.LoggerFactory;
131-
import java.lang.invoke.MethodHandles;
132131

132+
import static org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants.NETTY_HTTP_HEADER_PREFIX;
133133
import static org.apache.activemq.artemis.utils.Base64.encodeBytes;
134134

135135
public class NettyConnector extends AbstractConnector {
@@ -552,29 +552,29 @@ public synchronized void start() {
552552

553553
if (useEpoll && CheckDependencies.isEpollAvailable()) {
554554
if (useGlobalWorkerPool) {
555-
group = SharedEventLoopGroup.getInstance((threadFactory -> new EpollEventLoopGroup(remotingThreads, threadFactory)));
555+
group = SharedEventLoopGroup.getInstance((threadFactory -> new MultiThreadIoEventLoopGroup(remotingThreads, threadFactory, EpollIoHandler.newFactory())));
556556
} else {
557-
group = new EpollEventLoopGroup(remotingThreads);
557+
group = new MultiThreadIoEventLoopGroup(remotingThreads, EpollIoHandler.newFactory());
558558
}
559559
connectorType = EPOLL_CONNECTOR_TYPE;
560560
channelClazz = EpollSocketChannel.class;
561561
logger.debug("Connector {} using native epoll", this);
562562
} else if (useKQueue && CheckDependencies.isKQueueAvailable()) {
563563
if (useGlobalWorkerPool) {
564-
group = SharedEventLoopGroup.getInstance((threadFactory -> new KQueueEventLoopGroup(remotingThreads, threadFactory)));
564+
group = SharedEventLoopGroup.getInstance((threadFactory -> new MultiThreadIoEventLoopGroup(remotingThreads, threadFactory, KQueueIoHandler.newFactory())));
565565
} else {
566-
group = new KQueueEventLoopGroup(remotingThreads);
566+
group = new MultiThreadIoEventLoopGroup(remotingThreads, KQueueIoHandler.newFactory());
567567
}
568568
connectorType = KQUEUE_CONNECTOR_TYPE;
569569
channelClazz = KQueueSocketChannel.class;
570570
logger.debug("Connector {} using native kqueue", this);
571571
} else {
572572
if (useGlobalWorkerPool) {
573573
channelClazz = NioSocketChannel.class;
574-
group = SharedEventLoopGroup.getInstance((threadFactory -> new NioEventLoopGroup(remotingThreads, threadFactory)));
574+
group = SharedEventLoopGroup.getInstance((threadFactory -> new MultiThreadIoEventLoopGroup(remotingThreads, threadFactory, NioIoHandler.newFactory())));
575575
} else {
576576
channelClazz = NioSocketChannel.class;
577-
group = new NioEventLoopGroup(remotingThreads);
577+
group = new MultiThreadIoEventLoopGroup(remotingThreads, NioIoHandler.newFactory());
578578
}
579579
connectorType = NIO_CONNECTOR_TYPE;
580580
channelClazz = NioSocketChannel.class;

artemis-distribution/src/main/resources/bin/artemis

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,15 @@ if $cygwin ; then
9090
CLASSPATH=`cygpath --windows "$CLASSPATH"`
9191
fi
9292

93+
# Whether to allow Unsafe
94+
$JAVACMD --sun-misc-unsafe-memory-access=allow --version > /dev/null 2>&1 && ALLOW_UNSAFE="--sun-misc-unsafe-memory-access=allow"
95+
9396
exec "$JAVACMD" $JAVA_ARGS $ARTEMIS_CLUSTER_PROPS \
9497
-classpath "$CLASSPATH" \
9598
-Dartemis.home="$ARTEMIS_HOME" \
9699
-Djava.library.path="$ARTEMIS_HOME/bin/lib/linux-$(uname -m)" \
100+
--enable-native-access=ALL-UNNAMED \
101+
$ALLOW_UNSAFE \
97102
$DEBUG_ARGS \
98103
$JAVA_ARGS_APPEND \
99104
org.apache.activemq.artemis.boot.Artemis "$@"

0 commit comments

Comments
 (0)