Benefits of 64bit Java platform

2019-01-12 05:44发布

问题:

I'm an absolute n00b into the java platform I would like to know whether I need to change anything in my code to get the benefits of 64bit JRE ?

or is it something like when I initiate it with "java -d64" its gonna run in some turbo mode?

Your help is highly appreciated

回答1:

My previous version, while not false, was a quickly written oversimplification.

Changing from 32 to 64 bits will not automatically make your application run faster, it may in some cases lead to the opposite. On the "negative" side Doing de-referencing of memory pointers in the JVM can take a longer time with 64 bit pointers than 32 bit. A full garbage collect and compaction of a 16 GB heap will likely take a longer time than with a 2 GB heap.

On the positive side: There 64 bit processor instructions that are more effective than the 32 bit ones. 64 bit JVM will allow you to have a heap size 2^32 times bigger than the, slightly less than, 4 GB one you can get with 32 bit. (If you can afford to buy that amount of RAM) Some JVMs can work with compressed references if you have a heap size less than 4 GB, giving you the advantage of 64 bit instructions without having to pay the 64 bit de-referencing price.

If you have a good JVM I would go to 64 bits no matter the heap size, just be prepared that you may have to take a performance hit for having a really big heap.



回答2:

I don't think 64 bit JVM will gain performance of application? How?

In fact 64 bit processors are a little bit slower. They have more complicated decoding pipeline (backward support of 32 bit operations). They need more memory throughput (all pointers are double sized right?). The only thing you have on 64 bit processor is a lot of RAM. And size is speed, as we know. A lot of RAM can gain performance of some applications very nice (if application could use it). So 64 bit — no. A lot of RAM — definitely yes.

There is one more thing that 64 bit processors could do faster. Atomic write/read of 64 bit numbers. If you work with 64 bit numbers (long in java) 64 bit processors would be better, cause they have machine CAS instructions for working with that kind of numbers.



回答3:

No you dont need to change anything. There is no inherent benefit is using 64 bit. In fact it will make your program larger in memory since all pointers will become 64 bit wide instead of 32 bit.

The only advantage comes when you are doing 64 bit calculations, eg using lot of 'longs' in your code or if your app requires memory more than 4gb.



回答4:

Because the JVM, where the code is executed, should behave the same (integers are always 32 bit signed, etc), your code is guaranteed (in theory) to run identically, no matter what platform you run it.

The 32/64 bit difference comes in how the JVM is able to optimize the runtime. So, while the executed bytecode remains the same, it might (or might not) be optimized in a different way.

In a nutshell, a 64-bit system running Java might execute the code faster than an 32-bit system equivalent.



回答5:

You should have to change nothing. Unlike C or C++, Java has a spec written for it that ensures that ints(and other data types) are always the same length no matter what platform you are on.



回答6:

Do you have any JNI in your application code? Then maybe you need to worry about 32 vs. 64 bit native binaries.

32 or 64 is all the same to your Java code. The performance aspects already seem well covered by previous posters.



回答7:

Yes, you don't need to change anything. It's the JRE that is different, not the code you write.



回答8:

I have found that 64-bit JVMs have been slower than 32-bit versions. However with the latest version Java 6 update 14 I have seen many of my tests are marginally faster with the 64-bit version vs the 32-bit. Either way there is only 5% to 10% difference.

Whether your program uses a 32-bit or 64-bit version is down to the choice of JVM you use. As has been mentioned you need to check you have appropriate shared libraries. (or ideally none)

The main difference is being able to use more memory esp if you need 4 GB or more.



回答9:

Try this:

public class Benchmark {
public static void main(String args[]) {
long time = System.currentTimeMillis();
for (int a = 1; a < 900000000; a++) {
    for (int b = 1; b < 20; b++) {
    }
}
long time2 = System.currentTimeMillis() - time;
System.out.println("\nTime counter stopped: " + time2);

}

In 32 and 64 bit and laugh at the difference.



标签: java 64bit