From b94e9ad373451738852b6e2f2f559672b6125384 Mon Sep 17 00:00:00 2001 From: Dmytro Vyazelenko <696855+vyazelenko@users.noreply.github.com> Date: Sat, 18 Jan 2025 00:32:57 +0100 Subject: [PATCH] [Java] Upgrade to Aeron 1.47.0 and Agrona 2.0.1. --- .../remote/InMemoryMessageTransceiver.java | 25 +++++++++---------- build.gradle | 1 + gradle/libs.versions.toml | 4 +-- scripts/run-java | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/InMemoryMessageTransceiver.java b/benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/InMemoryMessageTransceiver.java index 7dc2e4a6..6bf20438 100644 --- a/benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/InMemoryMessageTransceiver.java +++ b/benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/InMemoryMessageTransceiver.java @@ -17,21 +17,20 @@ import org.HdrHistogram.Histogram; import org.HdrHistogram.ValueRecorder; +import org.agrona.UnsafeApi; import org.agrona.concurrent.NanoClock; import static java.lang.Integer.numberOfLeadingZeros; import static java.util.Arrays.fill; import static org.agrona.BitUtil.CACHE_LINE_LENGTH; import static org.agrona.BitUtil.SIZE_OF_LONG; -import static org.agrona.UnsafeAccess.UNSAFE; -import static sun.misc.Unsafe.ARRAY_LONG_BASE_OFFSET; -import static sun.misc.Unsafe.ARRAY_LONG_INDEX_SCALE; public final class InMemoryMessageTransceiver extends MessageTransceiver { static final int SIZE = 4096; + private static final int ARRAY_LONG_BASE_OFFSET = UnsafeApi.arrayBaseOffset(long[].class); private static final int MASK = SIZE - 1; - private static final int SHIFT = 31 - numberOfLeadingZeros(ARRAY_LONG_INDEX_SCALE); + private static final int SHIFT = 31 - numberOfLeadingZeros(UnsafeApi.arrayIndexScale(long[].class)); private static final int PADDING = CACHE_LINE_LENGTH / SIZE_OF_LONG - 1; private final long[] messages = new long[SIZE]; @@ -62,19 +61,19 @@ public int send(final int numberOfMessages, final int messageLength, final long { final long[] messages = this.messages; final long index = sendIndex; - if (0L != UNSAFE.getLongVolatile(messages, offset(index + 1 + messageIndexOffset(numberOfMessages)))) + if (0L != UnsafeApi.getLongVolatile(messages, offset(index + 1 + messageIndexOffset(numberOfMessages)))) { return 0; } for (int i = numberOfMessages; i > 1; i--) { - UNSAFE.putLong(messages, offset(index + messageIndexOffset(i)), timestamp); - UNSAFE.putLong(messages, offset(index + 1 + messageIndexOffset(i)), checksum); + UnsafeApi.putLong(messages, offset(index + messageIndexOffset(i)), timestamp); + UnsafeApi.putLong(messages, offset(index + 1 + messageIndexOffset(i)), checksum); } - UNSAFE.putLong(messages, offset(index), timestamp); - UNSAFE.putOrderedLong(messages, offset(index + 1), checksum); + UnsafeApi.putLong(messages, offset(index), timestamp); + UnsafeApi.putLongRelease(messages, offset(index + 1), checksum); sendIndex += messageIndexOffset(numberOfMessages + 1); @@ -90,13 +89,13 @@ public void receive() { final long checksumOffset = offset(receiveIndex + 1); final long[] messages = this.messages; - final long checksum = UNSAFE.getLongVolatile(messages, checksumOffset); + final long checksum = UnsafeApi.getLongVolatile(messages, checksumOffset); if (0L != checksum) { final long timestampOffset = offset(receiveIndex); - final long timestamp = UNSAFE.getLong(messages, timestampOffset); - UNSAFE.putLong(messages, timestampOffset, 0L); - UNSAFE.putOrderedLong(messages, checksumOffset, 0L); + final long timestamp = UnsafeApi.getLong(messages, timestampOffset); + UnsafeApi.putLong(messages, timestampOffset, 0L); + UnsafeApi.putLongRelease(messages, checksumOffset, 0L); onMessageReceived(timestamp, checksum); receiveIndex += (1 + PADDING); } diff --git a/build.gradle b/build.gradle index 0f14fd65..5fc5b17f 100644 --- a/build.gradle +++ b/build.gradle @@ -104,6 +104,7 @@ subprojects { tasks.withType(Test).configureEach { useJUnitPlatform() + jvmArgs('--add-opens', 'java.base/jdk.internal.misc=ALL-UNNAMED') if (buildJavaVersion >= 21) { jvmArgs('-XX:+EnableDynamicAgentLoading') diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ebc0177d..ef7c8855 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -aeron = "1.46.8" +aeron = "1.47.0" checkstyle = "10.21.0" junit = "5.11.4" jmh = "1.37" @@ -12,7 +12,7 @@ jackson = "2.16.2" gradle = "8.11.1" [libraries] -agrona = { group = "org.agrona", name = "agrona", version = "1.23.1" } +agrona = { group = "org.agrona", name = "agrona", version = "2.0.1" } aeron-cluster = { group = "io.aeron", name = "aeron-cluster", version.ref = "aeron" } aeron-samples = { group = "io.aeron", name = "aeron-samples", version.ref = "aeron" } mockito = { group = "org.mockito", name = "mockito-core", version = "5.15.2" } diff --git a/scripts/run-java b/scripts/run-java index cbf80ee8..4c085440 100755 --- a/scripts/run-java +++ b/scripts/run-java @@ -46,7 +46,7 @@ java_options=( -XX:+EnableDynamicAgentLoading "-Xlog:gc*,safepoint=info,arguments=info:file=${gc_log_file}:time") -add_opens=(--add-opens java.base/java.util.zip=ALL-UNNAMED) +add_opens=(--add-opens java.base/java.util.zip=ALL-UNNAMED --add-opens java.base/jdk.internal.misc=ALL-UNNAMED) jvm_opts=()