question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CAS operation fails in readMarshallable()

See original GitHub issue

Hi, please check this code example:

    public void testCAS() {
        final File dir = getTmpDir();
        try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(dir)
                .build()) {
            final ExcerptAppender appender = queue.acquireAppender();
            final ExcerptTailer tailer = queue.createTailer();
            final WriteBytesMarshallable writeBytesMarshallable = bytes -> bytes.writeLong(123L);
            final ReadBytesMarshallable readBytesMarshallable = bytes -> bytes.compareAndSwapLong(bytes.readPosition(), 123L, 321L);

            final int iterations = 5; // fails at 5th iteration
            for (int i = 0; i < iterations; i++) {
                appender.writeBytes(writeBytesMarshallable);
                tailer.readBytes(readBytesMarshallable);
            }
        }
    }

It fails with exception:

net.openhft.chronicle.core.util.MisAlignedAssertionError at net.openhft.chronicle.core.UnsafeMemory.compareAndSwapLong(UnsafeMemory.java:983) at net.openhft.chronicle.bytes.internal.NativeBytesStore.compareAndSwapLong(NativeBytesStore.java:342) at net.openhft.chronicle.bytes.MappedBytesStore.compareAndSwapLong(MappedBytesStore.java:187) at net.openhft.chronicle.bytes.internal.ChunkedMappedBytes.compareAndSwapLong(ChunkedMappedBytes.java:607) at net.openhft.chronicle.queue.AcquireReleaseTest.lambda$testCAS$5(AcquireReleaseTest.java:147) at net.openhft.chronicle.wire.MarshallableIn.readBytes(MarshallableIn.java:69) at net.openhft.chronicle.queue.AcquireReleaseTest.testCAS(AcquireReleaseTest.java:152)

I guess it is somehow connected with padding/alignment. There were some changes in Chronicle Core library, addressing padding. My environment is Intel Macbook Pro 2013, Oracle JDK 1.8.0_201. Currently we are using 5.21ea44 in production, there is no such problem.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
garikjancommented, Dec 8, 2021

Sorry, I was wrong. To be more precise, I am testing at commit 161dda49bed41df9bdc0e36a261ce2dadcd29611 of ea branch.

0reactions
peter-lawreycommented, May 20, 2022

Can we close this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

OpenHFT/Chronicle-Wire: A Low Garbage Java ... - GitHub
When a marshallable object is re-used or initialised by the framework, it is first reset by way of Marshallable.reset() which is recommended over...
Read more >
CAS operation does not return value on failure
Hi, I am doing some testing on CAS operations and I am frequently having the issue that my resultset says wasApplied()==false, but it...
Read more >
Regarding busy loop for getting updates of Chronicle queue
This is a copy-paste error. None of the operations are blocking, nor where they ever. In the case of read() it can return...
Read more >
Chronicle-Map - Java - Gitee
If a concurrent process is accessing the Chronicle Map while another process is attempting to perform recovery, result of operations on the accessing...
Read more >
Fastest Way of Serializing Java Field - DZone
The default way (whereby the magic writeObject() and readObject() are not ... at all (eg unaligned CAS operations on the ARM architecture).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found