Dalvik 的内存模型与 Java 的内存模型相同吗?

发布于 2024-10-10 04:20:13 字数 130 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

悲欢浪云 2024-10-17 04:20:13

从 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.

那支青花 2024-10-17 04:20:13

一个文档Dalvik 来源 说:

从用 Java 编程语言编写的一段代码或以相同方式针对 .class 文件的代码的角度来看,Dalvik VM 旨在以完全符合该语言定义的方式运行。也就是说,在 Dalvik 中运行的代码的行为与在任何其他虚拟机中运行的代码相同。

这应该意味着行为与正确的 Java 中的行为相同。不管是不是真的,我不知道。

There is a document in the Dalvik source which says:

From the point of view of a piece of code written in the Java programming language or targeted in the same way to .class files, the Dalvik VM aims to behave in a way that is fully consistent with the language's definition. That is, the code running in Dalvik will behave the same as it would have running in any other virtual machine.

Which should mean that the behaviour is the same as in proper Java. Whether it actually is or not, i have no idea.

猫弦 2024-10-17 04:20:13

该规范规定,对 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文