Repository navigation
Generate atomic/unpadded/varhandle variants for xadd queue family - #416
Conversation
Extend the existing code generators to produce all 5 variant types (atomic, atomic-unpadded, unpadded, varhandle, varhandle-unpadded) for MpUnboundedXaddArrayQueue, MpUnboundedXaddChunk, and their Mpsc/Mpmc specializations. This was the only queue family without generated variants. Key generator changes: - Handle Chunk class name translation in translateQueueName() - Support getAndAdd/getAndIncrement method accessor patterns - Add xadd-specific field names (producerChunk, consumerChunk, etc.) - Skip final fields during accessor method patching - Preserve type arguments when replacing SpscArrayQueue references - Guard against double-translation of already-translated names - Translate static imports from Chunk classes Source file adjustments: - Move $gen:ordered-fields directive on MpUnboundedXaddChunk - Remove SUPPORTS_GET_AND_ADD_LONG conditional in base queue - Replace Arrays.fill with soLongElement loop in MpmcUnboundedXaddChunk - Add calcLongElementOffset to VarHandleQueueUtil
nitsanw
left a comment
There was a problem hiding this comment.
Please document the parser changes, I will review the generated code just now
|
Where are the tests? |
I haven't yet updated the existing tests to cover for the new impls, good point @nitsanw |
Add comments explaining the purpose of each new code path in the generators: Chunk type/name renaming visitors, static import rewriting, getAndAdd/getAndIncrement method patching, final field skipping, double-translation guards, SpscArrayQueue pool queue replacement, and _OFFSET-only static field removal.
Tests: Add atomic, atomic-unpadded, unpadded parameters to existing jctools-core xadd test files. Create 4 new VarHandle test files in jctools-core-jdk11. Generator fixes found by running the new tests: - Fix translateQueueName() ordering: check "ArrayQueue" before "Chunk" because inner hierarchy classes like MpUnboundedXaddArrayQueueProducerChunk contain both patterns and must be treated as ArrayQueue classes. - Fix AtomicReferenceFieldUpdater type for generic fields: resolve single-letter type parameters (e.g. R) to their erased bound (e.g. MpUnboundedXaddAtomicChunk) instead of using Object.class, which causes ClassCastException at runtime. - Same fix for VarHandle findVarHandle: resolve generic type params to erased bound for the field type class argument.
|
@nitsanw addressed your comments and run the tests on the new variants - just one note: I have noticed we have no github workflow to handle tests on PRs as well (running on ARM, x86 and MacOS) - do you want to me add it to JCTools? It seems a good idea |
|
Sound like a good idea. |
I would do it as a follow up or in parallel, if you agree! |
VarHandle polymorphic signatures require exact type matching. Passing int 1 to getAndAdd on a long field silently compiles but can fail at runtime with strict VarHandle type checking enabled.
|
PTAL again @nitsanw |
|
|
||
| /** | ||
| * Replaces {@code new SpscArrayQueue<R>(...)} with the unpadded pool queue variant appropriate | ||
| * for this generator (e.g. {@code new SpscAtomicUnpaddedArrayQueue<R>(...)}). |
There was a problem hiding this comment.
Why unpadded? The unsafe variant is padded
There was a problem hiding this comment.
I changed that one (I have to check it applies to the existing unsafe variant) because is not supposed to be an hot path and have a bigger footprint
Extend the existing code generators to produce all 5 variant types (atomic, atomic-unpadded, unpadded, varhandle, varhandle-unpadded) for MpUnboundedXaddArrayQueue, MpUnboundedXaddChunk, and their Mpsc/Mpmc specializations. This was the only queue family without generated variants.
Key generator changes:
Source file adjustments: