tags:

views:

1705

answers:

8

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

+3  A: 

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.

jjnguy
+1  A: 

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

michelemarcon
+4  A: 

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.

Henrik Paul
+6  A: 

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.

pdeva
Isn't one benefit, at least on Windows, the possibility to use more memory than about 1.5GB? There is some such limit for a 32-bit Java process. http://mystyleit.com/blogs/mystyleit/archive/2009/05/27/32bit-windows-memory-and-java.aspx
Jonik
Aren't the latest 64-bit JVMs a little smarter about assigning references though? I.e., using only 32-bit references if it doesn't need the full 64-bit. I think I read that somewhere.
Jack Leow
+6  A: 

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.

Tnilsson
+3  A: 

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.

dotsid
+1  A: 

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.

A: 

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.

Peter Lawrey