[concurrency-interest] padding in Exchanger

Ruslan Cheremin cheremin at gmail.com
Tue Jan 17 07:28:00 EST 2012

Thank you for your comment. I've just read both links, but still do
not find answer.

Let me clarify my question. I understand the reasons for cache line
padding in general. I understand what it is better to have both-side
padding like it is in Striped64.Cell
static final class Cell {
        volatile long p0, p1, p2, p3, p4, p5, p6;
        volatile long value;
        volatile long q0, q1, q2, q3, q4, q5, q6;

     ...other methods...


since it is close to bulletproof version (assuming field layout
algorithm in JVM is stable, and does not reorder same-type adjusted
fields -- which is true for now, AFAIK). But Exchanger.Slot in my JDK,
end even Exchanger.Node in version you've refered to used one-side
padding. And it is not clear for me how, on system with 64 bytes cache
line, one-side padding 128 bytes long can be better then one side
padding 64 bytes long. Even taking in account possible field
reordering by JVM. From my point of view one side padding is not
bulletproof anyway...

> The short answer is that JVMs do not guarantee alignment.
> For a longer answer, see the internals of the new Striped64 class at
> http://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/jsr166e/Striped64.java?view=log
> and/or the overhauled Exchanger class at
> http://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/main/java/util/concurrent/Exchanger.java?view=log
> In general, especially on multisocket multicores these days,
> you need to waste a lot of space to overcome crippling memory
> contention effects that can easily slow down an application
> by a factor of 4; sometimes more. Were trying to isolate
> the cases where doing so is worthwhile inside libraries,
> so that users don't need to think about it very often, so
> long as they use the provided components.
> -Doug
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest

More information about the Concurrency-interest mailing list