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?


Asked by: Carina963 | Posted: 21-01-2022






Answer 1

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.

Answered by: Brooke262 | Posted: 22-02-2022



Answer 2

From TalkingTree, and the Java 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. 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.
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. 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.

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. On AMD64 and EM64T platforms this difference ranges from 0-15% depending on the amount of pointer accessing your application performs.

Answered by: Walter209 | Posted: 22-02-2022



Similar questions

java - Is there any XPath processor for SAX model?

I'm looking for an XPath evaluator that doesn't rebuild the whole DOM document to look for the nodes of a document: actually the object is to manage a large amount of XML data (ideally over 2Gb) with SAX model, which is very good for memory management, and give the possibility to search for nodes. Thank you all for the support! For all those who say it's not possible: I recently, after asked the question, f...


Cannot access updated Java object from Saxon XSLT processor

I am working with an open source version of the Saxon XSLT processor "Saxon 9.0.0.2J from Saxonica" and am trying to make use of the java extensibility for the first time. I am running into an issue I suspect may be a limitation on the open source version, but wanted to check first whether there might be something I am just missing here. From the snippet below, my result is that the final value of $c1 does not cha...


java - Is there a way to force the JVM to run on a single processor or Core

In Java, is there a way to force a JVM instance to run on a single CPU/Core. Additionally is there a way for given thread to figure out what CPU it is running on?


hardware - Java: add listener to the processor

how can I add a listener to the computer's processor? I want the mouse cursor to change when the processing is hight.


java - Binding specific threads to specific processor cores

I've word a bit with parallel processing in college and now I'm trying to get better at it. I can write code that can run in parallel and then start up threads, but after that I loose control over what the threads do. I would like to know how I can control the threads to things like for example bind a specific thread to a specific processor core. I am mostly interested in c++ but I've done some coding of this in Ja...


java - Custom JSP Tag processor is caching a dated property, so the page shows old data and don't update, how to avoid this?

I made a custom jsp tag that search a historical value on a database an render it on the page. The attributes that the tag requires are the variable name and the date. The problem is that the 'date' property changes according clock move on ('date' points always to the last hour),


java - Jackson JSON processor problems

I have been scratching my head over this for hours now : Jsckson deserializes B but bombs on C below : B and C are both subclasses of A, and thus has a setter getName. Note that the uppercase N in Name is intentional, that is how my JSON looks. Deserializing C complains about Unrecognized fi...


java - Running processor gives duplicate classes warning

After running javac with some processor selected, I get the proper source files generated. Unfortunately, every time I rerun the process I see warnings about duplicate class: com..... (one being processed). This does not cause the ant task to fail, so it's not a real problem, but I'd be glad to get rid of the message. How can I do that? I'm basically running: JavaFi...


java - Should I use Threads for a Task Processor?

I am building a service that involves node(s) pulling tasks from a task server. To carry out the task is pretty simple, it just pulls some stuff from a DB and sends it to a SMTP server. Right now it pulls like 20 tasks I think at a time, loops through and finishes them, then goes and asks for more tasks. Since the program itself isn't very resource intensive (it's like 25 MB of RAM when processing a task), would it...


javascript - How to run a CSL processor in Java?

I need to use Citation Style Language (CSL) styles in my Java application but I can't find how to do that. I found a CSL processor written in JavaScript here, but I don't understand how to use it. Can anybody help me please...?






Still can't find your answer? Check out these amazing Java communities for help...



Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)



top