Why does java Exchanger.Slot cache strings like this?

When I read the False Exchange mechanism in java, I found the following code in java.util.concurrent.Exchanger.Slot

    /**
 * A Slot is an AtomicReference with heuristic padding to lessen
 * cache effects of this heavily CAS'ed location.  While the
 * padding adds noticeable space, all slots are created only on
 * demand, and there will be more than one of them only when it
 * would improve throughput more than enough to outweigh using
 * extra space.
 */
private static final class Slot extends AtomicReference<Object> {
    // Improve likelihood of isolation on <= 64 byte cache lines
    long q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, qa, qb, qc, qd, qe;
}

This is strange. It seems that the number of long ones is 15 (q0 - qe), so I can calculate the size of the object, which should be:
15 * 8 (long) + 8 (parent long value) + 16 (object header pointer in 64 bits jvm) = 144 bytes .
or:
15 * 8 (long) + 8 (parent long value) + 8 (object header pointer with 32-bit jvm) = 136 bytes.
When I read Disruptor Deployment:

public long p1, p2, p3, p4, p5, p6, p7; // cache line padding

private volatile long cursor = INITIAL_CURSOR_VALUE;

public long p8, p9, p10, p11, p12, p13, p14; // cache line padding

7 * 8 + 8 + 7 * 8 + 8 ( 32 jvm) = 128 = 64 * 2.
64 , discruptor impl " ".
, - java.util.concurrent.Exchanger.Slot ?

+4
2

java.util.concurrent.Exchanger.Slot . , , .

, JVM , - 128 . , :

class MemoryFieldAddress {
    private long address;

    public final long getAddress() {
        return address;
    }

    protected final void setAddress(final long address) {
        this.address = address;
    }
}

class MemoryAddressPad1 extends MemoryFieldAddress {
    long p1_1, p1_2, p1_3, p1_4, p1_5, p1_6, p1_7, p1_8, p1_9, p1_10, p1_11, p1_12, p1_13, p1_14, p1_15, p1_16, p1_17;
}

class MemoryFieldBytes extends MemoryAddressPad1 {
    private long bytes;

    public final long getBytes() {
        return bytes;
    }

    protected final void setBytes(final long bytes) {
        this.bytes = bytes;
    }
}

class MemoryAddressPad2 extends MemoryFieldBytes {
    long p2_1, p2_2, p2_3, p2_4, p2_5, p2_6, p2_7, p2_8, p2_9, p2_10, p2_11, p2_12, p2_13, p2_14, p2_15, p2_16, p2_17;
}

// Finally the full implimentation
public class Memory extends MemoryAddressPad2 {}

, .

0

java obj, java obj , long/double, int, oops,.... : , :

public class testObj{
    int a,b,c;
    Object obj1;
    Object obj2;
    short s1,s2;
    long  l1,l2;
}

,

    public class testObj{

    long l1,l2;
    int a,b,c;
    short s1,s2
    Object 1
    Object 2
}

, q1....... qe java obj, , , , , ,

  • cacheline 1 ---------- ++++++
  • 2 ++++++++++ X (, ) ***
  • 3 ******

(X) , .


(+) 120


(*) obj

, , ,

cacheline: xxxxxxxx [0] xx

cacheline: xxxxxxx [1] xx

x

0

All Articles