Dalvik 的内存模型与 Java 的内存模型相同吗?
Dalvik 的内存模型与 Java 的内存模型相同吗?我特别感兴趣的是引用和非long
/non-double
基元变量的读写是否是原子的,但我也想知道是否有任何区别两个平台的内存模型之间的关系。
Is Dalvik's memory model the same as Java's? I am particularly interested in whether reads and writes of reference and non-long
/non-double
primitive variables are atomic, but I would also like to know whether there are any differences between the two platforms' memory models.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从 4.0(Ice Cream Sandwich)开始,Dalvik 的行为应该与 JSR-133(Java 内存模型)相匹配。
从 3.0(Honeycomb)开始,大部分内容都已就位,但忽略了一些在实践中很难遇到的小事情(例如最终确定中的一些边缘情况)。
从 2.3 (Gingerbread) 开始,Dalvik 在单处理器上通常是正确的,但缺少在 SMP 硬件上正确运行所需的一些关键功能(例如正确的
final
字段处理)。在 Gingerbread 出现之前,根本不存在内存屏障,并且像
volatile long
这样的基本东西都被破坏了。As of 4.0 (Ice Cream Sandwich), Dalvik's behavior should match up with JSR-133 (the Java Memory Model).
As of 3.0 (Honeycomb), most of the pieces were in place, but some minor things had been overlooked that would be difficult to encounter in practice (e.g. some edge cases in finalization).
As of 2.3 (Gingerbread), Dalvik was generally correct on uniprocessors, but some key features required for proper behavior on SMP hardware (e.g. proper
final
field handling) was missing.Pre-Gingerbread, there were no memory barriers at all, and basic stuff like
volatile long
was broken.有 一个文档Dalvik 来源 说:
这应该意味着行为与正确的 Java 中的行为相同。不管是不是真的,我不知道。
There is a document in the Dalvik source which says:
Which should mean that the behaviour is the same as in proper Java. Whether it actually is or not, i have no idea.
该规范规定,对 32 位数字(非双精度、非长数字)的所有操作都是原子的。无法保证 64 位数字的操作也是原子的。
The specification says that all operations on 32 bit numbers (the non-double, non-long numbers) are atomic. There is no guarantee that operations on 64 bit numbers are atomic as well.