ARTEMIS-4751 upgrade to Apache parent 32

Due to https://github.com/apache/maven-apache-parent/pull/188 the
property `maven.compiler.release` is now being set which precludes
exporting and using any internal Java classes. Therefore this commit
removed references to `--add-exports` from the build, switches to
reflection, and adds `--add-opens` to the runtime JVM parameters.
This commit is contained in:
Justin Bertram 2024-05-01 13:33:05 -05:00
parent e8f449973a
commit eac816f6bd
6 changed files with 39 additions and 53 deletions

View File

@ -16,6 +16,8 @@
*/
package org.apache.activemq.artemis.cli.commands.messages.perf;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;
public class MicrosClock {
@ -23,6 +25,8 @@ public class MicrosClock {
// no need for volatile here
private static long offset = -1;
private static long NANOS_PER_SECOND = TimeUnit.SECONDS.toNanos(1);
private static Class vm;
private static Method getNanoTimeAdjustment;
private static final boolean AVAILABLE = checkAvailable();
@ -43,23 +47,32 @@ public class MicrosClock {
}
public static long now() {
long epochSecond = offset;
long nanoAdjustment = jdk.internal.misc.VM.getNanoTimeAdjustment(epochSecond);
if (nanoAdjustment == -1) {
epochSecond = System.currentTimeMillis() / 1000 - 1024;
nanoAdjustment = jdk.internal.misc.VM.getNanoTimeAdjustment(epochSecond);
if (nanoAdjustment == -1) {
throw new InternalError("Offset " + epochSecond + " is not in range");
} else {
offset = epochSecond;
try {
long epochSecond = offset;
if (vm == null) {
vm = Class.forName("jdk.internal.misc.VM");
}
}
final long secs = Math.addExact(epochSecond, Math.floorDiv(nanoAdjustment, NANOS_PER_SECOND));
final long secsInUs = TimeUnit.SECONDS.toMicros(secs);
final long nsOffset = (int) Math.floorMod(nanoAdjustment, NANOS_PER_SECOND);
final long usOffset = TimeUnit.NANOSECONDS.toMicros(nsOffset);
return secsInUs + usOffset;
}
if (getNanoTimeAdjustment == null) {
getNanoTimeAdjustment = vm.getMethod("getNanoTimeAdjustment", long.class);
}
long nanoAdjustment = (long) getNanoTimeAdjustment.invoke(getNanoTimeAdjustment, epochSecond);
}
if (nanoAdjustment == -1) {
epochSecond = System.currentTimeMillis() / 1000 - 1024;
nanoAdjustment = (long) getNanoTimeAdjustment.invoke(getNanoTimeAdjustment, epochSecond);
if (nanoAdjustment == -1) {
throw new InternalError("Offset " + epochSecond + " is not in range");
} else {
offset = epochSecond;
}
}
final long secs = Math.addExact(epochSecond, Math.floorDiv(nanoAdjustment, NANOS_PER_SECOND));
final long secsInUs = TimeUnit.SECONDS.toMicros(secs);
final long nsOffset = (int) Math.floorMod(nanoAdjustment, NANOS_PER_SECOND);
final long usOffset = TimeUnit.NANOSECONDS.toMicros(nsOffset);
return secsInUs + usOffset;
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
throw new IllegalStateException(e);
}
}
}

View File

@ -37,7 +37,7 @@ HAWTIO_ROLE='${role}'
# Java Opts
if [ -z "$JAVA_ARGS" ]; then
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=${ARTEMIS_INSTANCE_ETC_URI}jolokia-access.xml -Dlog4j2.disableJmx=true ${java-opts}"
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=${ARTEMIS_INSTANCE_ETC_URI}jolokia-access.xml -Dlog4j2.disableJmx=true --add-opens java.base/jdk.internal.misc=ALL-UNNAMED ${java-opts}"
fi
# Uncomment to enable logging for Safepoint JVM pauses

View File

@ -33,7 +33,7 @@ rem Cluster Properties: Used to pass arguments to ActiveMQ Artemis which can be
rem set ARTEMIS_CLUSTER_PROPS=-Dactivemq.remoting.default.port=61617 -Dactivemq.remoting.amqp.port=5673 -Dactivemq.remoting.stomp.port=61614 -Dactivemq.remoting.hornetq.port=5446
rem Java Opts
IF "%JAVA_ARGS%"=="" (set JAVA_ARGS=${java-opts} -XX:AutoBoxCacheMax=20000 -XX:+PrintClassHistogram -XX:+UseG1GC -XX:+UseStringDeduplication -Xms512M -Xmx${java-memory} -Djava.security.auth.login.config=%ARTEMIS_ETC_DIR%\login.config -Dhawtio.disableProxy=true -Dhawtio.offline=true -Dhawtio.realm=activemq -Dhawtio.role=${role} -Dhawtio.rolePrincipalClasses=org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal -Dhawtio.http.strictTransportSecurity=max-age=31536000;includeSubDomains;preload -Djolokia.policyLocation=%ARTEMIS_INSTANCE_ETC_URI%\jolokia-access.xml -Dartemis.instance=%ARTEMIS_INSTANCE% -Dlog4j2.disableJmx=true)
IF "%JAVA_ARGS%"=="" (set JAVA_ARGS=${java-opts} -XX:AutoBoxCacheMax=20000 -XX:+PrintClassHistogram -XX:+UseG1GC -XX:+UseStringDeduplication -Xms512M -Xmx${java-memory} -Djava.security.auth.login.config=%ARTEMIS_ETC_DIR%\login.config -Dhawtio.disableProxy=true -Dhawtio.offline=true -Dhawtio.realm=activemq -Dhawtio.role=${role} -Dhawtio.rolePrincipalClasses=org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal -Dhawtio.http.strictTransportSecurity=max-age=31536000;includeSubDomains;preload -Djolokia.policyLocation=%ARTEMIS_INSTANCE_ETC_URI%\jolokia-access.xml -Dartemis.instance=%ARTEMIS_INSTANCE% --add-opens java.base/jdk.internal.misc=ALL-UNNAMED -Dlog4j2.disableJmx=true)
rem Logs Safepoints JVM pauses: Uncomment to enable them
rem In addition to the traditional GC logs you could enable some JVM flags to know any meaningful and "hidden" pause that could

