Java programming for 64-bit JVM

A few questions:):

How to determine which JVM is currently installed? (64 bit / 32 bit)

Do I need to make some programming considerations for the 64-bit target JVM platform?

Can my Java code work with both 32-bit and 64-bit JVM?

How to run a Java application on a 64-bit JVM?

How to determine which JVM is used for my Java application?

+5
java 64bit 32bit-64bit
source share
4 answers

Usually a 64-bit jvm will identify itself as such.

32/64 bit. Considerations I have seen:

  • address space - if you do not expect to receive more than 1.3 GB of memory, then you will not see the difference
  • native libraries - if you download any JNI libraries, then they must match your VM architecture. For example, do not try to load 32-bit native libraries from 64-bit vm (without the -d32 flags)

Yes, the same code will work on both JVMs.

The system property "sun.arch.data.model" has a 32/64 flag, I think.

There is useful information here: http://www.oracle.com/technetwork/java/hotspotfaq-138619.html

+10
source share

In your own Java code, you do not need to do anything special regarding 32-bit or 64-bit. Unlike C and C ++, int in Java is always 32 bits, and long always 64 bits (in C and C ++ the size of these types depends on the system).

There are no separate 32-bit and 64-bit versions of Java bytecode; the bytecode is exactly the same, regardless of whether the JVM on which you can run it is 32-bit or 64-bit. You do not need to compile your Java source differently for 32-bit or 64-bit. As far as functionality is concerned, it doesn’t matter for your Java application if it runs on a 32-bit or 64-bit JVM.

There may be some technical differences already mentioned in jowierun. There may also be differences in performance; for example, the Oracle 64-bit JVM for Windows is configured differently from the 32-bit JVM, it does other JIT optimizations. I myself noticed this with an intensive computing application that I wrote recently; it runs much faster on a 64-bit JVM than on a 32-bit JVM. (But this is just one example, do not consider this as proof that any program runs much faster on a 64-bit JVM).

+4
source share

If you plan to write your own code using the Java Native Interface (JNI), you need to be especially careful when writing proper C code that will work on both 64 and 32-bit machines. Make sure you use the correct Java types when passing arguments to / from java code (JNI provides a set of typedef for java types), especially when converting arrays. And when testing your own code, the test on both architectures (-m32 will force a 32-bit arch on GNU gcc) with different JVMs.

+2
source share

You have these questions back.

  • You do not need to do anything in the Java code, it will work on both 32 and 64-bit.
  • Therefore, you do not need to know if it is a 64-bit JVM or not.
+1
source share

All Articles