Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?


Can it utilise mulitple cores in parallel when on a Multi-Core 32bit machine?
How much slower are 64bit operations on a 32bit machine?

like image 547
Ande Turner Avatar asked Oct 26 '08 01:10

Ande Turner


1 Answers

It may use multiple cores to run different threads, but it does not use them in parallel for 64 bit calculations. A 64 bit long is basically stored as two 32 bit ints. 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.

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. Most programs spend most of their time waiting for IO to/from the disk or network.

like image 54
Andru Luvisi Avatar answered Nov 09 '22 00:11

Andru Luvisi