- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
当我阅读 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<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;
}
奇怪,为什么long的个数是15(q0 - qe),所以我可以计算出对象的大小应该是:
15 * 8 (long) + 8 (parent's long value) + 16 (object header pointer at 64 bit jvm) = 144 byte.
或者:
15 * 8 (long) + 8 (parent's long value) + 8 (object header pointer at 32 bit jvm) = 136 byte.
当我阅读 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(object head opinter'size at 32 bit jvm)= 128 = 64 * 2。
由于大多数 cpu 的默认缓存行大小为 64 字节,因此 discruptor 的 impl 可以避免“虚假共享”。
所以我的问题是在类里面填充了多少个longjava.util.concurrent.Exchanger.Slot 是对还是错?
最佳答案
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 {}
如果您愿意,可以将最终字段和很少更新的字段计入填充。
关于java - 为什么java的Exchanger.Slot cache line padding是这样的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35605860/
我正在学习 Vue.js,并且正在努力寻找一种组织代码的方法。我试图让一切尽可能模块化,所以在制作 slider 时我做了以下事情: export
我有一个像这样定义的 Web 组件自定义元素。 class Dropdown extends HT
我遇到了这样的崩溃: #0 0x90b05955 in __gnu_debug::_Safe_iterator_base::_M_detach #1 0x90b059ce in __gnu_deb
正如标题中所写 - “信号和插槽”是一种简单的响应式(Reactive)编程方式吗? 最佳答案 Signals/Slots是 Observer Pattern 的实现. 来自维基 Reactive P
我有一个关于太阳系行星列表的 intent 。 { "intent": "PlanetIntent", "slots": [ { "nam
我们的消费计划中有一个 Azure Function v3 实例,其中包括一个暂存槽以减少部署期间的停机时间。 我们的部署流程是: 将代码部署到暂存槽 启动暂存槽 将暂存槽与生产槽交换 停止暂存槽 我
我们的消费计划中有一个 Azure Function v3 实例,其中包括一个暂存槽以减少部署期间的停机时间。 我们的部署流程是: 将代码部署到暂存槽 启动暂存槽 将暂存槽与生产槽交换 停止暂存槽 我
我遇到一个同步组件 JavaScript 在实际显示之前加载的问题。 使用 dynamic-import 导入的组件在需要时使用 v-if 显示以加载它们。当它们被显示时,它们的 JavaScript
我有 6 个 subdag。它们中的每一个都包含一个带有 pool='crawler' 的任务。这需要大量资源,所以我创建了一个池 crawler只有 1 个插槽。 当我运行 DAG 时,似乎绕过了池
Vue 对象有一个非常有用的成员,叫做 $attrs。什么$attrs does 包含所有未被识别为当前组件 props 的属性。 $attrs 的一个很好的例子是 here . 我想知道 $scop
我有一个运行 Node.js 应用程序的 Azure Function App v3,该应用程序具有生产槽和阶段槽。使用在部署中心创建的操作将其部署到 GitHub。我有一项针对 prod 的部署操作
我有一个运行 Node.js 应用程序的 Azure Function App v3,该应用程序具有生产槽和阶段槽。使用在部署中心创建的操作将其部署到 GitHub。我有一项针对 prod 的部署操作
我有一个事件架构: owner: { type: Schema.Types.ObjectId, ref: 'User', required: true }, participa
我想测试这个FooComponent: 它是这样使用的(例如在 ParentComponent 中): 因此,我想测试我的组件对从 slot Prop 调用此“fn
我有一个意图,其中包含三个必需的插槽(我们称它们为:slot_a、slot_b、slot_c),所有类型都是 @系统编号。当检测到意图时,系统会提示我询问缺少的插槽: What's slot_a? 我
我有这个预订表结构 |ID|timeBooked | duration | |2 |2013-05-09 11:10:00| 30 | |1 |2013-05-09 14:
突然开始在所有 Azure App Services 中持续发生使用Deployment Slots . Error Message: "Failed swapping site. Error: Ca
我在我的azure应用程序服务中创建了多个插槽(测试、阶段和产品)。同样,我为每个环境创建了各自的 web.config 文件。我正在测试环境槽中通过 octopus 部署工具部署我的应用程序,因此最
所以我正在尝试使用 C++ 学习 Qt Framework。我正在了解信号和插槽,但我很难创建自定义插槽。因此,当我按照一些教程进行操作时,我的程序出现了以下错误: QObject::connec
如何引用 Vue.js 中的文本? Vue.component('component', { template: ``, created: function() { // i woul
我是一名优秀的程序员,十分优秀!