Skip to content

Commit

Permalink
[Java] Upgrade to Aeron 1.47.0 and Agrona 2.0.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
vyazelenko committed Jan 17, 2025
1 parent 442901b commit b94e9ad
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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);

Expand All @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
aeron = "1.46.8"
aeron = "1.47.0"
checkstyle = "10.21.0"
junit = "5.11.4"
jmh = "1.37"
Expand All @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion scripts/run-java
Original file line number Diff line number Diff line change
Expand Up @@ -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=()

Expand Down

0 comments on commit b94e9ad

Please sign in to comment.