java怎么缓存行填充_为什么java的Exchanger.Slot缓存行填充像这样?
當我在
java中閱讀’虛假共享’機制時,我在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 {
// 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;
}
這很奇怪.為什么長數是15(q0-qe),
所以我可以計算出對象的大小應該是:
15 * 8(長)8(父值的長值)16(64位jvm的對象頭指針)= 144字節.
要么:
15 * 8(長)8(父的長值)8(32位jvm的對象頭指針)= 136字節.
當我讀到Disruptor’s implemention:時
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.
由于大多數cpu的默認緩存行大小為64字節,因此discruptor的impl可以避免’False sharing’.
所以我的問題是在課堂上填充的數量
java.util.concurrent.Exchanger.Slot是對還是錯?
總結
以上是生活随笔為你收集整理的java怎么缓存行填充_为什么java的Exchanger.Slot缓存行填充像这样?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微软发布 Windows Server
- 下一篇: 比亚迪宋 L 新增际云青外观,11 月