Java programing for 64 bit JVM

泄露秘密 提交于 2019-12-05 09:35:24

Normally a 64 bit jvm will identify itself as such.

32/64 bit Considerations I have seen:

  1. address space - if you're not expecting to address more that 1.3Gb of memory then you won't see a difference
  2. native libraries - if you're loading any JNI libs, then they will need to match your VM architecture. For example, don't try loading 32-bit native libraries from a 64-bit vm (without -d32 type of flags)

Yes, the same code will run on both JVMs.

System Property "sun.arch.data.model" has the 32/64 flag I think.

There's some helpful info here: http://www.oracle.com/technetwork/java/hotspotfaq-138619.html

In your own Java code, you don't have to do anything special with regard to 32- or 64-bit. Unlike for example C and C++, an int in Java is always 32 bits and a long is always 64 bits (in C and C++, the size of those types is system-dependent).

There are no separate 32-bit and 64-bit versions of Java bytecode; the bytecode is exactly the same, regardless of the fact that the JVM you might be running it on is 32-bit or 64-bit. You don't have to compile your Java source differently for 32-bit or 64-bit. With regard to functionality it does not matter for your Java application if it runs on a 32-bit or 64-bit JVM.

There might be some technical differences that jowierun already mentioned. There might also be performance differences; for example Oracle's 64-bit JVM for Windows is tuned differently than the 32-bit JVM, it does other JIT optimizations. I noticed this myself with a computation-intensive application that I wrote recently; on a 64-bit JVM it runs much faster than on a 32-bit JVM. (But that's only one example, don't take this as proof that any program runs much faster on a 64-bit JVM).

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

You have these questions back to front.

  1. You don't have to do anything in your Java code, it will run on both 32-but and 64-bit.
  2. Therefore you don't need to know whether it's a 64 bit JVM or not.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!