32/64位jvm上java原语的大小? [英] Size of java primitives on 32/64 bit jvm?

查看:302
本文介绍了32/64位jvm上java原语的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. int 的大小为32位且 long / double 是64位。这些尺寸在
  1. The size of int is 32 bits and long/double are 64 bits. Will these sizes remain same on

  1. 32/64位JVM

  2. 32/64位处理器


  • 如果是,那么 / 的操作在64位处理器/ JVM上是原子的吗?

  • if yes then will the operations on long/double be atomic on a 64 bit processor/JVM?
  • Oracle Java教程说


    读取和写入是原子的以供参考变量和大多数原始变量(除long和double之外的所有类型)。

    Reads and writes are atomic for reference variables and for most primitive variables (all types except long and double).

    此声明是否与jvm / processor体系结构有关?
    有人可以解释。

    Does this statement has anything to do with jvm/processor architecture? Can someone please explain.

    3。最后,如果我使用64位jvm和处理器

    推荐答案

    <,我将能够读取/写入双/长原子p>是的,32位和64位JVM的大小相同。对于Java中的long或double,分配不保证是原子的。原子分配仍然无法保证来自另一个线程的可见性。因为允许线程在内存中遮蔽变量,所以即使对变量进行原子赋值也不一定要写入主内存(但是当主内存 更新时,它将以原子方式完成)。如果您希望一个线程始终看到另一个线程的更改,那么必须始终使用某种类型的同步障碍时才能从两个或多个线程访问共享状态。

    Yes, the sizes are the same on both 32-bit and 64-bit JVM. Assignment is not guaranteed to be atomic for either long or double in Java. Atomic assignment, is still no guarantee of visibility from another thread. Because threads are allowed to 'shadow' variables in memory, even atomic assignment to a variable does not necessarily write-thru to main memory (but when main memory is updated, it will be done so atomically). You must always use synchronization barriers of some kind when accessing shared state from two or more threads if you expect one thread to consistently see changes by the other.

    这篇关于32/64位jvm上java原语的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