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

Adding Atomic Unpadded queues #389

Merged
merged 2 commits into from Feb 14, 2024
Merged

Conversation

franz1981
Copy link
Collaborator

@franz1981 franz1981 commented Feb 7, 2024

This is replacing #388

Right now it modifies the atomic generators, which are doing already the heavy-lifting of replacing methods/primitive utils and classes to allow Atomics to be used, but adding the 2 required behaviour:

  1. removing padding comments
  2. removing padding fields

It looked like a natural thing to me, given that it would add unpadding to the existing atomic generation mechanism.

As promised on #388 (comment), I'm exploring how to modify the existing JavaParsingUnpaddedQueueGenerator to create Atomic variants, but TBH it seems to add more changes (probably taking them - by decoration or copy - from the existing Atomic generators)

final int offsetInOld = modifiedCalcCircularRefElementOffset(pIndex, oldMask);
final int offsetInNew = modifiedCalcCircularRefElementOffset(pIndex, newMask);
// element in new array
soRefElement(newBuffer, offsetInNew, e == null ? s.get() : e);

Check warning

Code scanning / CodeQL

Dereferenced variable may be null Warning

Variable
s
may be null at this access as suggested by
this
null guard.
Variable
s
may be null at this access as suggested by
this
null guard.
Variable
s
may be null at this access because of
this
null argument.
@franz1981
Copy link
Collaborator Author

franz1981 commented Feb 7, 2024

IDK if e1d445e vs this one matches some of your requests: I didn't enhanced the unpadded generator, because the most of the parts I needed to reuse were from the atomic generators, while unpadding just requires to remove unpadded fields & comments.
I'm not a big fan of inheritance, in general, but I've replaced the changes in the atomic generator with some extension points to allow the atomic unpadded generators to inject the package/queue names they needed, in order to reuse as much as possible what we already have.

I tried to extract the parts from the atomic generator, to enhance the unpadded one, without much luck, due to lack of time (admit), but if you have any hint I'm open to do things differently, bud

generator.organiseImports(cu);
generator.cleanupComments(cu);

String outputFileName = generator.translateQueueName(file.getName().replace(".java", "")) + ".java";
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could make JCToolsGenerator to use a single method String generate(String queueName) which return the translated queue name instead of having 3 different methods, executing a generic generation process

Copy link
Collaborator Author

@franz1981 franz1981 Feb 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm saving to add more abstractions @nitsanw because I don't know yet if this PR is decent enough; IDK if makes sense to create abstractions of any kind for some task like this, if not for the sake of re-using code, given that generating code isn't a proper domain which require being strongly defined (in order to get used elsewhere - in other layers), but I see it more as a set of transformation steps/scripts which we want to write once and modify after 4-5 years (unless bugs).

import static org.jctools.queues.atomic.unpadded.AtomicQueueUtil.calcCircularRefElementOffset;
import static org.jctools.queues.atomic.unpadded.AtomicQueueUtil.lvRefElement;

abstract class AtomicReferenceArrayQueue<E> extends AbstractQueue<E> implements IndexedQueue, QueueProgressIndicators, MessagePassingQueue<E>, SupportsIterator
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can avoid the copy by making the original public and annotating as InternalAPI


import java.util.concurrent.atomic.AtomicReference;

public final class LinkedQueueAtomicNode<E> extends AtomicReference<LinkedQueueAtomicNode<E>>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can reuse original which is unpadded

Copy link
Contributor

@nitsanw nitsanw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I think it looks OK, please avoid copying stuff where possible, even if it requires changing class visibility (just mark as internal)

@franz1981
Copy link
Collaborator Author

Nice one, ok @nitsanw I will reuse as much as we can 👍 thanks for taking a look!

@franz1981
Copy link
Collaborator Author

@nitsanw PTAL

@@ -173,6 +173,57 @@
</arguments>
</configuration>
</execution>
<execution>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's happening with the indentation here?

@nitsanw nitsanw merged commit 173423c into JCTools:master Feb 14, 2024
2 checks passed
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

Successfully merging this pull request may close these issues.

None yet

2 participants