简体   繁体   English

Java:VM如何在32位处理器上处理64位`long`

[英]Java: How does the VM handle a 64bit `long` on a 32bit processor

How does the JVM handle a primitive "long", which is 64bits, on a 32bit processor? JVM如何在32位处理器上处理原始的“长”(64位)?


Can it utilise mulitple cores in parallel when on a Multi-Core 32bit machine? 在多核32位机器上,它可以并行使用多个内核吗?
How much slower are 64bit operations on a 32bit machine? 32位机器上64位操作的速度要慢多少?

It may use multiple cores to run different threads, but it does not use them in parallel for 64 bit calculations. 它可能使用多个内核来运行不同的线程,但它不会并行使用它们进行64位计算。 A 64 bit long is basically stored as two 32 bit ints. 64位长基本上存储为两个32位整数。 In order to add them, two additions are needed, keeping track of the carry bit. 为了添加它们,需要两次添加,跟踪进位。 Multiplication is kind of like multiplying two two-digit numbers, except each digit is in base 2^32 instead of base 10. So on for other arithmetic operations. 乘法有点像两个两位数的乘法,除了每个数字在基数2 ^ 32而不是基数10之外。所以对于其他算术运算。

Edit about speed: I can only guess about the speed difference. 编辑速度:我只能猜测速度差异。 An addition requires two adds instead of one, and a multiplication would (I think) require four multiplies instead of one. 添加需要两个加法而不是一个,并且乘法(我认为)需要四个乘法而不是一个。 However, I suspect that if everything can be kept in registers then the actual time for the computation would be dwarfed by the time required to go to memory twice for the read and twice for the write, so my guess is about twice as long for most operations. 但是,我怀疑如果所有内容都可以保存在寄存器中,那么计算的实际时间将相当于读取内存两次所需的时间和写入两次所需的时间,所以我的猜测是大多数时间的两倍。操作。 I imagine that it would depend on the processor, the particular JVM implementation, the phase of the moon, etc. Unless you are doing heavy number crunching, I wouldn't worry about it. 我想这将取决于处理器,特定的JVM实现,月亮的阶段等。除非你做大量的数字运算,否则我不会担心它。 Most programs spend most of their time waiting for IO to/from the disk or network. 大多数程序花费大部分时间等待IO进出磁盘或网络。

From TalkingTree , and the Java HotSpot FAQ : 来自TalkingTreeJava HotSpot FAQ

Generally, the benefits of being able to address larger amounts of memory come with a small performance loss in 64-bit VMs versus running the same application on a 32-bit VM. 通常,与在32位VM上运行相同的应用程序相比,能够处理更大量内存的好处与64位VM中的性能损失相比较小。 This is due to the fact that every native pointer in the system takes up 8 bytes instead of 4. The loading of this extra data has an impact on memory usage which translates to slightly slower execution depending on how many pointers get loaded during the execution of your Java program. 这是因为系统中的每个本机指针占用8个字节而不是4个。这个额外数据的加载会对内存使用产生影响,这会导致执行速度稍慢,具体取决于执行期间加载的指针数量。你的Java程序。
The good news is that with AMD64 and EM64T platforms running in 64-bit mode, the Java VM gets some additional registers which it can use to generate more efficient native instruction sequences. 好消息是,在64位模式下运行AMD64和EM64T平台时,Java VM会获得一些额外的寄存器,可用于生成更高效的本机指令序列。 These extra registers increase performance to the point where there is often no performance loss at all when comparing 32 to 64-bit execution speed. 这些额外的寄存器将性能提高到在比较32位到64位执行速度时通常没有性能损失的程度。

The performance difference comparing an application running on a 64-bit platform versus a 32-bit platform on SPARC is on the order of 10-20% degradation when you move to a 64-bit VM . 当您迁移到64位VM时,将64位平台上运行的应用程序与SPARC上的32位平台相比,性能差异大约为10-20% On AMD64 and EM64T platforms this difference ranges from 0-15% depending on the amount of pointer accessing your application performs. 在AMD64和EM64T平台上,这种差异范围为0-15%,具体取决于访问应用程序的指针数量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM