Skip to content

Commit

Permalink
[Java] Upgrade to Aeron 1.47.0, Agrona 2.0.1 and SBE 1.34.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
vyazelenko committed Jan 17, 2025
1 parent 529a2e3 commit 8fb87dc
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
*/
package uk.co.real_logic.artio.util;

import org.agrona.UnsafeApi;
import org.agrona.collections.LongHashSet;

import java.util.Set;

import static org.agrona.BufferUtil.ARRAY_BASE_OFFSET;
import static org.agrona.UnsafeAccess.UNSAFE;

/**
* Class for handling the encoding and decoding of Artio's packed message types.
*
* <p>
* FIX uses 1 or 2 character ascii sequences as a way of representing the message type of messages. Some venues
* have a longer representation with more message types in. Artio has a packed representation where the bytes of
* the message type are encoded into a long.
Expand Down Expand Up @@ -69,7 +69,7 @@ public static LongHashSet packAllMessageTypes(final Set<String> messageTypes)
* Creates a packed message type from a char[] and length.
*
* @param messageType message type as ascii char[].
* @param length the number of characters within messageType to use.
* @param length the number of characters within messageType to use.
* @return the packed message type.
* @throws IllegalArgumentException if messageType parameter is too long.
*/
Expand Down Expand Up @@ -99,8 +99,8 @@ private static void checkLength(final int length)
* Creates a packed message type from a byte[] and length.
*
* @param messageType message type as ascii byte[].
* @param offset the offset within the messagetype to start looking
* @param length the number of characters within messageType to use.
* @param offset the offset within the messagetype to start looking
* @param length the number of characters within messageType to use.
* @return the packed message type.
* @throws IllegalArgumentException if messageType parameter is too long.
*/
Expand All @@ -115,18 +115,18 @@ static long packMessageType(final byte[] messageType, final long baseOffset, fin

if (length == 1)
{
return UNSAFE.getByte(messageType, baseOffset + offset);
return UnsafeApi.getByte(messageType, baseOffset + offset);
}
else if (length == 2)
{
return UNSAFE.getShort(messageType, baseOffset + offset);
return UnsafeApi.getShort(messageType, baseOffset + offset);
}
else
{
long packed = 0;
for (int index = 0; index < length; index++)
{
final int asciiValue = UNSAFE.getByte(messageType, baseOffset + offset + index);
final int asciiValue = UnsafeApi.getByte(messageType, baseOffset + offset + index);
packed |= asciiValue << (MESSAGE_TYPE_BITSHIFT * index);
}
return packed;
Expand All @@ -141,10 +141,9 @@ else if (length == 2)
* type.
*
* @param packedMessageType the FIX message type in packed format.
* @param dest a destination byte array where the unpacked value is put, should be at least two bytes long.
* @throws ArrayIndexOutOfBoundsException if dest is too short.
*
* @param dest a destination byte array where the unpacked value is put, should be at least two bytes long.
* @return the length of the unpacked value
* @throws ArrayIndexOutOfBoundsException if dest is too short.
*/
public static int unpackMessageType(final long packedMessageType, final byte[] dest)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@

import java.io.File;
import java.io.IOException;
import java.lang.invoke.VarHandle;
import java.util.ArrayList;
import java.util.List;
import java.util.function.LongFunction;

import static io.aeron.archive.status.RecordingPos.NULL_RECORDING_ID;
import static io.aeron.logbuffer.FrameDescriptor.*;
import static org.agrona.UnsafeAccess.UNSAFE;
import static uk.co.real_logic.artio.dictionary.SessionConstants.SEQUENCE_RESET_MESSAGE_TYPE;
import static uk.co.real_logic.artio.engine.SequenceNumberExtractor.NO_SEQUENCE_NUMBER;
import static uk.co.real_logic.artio.engine.logger.ReplayIndexDescriptor.*;
Expand Down Expand Up @@ -579,7 +579,7 @@ void onRecord(
final long beginPosition = endPosition - length;

beginChangeOrdered(headerBuffer, changePosition);
UNSAFE.storeFence();
VarHandle.storeStoreFence();

final int segmentIndex = ReplayIndexDescriptor.segmentIndex(
beginChangePosition, segmentSizeBitShift, indexFileSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
import uk.co.real_logic.artio.util.CharFormatter;

import java.io.File;
import java.lang.invoke.VarHandle;
import java.util.ArrayList;
import java.util.List;
import java.util.function.LongFunction;

import static io.aeron.Aeron.NULL_VALUE;
import static io.aeron.CommonContext.IPC_CHANNEL;
import static io.aeron.logbuffer.FrameDescriptor.FRAME_ALIGNMENT;
import static org.agrona.UnsafeAccess.UNSAFE;
import static uk.co.real_logic.artio.DebugLogger.IS_REPLAY_ATTEMPT_ENABLED;
import static uk.co.real_logic.artio.engine.logger.ReplayIndexDescriptor.*;
import static uk.co.real_logic.artio.engine.logger.Replayer.MOST_RECENT_MESSAGE;
Expand Down Expand Up @@ -284,7 +284,7 @@ ReplayOperation query(
final long recordingId = indexRecord.recordingId();
final int readLength = indexRecord.length();

UNSAFE.loadFence(); // LoadLoad required so previous loads don't move past version check below.
VarHandle.loadLoadFence(); // LoadLoad required so previous loads don't move past version check below.

if (log)
{
Expand Down Expand Up @@ -475,7 +475,7 @@ public Long2ObjectHashMap<PrunePosition> queryStartPositions()
final long recordingId = indexRecord.recordingId();
final int sequenceNumber = indexRecord.sequenceNumber();

UNSAFE.loadFence(); // LoadLoad required so previous loads don't move past version check below.
VarHandle.loadLoadFence(); // LoadLoad required so previous loads don't move past version check below.

// if the block was read atomically with no updates
if (changePosition == beginChangeVolatile(headerBuffer))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@

import org.agrona.BitUtil;
import org.agrona.BufferUtil;
import org.agrona.UnsafeApi;
import org.openjdk.jmh.annotations.*;

import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import static org.agrona.UnsafeAccess.UNSAFE;

@State(Scope.Benchmark)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
Expand Down Expand Up @@ -59,16 +58,16 @@ public int[] arraysFill()
public int[] memset()
{
final int[] values = this.values;
UNSAFE.setMemory(values, BufferUtil.ARRAY_BASE_OFFSET, sizeInBytes, MISSING_BYTE);
UnsafeApi.setMemory(values, BufferUtil.ARRAY_BASE_OFFSET, sizeInBytes, MISSING_BYTE);
return values;
}

@Benchmark
public int[] offsetMemset()
{
final int[] values = this.values;
UNSAFE.putByte(values, BufferUtil.ARRAY_BASE_OFFSET, MISSING_BYTE);
UNSAFE.setMemory(values, BufferUtil.ARRAY_BASE_OFFSET + 1, sizeInBytes - 1, MISSING_BYTE);
UnsafeApi.putByte(values, BufferUtil.ARRAY_BASE_OFFSET, MISSING_BYTE);
UnsafeApi.setMemory(values, BufferUtil.ARRAY_BASE_OFFSET + 1, sizeInBytes - 1, MISSING_BYTE);
return values;
}

Expand Down
9 changes: 8 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ allprojects {
configurations.configureEach {
resolutionStrategy {
failOnVersionConflict()
force "org.agrona:agrona:${libs.versions.agrona.get()}",
force libs.agrona,
libs.byteBuddy,
libs.byteBuddy.agent,
// patching conflicting Checkstyle dependencies
Expand Down Expand Up @@ -178,6 +178,7 @@ subprojects {
useJUnitPlatform()

jvmArgs('--add-opens', 'java.base/sun.nio.ch=ALL-UNNAMED')
jvmArgs('--add-opens', 'java.base/jdk.internal.misc=ALL-UNNAMED')
jvmArgs('--add-opens', 'java.base/java.util.zip=ALL-UNNAMED')

if (buildJavaVersion >= 21) {
Expand Down Expand Up @@ -319,6 +320,7 @@ project(':artio-codecs') {

tasks.register('generateMessages', JavaExec) {
mainClass.set('uk.co.real_logic.sbe.SbeTool')
jvmArgs('--add-opens', 'java.base/jdk.internal.misc=ALL-UNNAMED')
classpath = configurations.codecGeneration
systemProperties('sbe.output.dir': generatedDir,
'sbe.target.language': 'Java',
Expand Down Expand Up @@ -391,6 +393,7 @@ project(':artio-ilink3-codecs') {

tasks.register('generateMessages', JavaExec) {
mainClass.set('uk.co.real_logic.sbe.SbeTool')
jvmArgs('--add-opens', 'java.base/jdk.internal.misc=ALL-UNNAMED')
classpath = configurations.codecGeneration
systemProperties(
'sbe.output.dir': generatedDir,
Expand Down Expand Up @@ -472,6 +475,7 @@ project(':artio-binary-entrypoint-codecs') {

tasks.register('generateMessages', JavaExec) {
mainClass.set('uk.co.real_logic.sbe.SbeTool')
jvmArgs('--add-opens', 'java.base/jdk.internal.misc=ALL-UNNAMED')
classpath = configurations.codecGeneration
systemProperties(
'sbe.output.dir': generatedDir,
Expand Down Expand Up @@ -607,6 +611,7 @@ project(':artio-session-codecs') {

tasks.register('generateCodecs', JavaExec) {
mainClass.set('uk.co.real_logic.artio.dictionary.CodecGenerationTool')
jvmArgs('--add-opens', 'java.base/jdk.internal.misc=ALL-UNNAMED')
classpath = configurations.codecGeneration
def dictionaryFile = 'src/main/resources/session_dictionary.xml'
inputs.file(dictionaryFile)
Expand All @@ -617,6 +622,7 @@ project(':artio-session-codecs') {

tasks.register('generateOtherCodecs', JavaExec) {
mainClass.set('uk.co.real_logic.artio.dictionary.CodecGenerationTool')
jvmArgs('--add-opens', 'java.base/jdk.internal.misc=ALL-UNNAMED')
classpath = configurations.codecGeneration
def dictionaryFile = 'src/main/resources/other_session_dictionary.xml'
inputs.file(dictionaryFile)
Expand Down Expand Up @@ -684,6 +690,7 @@ project(':artio-session-fixt-codecs') {

tasks.register('generateCodecs', JavaExec) {
mainClass.set('uk.co.real_logic.artio.dictionary.CodecGenerationTool')
jvmArgs('--add-opens', 'java.base/jdk.internal.misc=ALL-UNNAMED')
classpath = configurations.codecGeneration
systemProperty("fix.codecs.parent_package", "uk.co.real_logic.artio.fixt")
args = [generatedDir, 'src/main/resources/FIXT11.xml']
Expand Down
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[versions]
aeron = "1.46.8"
agrona = "1.23.1"
aeron = "1.47.0"
agrona = "2.0.1"
byteBuddy = "1.15.11"
checkstyle = "10.20.1"
junit = "5.11.4"
gradle = "8.11.1"
jmh = "1.37"

[libraries]
agrona = { group = "org.agrona", name = "agrona", version = { strictly = "[1.23.1, 2.0[", require = "1.23.1" } }
agrona = { group = "org.agrona", name = "agrona", version.ref = "agrona" }
aeron-client = { group = "io.aeron", name = "aeron-client", version.ref = "aeron" }
aeron-archive = { group = "io.aeron", name = "aeron-archive", version.ref = "aeron" }
sbe = { group = "uk.co.real-logic", name = "sbe-tool", version = "1.33.2" }
sbe = { group = "uk.co.real-logic", name = "sbe-tool", version = "1.34.1" }
mockito = { group = "org.mockito", name = "mockito-core", version = "5.15.2" }
hamcrest = { group = "org.hamcrest", name = "hamcrest", version = "3.0" }
junit4 = { group = "junit", name = "junit", version = "4.13.2" }
Expand Down

0 comments on commit 8fb87dc

Please sign in to comment.