19
pom.xml
View File

@ -25,7 +25,7 @@
<parent>
<groupId>org.apache</groupId>
<artifactId>apache</artifactId>
<version>31</version>
<version>32</version>
<relativePath>org.apache:apache</relativePath>
</parent>
@ -119,9 +119,6 @@
<zookeeper.version>3.9.1</zookeeper.version>
<woodstox.version>4.4.0</woodstox.version>
<pem-keystore.version>2.3.0</pem-keystore.version>
<!-- This overrides the Apache parent POM due to https://issues.apache.org/jira/browse/MSHADE-462. Once that issue
is resolved and a new Apache parent is released then we can get rid of this. -->
<version.maven-shade-plugin>3.4.1</version.maven-shade-plugin>
<!-- This overrides the Apache parent POM. Once a new Apache parent is released with the latest version then we
can get rid of this. -->
@ -340,8 +337,6 @@
<configuration>
<compilerArgs>
<arg>-Xdiags:verbose</arg>
<arg>--add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED</arg>
<arg>--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED</arg>
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne -Xep:ThreadLocalUsage:ERROR -Xep:MissingOverride:ERROR -Xep:NonAtomicVolatileUpdate:ERROR -Xep:SynchronizeOnNonFinalField:ERROR -Xep:StaticQualifiedUsingExpression:ERROR -Xep:WaitNotInLoop:ERROR -Xep:BanJNDI:OFF -XepExcludedPaths:.*/generated-sources/.*</arg>
</compilerArgs>
@ -376,8 +371,6 @@
<fork>true</fork>
<compilerArgs>
<arg>-Xdiags:verbose</arg>
<arg>--add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED</arg>
<arg>--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED</arg>
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne -Xep:ThreadLocalUsage:ERROR -Xep:MissingOverride:WARN -Xep:NonAtomicVolatileUpdate:ERROR -Xep:SynchronizeOnNonFinalField:ERROR -Xep:StaticQualifiedUsingExpression:ERROR -Xep:WaitNotInLoop:ERROR -Xep:BanJNDI:OFF -XepExcludedPaths:.*/generated-sources/.*</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
@ -829,16 +822,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<showWarnings>true</showWarnings>
<compilerArgs>
<arg>--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-rar-plugin</artifactId>

View File

@ -291,16 +291,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>--add-exports=java.rmi/sun.rmi.server=ALL-UNNAMED</arg>
<arg>--add-exports=java.rmi/sun.rmi.transport=ALL-UNNAMED</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-maven-plugin</artifactId>

View File

@ -24,6 +24,7 @@ import javax.management.remote.rmi.RMIConnection;
import javax.management.remote.rmi.RMIConnector;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.rmi.server.RemoteObject;
import java.rmi.server.RemoteRef;
@ -36,8 +37,6 @@ import org.junit.Assume;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import sun.rmi.server.UnicastRef;
import sun.rmi.transport.LiveRef;
/**
* This test checks JMX connection to Artemis with both necessary ports set up so that it's easier to tunnel through
@ -142,12 +141,13 @@ public class JmxConnectionTest extends SmokeTestBase {
remoteRefField = (RemoteRef) UnsafeAccess.UNSAFE.getObject(remoteRef, UnsafeAccess.UNSAFE.objectFieldOffset(refField));
}
Assert.assertNotNull(remoteRefField);
Assert.assertTrue(remoteRefField instanceof UnicastRef);
Assert.assertEquals("sun.rmi.server.UnicastRef2", remoteRefField.getClass().getTypeName());
// 5. UnicastRef::getLiveRef returns LiveRef
LiveRef liveRef = ((UnicastRef) remoteRefField).getLiveRef();
Method getLiveRef = remoteRefField.getClass().getMethod("getLiveRef");
Object liveRef = getLiveRef.invoke(remoteRefField);
Assert.assertEquals(RMI_REGISTRY_PORT, liveRef.getPort());
Assert.assertEquals(RMI_REGISTRY_PORT, liveRef.getClass().getMethod("getPort").invoke(liveRef));
} finally {
jmxConnector.close();