Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disparity between Java and C++ versions of putRawTailOrdered() #589

Closed
denizevrenci opened this issue Dec 4, 2018 · 0 comments
Closed

Comments

@denizevrenci
Copy link
Contributor

denizevrenci commented Dec 4, 2018

putRawTailOrdered() in Java is implemented with packTail() with the implementation below:

return ((long)termId << 32) | (termOffset & 0xFFFF_FFFFL);

This has the expected behaviour of 32 termId bits followed by 32 termOffset bits.

While in C++ the same code is implemented with:

((termId << 32) + termOffset)

Where termId is cast to an int64_t implicitly at the function call.

I suppose both termId and termOffset can take negative values. In that case the two implementations produce different results. Also it is possible to get numeric overflow. And, furthermore, left shift of negative integers is undefined in C and C++ even though most implementations pad zeroes.

Compatible C++ implementation is:

inline void putRawTailOrdered(const std::int32_t termId, const std::int32_t termOffset)
{
    aeron::concurrent::atomic::putInt64Ordered(m_tailAddr, termId * ((int64_t(1) << 32) | (int64_t(0xFFFFFFFF) & termOffset);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants